Project

General

Profile

1
import { Component, OnInit, ViewChild } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { CompatibilityValidateStep1Component } from './compatibility-validate-forms/compatibility-validate-step1.component';
4
import { RepositoryService } from '../../services/repository.service';
5
import { InterfaceInformation, Repository, RuleSet } from '../../domain/typeScriptClasses';
6
import { AuthenticationService } from '../../services/authentication.service';
7
import {
8
  loadingReposMessage, loadingRuleSets, loadingRuleSetsError,
9
  loadingUserRepoInfoError, loadingValSets, loadingValSetsError, noRuleSets
10
} from '../../domain/shared-messages';
11
import { ValidatorService } from '../../services/validator.service';
12
import { CompatibilityValidateStep2Component } from './compatibility-validate-forms/compatibility-validate-step2.component';
13
import { CompatibilityValidateStep3Component } from './compatibility-validate-forms/compatibility-validate-step3.component';
14

    
15
@Component ({
16
  selector: 'compatibility-validate-literature',
17
  templateUrl: 'compatibility-validate-type.component.html'
18
})
19

    
20
export class CompatibilityValidateTypeComponent implements OnInit {
21
  type: string = '';
22

    
23
  showDatasource: boolean;
24
  showGuidelines: boolean;
25
  showParameters: boolean;
26
  showFinish: boolean;
27

    
28
  step2: string = '';
29
  step3: string = '';
30
  step4: string = '';
31

    
32
  baseUrlList: string[] = [];
33
  ruleSets: RuleSet[] = [];
34
  valSets: string[] = [];
35
  chosenInterface: InterfaceInformation;
36

    
37
  chosenUrl: string;
38
  chosenValSet: string;
39
  noOfRecords: number;
40
  xPath: string;
41

    
42
  errorMessage: string;
43
  loadingMessage: string;
44

    
45
  @ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
46
  @ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
47
  @ViewChild('step3ChooseParameters') step3ChooseParameters : CompatibilityValidateStep3Component;
48

    
49
  constructor(private route: ActivatedRoute,
50
              private authService: AuthenticationService,
51
              private repoService: RepositoryService,
52
              private valService: ValidatorService) {}
53

    
54
  ngOnInit() {
55
    this.readType();
56
    this.getBaseUrlList();
57
  }
58

    
59
  readType() {
60
    this.type = this.route.snapshot.paramMap.get('type');
61
    console.log(this.type);
62
  }
63

    
64
  moveAStep() {
65
    let stepValidation: boolean;
66
    if (this.showDatasource) {
67
      stepValidation = this.step1ChooseBaseUrl.submitForm();
68
      if (stepValidation) {
69
        this.getRuleSetsForType();
70
        console.log(`The chosenUrl is: ${this.chosenUrl} !!`);
71
      }
72
    } else if (this.showGuidelines) {
73
      this.step2ChooseGuidelines.saveChanges();
74
      this.getInterfaceInfo();
75
      //this.getValidationSets();
76
      this.showParameters = true;
77
      this.showGuidelines = false;
78
      this.step3 = 'active';
79
    } else if (this.showParameters) {
80
      this.step3ChooseParameters.submitChanges();
81
      //save all changes
82
      this.showFinish = true;
83
      this.showParameters = false;
84
      this.step4 = 'active';
85
    }
86
  }
87

    
88
  moveBackAStep () {
89
    if (this.showGuidelines) {
90
      this.showDatasource = true;
91
      this.showGuidelines = false;
92
      this.step2 = '';
93
      this.errorMessage = '';
94
    } else if (this.showParameters) {
95
      this.step3 = '';
96
      this.showGuidelines = true;
97
      this.showParameters = false;
98
      this.errorMessage = '';
99
    }
100
  }
101

    
102
  /* retrieves the baseUrl list for the registered repositories of the user */
103
  getBaseUrlList() {
104
    this.loadingMessage = loadingReposMessage;
105
//    this.repoService.getUrlsOfUserRepos(this.authService.getUserEmail()) RESTORE AFTER FINISH!!
106
    this.repoService.getUrlsOfUserRepos('ant.lebesis@gmail.com')
107
      .subscribe(
108
        repos => this.baseUrlList = repos.sort( function(a , b){
109
          if(a < b ){
110
            return -1;
111
          } else if(a > b ){
112
            return 1;
113
          } else {
114
            return 0;
115
          }
116
        }),
117
        error => {
118
          console.log(error);
119
          this.loadingMessage = '';
120
          this.errorMessage = loadingUserRepoInfoError;
121
        },
122
        () => {
123
          this.loadingMessage = '';
124
          this.showDatasource = true;
125
        }
126
      );
127
  }
128

    
129
  getRuleSetsForType() {
130
    this.loadingMessage = loadingRuleSets;
131
    this.valService.getRuleSets(this.type)
132
      .subscribe(
133
        rules => this.ruleSets = rules,
134
        error => {
135
          this.loadingMessage = '';
136
          this.errorMessage = loadingRuleSetsError;
137
        },
138
        () => {
139
          this.loadingMessage = '';
140
          this.showDatasource = false;
141
          this.step2 = 'active';
142
          if (this.ruleSets.length) {
143
            this.showGuidelines = true;
144
          } else {
145
            this.errorMessage = noRuleSets;
146
          }
147
        }
148
      );
149
  }
150

    
151
  getInterfaceInfo() {
152
    this.loadingMessage = loadingValSets;
153
    this.valService.getInterfaceInformation(this.chosenUrl).subscribe(
154
      info => this.chosenInterface = info,
155
      error => {
156
        console.log(error);
157
        this.loadingMessage = '';
158
        this.errorMessage = loadingValSetsError;
159
      },
160
      () => {
161
        this.loadingMessage = '';
162
        this.step3 = 'active';
163
        this.showParameters = true;
164
        if (this.chosenInterface) {
165
          this.valSets = this.chosenInterface.sets;
166
        }
167
      }
168
    );
169
  }
170

    
171
  getValidationSets() {
172
    this.loadingMessage = loadingValSets;
173
    this.valService.getSetsOfRepository(this.chosenUrl)
174
      .subscribe(
175
        sets => this.valSets = sets,
176
        error => {
177
          this.errorMessage = loadingValSetsError
178
        },
179
        () => {
180
          this.loadingMessage = '';
181
          this.step2 = 'active';
182
          this.showParameters = true;
183
        }
184
      );
185
  }
186

    
187
  getChosenUrl(url: string) {
188
    this.chosenUrl = url;
189
  }
190

    
191
  getParameters (params: string[]) {
192
    this.chosenValSet = params[0];
193
    this.noOfRecords = +params[1];
194
    this.xPath = params[2];
195
  }
196

    
197
  submitForValidation(){
198
    /*
199
    * selectedCrisEntities  string[]
200
    * selectedContentRules number[]
201
    * selectedUsageRules number[]
202
    *
203
    * validationSet
204
    * records
205
    * groupByXpath
206
    *
207
    * adminEmails string[]
208
    * officialName
209
    * baseUrl
210
    * userEmail
211
    * datasourceId
212
    * interfaceId
213
    * desiredCompatibilityLevel
214
    * activationId
215
    * repoType
216
    * interfaceIdOld
217
    * metadataPrefix
218
    *
219
    * registration boolean
220
    * updateExisting boolean
221
    * cris boolean
222
    * crisReferentialChecks boolean
223
    */
224
  }
225

    
226
}
(6-6/15)