From 8ead52b5bf62525b2697b7ca6aaf0b896bbd3400 Mon Sep 17 00:00:00 2001 From: "SANDHYA.JS" Date: Mon, 10 Jun 2024 18:23:41 +0530 Subject: [PATCH] Feature 11011: Multiple NS deletion in OSM - Added multi option in smart table - Added new terminate api for multi select deletion Change-Id: Ia03d24e30c1c0a549ac1eda87264d58ab6d3bccd Signed-off-by: SANDHYA.JS --- .../ns-instances/NSInstancesComponent.html | 6 +- .../ns-instances/NSInstancesComponent.ts | 82 ++++++++++++++----- src/app/utilities/delete/DeleteComponent.html | 5 +- src/app/utilities/delete/DeleteComponent.ts | 81 ++++++++++++++++-- .../NSInstancesActionComponent.ts | 7 +- src/assets/i18n/de.json | 3 + src/assets/i18n/en.json | 3 + src/assets/i18n/es.json | 3 + src/assets/i18n/pt.json | 3 + src/environments/environment.prod.ts | 1 + src/environments/environment.ts | 1 + src/models/CommonModel.ts | 1 + 12 files changed, 163 insertions(+), 33 deletions(-) diff --git a/src/app/instances/ns-instances/NSInstancesComponent.html b/src/app/instances/ns-instances/NSInstancesComponent.html index 8ee93b8..2f01b87 100644 --- a/src/app/instances/ns-instances/NSInstancesComponent.html +++ b/src/app/instances/ns-instances/NSInstancesComponent.html @@ -18,6 +18,10 @@ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.i
{{'NSINSTANCES' | translate}}
+
-
diff --git a/src/app/instances/ns-instances/NSInstancesComponent.ts b/src/app/instances/ns-instances/NSInstancesComponent.ts index 14d6349..34719f3 100644 --- a/src/app/instances/ns-instances/NSInstancesComponent.ts +++ b/src/app/instances/ns-instances/NSInstancesComponent.ts @@ -18,18 +18,20 @@ /** * @file NS Instance Component */ -import { Component, Injector, OnInit } from '@angular/core'; +import { Component, Injector, OnInit, ViewChild } from '@angular/core'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; import { CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel'; import { DataService } from 'DataService'; +import { DeleteComponent } from 'DeleteComponent'; import { environment } from 'environment'; import { InstantiateNsComponent } from 'InstantiateNs'; -import { LocalDataSource } from 'ng2-smart-table'; +import { LocalDataSource, Ng2SmartTableComponent } from 'ng2-smart-table'; import { NSDInstanceData, NSInstanceDetails } from 'NSInstanceModel'; import { NSInstancesActionComponent } from 'NSInstancesActionComponent'; import { RestService } from 'RestService'; import { Subscription } from 'rxjs'; +import { isNullOrUndefined } from 'SharedService'; import { SharedService } from 'SharedService'; /** @@ -42,6 +44,8 @@ import { SharedService } from 'SharedService'; }) /** Exporting a class @exports NSInstancesComponent */ export class NSInstancesComponent implements OnInit { + @ViewChild('table') table: Ng2SmartTableComponent; + /** Injector to invoke other services @public */ public injector: Injector; @@ -52,10 +56,11 @@ export class NSInstancesComponent implements OnInit { public dataSource: LocalDataSource = new LocalDataSource(); /** SelectedRows array @public */ - public selectedRows: object[] = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public selectedRows: any; /** Selected list array @public */ - public selectList: object[] = []; + public selectList: [] = []; /** Instance component are stored in settings @public */ public settings: {} = {}; @@ -136,6 +141,7 @@ export class NSInstancesComponent implements OnInit { /** Generate smart table row title and filters @public */ public generateTableSettings(): void { this.settings = { + selectMode: 'multi', columns: this.columnList, actions: { add: false, edit: false, delete: false, position: 'right' }, attr: this.sharedService.tableClassConfig(), @@ -172,25 +178,25 @@ export class NSInstancesComponent implements OnInit { valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => { if (row.OperationalStatus === this.operationalStateFirstStep) { return ` - - `; + + `; } else if (row.OperationalStatus === this.operationalStateSecondStep) { return ` - - `; + + `; } else if (row.OperationalStatus === this.operationalStateThirdStep) { return ` - - `; + + `; } else if (row.OperationalStatus === this.operationalStateFourthStep) { return ` - - `; + + `; } else if (row.OperationalStatus === this.operationalStateFifthStep) { return ` - - `; + + `; } else { return `${row.OperationalStatus}`; } @@ -212,16 +218,16 @@ export class NSInstancesComponent implements OnInit { valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => { if (row.ConfigStatus === this.configStateFirstStep) { return ` - - `; + + `; } else if (row.ConfigStatus === this.configStateSecondStep) { return ` - - `; + + `; } else if (row.ConfigStatus === this.configStateThirdStep) { return ` - - `; + + `; } else { return `${row.ConfigStatus}`; } @@ -285,14 +291,46 @@ export class NSInstancesComponent implements OnInit { /** smart table listing manipulation @public */ public onUserRowSelect(event: MessageEvent): void { - Object.assign(event.data, { page: 'ns-instance' }); - this.dataService.changeMessage(event.data); + if (!isNullOrUndefined(event)) { + this.selectedRows = event; + if (this.selectedRows.selected.length !== 0) { + this.selectList = this.selectedRows.selected; + } else { + if (!isNullOrUndefined(event.data)) { + Object.assign(event.data, { page: 'ns-instance' }); + this.dataService.changeMessage(event.data); + } + this.selectList.length = 0; + } + } + } + + /** delete NS using modalservice @public */ + public deleteNS(): void { + // eslint-disable-next-line security/detect-non-literal-fs-filename + const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); + modalRef.componentInstance.params = { + identifierList: this.selectList, + page: 'instantiateNS' + }; + modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { + if (result) { + this.sharedService.callData(); + this.table.isAllSelected = false; + this.selectList.length = 0; + } + }).catch((): void => { + // Catch Navigation Error + }); } /** Instantiate NS using modalservice @public */ public instantiateNS(): void { // eslint-disable-next-line security/detect-non-literal-fs-filename const modalRef: NgbModalRef = this.modalService.open(InstantiateNsComponent, { backdrop: 'static' }); + modalRef.componentInstance.params = { + titleName: 'instantiateNS' + }; modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { if (result) { this.generateData(); diff --git a/src/app/utilities/delete/DeleteComponent.html b/src/app/utilities/delete/DeleteComponent.html index a39cb61..513bc21 100644 --- a/src/app/utilities/delete/DeleteComponent.html +++ b/src/app/utilities/delete/DeleteComponent.html @@ -28,6 +28,9 @@ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.i \ No newline at end of file diff --git a/src/app/utilities/delete/DeleteComponent.ts b/src/app/utilities/delete/DeleteComponent.ts index b403e9b..d79d4e4 100644 --- a/src/app/utilities/delete/DeleteComponent.ts +++ b/src/app/utilities/delete/DeleteComponent.ts @@ -23,10 +23,11 @@ import { Component, Injector, Input } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { TranslateService } from '@ngx-translate/core'; import { NotifierService } from 'angular-notifier'; -import { DELETEPARAMS, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel'; +import { APIURLHEADER, DELETEPARAMS, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel'; import { DataService } from 'DataService'; import { environment } from 'environment'; import { RestService } from 'RestService'; +import { isNullOrUndefined } from 'SharedService'; /** * Creating component @@ -54,6 +55,13 @@ export class DeleteComponent { /** Check the loading results @public */ public isLoadingResults: Boolean = false; + /** Check the page @public */ + public isPage: Boolean = false; + + /** Number of instances @public */ + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + public noOfInstances: Number = 25; + /** Give the message for the loading @public */ public notifyMessage: string = 'DELETELOADERMESSAGE'; @@ -106,8 +114,20 @@ export class DeleteComponent { if (data.identifier !== undefined || data.identifier !== '' || data.identifier !== null) { this.id = data.identifier; } - this.createTitleandID(data); - this.createDeleteUrl(data); + if (!isNullOrUndefined(this.params)) { + if (this.params.page === 'instantiateNS') { + this.isPage = true; + this.title = ''; + this.createDeleteUrl(data); + } else if (this.params.page === 'ns-instance') { + this.createDeleteUrl(data); + this.isPage = false; + } + } else { + this.createTitleandID(data); + this.createDeleteUrl(data); + this.isPage = false; + } }); } /** Generate Title and Id from data @public */ @@ -129,10 +149,18 @@ export class DeleteComponent { /** Generate Delete url from data @public */ public createDeleteUrl(data: DELETEPARAMS): void { this.deleteURL = ''; - if (data.page === 'ns-instance') { - this.deleteURL = environment.NSINSTANCESCONTENT_URL; - this.forceDelete = this.params.forceDeleteType; - } else if (data.page === 'ns-package') { + if (!isNullOrUndefined(this.params)) { + if (this.params.page === 'ns-instance') { + this.deleteURL = environment.NSINSTANCESCONTENT_URL; + this.forceDelete = this.params.forceDeleteType; + this.title = this.params.name; + this.id = this.params.id; + } else if (this.params.page === 'instantiateNS') { + this.deleteURL = environment.NSINSTANCESTERMINATE_URL; + this.notifyMessage = 'DELETEDSUCCESSFULLY'; + } + } + if (data.page === 'ns-package') { this.deleteURL = environment.NSDESCRIPTORSCONTENT_URL; this.notifyMessage = 'DELETEDSUCCESSFULLY'; } else if (data.page === 'vnf-package') { @@ -191,7 +219,7 @@ export class DeleteComponent { } this.restService.deleteResource(deletingURl).subscribe((res: {}) => { this.activeModal.close(modalData); - this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title})); + this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title })); }, (error: ERRORDATA) => { this.isLoadingResults = false; this.restService.handleError(error, 'delete'); @@ -199,4 +227,41 @@ export class DeleteComponent { this.isLoadingResults = false; }); } + + /** terminate multiple ns instances function @public */ + public terminate(): void { + this.isLoadingResults = true; + const modalData: MODALCLOSERESPONSEDATA = { + message: 'Done' + }; + const idData: string[] = []; + this.params.identifierList.forEach((data: DELETEPARAMS) => { + idData.push(data.identifier); + }); + if (idData.length > this.noOfInstances) { + this.activeModal.close(modalData); + this.notifierService.notify('warning', this.translateService.instant('WARNINGMESSAGE')); + } else { + const postData: {} = { + ns_ids: idData + }; + let deletingURl: string = ''; + deletingURl = this.deleteURL; + this.notifyMessage = 'DELETELOADMESSAGE'; + const apiURLHeader: APIURLHEADER = { + url: deletingURl, + httpOptions: { headers: this.headers } + }; + this.restService.postResource(apiURLHeader, postData).subscribe(() => { + this.activeModal.close(modalData); + this.isLoadingResults = false; + this.notifierService.notify('success', this.translateService.instant(this.notifyMessage)); + }, (error: ERRORDATA) => { + this.isLoadingResults = false; + this.restService.handleError(error, 'post'); + }, () => { + this.isLoadingResults = false; + }); + } + } } diff --git a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts index 1582bc4..61f6d16 100644 --- a/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts +++ b/src/app/utilities/ns-instances-action/NSInstancesActionComponent.ts @@ -163,7 +163,12 @@ export class NSInstancesActionComponent { public deleteNSInstance(forceAction: boolean): void { // eslint-disable-next-line security/detect-non-literal-fs-filename const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); - modalRef.componentInstance.params = { forceDeleteType: forceAction }; + modalRef.componentInstance.params = { + forceDeleteType: forceAction, + name: this.value.name, + page: 'ns-instance', + id: this.instanceID + }; modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { if (result) { this.sharedService.callData(); diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index dd6e156..30340a5 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -92,6 +92,9 @@ "SESSIONEXPIRY": "Sitzung abgelaufen, bitte erneut anmelden", "DELETECONFIRMPOPUPMESSAGE": "Möchten Sie wirklich löschen?", "DELETELOADERMESSAGE": "Bitte warten Sie, während der Löschvorgang ausgeführt wird", + "DELETELOADMESSAGE": "Bitte warten Sie, während der Löschvorgang ausgeführt wird", + "WARNINGMESSAGE": "Es können nicht mehr als 25 Instanzen gelöscht werden", + "DELETENS":"NS löschen", "VALUE": "Wert", "PERFORMACTION": "Aktion ausführen", "EXECUTE": "Execute", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index ebe8d7c..b18a013 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -92,6 +92,9 @@ "SESSIONEXPIRY": "Session expired, please login again", "DELETECONFIRMPOPUPMESSAGE": "Are you sure want to delete", "DELETELOADERMESSAGE": "Please wait while {{title}} deletion is in progress", + "DELETELOADMESSAGE": "Please wait while deletion is in progress", + "WARNINGMESSAGE": "Cannot delete more than 25 instances", + "DELETENS":"Delete NS", "VALUE": "Value", "PERFORMACTION": "Perform Action", "EXECUTE": "Execute", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index 354058b..29b9044 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -92,6 +92,9 @@ "SESSIONEXPIRY": "Sesión expirada, por favor ingrese de nuevo", "DELETECONFIRMPOPUPMESSAGE": "¿Seguro que lo quiere eliminar?", "DELETELOADERMESSAGE": "Por favor, espere mientras la eliminación está en progreso", + "DELETELOADMESSAGE": "Por favor, espere mientras la eliminación está en progreso", + "WARNINGMESSAGE": "No se pueden eliminar más de 25 instancias", + "DELETENS":"Eliminar NS", "VALUE": "Valor", "PERFORMACTION": "Realizar una acción", "EXECUTE": "Ejecutar", diff --git a/src/assets/i18n/pt.json b/src/assets/i18n/pt.json index 98b3c46..4508b5a 100644 --- a/src/assets/i18n/pt.json +++ b/src/assets/i18n/pt.json @@ -92,6 +92,9 @@ "SESSIONEXPIRY": "Sessão expirada, faça o login novamente", "DELETECONFIRMPOPUPMESSAGE": "Tem certeza de que deseja excluir", "DELETELOADERMESSAGE": "Aguarde enquanto a exclusão está em andamento", + "DELETELOADMESSAGE": "Aguarde enquanto a exclusão está em andamento", + "WARNINGMESSAGE": "Não é possível excluir mais de 25 instâncias", + "DELETENS":"Excluir NS", "VALUE": "Valor", "PERFORMACTION": "Executar a ação", "EXECUTE": "Executar", diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 9ab1c1f..b3b625d 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -66,6 +66,7 @@ export const environment = { NSDINSTANCES_URL: OSM_NSLCM_ENDPOINT + 'ns_instances', VNFINSTANCES_URL: OSM_NSLCM_ENDPOINT + 'vnfrs', NSINSTANCESCONTENT_URL: OSM_NSLCM_ENDPOINT + 'ns_instances_content', + NSINSTANCESTERMINATE_URL: OSM_NSLCM_ENDPOINT + 'ns_instances_terminate', NSHISTORYOPERATIONS_URL: OSM_NSLCM_ENDPOINT + 'ns_lcm_op_occs', NETWORKSLICEINSTANCESCONTENT_URL: OSM_NSILCM_ENDPOINT + 'netslice_instances_content', NSTHISTORYOPERATIONS_URL: OSM_NSILCM_ENDPOINT + '/nsi_lcm_op_occs', diff --git a/src/environments/environment.ts b/src/environments/environment.ts index bd45964..3f80777 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -66,6 +66,7 @@ export const environment = { NSDINSTANCES_URL: OSM_NSLCM_ENDPOINT + 'ns_instances', VNFINSTANCES_URL: OSM_NSLCM_ENDPOINT + 'vnfrs', NSINSTANCESCONTENT_URL: OSM_NSLCM_ENDPOINT + 'ns_instances_content', + NSINSTANCESTERMINATE_URL: OSM_NSLCM_ENDPOINT + 'ns_instances_terminate', NSHISTORYOPERATIONS_URL: OSM_NSLCM_ENDPOINT + 'ns_lcm_op_occs', NETWORKSLICEINSTANCESCONTENT_URL: OSM_NSILCM_ENDPOINT + 'netslice_instances_content', NSTHISTORYOPERATIONS_URL: OSM_NSILCM_ENDPOINT + 'nsi_lcm_op_occs', diff --git a/src/models/CommonModel.ts b/src/models/CommonModel.ts index a3038f1..581bbfb 100644 --- a/src/models/CommonModel.ts +++ b/src/models/CommonModel.ts @@ -128,6 +128,7 @@ export interface URLPARAMS { configs?: object; actions?: object; executedActions?: EXECUTEDACTIONS[]; + identifierList: []; } /** Handle the Delete params */ export interface DELETEPARAMS { -- 2.25.1