blob: 34719f3d806abd2c05688c2a41cbb98d66307005 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18/**
19 * @file NS Instance Component
20 */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053021import { Component, Injector, OnInit, ViewChild } from '@angular/core';
kumaran.m3b4814a2020-05-01 19:48:54 +053022import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23import { TranslateService } from '@ngx-translate/core';
24import { CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
25import { DataService } from 'DataService';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053026import { DeleteComponent } from 'DeleteComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { environment } from 'environment';
28import { InstantiateNsComponent } from 'InstantiateNs';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053029import { LocalDataSource, Ng2SmartTableComponent } from 'ng2-smart-table';
kumaran.m3b4814a2020-05-01 19:48:54 +053030import { NSDInstanceData, NSInstanceDetails } from 'NSInstanceModel';
31import { NSInstancesActionComponent } from 'NSInstancesActionComponent';
32import { RestService } from 'RestService';
33import { Subscription } from 'rxjs';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053034import { isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053035import { SharedService } from 'SharedService';
36
37/**
38 * Creating component
39 * @Component takes NSInstancesComponent.html as template url
40 */
41@Component({
42 templateUrl: './NSInstancesComponent.html',
43 styleUrls: ['./NSInstancesComponent.scss']
44})
45/** Exporting a class @exports NSInstancesComponent */
46export class NSInstancesComponent implements OnInit {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053047 @ViewChild('table') table: Ng2SmartTableComponent;
48
kumaran.m3b4814a2020-05-01 19:48:54 +053049 /** Injector to invoke other services @public */
50 public injector: Injector;
51
52 /** NS Instance array @public */
53 public nsInstanceData: object[] = [];
54
55 /** Datasource instance @public */
56 public dataSource: LocalDataSource = new LocalDataSource();
57
58 /** SelectedRows array @public */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053059 // eslint-disable-next-line @typescript-eslint/no-explicit-any
60 public selectedRows: any;
kumaran.m3b4814a2020-05-01 19:48:54 +053061
62 /** Selected list array @public */
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053063 public selectList: [] = [];
kumaran.m3b4814a2020-05-01 19:48:54 +053064
65 /** Instance component are stored in settings @public */
66 public settings: {} = {};
67
68 /** Contains objects for menu settings @public */
69 public columnList: {} = {};
70
71 /** Check the loading results @public */
72 public isLoadingResults: boolean = true;
73
74 /** Give the message for the loading @public */
75 public message: string = 'PLEASEWAIT';
76
77 /** Class for empty and present data @public */
78 public checkDataClass: string;
79
80 /** operational State init data @public */
81 public operationalStateFirstStep: string = CONFIGCONSTANT.operationalStateFirstStep;
82
83 /** operational State running data @public */
84 public operationalStateSecondStep: string = CONFIGCONSTANT.operationalStateSecondStep;
85
86 /** operational State failed data @public */
87 public operationalStateThirdStep: string = CONFIGCONSTANT.operationalStateThirdStep;
88
Barath Kumar R07698ab2021-03-30 11:50:42 +053089 /** operational State scaling data @public */
90 public operationalStateFourthStep: string = CONFIGCONSTANT.operationalStateFourthStep;
91
SANDHYA.JS219fe612024-01-23 15:52:43 +053092 /** operational State healing data @public */
93 public operationalStateFifthStep: string = CONFIGCONSTANT.operationalStateFifthStep;
94
kumaran.m3b4814a2020-05-01 19:48:54 +053095 /** Config State init data @public */
96 public configStateFirstStep: string = CONFIGCONSTANT.configStateFirstStep;
97
98 /** Config State init data @public */
99 public configStateSecondStep: string = CONFIGCONSTANT.configStateSecondStep;
100
101 /** Config State init data @public */
102 public configStateThirdStep: string = CONFIGCONSTANT.configStateThirdStep;
103
104 /** Instance of the modal service @private */
105 private modalService: NgbModal;
106
107 /** dataService to pass the data from one component to another @private */
108 private dataService: DataService;
109
110 /** Utilizes rest service for any CRUD operations @private */
111 private restService: RestService;
112
113 /** Contains all methods related to shared @private */
114 private sharedService: SharedService;
115
116 /** Contains tranlsate instance @private */
117 private translateService: TranslateService;
118
119 /** Instance of subscriptions @private */
120 private generateDataSub: Subscription;
121
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);
129 }
130
131 /**
132 * Lifecyle Hooks the trigger before component is instantiate
133 */
134 public ngOnInit(): void {
135 this.generateTableColumn();
136 this.generateTableSettings();
137 this.generateData();
Barath Kumar R063a3f12020-12-29 16:35:09 +0530138 this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
kumaran.m3b4814a2020-05-01 19:48:54 +0530139 }
140
141 /** Generate smart table row title and filters @public */
142 public generateTableSettings(): void {
143 this.settings = {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530144 selectMode: 'multi',
kumaran.m3b4814a2020-05-01 19:48:54 +0530145 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')
150 };
151 }
152
153 /** Generate smart table row title and filters @public */
154 public generateTableColumn(): void {
155 this.columnList = {
SANDHYA.JS5f8c8022023-10-13 11:45:25 +0530156 name: { title: this.translateService.instant('NAME'), width: '15%' },
kumaran.m3b4814a2020-05-01 19:48:54 +0530157 identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
158 NsdName: { title: this.translateService.instant('NSDNAME'), width: '15%' },
SANDHYA.JS5f8c8022023-10-13 11:45:25 +0530159 'create-time': {
160 title: this.translateService.instant('DATE'), width: '15%', sortDirection: 'desc',
161 compareFunction: this.sharedService.compareFunction
162 },
kumaran.m3b4814a2020-05-01 19:48:54 +0530163 OperationalStatus: {
164 title: this.translateService.instant('OPERATIONALSTATUS'), width: '10%', type: 'html',
165 filter: {
166 type: 'list',
167 config: {
168 selectText: 'Select',
169 list: [
170 { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
171 { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
Barath Kumar R07698ab2021-03-30 11:50:42 +0530172 { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
SANDHYA.JS219fe612024-01-23 15:52:43 +0530173 { value: this.operationalStateFourthStep, title: this.operationalStateFourthStep },
174 { value: this.operationalStateFifthStep, title: this.operationalStateFifthStep }
kumaran.m3b4814a2020-05-01 19:48:54 +0530175 ]
176 }
177 },
178 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
179 if (row.OperationalStatus === this.operationalStateFirstStep) {
180 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530181 <i class="fas fa-clock text-warning"></i>
182 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530183 } else if (row.OperationalStatus === this.operationalStateSecondStep) {
184 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530185 <i class="fas fa-check-circle text-success"></i>
186 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530187 } else if (row.OperationalStatus === this.operationalStateThirdStep) {
188 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530189 <i class="fas fa-times-circle text-danger"></i>
190 </span>`;
Barath Kumar R07698ab2021-03-30 11:50:42 +0530191 } else if (row.OperationalStatus === this.operationalStateFourthStep) {
192 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530193 <i class="fas fa-compress-alt text-success"></i>
194 </span>`;
SANDHYA.JS219fe612024-01-23 15:52:43 +0530195 }
196 else if (row.OperationalStatus === this.operationalStateFifthStep) {
197 return `<span class="icon-label" title="${row.OperationalStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530198 <i class="fas fa-briefcase-medical text-success"></i>
199 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530200 } else {
201 return `<span>${row.OperationalStatus}</span>`;
202 }
203 }
204 },
205 ConfigStatus: {
206 title: this.translateService.instant('CONFIGSTATUS'), width: '10%', type: 'html',
207 filter: {
208 type: 'list',
209 config: {
210 selectText: 'Select',
211 list: [
212 { value: this.configStateFirstStep, title: this.configStateFirstStep },
213 { value: this.configStateSecondStep, title: this.configStateSecondStep },
214 { value: this.configStateThirdStep, title: this.configStateThirdStep }
215 ]
216 }
217 },
218 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
219 if (row.ConfigStatus === this.configStateFirstStep) {
220 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530221 <i class="fas fa-clock text-warning"></i>
222 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530223 } else if (row.ConfigStatus === this.configStateSecondStep) {
224 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530225 <i class="fas fa-check-circle text-success"></i>
226 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530227 } else if (row.ConfigStatus === this.configStateThirdStep) {
228 return `<span class="icon-label" title="${row.ConfigStatus}">
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530229 <i class="fas fa-times-circle text-danger"></i>
230 </span>`;
kumaran.m3b4814a2020-05-01 19:48:54 +0530231 } else {
232 return `<span>${row.ConfigStatus}</span>`;
233 }
234 }
235 },
236 DetailedStatus: { title: this.translateService.instant('DETAILEDSTATUS'), width: '15%' },
237 Actions: {
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
242 }
243 };
244 }
245
246 /** generateData initiate the ns-instance list @public */
247 public generateData(): void {
248 this.isLoadingResults = true;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530249 this.restService.getResource(environment.NSDINSTANCES_URL).subscribe((nsdInstancesData: NSInstanceDetails[]): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530250 this.nsInstanceData = [];
Barath Kumar R063a3f12020-12-29 16:35:09 +0530251 nsdInstancesData.forEach((nsdInstanceData: NSInstanceDetails): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530252 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'],
Barath Kumar R063a3f12020-12-29 16:35:09 +0530259 memberIndex: nsdInstanceData.nsd.df,
Barath Kumar R07698ab2021-03-30 11:50:42 +0530260 nsConfig: nsdInstanceData.nsd['ns-configuration'],
261 adminDetails: nsdInstanceData._admin,
262 vnfID: nsdInstanceData['vnfd-id'],
263 nsd: nsdInstanceData.nsd,
Barath Kumar Rf2ae5462021-03-01 12:52:33 +0530264 'nsd-id': nsdInstanceData['nsd-id'],
SANDHYA.JS1584e3e2022-10-31 20:11:50 +0530265 vcaStatus: nsdInstanceData.vcaStatus,
SANDHYA.JS5f8c8022023-10-13 11:45:25 +0530266 constituent: nsdInstanceData['constituent-vnfr-ref'],
267 'create-time': this.sharedService.convertEpochTime(Number(nsdInstanceData['create-time']))
kumaran.m3b4814a2020-05-01 19:48:54 +0530268 };
269 this.nsInstanceData.push(nsDataObj);
270 });
271 if (this.nsInstanceData.length > 0) {
272 this.checkDataClass = 'dataTables_present';
273 } else {
274 this.checkDataClass = 'dataTables_empty';
275 }
Barath Kumar R063a3f12020-12-29 16:35:09 +0530276 this.dataSource.load(this.nsInstanceData).then((data: {}): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530277 this.isLoadingResults = false;
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530278 }).catch((): void => {
279 // Catch Navigation Error
280 });
Barath Kumar R063a3f12020-12-29 16:35:09 +0530281 }, (error: ERRORDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530282 this.restService.handleError(error, 'get');
283 this.isLoadingResults = false;
284 });
285 }
286
287 /** smart table listing manipulation @public */
288 public onChange(perPageValue: number): void {
289 this.dataSource.setPaging(1, perPageValue, true);
290 }
291
292 /** smart table listing manipulation @public */
293 public onUserRowSelect(event: MessageEvent): void {
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530294 if (!isNullOrUndefined(event)) {
295 this.selectedRows = event;
296 if (this.selectedRows.selected.length !== 0) {
297 this.selectList = this.selectedRows.selected;
298 } else {
299 if (!isNullOrUndefined(event.data)) {
300 Object.assign(event.data, { page: 'ns-instance' });
301 this.dataService.changeMessage(event.data);
302 }
303 this.selectList.length = 0;
304 }
305 }
306 }
307
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'
315 };
316 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
317 if (result) {
318 this.sharedService.callData();
319 this.table.isAllSelected = false;
320 this.selectList.length = 0;
321 }
322 }).catch((): void => {
323 // Catch Navigation Error
324 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530325 }
326
327 /** Instantiate NS using modalservice @public */
328 public instantiateNS(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530329 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530330 const modalRef: NgbModalRef = this.modalService.open(InstantiateNsComponent, { backdrop: 'static' });
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530331 modalRef.componentInstance.params = {
332 titleName: 'instantiateNS'
333 };
Barath Kumar R063a3f12020-12-29 16:35:09 +0530334 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530335 if (result) {
336 this.generateData();
337 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530338 }).catch((): void => {
339 // Catch Navigation Error
340 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530341 }
342
343 /**
344 * Lifecyle hook which get trigger on component destruction
345 */
346 public ngOnDestroy(): void {
347 this.generateDataSub.unsubscribe();
348 }
349}