1
|
/*
|
2
|
* created by myrto on 12/12/2017
|
3
|
*/
|
4
|
|
5
|
import { Component, OnInit, Type, ViewChild } from '@angular/core';
|
6
|
import { RegisterDatasourceShareableComponent } from './register-datasource-shareable.component';
|
7
|
import { DatasourceUpdateFormComponent } from '../sources-forms/datasource-update-form.component';
|
8
|
import { Repository, RepositoryInterface } from '../../../domain/typeScriptClasses';
|
9
|
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
|
10
|
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
|
11
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
12
|
import { RepositoryService } from '../../../services/repository.service';
|
13
|
import {formInfoLoading, loadingRepoError, noInterfacesSaved} from '../../../domain/shared-messages';
|
14
|
import {ActivatedRoute, Params, Router} from "@angular/router";
|
15
|
import {MyArray} from "../../../shared/reusablecomponents/forms/my-array.interface";
|
16
|
import {
|
17
|
AsideHelpContentComponent,
|
18
|
HelpContentComponent
|
19
|
} from "../../../shared/reusablecomponents/help-content.component";
|
20
|
|
21
|
@Component ({
|
22
|
selector: 'app-sr-data',
|
23
|
templateUrl: 'sr-data.component.html'
|
24
|
})
|
25
|
|
26
|
export class SrDataComponent implements OnInit {
|
27
|
loadingMessage: string;
|
28
|
errorMessage: string;
|
29
|
|
30
|
showRepositories: boolean;
|
31
|
showForm: boolean;
|
32
|
showInterfaces: boolean;
|
33
|
showFinish: boolean;
|
34
|
step2: string = '';
|
35
|
step3: string = '';
|
36
|
step4: string = '';
|
37
|
|
38
|
datasourceId: string;
|
39
|
repo: Repository;
|
40
|
|
41
|
/* queryParams is used to change the queryParams without refreshing the page
|
42
|
* This was needed for Help Service [which sends back info according to the current router.url]
|
43
|
* the param that is used is 'step' and the values are: 'selectDatasource','basicInformation','interfaces','finish'
|
44
|
*/
|
45
|
queryParams: Params = Object.assign({}, this.route.snapshot.queryParams);
|
46
|
@ViewChild('topHelperContent')
|
47
|
public topHelperContent: HelpContentComponent;
|
48
|
@ViewChild('leftHelperContent')
|
49
|
public leftHelperContent: AsideHelpContentComponent;
|
50
|
@ViewChild('rightHelperContent')
|
51
|
public rightHelperContent: AsideHelpContentComponent;
|
52
|
@ViewChild('bottomHelperContent')
|
53
|
public bottomHelperContent: HelpContentComponent;
|
54
|
|
55
|
|
56
|
@ViewChild('datasourcesByCountry')
|
57
|
public datasourcesByCountry: RegisterDatasourceShareableComponent;
|
58
|
|
59
|
@ViewChild('updateDatasource')
|
60
|
public updateDatasource: DatasourceUpdateFormComponent;
|
61
|
|
62
|
@ViewChild('interfaceFormArray')
|
63
|
public interfaceFormArray: MyArray;
|
64
|
|
65
|
group: FormGroup;
|
66
|
interfaceFormDesc: Description = interfaceFormDesc;
|
67
|
updateDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
|
68
|
repoInterfaces: RepositoryInterface[] = [];
|
69
|
|
70
|
constructor(
|
71
|
private fb: FormBuilder,
|
72
|
private route: ActivatedRoute,
|
73
|
private router: Router,
|
74
|
private repoService: RepositoryService) {}
|
75
|
|
76
|
ngOnInit() {
|
77
|
this.setQueryParam('selectDatasource');
|
78
|
this.showRepositories=true;
|
79
|
}
|
80
|
|
81
|
moveAStep(){
|
82
|
if(this.showRepositories) {
|
83
|
if (this.datasourcesByCountry.goToNextStep()) {
|
84
|
this.setQueryParam('basicInformation');
|
85
|
this.showRepositories = false;
|
86
|
this.showForm = true;
|
87
|
this.step2 = 'active';
|
88
|
console.log(`got datasource with id ${this.datasourceId}`);
|
89
|
}
|
90
|
} else if(this.showForm) {
|
91
|
this.updateDatasource.updateRepo();
|
92
|
} else if(this.showInterfaces) {
|
93
|
if (this.interfaceFormArray.checkIfOneElementExists()) {
|
94
|
this.setQueryParam('finish');
|
95
|
this.showInterfaces = false;
|
96
|
this.showFinish = true;
|
97
|
this.step4 = 'active';
|
98
|
} else {
|
99
|
this.errorMessage = noInterfacesSaved;
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
moveBackAStep(){
|
105
|
if(this.showForm) {
|
106
|
this.setQueryParam('selectDatasource');
|
107
|
this.showRepositories = true;
|
108
|
this.showForm = false;
|
109
|
this.step2 = '';
|
110
|
} else if(this.showInterfaces) {
|
111
|
this.setQueryParam('basicInformation');
|
112
|
this.showForm = true;
|
113
|
this.showInterfaces = false;
|
114
|
this.step3 = '';
|
115
|
} else if(this.showFinish) {
|
116
|
this.setQueryParam('interfaces');
|
117
|
this.showInterfaces = true;
|
118
|
this.showFinish = false;
|
119
|
this.step4 = '';
|
120
|
}
|
121
|
}
|
122
|
|
123
|
goToStep2(emitted: boolean) {
|
124
|
if (emitted) {
|
125
|
this.moveAStep();
|
126
|
}
|
127
|
}
|
128
|
|
129
|
getRepoId(emitedId: string) {
|
130
|
this.datasourceId = emitedId;
|
131
|
this.getRepo();
|
132
|
}
|
133
|
|
134
|
getRepo() {
|
135
|
this.loadingMessage = formInfoLoading;
|
136
|
if (this.datasourceId) {
|
137
|
this.repoService.getRepositoryById(this.datasourceId).subscribe(
|
138
|
repo => {
|
139
|
this.repo = repo;
|
140
|
},
|
141
|
error => {
|
142
|
console.log(error);
|
143
|
this.loadingMessage = '';
|
144
|
this.errorMessage = loadingRepoError;
|
145
|
},
|
146
|
() => {
|
147
|
this.loadingMessage = '';
|
148
|
}
|
149
|
);
|
150
|
}
|
151
|
}
|
152
|
|
153
|
getUpdatedRepo(repo: Repository){
|
154
|
this.repo = repo;
|
155
|
console.log(`repo was updated!`);
|
156
|
this.group = this.fb.group({});
|
157
|
this.getRepoInterfaces();
|
158
|
}
|
159
|
|
160
|
getRepoInterfaces() {
|
161
|
this.repoService.getRepositoryInterface(this.datasourceId).subscribe(
|
162
|
interfaces => {
|
163
|
this.repoInterfaces = interfaces.sort( function(a, b) {
|
164
|
if (a.id<b.id) {
|
165
|
return -1;
|
166
|
} else if (a.id>b.id) {
|
167
|
return 1;
|
168
|
} else {
|
169
|
return 0;
|
170
|
}
|
171
|
});
|
172
|
console.log(`the number of interfaces is ${this.repoInterfaces.length}`);
|
173
|
},
|
174
|
error => console.log(error),
|
175
|
() => {
|
176
|
this.setQueryParam('interfaces');
|
177
|
this.showForm = false;
|
178
|
this.showInterfaces = true;
|
179
|
this.step3 = 'active';
|
180
|
}
|
181
|
);
|
182
|
}
|
183
|
|
184
|
downloadLogo() {
|
185
|
window.open("../../../assets/imgs/3_0ValidatedLogo.png","_blank", "enabledstatus=0,toolbar=0,menubar=0,location=0");
|
186
|
}
|
187
|
|
188
|
setQueryParam(value: string) {
|
189
|
// set param for step
|
190
|
this.queryParams['step'] = value;
|
191
|
this.router.navigate([], { relativeTo: this.route, queryParams: this.queryParams });
|
192
|
this.rightHelperContent.ngOnInit();
|
193
|
this.topHelperContent.ngOnInit();
|
194
|
this.leftHelperContent.ngOnInit();
|
195
|
this.bottomHelperContent.ngOnInit();
|
196
|
}
|
197
|
|
198
|
}
|