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