2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file NS Instance Component
21 import { Component, Injector, OnInit, ViewChild } from '@angular/core';
22 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23 import { TranslateService } from '@ngx-translate/core';
24 import { CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
25 import { DataService } from 'DataService';
26 import { DeleteComponent } from 'DeleteComponent';
27 import { environment } from 'environment';
28 import { InstantiateNsComponent } from 'InstantiateNs';
29 import { LocalDataSource, Ng2SmartTableComponent } from 'ng2-smart-table';
30 import { NSDInstanceData, NSInstanceDetails } from 'NSInstanceModel';
31 import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
32 import { RestService } from 'RestService';
33 import { Subscription } from 'rxjs';
34 import { isNullOrUndefined } from 'SharedService';
35 import { SharedService } from 'SharedService';
39 * @Component takes NSInstancesComponent.html as template url
42 templateUrl: './NSInstancesComponent.html',
43 styleUrls: ['./NSInstancesComponent.scss']
45 /** Exporting a class @exports NSInstancesComponent */
46 export class NSInstancesComponent implements OnInit {
47 @ViewChild('table') table: Ng2SmartTableComponent;
49 /** Injector to invoke other services @public */
50 public injector: Injector;
52 /** NS Instance array @public */
53 public nsInstanceData: object[] = [];
55 /** Datasource instance @public */
56 public dataSource: LocalDataSource = new LocalDataSource();
58 /** SelectedRows array @public */
59 // eslint-disable-next-line @typescript-eslint/no-explicit-any
60 public selectedRows: any;
62 /** Selected list array @public */
63 public selectList: [] = [];
65 /** Instance component are stored in settings @public */
66 public settings: {} = {};
68 /** Contains objects for menu settings @public */
69 public columnList: {} = {};
71 /** Check the loading results @public */
72 public isLoadingResults: boolean = true;
74 /** Give the message for the loading @public */
75 public message: string = 'PLEASEWAIT';
77 /** Class for empty and present data @public */
78 public checkDataClass: string;
80 /** operational State init data @public */
81 public operationalStateFirstStep: string = CONFIGCONSTANT.operationalStateFirstStep;
83 /** operational State running data @public */
84 public operationalStateSecondStep: string = CONFIGCONSTANT.operationalStateSecondStep;
86 /** operational State failed data @public */
87 public operationalStateThirdStep: string = CONFIGCONSTANT.operationalStateThirdStep;
89 /** operational State scaling data @public */
90 public operationalStateFourthStep: string = CONFIGCONSTANT.operationalStateFourthStep;
92 /** operational State healing data @public */
93 public operationalStateFifthStep: string = CONFIGCONSTANT.operationalStateFifthStep;
95 /** Config State init data @public */
96 public configStateFirstStep: string = CONFIGCONSTANT.configStateFirstStep;
98 /** Config State init data @public */
99 public configStateSecondStep: string = CONFIGCONSTANT.configStateSecondStep;
101 /** Config State init data @public */
102 public configStateThirdStep: string = CONFIGCONSTANT.configStateThirdStep;
104 /** Instance of the modal service @private */
105 private modalService: NgbModal;
107 /** dataService to pass the data from one component to another @private */
108 private dataService: DataService;
110 /** Utilizes rest service for any CRUD operations @private */
111 private restService: RestService;
113 /** Contains all methods related to shared @private */
114 private sharedService: SharedService;
116 /** Contains tranlsate instance @private */
117 private translateService: TranslateService;
119 /** Instance of subscriptions @private */
120 private generateDataSub: Subscription;
122 constructor(injector: Injector) {
123 this.injector = injector;
124 this.restService = this.injector.get(RestService);
125 this.dataService = this.injector.get(DataService);
126 this.sharedService = this.injector.get(SharedService);
127 this.translateService = this.injector.get(TranslateService);
128 this.modalService = this.injector.get(NgbModal);
132 * Lifecyle Hooks the trigger before component is instantiate
134 public ngOnInit(): void {
135 this.generateTableColumn();
136 this.generateTableSettings();
138 this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
141 /** Generate smart table row title and filters @public */
142 public generateTableSettings(): void {
145 columns: this.columnList,
146 actions: { add: false, edit: false, delete: false, position: 'right' },
147 attr: this.sharedService.tableClassConfig(),
148 pager: this.sharedService.paginationPagerConfig(),
149 noDataMessage: this.translateService.instant('NODATAMSG')
153 /** Generate smart table row title and filters @public */
154 public generateTableColumn(): void {
156 name: { title: this.translateService.instant('NAME'), width: '15%' },
157 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
158 NsdName: { title: this.translateService.instant('NSDNAME'), width: '15%' },
160 title: this.translateService.instant('DATE'), width: '15%', sortDirection: 'desc',
161 compareFunction: this.sharedService.compareFunction
164 title: this.translateService.instant('OPERATIONALSTATUS'), width: '10%', type: 'html',
168 selectText: 'Select',
170 { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
171 { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
172 { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
173 { value: this.operationalStateFourthStep, title: this.operationalStateFourthStep },
174 { value: this.operationalStateFifthStep, title: this.operationalStateFifthStep }
178 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
179 if (row.OperationalStatus === this.operationalStateFirstStep) {
180 return `<span class="icon-label" title="${row.OperationalStatus}">
181 <i class="fas fa-clock text-warning"></i>
183 } else if (row.OperationalStatus === this.operationalStateSecondStep) {
184 return `<span class="icon-label" title="${row.OperationalStatus}">
185 <i class="fas fa-check-circle text-success"></i>
187 } else if (row.OperationalStatus === this.operationalStateThirdStep) {
188 return `<span class="icon-label" title="${row.OperationalStatus}">
189 <i class="fas fa-times-circle text-danger"></i>
191 } else if (row.OperationalStatus === this.operationalStateFourthStep) {
192 return `<span class="icon-label" title="${row.OperationalStatus}">
193 <i class="fas fa-compress-alt text-success"></i>
196 else if (row.OperationalStatus === this.operationalStateFifthStep) {
197 return `<span class="icon-label" title="${row.OperationalStatus}">
198 <i class="fas fa-briefcase-medical text-success"></i>
201 return `<span>${row.OperationalStatus}</span>`;
206 title: this.translateService.instant('CONFIGSTATUS'), width: '10%', type: 'html',
210 selectText: 'Select',
212 { value: this.configStateFirstStep, title: this.configStateFirstStep },
213 { value: this.configStateSecondStep, title: this.configStateSecondStep },
214 { value: this.configStateThirdStep, title: this.configStateThirdStep }
218 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
219 if (row.ConfigStatus === this.configStateFirstStep) {
220 return `<span class="icon-label" title="${row.ConfigStatus}">
221 <i class="fas fa-clock text-warning"></i>
223 } else if (row.ConfigStatus === this.configStateSecondStep) {
224 return `<span class="icon-label" title="${row.ConfigStatus}">
225 <i class="fas fa-check-circle text-success"></i>
227 } else if (row.ConfigStatus === this.configStateThirdStep) {
228 return `<span class="icon-label" title="${row.ConfigStatus}">
229 <i class="fas fa-times-circle text-danger"></i>
232 return `<span>${row.ConfigStatus}</span>`;
236 DetailedStatus: { title: this.translateService.instant('DETAILEDSTATUS'), width: '15%' },
238 name: 'Action', width: '15%', filter: false, sort: false, type: 'custom',
239 title: this.translateService.instant('ACTIONS'),
240 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): NSDInstanceData => row,
241 renderComponent: NSInstancesActionComponent
246 /** generateData initiate the ns-instance list @public */
247 public generateData(): void {
248 this.isLoadingResults = true;
249 this.restService.getResource(environment.NSDINSTANCES_URL).subscribe((nsdInstancesData: NSInstanceDetails[]): void => {
250 this.nsInstanceData = [];
251 nsdInstancesData.forEach((nsdInstanceData: NSInstanceDetails): void => {
252 const nsDataObj: NSDInstanceData = {
253 name: nsdInstanceData.name,
254 identifier: nsdInstanceData.id,
255 NsdName: nsdInstanceData['nsd-name-ref'],
256 OperationalStatus: nsdInstanceData['operational-status'],
257 ConfigStatus: nsdInstanceData['config-status'],
258 DetailedStatus: nsdInstanceData['detailed-status'],
259 memberIndex: nsdInstanceData.nsd.df,
260 nsConfig: nsdInstanceData.nsd['ns-configuration'],
261 adminDetails: nsdInstanceData._admin,
262 vnfID: nsdInstanceData['vnfd-id'],
263 nsd: nsdInstanceData.nsd,
264 'nsd-id': nsdInstanceData['nsd-id'],
265 vcaStatus: nsdInstanceData.vcaStatus,
266 constituent: nsdInstanceData['constituent-vnfr-ref'],
267 'create-time': this.sharedService.convertEpochTime(Number(nsdInstanceData['create-time']))
269 this.nsInstanceData.push(nsDataObj);
271 if (this.nsInstanceData.length > 0) {
272 this.checkDataClass = 'dataTables_present';
274 this.checkDataClass = 'dataTables_empty';
276 this.dataSource.load(this.nsInstanceData).then((data: {}): void => {
277 this.isLoadingResults = false;
278 }).catch((): void => {
279 // Catch Navigation Error
281 }, (error: ERRORDATA): void => {
282 this.restService.handleError(error, 'get');
283 this.isLoadingResults = false;
287 /** smart table listing manipulation @public */
288 public onChange(perPageValue: number): void {
289 this.dataSource.setPaging(1, perPageValue, true);
292 /** smart table listing manipulation @public */
293 public onUserRowSelect(event: MessageEvent): void {
294 if (!isNullOrUndefined(event)) {
295 this.selectedRows = event;
296 if (this.selectedRows.selected.length !== 0) {
297 this.selectList = this.selectedRows.selected;
299 if (!isNullOrUndefined(event.data)) {
300 Object.assign(event.data, { page: 'ns-instance' });
301 this.dataService.changeMessage(event.data);
303 this.selectList.length = 0;
308 /** delete NS using modalservice @public */
309 public deleteNS(): void {
310 // eslint-disable-next-line security/detect-non-literal-fs-filename
311 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
312 modalRef.componentInstance.params = {
313 identifierList: this.selectList,
314 page: 'instantiateNS'
316 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
318 this.sharedService.callData();
319 this.table.isAllSelected = false;
320 this.selectList.length = 0;
322 }).catch((): void => {
323 // Catch Navigation Error
327 /** Instantiate NS using modalservice @public */
328 public instantiateNS(): void {
329 // eslint-disable-next-line security/detect-non-literal-fs-filename
330 const modalRef: NgbModalRef = this.modalService.open(InstantiateNsComponent, { backdrop: 'static' });
331 modalRef.componentInstance.params = {
332 titleName: 'instantiateNS'
334 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
338 }).catch((): void => {
339 // Catch Navigation Error
344 * Lifecyle hook which get trigger on component destruction
346 public ngOnDestroy(): void {
347 this.generateDataSub.unsubscribe();