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
|
chosenUrl: string;
|
34
|
ruleSets: RuleSet[] = [];
|
35
|
valSets: string[] = [];
|
36
|
chosenInterface: InterfaceInformation;
|
37
|
|
38
|
errorMessage: string;
|
39
|
loadingMessage: string;
|
40
|
showSpinner: boolean;
|
41
|
|
42
|
@ViewChild('step1ChooseBaseUrl') step1ChooseBaseUrl : CompatibilityValidateStep1Component;
|
43
|
@ViewChild('step2ChooseGuidelines') step2ChooseGuidelines : CompatibilityValidateStep2Component;
|
44
|
@ViewChild('step3ChooseParameters') step3ChooseParameters : CompatibilityValidateStep3Component;
|
45
|
|
46
|
constructor(private route: ActivatedRoute,
|
47
|
private authService: AuthenticationService,
|
48
|
private repoService: RepositoryService,
|
49
|
private valService: ValidatorService) {}
|
50
|
|
51
|
ngOnInit() {
|
52
|
this.readType();
|
53
|
this.getBaseUrlList();
|
54
|
}
|
55
|
|
56
|
readType() {
|
57
|
this.type = this.route.snapshot.paramMap.get('type');
|
58
|
console.log(this.type);
|
59
|
}
|
60
|
|
61
|
moveAStep() {
|
62
|
let stepValidation: boolean;
|
63
|
if (this.showDatasource) {
|
64
|
stepValidation = this.step1ChooseBaseUrl.submitForm();
|
65
|
if (stepValidation) {
|
66
|
this.getRuleSetsForType();
|
67
|
console.log(`The chosenUrl is: ${this.chosenUrl} !!`);
|
68
|
}
|
69
|
} else if (this.showGuidelines) {
|
70
|
this.getInterfaceInfo();
|
71
|
this.showParameters = true;
|
72
|
this.showGuidelines = false;
|
73
|
this.step3 = 'active';
|
74
|
} else if (this.showParameters) {
|
75
|
this.step3ChooseParameters.submitChanges();
|
76
|
//save all changes
|
77
|
this.showFinish = true;
|
78
|
this.showParameters = false;
|
79
|
this.step4 = 'active';
|
80
|
}
|
81
|
}
|
82
|
|
83
|
moveBackAStep () {
|
84
|
if (this.showGuidelines) {
|
85
|
this.showDatasource = true;
|
86
|
this.showGuidelines = false;
|
87
|
this.step2 = '';
|
88
|
} else if (this.showParameters) {
|
89
|
this.step3 = '';
|
90
|
this.showGuidelines = true;
|
91
|
this.showParameters = false;
|
92
|
} else if (this.showFinish) {
|
93
|
this.showParameters = true;
|
94
|
this.showFinish = false;
|
95
|
this.step4 = '';
|
96
|
}
|
97
|
}
|
98
|
|
99
|
/* retrieves the baseUrl list for the registered repositories of the user */
|
100
|
getBaseUrlList() {
|
101
|
this.showSpinner = true;
|
102
|
this.loadingMessage = loadingReposMessage;
|
103
|
// this.repoService.getUrlsOfUserRepos(this.authService.getUserEmail()) RESTORE AFTER FINISH!!
|
104
|
this.repoService.getUrlsOfUserRepos('ant.lebesis@gmail.com')
|
105
|
.subscribe(
|
106
|
repos => this.baseUrlList = repos.sort( function(a , b){
|
107
|
if(a < b ){
|
108
|
return -1;
|
109
|
} else if(a > b ){
|
110
|
return 1;
|
111
|
} else {
|
112
|
return 0;
|
113
|
}
|
114
|
}),
|
115
|
error => {
|
116
|
console.log(error);
|
117
|
this.showSpinner = false;
|
118
|
this.loadingMessage = '';
|
119
|
this.errorMessage = loadingUserRepoInfoError;
|
120
|
},
|
121
|
() => {
|
122
|
this.showSpinner = false;
|
123
|
this.loadingMessage = '';
|
124
|
this.showDatasource = true;
|
125
|
}
|
126
|
);
|
127
|
}
|
128
|
|
129
|
getRuleSetsForType() {
|
130
|
this.showSpinner = true;
|
131
|
this.loadingMessage = loadingRuleSets;
|
132
|
this.valService.getRuleSets(this.type)
|
133
|
.subscribe(
|
134
|
rules => this.ruleSets = rules,
|
135
|
error => {
|
136
|
this.showSpinner = false;
|
137
|
this.loadingMessage = '';
|
138
|
this.errorMessage = loadingRuleSetsError;
|
139
|
},
|
140
|
() => {
|
141
|
this.showSpinner = false;
|
142
|
this.loadingMessage = '';
|
143
|
this.showDatasource = false;
|
144
|
this.step2 = 'active';
|
145
|
if (this.ruleSets.length) {
|
146
|
this.showGuidelines = true;
|
147
|
} else {
|
148
|
this.errorMessage = noRuleSets;
|
149
|
}
|
150
|
}
|
151
|
);
|
152
|
}
|
153
|
|
154
|
getInterfaceInfo() {
|
155
|
this.valService.getInterfaceInformation(this.chosenUrl).subscribe(
|
156
|
info => this.chosenInterface = info,
|
157
|
error => console.log(error)
|
158
|
);
|
159
|
}
|
160
|
|
161
|
getValidationSets() {
|
162
|
this.showGuidelines = false;
|
163
|
this.showSpinner = true;
|
164
|
this.loadingMessage = loadingValSets;
|
165
|
this.valService.getSetsOfRepository(this.chosenUrl)
|
166
|
.subscribe(
|
167
|
sets => this.valSets = sets,
|
168
|
error => {
|
169
|
this.showSpinner = false;
|
170
|
this.loadingMessage = '';
|
171
|
this.errorMessage = loadingValSetsError
|
172
|
},
|
173
|
() => {
|
174
|
this.showSpinner = false;
|
175
|
this.loadingMessage = '';
|
176
|
this.step2 = 'active';
|
177
|
this.showParameters = true;
|
178
|
}
|
179
|
);
|
180
|
}
|
181
|
|
182
|
getChosenUrl(url: string) {
|
183
|
this.chosenUrl = url;
|
184
|
}
|
185
|
|
186
|
getParameters(params: string[]) {
|
187
|
// no of records = params[0]
|
188
|
// xpath = params[1]
|
189
|
}
|
190
|
|
191
|
}
|