Project

General

Profile

« Previous | Next » 

Revision 50504

almost finished compatibility-validate-guidelines

View differences:

modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility.module.ts
1 1
import {NgModule} from "@angular/core";
2 2
import {CommonModule} from "@angular/common";
3 3
import {TabsModule} from "ngx-bootstrap";
4
import { ReactiveFormsModule } from '@angular/forms';
4 5
import {CompatibilityComponent} from "./compatibility.component";
5 6
import {CompatibilityValidateComponent} from "./compatibility-validate.component";
6 7
import {CompatibilityRouting} from "./compatibility.routing";
......
10 11
import { CompatibilityMonitorRepoComponent } from './compatibility-monitor-repo.component';
11 12
import { CompatibilityValidateTypeComponent } from './compatibility-validate-type.component';
12 13
import { CompatibilityValidateStep1Component } from './compatibility-validate-forms/compatibility-validate-step1.component';
13
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
14
import { CompatibilityValidateStep2Component } from './compatibility-validate-forms/compatibility-validate-step2.component';
14 15

  
15 16
@NgModule ({
16 17
  imports: [
......
27 28
    CompatibilityMonitorComponent,
28 29
    CompatibilityMonitorRepoComponent,
29 30
    CompatibilityValidateTypeComponent,
30
    CompatibilityValidateStep1Component
31
    CompatibilityValidateStep1Component,
32
    CompatibilityValidateStep2Component
31 33
  ]
32 34
})
33 35

  
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-type.component.html
42 42
            </div>
43 43
            <div *ngIf="showDatasource">
44 44
              <compatibility-validate-step1 #step1ChooseBaseUrl
45
                                            [type]="type"
46 45
                                            [baseUrlList]="baseUrlList"></compatibility-validate-step1>
47 46
            </div>
48 47
            <div *ngIf="showGuidelines">
49
              <div>
50
                Select Guidlines
51
              </div>
48
              <compatibility-validate-step2 #step2ChooseGuidelines
49
                                            [ruleSets]="ruleSets">
50
              </compatibility-validate-step2>
52 51
            </div>
53 52
            <div *ngIf="showParameters">
54 53
              <div>
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-forms/compatibility-validate-step2.component.html
1
<div *ngIf="ruleSets" class="form-group">
2
  <div *ngFor="let set of ruleSets; let set_index = index">
3
    <label class="btn btn-link" for="ruleSet{{ set_index }}">
4
      <input id="ruleSet{{ set_index }}" #ruleSet value="{{ set.id }}" name="ruleSet" type="radio" (change)="getCurrentRuleSets(set_index)" [checked]="set_index === 0">
5
      <span>{{ set.name }}</span>
6
    </label>
7
  </div>
8
  <div class="uk-grid">
9
    <div class="uk-width-expand@m uk-width-1-2@s uk-grid-item-match uk-first-column">
10
      <div *ngFor="let content of currentContentRules; let content_index = index" class="margin10">
11
        <label class="btn btn-link" for="rule{{ content.id }}">
12
          <input id="rule{{ content.id }}" value="{{ content.id }}" name="contentRules_{{content_index}}" type="checkbox" (change)="toggleChooseContentRule($event, content_index)" checked>
13
          <span>{{ content.name }}</span>
14
        </label>
15
      </div>
16
    </div>
17
    <div class="uk-width-expand@m uk-width-1-2@s uk-grid-item-match uk-first-column">
18
      <div *ngFor="let usage of currentUsageRules; let usage_index = index" class="margin10">
19
        <label class="btn btn-link" for="rule{{ usage_index }}">
20
          <input id="rule{{ usage_index }}" value="{{ usage.id }}" name="usageRules_{{usage_index}}" type="checkbox" (change)="toggleChooseUsageRule(usage_index)" [checked]="true">
21
          <span>{{ usage.name }}</span>
22
        </label>
23
      </div>
24
    </div>
25
  </div>
26
</div>
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-forms/compatibility-validate-step1.component.ts
13 13
  errorMessage: string;
14 14

  
15 15
  chosenUrl: string;
16
  identifiedUrl: boolean;
16 17

  
17
  @Input() type: string;
18 18
  @Input() baseUrlList: string[];
19 19

  
20 20
  constructor(private fb: FormBuilder,
......
38 38
    }
39 39
  }
40 40

  
41

  
42
  identifyUrl() {
43
    if (this.group.get('customBaseUrl').value) {
44
      console.log(`looking for ${this.group.get('customBaseUrl').value}`);
45
      this.valService.identifyRepository(this.group.get('customBaseUrl').value).subscribe(
46
        res => this.identifiedUrl = res,
47
        error =>  console.log(error)
48
      );
49
    }
50
  }
51

  
41 52
  submitForm() {
42 53
    let response: boolean;
43 54
    if (this.group.get('selectBaseUrl').enabled){
44 55
      if ( this.group.get('selectBaseUrl').value) {
45 56
        this.chosenUrl = this.group.get('selectBaseUrl').value;
46 57
        console.log('selected baseUrl!');
58
        return true;
47 59
      } else {
48 60
        this.errorMessage = didntChooseBaseUrl;
61
        return false;
49 62
      }
50 63
    } else if (this.group.get('customBaseUrl').enabled) {
51 64
      if ( this.group.get('customBaseUrl').value ) {
52
        console.log(`looking for ${this.group.get('customBaseUrl').value}`);
53
        this.valService.identifyRepository(this.group.get('customBaseUrl').value).subscribe(
54
          res => response = res,
55
          error =>  console.log(error),
56
          () => {
57
            if ( response ) {
58
              this.chosenUrl = this.group.get('customBaseUrl').value;
59
              console.log('added new baseUrl!');
60
            } else {
61
              this.errorMessage = invalidCustomBaseUrl;
62
            }
63
          }
64
        );
65
        if (this.identifiedUrl) {
66
          this.chosenUrl = this.group.get('customBaseUrl').value;
67
          console.log('added new baseUrl!');
68
          return true;
69
        } else {
70
          this.errorMessage = invalidCustomBaseUrl;
71
          return false;
72
        }
65 73
      } else {
66 74
        this.errorMessage = didntChooseBaseUrl;
75
        return false;
67 76
      }
68 77
    }
69 78
  }
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-forms/compatibility-validate-step2.component.ts
1
import { Component, Input, OnInit } from '@angular/core';
2
import { Rule, RuleSet } from '../../../domain/typeScriptClasses';
3
import { FormControl } from '@angular/forms';
4

  
5
@Component ({
6
  selector: 'compatibility-validate-step2',
7
  templateUrl: 'compatibility-validate-step2.component.html'
8
})
9

  
10
export class CompatibilityValidateStep2Component implements OnInit {
11

  
12
  currentContentRules: Rule[] = [];
13
  currentUsageRules: Rule[] = [];
14

  
15

  
16
  @Input() ruleSets: RuleSet[];
17

  
18
  constructor() {}
19

  
20
  ngOnInit() {
21
    if ( this.ruleSets.length ) {
22
      this.getCurrentRuleSets(0);
23
    }
24
  }
25

  
26
  getCurrentRuleSets(index: number){
27
    let id = this.ruleSets[index].id;
28
    let current: RuleSet[] = this.ruleSets.filter(
29
      set => {
30
        if (set.id = id) {
31
          return set;
32
        }
33
      }
34
    );
35
    this.currentContentRules = current[index].contentRules;
36
    this.currentUsageRules = current[index].usageRules;
37
  }
38

  
39
  toggleChooseContentRule(e: any, id: number) {
40
    if(e.target.checked) {
41
      console.log(this.currentContentRules[id].name);
42
    }
43
  }
44

  
45
  toggleChooseUsageRule(id: number) {
46
    console.log(this.currentUsageRules[id].name);
47
  }
48
}
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-forms/compatibility-validate-step1.component.html
16 16
      <span>or enter new</span>
17 17
    </label>
18 18
  </div>
19
  <input id="customBaseUrl" formControlName="customBaseUrl" class="form-control" type="text">
19
  <input id="customBaseUrl" formControlName="customBaseUrl" class="form-control" type="text" (blur)="identifyUrl()">
20 20
</div>
modules/uoa-repository-dashboard-gui/trunk/app/pages/compatibility/compatibility-validate-type.component.ts
2 2
import { ActivatedRoute } from '@angular/router';
3 3
import { CompatibilityValidateStep1Component } from './compatibility-validate-forms/compatibility-validate-step1.component';
4 4
import { RepositoryService } from '../../services/repository.service';
5
import { Repository } from '../../domain/typeScriptClasses';
5
import { Repository, RuleSet } from '../../domain/typeScriptClasses';
6 6
import { AuthenticationService } from '../../services/authentication.service';
7 7
import {
8
  loadingReposMessage, loadingUserRepoInfo, loadingUserRepoInfoEmpty,
9
  loadingUserRepoInfoError
8
  loadingReposMessage, loadingRuleSets, loadingRuleSetsError, loadingUserRepoInfo, loadingUserRepoInfoEmpty,
9
  loadingUserRepoInfoError, noRuleSets
10 10
} from '../../domain/shared-messages';
11
import { ValidatorService } from '../../services/validator.service';
12
import { CompatibilityValidateStep2Component } from './compatibility-validate-forms/compatibility-validate-step2.component';
11 13

  
12 14
@Component ({
13 15
  selector: 'compatibility-validate-literature',
......
16 18

  
17 19
export class CompatibilityValidateTypeComponent implements OnInit {
18 20
  type: string = '';
21

  
19 22
  showDatasource: boolean;
20 23
  showGuidelines: boolean;
21 24
  showParameters: boolean;
22 25
  showFinish: boolean;
26

  
23 27
  step2: string = '';
24 28
  step3: string = '';
25 29
  step4: string = '';
26 30

  
27 31
  baseUrlList: string[] = [];
32
  ruleSets: RuleSet[] = [];
33

  
28 34
  errorMessage: string;
29 35
  loadingMessage: string;
30 36
  showSpinner: boolean;
31 37

  
32 38
  @ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
39
  @ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
33 40

  
34 41
  constructor(private route: ActivatedRoute,
35 42
              private authService: AuthenticationService,
36
              private repoService: RepositoryService) {}
43
              private repoService: RepositoryService,
44
              private valService: ValidatorService) {}
37 45

  
38 46
  ngOnInit() {
39 47
    this.readType();
......
47 55

  
48 56
  moveAStep(){
49 57
    if (this.showDatasource) {
50
      this.step1ChooseBaseUrl.submitForm();
51
      if (this.step1ChooseBaseUrl.chosenUrl) {
52
        this.showGuidelines = true;
53
        this.showDatasource = false;
54
        this.step2 = 'active';
58
      if (this.step1ChooseBaseUrl.submitForm()) {
59
        this.getRuleSetsForType();
55 60
      }
56 61
    } else if (this.showGuidelines) {
57 62
      this.showParameters = true;
......
64 69
    }
65 70
  }
66 71

  
67
  moveBackAStep(){
72
  moveBackAStep () {
68 73
    if (this.showGuidelines) {
69 74
      this.showDatasource = true;
70 75
      this.showGuidelines = false;
......
110 115
      );
111 116
  }
112 117

  
118
  getRuleSetsForType() {
119
    this.showSpinner = true;
120
    this.loadingMessage = loadingRuleSets;
121
    this.valService.getRuleSets(this.type)
122
      .subscribe(
123
        rules => this.ruleSets = rules,
124
        error => {
125
          this.showSpinner = false;
126
          this.loadingMessage = '';
127
          this.errorMessage = loadingRuleSetsError;
128
        },
129
        () => {
130
          this.showSpinner = false;
131
          this.loadingMessage = '';
132
          this.showDatasource = false;
133
          this.step2 = 'active';
134
          if (this.ruleSets.length) {
135
            this.showGuidelines = true;
136
          } else {
137
            this.errorMessage = noRuleSets;
138
          }
139
        }
140
      );
141
  }
113 142
}
modules/uoa-repository-dashboard-gui/trunk/app/services/validator.service.ts
10 10
import { Injectable } from '@angular/core';
11 11
import { Http } from '@angular/http';
12 12
import { Observable } from 'rxjs/Observable';
13
import { RuleSet } from '../domain/typeScriptClasses';
13 14

  
14 15
const httpOptions = {
15 16
  headers: new HttpHeaders().set('Content-Type', 'application/json')
......
23 24

  
24 25
  constructor(private http: Http) { }
25 26

  
27
  /* returns array of sets of rules according to mode (literature, data, cris) */
28
  getRuleSets(mode: string): Observable<RuleSet[]> {
29
    let url = `${this.apiUrl}/validator/getRuleSets/${mode}`;
30
    console.log(`knocking on: ${url}`);
31
    return this.http.get(url)
32
      .map(res => <RuleSet[]>res.json())
33
      .catch(this.handleError);
34
  }
35

  
36

  
26 37
  /* returns true if there is a repository containing the identifier */
27 38
  identifyRepository(identifier: string): Observable<boolean> {
28 39
    let url = `${this.apiUrl}/validator/identifyRepository/{url}?url=${identifier}`;
......
32 43
      .catch(this.handleError);
33 44
  }
34 45

  
46

  
35 47
  /* from omtd project */
36 48
  private handleError(error: Response | any) {
37 49
    // In a real world app, we might use a remote logging infrastructure
modules/uoa-repository-dashboard-gui/trunk/app/domain/shared-messages.ts
7 7
export const loadingUserRepoInfoError = "Failed to load information on your registered repositories";
8 8
export const loadingUserRepoInfoEmpty = "You have not yet registered any repository";
9 9

  
10

  
11 10
/* Loading Repositories Messages */
12
export const reposRetrievalError = 'The repositories can not be retrieved at the moment!';
11
export const reposRetrievalError = 'The repositories can not be retrieved at the moment';
13 12
export const noRepositoriesFound = 'No Datasources were found';
14 13
export const noRepositoriesRegistered = 'No Datasources are registered under your account';
15 14
export const loadingReposMessage = 'Retrieving repositories ...';
16 15
export const noRepositoryChosenMsg = 'You need to select a repository first!';
17 16

  
17
/* Loading Rules Messages */
18
export const loadingRuleSets = 'Retrieving sets of rules ...';
19
export const loadingRuleSetsError = 'The rule sets can not be retrieved at the moment';
20
export const noRuleSets = 'No rule sets were found';
21

  
18 22
/* Loading Topics Messages */
19 23
export const loadingTopics = 'Loading topics for your datasource';
20 24
export const loadingTopicsError = 'Failed to load the topics for your datasource';
modules/uoa-repository-dashboard-gui/trunk/app/domain/typeScriptClasses.ts
298 298
  name: string;
299 299
  offset: number;
300 300
}
301

  
302

  
303
export class RuleSet {
304
  contentRules: Rule[];
305
  contentRulesIds: number[];
306
  description: string;
307
  guidelinesAcronym: string;
308
  id: number;
309
  name: string;
310
  shortName: string;
311
  usageRules: Rule[];
312
  usageRulesIds: number[];
313
  visibility: string[];
314
}
315

  
316
export class CustomProperties {
317
  properties: RuleSet[];
318
}
319

  
320
export class Rule {
321
    configuration: CustomProperties;
322
    description: string;
323
    entity_type: string;
324
    for_cris: boolean;
325
    id: number;
326
    job_type: string;
327
    mandatory: boolean;
328
    name: string;
329
    provider_information: string;
330
    type: string;
331
    weight: number;
332
}

Also available in: Unified diff