1
|
/*
|
2
|
* created by myrto on 12/12/2017
|
3
|
*/
|
4
|
|
5
|
import { Component, OnInit, Type, ViewChild } from '@angular/core';
|
6
|
import { Repository, RepositoryInterface } from '../../../domain/typeScriptClasses';
|
7
|
import { DatasourceInfoFormComponent } from '../sources-forms/datasource-info-form.component';
|
8
|
import { RegisterDatasourceShareableComponent } from './register-datasource-shareable.component';
|
9
|
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
|
10
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
11
|
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
|
12
|
import { RepositoryService } from '../../../services/repository.service';
|
13
|
|
14
|
@Component ({
|
15
|
selector:'app-sr-literature',
|
16
|
templateUrl: 'sr-literature.component.html'
|
17
|
})
|
18
|
|
19
|
export class SrLiteratureComponent implements OnInit {
|
20
|
showRepositories: boolean;
|
21
|
showForm: boolean;
|
22
|
showInterfaces: boolean;
|
23
|
showFinish: boolean;
|
24
|
step2: string = '';
|
25
|
step3: string = '';
|
26
|
step4: string = '';
|
27
|
|
28
|
datasourceId: string;
|
29
|
repo: Repository;
|
30
|
|
31
|
@ViewChild('datasourcesByCountry')
|
32
|
public datasourcesByCountry: RegisterDatasourceShareableComponent;
|
33
|
|
34
|
@ViewChild('updateDatasource')
|
35
|
public updateDatasource: DatasourceInfoFormComponent;
|
36
|
|
37
|
group: FormGroup;
|
38
|
interfaceFormDesc: Description = interfaceFormDesc;
|
39
|
updateDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
|
40
|
repoInterfaces: RepositoryInterface[] = [];
|
41
|
|
42
|
|
43
|
constructor(
|
44
|
private fb: FormBuilder,
|
45
|
private repoService: RepositoryService) {}
|
46
|
|
47
|
ngOnInit() {
|
48
|
this.showRepositories=true;
|
49
|
|
50
|
}
|
51
|
|
52
|
moveAStep(){
|
53
|
if(this.showRepositories) {
|
54
|
if (this.datasourcesByCountry.goToNextStep()) {
|
55
|
this.showRepositories = false;
|
56
|
this.showForm = true;
|
57
|
this.step2 = 'active';
|
58
|
console.log(`got datasource with id ${this.datasourceId}`);
|
59
|
}
|
60
|
} else if(this.showForm) {
|
61
|
if (this.updateDatasource.updateRepo()){
|
62
|
setTimeout( () => {
|
63
|
this.getRepoInterfaces();
|
64
|
this.group = this.fb.group({});
|
65
|
}, 500 );
|
66
|
}
|
67
|
} else if(this.showInterfaces) {
|
68
|
this.showInterfaces = false;
|
69
|
this.showFinish = true;
|
70
|
this.step4 = 'active';
|
71
|
}
|
72
|
}
|
73
|
|
74
|
moveBackAStep(){
|
75
|
if(this.showForm) {
|
76
|
this.showRepositories = true;
|
77
|
this.showForm = false;
|
78
|
this.step2 = '';
|
79
|
} else if(this.showInterfaces) {
|
80
|
this.showForm = true;
|
81
|
this.showInterfaces = false;
|
82
|
this.step3 = '';
|
83
|
} else if(this.showFinish) {
|
84
|
this.showInterfaces = true;
|
85
|
this.showFinish = false;
|
86
|
this.step4 = '';
|
87
|
}
|
88
|
}
|
89
|
|
90
|
getRepoId(emitedId: string) {
|
91
|
this.datasourceId = emitedId;
|
92
|
}
|
93
|
|
94
|
getCurrentRepo(repo: Repository) {
|
95
|
this.repo = repo;
|
96
|
}
|
97
|
|
98
|
getRepoInterfaces() {
|
99
|
this.repoService.getRepositoryInterface(this.datasourceId).subscribe(
|
100
|
interfaces => {
|
101
|
this.repoInterfaces = interfaces;
|
102
|
console.log(this.repoInterfaces.length);
|
103
|
},
|
104
|
error => console.log(error),
|
105
|
() => {
|
106
|
this.showForm = false;
|
107
|
this.showInterfaces = true;
|
108
|
this.step3 = 'active';
|
109
|
}
|
110
|
);
|
111
|
}
|
112
|
}
|