Revision 50977
Added by Myrto Koukouli about 6 years ago
datasource-interface-form.component.ts | ||
---|---|---|
2 | 2 |
import { MyGroup } from '../../../shared/reusablecomponents/forms/my-group.interface'; |
3 | 3 |
import { FormBuilder, Validators } from '@angular/forms'; |
4 | 4 |
import { |
5 |
formErrorRequiredFields, formSuccessAddedInterface,
|
|
5 |
formErrorRequiredFields, formErrorWasntSaved, formSubmitting, formSuccessAddedInterface, formSuccessUpdatedInterface,
|
|
6 | 6 |
invalidCustomBaseUrl, noServiceMessage |
7 | 7 |
} from '../../../domain/shared-messages'; |
8 | 8 |
import { ValidatorService } from '../../../services/validator.service'; |
9 | 9 |
import { ActivatedRoute } from '@angular/router'; |
10 | 10 |
import { RepositoryService } from '../../../services/repository.service'; |
11 |
import { InterfaceInformation, RepositoryInterface } from '../../../domain/typeScriptClasses'; |
|
11 |
import { InterfaceInformation, Repository, RepositoryInterface } from '../../../domain/typeScriptClasses';
|
|
12 | 12 |
|
13 | 13 |
@Component ({ |
14 | 14 |
selector: 'datasource-interface-form', |
... | ... | |
17 | 17 |
|
18 | 18 |
export class DatasourceInterfaceFormComponent extends MyGroup implements OnDestroy { |
19 | 19 |
|
20 |
loadingMessage: string; |
|
20 | 21 |
successMessage: string; |
21 | 22 |
errorMessage: string; |
22 | 23 |
|
23 |
mode: string;
|
|
24 |
currentRepository: Repository;
|
|
24 | 25 |
|
25 | 26 |
identifiedBaseUrl: boolean; |
26 | 27 |
existingValSet: boolean; |
27 | 28 |
interfaceInfo: InterfaceInformation; |
28 | 29 |
currentInterface: RepositoryInterface; |
29 |
valset: string[] = []; |
|
30 |
valsetList: string[] = [];
|
|
30 | 31 |
|
31 | 32 |
compClasses: Map<string,string> = new Map<string,string>(); |
32 | 33 |
classCodes: string[] = []; |
... | ... | |
40 | 41 |
|
41 | 42 |
constructor(injector: Injector, |
42 | 43 |
private valService: ValidatorService, |
43 |
private repoService: RepositoryService, |
|
44 |
private route: ActivatedRoute){ |
|
44 |
private repoService: RepositoryService){ |
|
45 | 45 |
super(injector); |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
ngOnInit() { |
49 |
this.currentRepository = <Repository>this.otherData; |
|
49 | 50 |
this.getCompatibilityClasses(); |
50 | 51 |
console.log(`other data is: ${JSON.stringify(this.otherData)}`); |
51 | 52 |
if (this.data && this.data.length) { |
... | ... | |
79 | 80 |
} |
80 | 81 |
|
81 | 82 |
saveInterface() { |
83 |
this.errorMessage = ''; |
|
84 |
this.successMessage = ''; |
|
82 | 85 |
if (this.group.valid) { |
83 | 86 |
if (this.identifiedBaseUrl) { |
84 | 87 |
let baseUrl = this.getMyControl('baseUrl').value; |
85 |
let valset: string; |
|
86 |
if (this.getMyControl('selectValidationSet').enabled ) {
|
|
88 |
let valset: string = '';
|
|
89 |
if (this.getMyControl('selectValidationSet').enabled) { |
|
87 | 90 |
valset = this.getMyControl('selectValidationSet').value; |
88 | 91 |
} else { |
89 | 92 |
valset = this.getMyControl('customValidationSet').value; |
... | ... | |
91 | 94 |
let compLvl = this.getMyControl('compatibilityLevel').value; |
92 | 95 |
|
93 | 96 |
if (this.currentInterface) { |
94 |
this.currentInterface.baseUrl = baseUrl; |
|
95 |
//this.currentInterface.accessSet = this.valset; CHECK IF THIS IS THE CORRECT FIELD |
|
96 |
this.currentInterface.desiredCompatibilityLevel = compLvl; |
|
97 |
/*update Interface*/ |
|
98 |
|
|
97 |
this.updateCurrent(baseUrl,valset,compLvl); |
|
99 | 98 |
} else { |
100 |
let currentInterface: RepositoryInterface = { |
|
101 |
desiredCompatibilityLevel: compLvl, |
|
102 |
complianceName: 'UNKNOWN', |
|
103 |
upgradeToV3: '', |
|
104 |
deleteApi: false, |
|
105 |
accessSet: valset, |
|
106 |
accessFormat: '', |
|
107 |
metadataIdentifierPath: '', |
|
108 |
lastCollectionDate: '', |
|
109 |
nextScheduledExecution: '', |
|
110 |
status: '', |
|
111 |
collectedFrom: '', |
|
112 |
id: '', |
|
113 |
typology: '', |
|
114 |
compliance: '', |
|
115 |
contentDescription: '', |
|
116 |
accessProtocol: '', |
|
117 |
baseUrl: '', |
|
118 |
active: false, |
|
119 |
removable: false, |
|
120 |
accessParams: {}, |
|
121 |
extraFields: {} |
|
122 |
}; |
|
123 |
this.repoService.addInterface(this.otherData[1], this.otherData[0], currentInterface).subscribe( |
|
124 |
addedInterface => { |
|
125 |
console.log(`addInterface responded ${addedInterface}`); |
|
126 |
this.currentInterface = addedInterface; |
|
127 |
}, |
|
128 |
error => console.log(error), |
|
129 |
() => { |
|
130 |
this.successMessage = formSuccessAddedInterface; |
|
131 |
this.errorMessage = ''; |
|
132 |
} |
|
133 |
); |
|
99 |
this.addCurrent(baseUrl,valset,compLvl); |
|
134 | 100 |
} |
135 | 101 |
} else { |
136 | 102 |
this.errorMessage = invalidCustomBaseUrl; |
... | ... | |
153 | 119 |
this.errorMessage = invalidCustomBaseUrl; |
154 | 120 |
} |
155 | 121 |
if (this.interfaceInfo.sets) { |
156 |
this.valset = this.interfaceInfo.sets; |
|
157 |
console.log(this.valset); |
|
122 |
this.valsetList = this.interfaceInfo.sets;
|
|
123 |
console.log(this.valsetList);
|
|
158 | 124 |
} |
159 | 125 |
}, |
160 | 126 |
error => { |
... | ... | |
166 | 132 |
} |
167 | 133 |
} |
168 | 134 |
|
169 |
getMode() { |
|
170 |
if (this.route.snapshot.paramMap.get('id')) { |
|
171 |
this.mode = this.route.snapshot.paramMap.get('id').split("_")[0]; |
|
172 |
} else { |
|
173 |
this.mode = this.route.snapshot.url[0].path; |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 | 135 |
getCompatibilityClasses() { |
178 |
this.getMode(); |
|
179 |
this.repoService.getCompatibilityClasses(this.mode).subscribe( |
|
136 |
this.repoService.getCompatibilityClasses(this.currentRepository.datasourceType).subscribe( |
|
180 | 137 |
classes => { |
181 | 138 |
this.compClasses = classes; |
182 | 139 |
for (let key in this.compClasses){ |
... | ... | |
190 | 147 |
); |
191 | 148 |
} |
192 | 149 |
|
150 |
updateCurrent (baseUrl: string, valset: string, compLvl: string) { |
|
151 |
this.successMessage = ''; |
|
152 |
this.errorMessage = ''; |
|
153 |
this.loadingMessage = formSubmitting; |
|
154 |
this.currentInterface.baseUrl = baseUrl; |
|
155 |
this.currentInterface.accessSet = valset; |
|
156 |
this.currentInterface.desiredCompatibilityLevel = compLvl; |
|
157 |
this.currentInterface.typology = this.currentRepository.datasourceClass; |
|
158 |
this.repoService.updateInterface(this.currentInterface).subscribe( |
|
159 |
response => { |
|
160 |
console.log(`updateRepository responded ${response}`); |
|
161 |
this.loadingMessage = ''; |
|
162 |
if (response == '200') { |
|
163 |
this.successMessage = formSuccessUpdatedInterface; |
|
164 |
} else { |
|
165 |
this.errorMessage = formErrorWasntSaved; |
|
166 |
} |
|
167 |
}, |
|
168 |
error => { |
|
169 |
console.log(error); |
|
170 |
this.loadingMessage = ''; |
|
171 |
this.errorMessage = formErrorWasntSaved; |
|
172 |
} |
|
173 |
); |
|
174 |
} |
|
175 |
|
|
176 |
addCurrent (baseUrl: string, valset: string, compLvl: string) { |
|
177 |
this.errorMessage = ''; |
|
178 |
this.successMessage = ''; |
|
179 |
this.loadingMessage = formSubmitting; |
|
180 |
this.currentInterface = new RepositoryInterface(); |
|
181 |
this.currentInterface.baseUrl = baseUrl; |
|
182 |
this.currentInterface.accessSet = valset; |
|
183 |
this.currentInterface.desiredCompatibilityLevel = compLvl; |
|
184 |
this.currentInterface.typology = this.currentRepository.datasourceClass; |
|
185 |
this.repoService.addInterface(this.currentRepository.datasourceType, this.currentRepository.id, this.currentInterface).subscribe( |
|
186 |
addedInterface => { |
|
187 |
console.log(`addInterface responded ${addedInterface}`); |
|
188 |
this.currentInterface = addedInterface; |
|
189 |
}, |
|
190 |
error => { |
|
191 |
console.log(error); |
|
192 |
this.loadingMessage = ''; |
|
193 |
this.errorMessage = formErrorWasntSaved; |
|
194 |
}, |
|
195 |
() => { |
|
196 |
this.loadingMessage = ''; |
|
197 |
if (this.currentInterface.id) { |
|
198 |
this.successMessage = formSuccessAddedInterface; |
|
199 |
} else { |
|
200 |
this.errorMessage = formErrorWasntSaved; |
|
201 |
} |
|
202 |
} |
|
203 |
); |
|
204 |
} |
|
205 |
|
|
193 | 206 |
ngOnDestroy() { |
194 | 207 |
if (this.currentInterface) { |
195 |
/* this.repoService.deleteInterface(this.currentInterface.id).subscribe(
|
|
208 |
this.repoService.deleteInterface(this.currentInterface.id).subscribe( |
|
196 | 209 |
response => console.log(`deleteInterface responded: ${response}`), |
197 | 210 |
error => console.log(error) |
198 |
);*/
|
|
211 |
); |
|
199 | 212 |
console.log(`deleting ${this.currentInterface.id}`); |
200 | 213 |
} else { |
201 | 214 |
console.log(`deleting empty interface form`); |
Also available in: Unified diff
finalized sources register and update