1
|
import { Component, Injector } from '@angular/core';
|
2
|
import { MyGroup } from '../../../shared/reusablecomponents/forms/my-group.interface';
|
3
|
import { Validators } from '@angular/forms';
|
4
|
import {
|
5
|
formErrorRequiredFields, formSuccessAddedInterface,
|
6
|
invalidCustomBaseUrl, loadingValSetsError, noServiceMessage
|
7
|
} from '../../../domain/shared-messages';
|
8
|
import { ValidatorService } from '../../../services/validator.service';
|
9
|
import { ActivatedRoute } from '@angular/router';
|
10
|
import { RepositoryService } from '../../../services/repository.service';
|
11
|
|
12
|
@Component ({
|
13
|
selector: 'datasource-interface-form',
|
14
|
templateUrl: './datasource-interface-form.component.html'
|
15
|
})
|
16
|
|
17
|
export class DatasourceInterfaceFormComponent extends MyGroup {
|
18
|
|
19
|
successMessage: string;
|
20
|
errorMessage: string;
|
21
|
|
22
|
mode: string;
|
23
|
|
24
|
identifiedBaseUrl: boolean;
|
25
|
valSets: string[] = [];
|
26
|
existingValSet: boolean;
|
27
|
|
28
|
compClasses: Map<string,string> = new Map<string,string>();
|
29
|
classCodes: string[] = [];
|
30
|
|
31
|
readonly groupDefinition = {
|
32
|
baseUrl: ['', Validators.required],
|
33
|
selectValidationSet: [''],
|
34
|
customValidationSet: [''],
|
35
|
compatibilityLevel: ['', Validators.required],
|
36
|
};
|
37
|
|
38
|
constructor(injector: Injector,
|
39
|
private valService: ValidatorService,
|
40
|
private repoService: RepositoryService,
|
41
|
private route: ActivatedRoute){
|
42
|
super(injector);
|
43
|
}
|
44
|
|
45
|
ngOnInit() {
|
46
|
|
47
|
setTimeout(() => {
|
48
|
super.ngOnInit();
|
49
|
this.getMode();
|
50
|
|
51
|
console.log(this.group, this.parentGroup);
|
52
|
if (this.data && this.data.length) {
|
53
|
/* this.group.patchValue({
|
54
|
baseUrl : this.data[0].baseUrl,
|
55
|
selectValidationSet : this.data[0].accessSet,
|
56
|
compatibilityLevel : this.data[0].desiredCompatibilityLevel
|
57
|
});*/
|
58
|
this.patchData.next({
|
59
|
baseUrl: this.data[0].baseUrl,
|
60
|
/* selectValidationSet: this.data[0].accessSet, [ IS THIS THE CORRECT FIELD ?????]*/
|
61
|
compatibilityLevel: this.data[0].desiredCompatibilityLevel
|
62
|
});
|
63
|
this.identifyBaseUrl(this.data[0].baseUrl);
|
64
|
this.getCompatibilityClasses();
|
65
|
this.data.splice(0, 1);
|
66
|
}
|
67
|
|
68
|
this.existingValSet = true;
|
69
|
this.getMyControl('customValidationSet').disable();
|
70
|
}, 1500);
|
71
|
}
|
72
|
|
73
|
chooseValSet(existingValSet: boolean) {
|
74
|
if(existingValSet) {
|
75
|
this.existingValSet = true;
|
76
|
this.getMyControl('selectValidationSet').enable();
|
77
|
this.getMyControl('customValidationSet').disable();
|
78
|
} else {
|
79
|
this.existingValSet = false;
|
80
|
this.getMyControl('selectValidationSet').disable();
|
81
|
this.getMyControl('customValidationSet').enable();
|
82
|
}
|
83
|
}
|
84
|
|
85
|
saveInterface() {
|
86
|
if (this.group.valid) {
|
87
|
if (this.identifiedBaseUrl) {
|
88
|
this.successMessage = formSuccessAddedInterface;
|
89
|
this.errorMessage = '';
|
90
|
} else {
|
91
|
let response: boolean;
|
92
|
response = this.identifyBaseUrl(this.group.get('baseUrl').value);
|
93
|
if (response) {
|
94
|
this.successMessage = formSuccessAddedInterface;
|
95
|
this.errorMessage = '';
|
96
|
} else {
|
97
|
this.errorMessage = invalidCustomBaseUrl;
|
98
|
this.successMessage = '';
|
99
|
}
|
100
|
}
|
101
|
} else {
|
102
|
this.errorMessage = formErrorRequiredFields;
|
103
|
this.successMessage = '';
|
104
|
}
|
105
|
}
|
106
|
|
107
|
identifyBaseUrl(url: string) {
|
108
|
let response: boolean;
|
109
|
this.valService.identifyRepository(url).subscribe(
|
110
|
res => {
|
111
|
response = res;
|
112
|
if (response) {
|
113
|
this.getValidationSets(url);
|
114
|
this.identifiedBaseUrl = true;
|
115
|
}
|
116
|
},
|
117
|
error => {
|
118
|
console.log(error);
|
119
|
response = false;
|
120
|
}
|
121
|
);
|
122
|
return response;
|
123
|
}
|
124
|
|
125
|
getValidationSets(url: string) {
|
126
|
if (url) {
|
127
|
this.valService.getSetsOfRepository(url)
|
128
|
.subscribe(
|
129
|
sets => this.valSets = sets,
|
130
|
error => {
|
131
|
this.errorMessage = loadingValSetsError
|
132
|
}
|
133
|
);
|
134
|
}
|
135
|
}
|
136
|
|
137
|
getCompatibilityClasses() {
|
138
|
this.repoService.getCompatibilityClasses(this.mode).subscribe(
|
139
|
classes => {
|
140
|
this.compClasses = classes;
|
141
|
for (let key in this.compClasses){
|
142
|
this.classCodes.push(key);
|
143
|
}
|
144
|
},
|
145
|
error => {
|
146
|
this.errorMessage = noServiceMessage;
|
147
|
console.log(error);
|
148
|
}
|
149
|
);
|
150
|
}
|
151
|
|
152
|
getMode() {
|
153
|
if (this.route.snapshot.paramMap.get('id')) {
|
154
|
this.mode = this.route.snapshot.paramMap.get('id').split("_")[0];
|
155
|
} else {
|
156
|
this.mode = this.route.snapshot.url[0].path;
|
157
|
}
|
158
|
}
|
159
|
|
160
|
}
|