1
|
import { Component, OnInit, Type, ViewChild } from '@angular/core';
|
2
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
3
|
import { Description, interfaceFormDesc } from '../../../domain/oa-description';
|
4
|
import { DatasourceInterfaceFormComponent } from '../sources-forms/datasource-interface-form.component';
|
5
|
import { Repository } from '../../../domain/typeScriptClasses';
|
6
|
import { DatasourceCreateFormComponent } from '../sources-forms/datasource-create-form.component';
|
7
|
import {ActivatedRoute, Params, Router} from "@angular/router";
|
8
|
import {MyArray} from "../../../shared/reusablecomponents/forms/my-array.interface";
|
9
|
import {noInterfacesSaved} from "../../../domain/shared-messages";
|
10
|
import {
|
11
|
AsideHelpContentComponent,
|
12
|
HelpContentComponent
|
13
|
} from "../../../shared/reusablecomponents/help-content.component";
|
14
|
|
15
|
@Component ({
|
16
|
selector: 'app-sr-journal',
|
17
|
templateUrl: 'sr-journal.component.html'
|
18
|
})
|
19
|
|
20
|
export class SrJournalComponent implements OnInit {
|
21
|
errorMessage: string;
|
22
|
|
23
|
showForm: boolean;
|
24
|
showInterfaces: boolean;
|
25
|
showFinish: boolean;
|
26
|
step2: string = '';
|
27
|
step3: string = '';
|
28
|
|
29
|
@ViewChild ('registerJournal')
|
30
|
registerJournal: DatasourceCreateFormComponent;
|
31
|
|
32
|
@ViewChild('interfaceFormArray')
|
33
|
public interfaceFormArray: MyArray;
|
34
|
|
35
|
group: FormGroup;
|
36
|
interfaceFormDesc: Description = interfaceFormDesc;
|
37
|
addDatasourceInterfaces: Type<any> = DatasourceInterfaceFormComponent;
|
38
|
|
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: '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
|
constructor(
|
56
|
private fb: FormBuilder,
|
57
|
private route: ActivatedRoute,
|
58
|
private router: Router) {}
|
59
|
|
60
|
ngOnInit() {
|
61
|
this.setQueryParam('basicInformation');
|
62
|
this.showForm = true;
|
63
|
}
|
64
|
|
65
|
moveAStep(){
|
66
|
if (this.showForm) {
|
67
|
this.registerJournal.registerDatasource();
|
68
|
} else if (this.showInterfaces) {
|
69
|
if (this.interfaceFormArray.checkIfOneElementExists()) {
|
70
|
this.setQueryParam('finish');
|
71
|
this.showInterfaces = false;
|
72
|
this.showFinish = true;
|
73
|
this.step3 = 'active';
|
74
|
} else {
|
75
|
this.errorMessage = noInterfacesSaved;
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
|
80
|
moveBackAStep(){
|
81
|
this.errorMessage = '';
|
82
|
if (this.showInterfaces) {
|
83
|
this.setQueryParam('basicInformation');
|
84
|
this.showForm = true;
|
85
|
this.showInterfaces = false;
|
86
|
this.step2 = '';
|
87
|
} else if (this.showFinish) {
|
88
|
this.setQueryParam('interfaces');
|
89
|
this.showInterfaces = true;
|
90
|
this.showFinish = false;
|
91
|
this.step3 = '';
|
92
|
}
|
93
|
}
|
94
|
|
95
|
getCurrentRepo(repo: Repository) {
|
96
|
this.repo = repo;
|
97
|
this.setQueryParam('interfaces');
|
98
|
this.showForm = false;
|
99
|
this.showInterfaces = true;
|
100
|
this.step2 = 'active';
|
101
|
this.group = this.fb.group({});
|
102
|
}
|
103
|
|
104
|
downloadLogo() {
|
105
|
window.open("../../../assets/imgs/3_0ValidatedLogo.png","_blank", "enabledstatus=0,toolbar=0,menubar=0,location=0");
|
106
|
}
|
107
|
|
108
|
setQueryParam(value: string) {
|
109
|
// set param for step
|
110
|
this.queryParams['step'] = value;
|
111
|
this.router.navigate([], { relativeTo: this.route, queryParams: this.queryParams });
|
112
|
this.rightHelperContent.ngOnInit();
|
113
|
this.topHelperContent.ngOnInit();
|
114
|
this.leftHelperContent.ngOnInit();
|
115
|
this.bottomHelperContent.ngOnInit();
|
116
|
}
|
117
|
|
118
|
}
|