1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
/*
============LICENSE_START==========================================
===================================================================
Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
Copyright (C) 2018 IBM Intellectual Property. All rights reserved.
===================================================================
Copyright (C) 2018 IBM.
===================================================================
Unless otherwise specified, all software contained herein is licensed
under the Apache License, Version 2.0 (the License);
you may not use this software except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
============LICENSE_END============================================
*/
import { Component, OnInit, ViewChild } from '@angular/core';
import { saveAs } from 'file-saver';
import { ParamShareService } from '../../../shared/services/paramShare.service';
import { MappingEditorService } from '../../../shared/services/mapping-editor.service';
import { ModalComponent } from '../../../shared/modal/modal.component';
import { HttpUtilService } from '../../../shared/services/httpUtil/http-util.service';
import { UtilityService } from '../../../shared/services/utilityService/utility.service';
import { environment } from '../../../../environments/environment';
import { NotificationsService } from 'angular2-notifications';
import { ParameterDefinitionService } from './parameter-definition.service';
import 'rxjs/add/operator/map';
import { NgProgress } from 'ngx-progressbar';
import { NgxSpinnerService } from 'ngx-spinner';
import { appConstants } from '../../../../constants/app-constants';
import { APIService } from "../../../shared/services/cdt.apicall";
let YAML = require('yamljs');
declare var $: any;
@Component({
selector: 'parameter-form',
templateUrl: './parameter.component.html',
styleUrls: ['../reference-dataform/reference-dataform.component.css'],
providers: [ParameterDefinitionService]
})
export class ParameterComponent implements OnInit {
clName= "ParameterCompon";
public paramForm: any;
public actionType: any;
public showFilterFields: boolean;
public filterByFieldvalues = appConstants.filterByFieldvalues;
public ruleTypeConfiguaration = appConstants.ruleTypeConfiguaration;
public requiredValues: boolean[] = appConstants.requiredValues;
public sourceValues = appConstants.sourceValues;
public ruleTypeValues = appConstants.ruleTypeValues;
public typeValues = appConstants.typeValues;
public responseKeyNameValues = appConstants.responseKeyNameValues;
public responseKeyValues = appConstants.responseKeyValues;
public requestKeyNameValues = appConstants.requestKeyNameValues;
public requestKeyValues = appConstants.requestKeyValues;
public myKeyFileName = null;
public myPdFileName = null;
public disposable: any;
public confirmation: boolean;
public showConfirmation: boolean;
public test: boolean;
apiToken = localStorage['apiToken'];
userId = localStorage['userId'];
public initialData: any;
public intialData: any;
public initialAction: any;
public item: any = {};
public subscription: any;
public Actions = [
{ action: appConstants.Actions.configBackup, value: appConstants.Actions.configBackup },
{ action: appConstants.Actions.ConfigModify, value: appConstants.Actions.ConfigModify },
{ action: appConstants.Actions.configRestore, value: appConstants.Actions.configRestore },
{ action: appConstants.Actions.configure, value: appConstants.Actions.configure },
{ action: appConstants.Actions.getRunningConfig, value: appConstants.Actions.getRunningConfig },
{ action: appConstants.Actions.healthCheck, value: appConstants.Actions.healthCheck },
{ action: appConstants.Actions.startApplication, value: appConstants.Actions.startApplication },
{ action: appConstants.Actions.stopApplication, value: appConstants.Actions.stopApplication },
{ action: appConstants.Actions.distributeTraffic, value: appConstants.Actions.distributeTraffic }
];
public uploadTypes = appConstants.uploadTypes;
options = appConstants.optionsToNotificationComponent;
public vnfcTypeData: string = '';
public selectedUploadType: string;
@ViewChild(ModalComponent) modalComponent: ModalComponent;
public title: string;
public parameterDefinitionMap: { [index: string]: string; } = {};
public parameterNameValues = {};
public displayParamObjects;
public modelParamDefinitionObjects;
public vnfType: any;
vnfcType: any;
protocol: any;
public refNameObj = {};
public action;
public artifactName;
public appDataObject: any;
public downloadDataObject: any;
public artifact_fileName="";
template_id: any;
private selectedActionReference: any;
constructor(private httpService: HttpUtilService,
private apiService:APIService,
private parameterDefinitionService: ParameterDefinitionService,
private paramShareService: ParamShareService,
private mappingEditorService: MappingEditorService,
private httpUtil: HttpUtilService,
private utilService: UtilityService,
private nService: NotificationsService,
private ngProgress: NgProgress,
private spinner: NgxSpinnerService) {
}
ngOnInit() {
var methName= "ngOnInit";
this.selectedActionReference = this.mappingEditorService.newObject;
if (this.selectedActionReference && this.selectedActionReference != undefined) {
this.vnfType = this.selectedActionReference.vnf;
this.protocol = this.selectedActionReference.protocol;
this.action = this.selectedActionReference.action;
if( this.utilService.getTracelvl() > 0 )
console.log( this.clName+": "+methName+": vnfType:["+this.vnfType+
"] action:["+this.action+"] protocol:["+this.protocol+"]");
if(this.selectedActionReference.vnfc) {
this.vnfcType = this.selectedActionReference.vnfc;
if( this.utilService.getTracelvl() > 0 )
console.log( this.clName+": "+methName+": have vnfcType:["+
this.vnfcType+"]");
}
if( this.action === 'ConfigScaleOut'){
// this.template_id = this.selectedActionReference.templateId;
this.template_id = this.mappingEditorService.identifier;
}
this.artifact_fileName = this.selectedActionReference.pd_artifact;
this.parameterDefinitionService.setValues(this.vnfType, this.vnfcType, this.protocol, this.action, this.artifact_fileName);
}
else {
this.selectedActionReference = {
'action': '',
'scope': { 'vnf-type': '', 'vnfc-type': '' },
'vm': [],
'protocol': '',
'download-dg-reference': '',
'user-name': '',
'port-number': '',
'artifact-list': [],
'deviceTemplate': '',
'scopeType': ''
};
}
//let path = this.location.path
/* this.activeRoutes.url.subscribe(UrlSegment => {
this.actionType = UrlSegment[0].path
})
*/
}
ngAfterViewInit() {
if( this.mappingEditorService.latestAction) {
this.displayParamObjects = [];
this.modelParamDefinitionObjects = [];
this.displayParamObjects= this.paramShareService.getSessionParamData();
// if( this.paramShareService.getSessionParamData() != undefined &&
// this.paramShareService.getSessionParamData().length > 0)
if( this.displayParamObjects != undefined &&
this.displayParamObjects.length > 0 )
{
this.parameterDefinitionService.populateDataUponSource( this.displayParamObjects);
} else {
this.getPD();
}
} else {
this.nService.error(appConstants.errors.error, appConstants.errors["noAction&VNFTypeInRDscreenError"]);
}
return this.displayParamObjects;
}
public getPD() {
let result: any;
let input=
this.utilService.createPayloadForRetrieve( false, this.action, this.vnfType,this.artifact_fileName);
let artifactContent: any;
this.ngProgress.start();
return this.apiService.callGetArtifactsApi(input).subscribe( data => {
if( this.utilService.checkResult(data)) {
let result: any = JSON.parse(data.output.data.block).artifactInfo[0];
var pdObject = YAML.parse(result['artifact-content']);
let fileModel = pdObject['vnf-parameter-list'];
this.displayParamObjects = this.parameterDefinitionService.populatePD(fileModel);
}
else {
}
this.ngProgress.done();
},
error => this.nService.error(appConstants.errors.error, appConstants.errors.connectionError));
}
public getPDFromSession() {
this.ngProgress.start();
return this.httpService.get({
url: 'testurl',
}).subscribe( data => {
this.displayParamObjects = this.paramShareService.getSessionParamData();
this.ngProgress.done();
},
error => {
this.displayParamObjects = this.paramShareService.getSessionParamData();
this.ngProgress.done();
});
}
selectedNavItem(item: any) {
this.item = item;
}
//========================== End of selectedNavItem() Method============================================
browsePdFile() {
$('#inputFile1').trigger('click');
}
//========================== End of browsePdFile() Method============================================
browseKeyFile() {
$('#inputFile2').trigger('click');
}
//========================== End of browseKeyFile() Method============================================
//========================== End of appendSlashes() Method============================================
//========================== End of prepareFileName() Method============================================
ngOnDestroy() {
this.parameterDefinitionService.destroy(this.displayParamObjects);
}
//========================== End of ngOnDestroy() Method============================================
public showUpload() {
this.selectedUploadType = this.uploadTypes[0].value;
};
//========================== End of showUpload() Method============================================
//This is called when the user selects new files from the upload button
public fileChange(input, uploadType) {
if (input.files && input.files[0]) {
this.spinner.show();
// Create the file reader
let reader = new FileReader();
this.readFile(input.files[0], reader, (result) => {
if ('keyfile' === uploadType) {
this.myKeyFileName = input.files[0].name;
this.displayParamObjects = this.parameterDefinitionService.processKeyFile(this.myKeyFileName, result);
}
if ('pdfile' === uploadType) {
this.myPdFileName = input.files[0].name;
this.displayParamObjects = this.parameterDefinitionService.processPDfile(this.myPdFileName, result);
}
});
setTimeout(() => {
/** spinner ends after 3.5 seconds */
this.spinner.hide();
}, 3500);
}
}
//========================== End of fileChange() Method============================================
public readFile(file, reader, callback) {
// Set a callback funtion to fire after the file is fully loaded
reader.onload = () => {
// callback with the results
callback(reader.result);
};
// Read the file
reader.readAsText(file, 'UTF-8');
}
//========================== End of readFile() Method============================================
fileChangeEvent(fileInput: any) {
let obj: any = fileInput.target.files;
}
sourceChanged( data, obj) {
if (data == 'A&AI') {
obj.ruleTypeValues = appConstants.ruleTypeValues;
for (let x = 0; x < 5; x++) {
obj['response-keys'][x]['key-name'] = null;
obj['response-keys'][x]['key-value'] = null;
}
} else if (data == 'Manual') {
obj.ruleTypeValues = [null];
obj['rule-type'] = null;
obj.showFilterFields = false;
for (let x = 0; x < 5; x++) {
obj['response-keys'][x]['key-name'] = null;
obj['response-keys'][x]['key-value'] = null;
}
}
else {
obj.ruleTypeValues = [null];
}
}
//========================== End of sourceChanged() Method============================================
ruleTypeChanged( data, obj) {
if (data == null || data == undefined || data == 'null') {
obj.showFilterFields = false;
obj['rule-type'] = null;
for (let x = 0; x < 5; x++) {
obj['response-keys'][x]['key-name'] = null;
obj['response-keys'][x]['key-value'] = null;
}
} else {
let sourceObject = this.ruleTypeConfiguaration[data];
if (data == 'vm-name-list' || data == 'vnfc-name-list' || data == 'vnfc-oam-ipv4-address-list') {
this.showFilterFields = false;
obj.showFilterFields = true;
this.filetrByFieldChanged(obj['response-keys'][3]['key-value'], obj);
} else {
obj.showFilterFields = false;
obj['response-keys'][3]['key-name'] = null;
obj['response-keys'][3]['key-value'] = null;
obj['response-keys'][4]['key-name'] = null;
obj['response-keys'][4]['key-value'] = null;
}
for (let x = 0; x < sourceObject.length; x++) {
obj['response-keys'][x]['key-name'] = sourceObject[x]['key-name'];
obj['response-keys'][x]['key-value'] = sourceObject[x]['key-value'];
}
}
}
//========================== End of ruleTypeChanged() Method============================================
filetrByFieldChanged(data, obj) {
if (data == null || data == undefined || data == 'null') {
obj.enableFilterByValue = false;
obj['response-keys'][4]['key-value'] = null;
} else {
obj.enableFilterByValue = true;
}
}
}
|