Feature 11011: Multiple NS deletion in OSM
[osm/NG-UI.git] / src / app / instances / ns-instances / NSInstancesComponent.ts
index 7b81d91..34719f3 100644 (file)
 /**
  * @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: {} = {};
@@ -84,6 +89,9 @@ export class NSInstancesComponent implements OnInit {
     /** operational State scaling data @public */
     public operationalStateFourthStep: string = CONFIGCONSTANT.operationalStateFourthStep;
 
+    /** operational State healing data @public */
+    public operationalStateFifthStep: string = CONFIGCONSTANT.operationalStateFifthStep;
+
     /** Config State init data @public */
     public configStateFirstStep: string = CONFIGCONSTANT.configStateFirstStep;
 
@@ -133,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(),
@@ -144,9 +153,13 @@ export class NSInstancesComponent implements OnInit {
     /** Generate smart table row title and filters @public  */
     public generateTableColumn(): void {
         this.columnList = {
-            name: { title: this.translateService.instant('NAME'), width: '15%', sortDirection: 'asc' },
+            name: { title: this.translateService.instant('NAME'), width: '15%' },
             identifier: { title: this.translateService.instant('IDENTIFIER'), width: '20%' },
             NsdName: { title: this.translateService.instant('NSDNAME'), width: '15%' },
+            'create-time': {
+                title: this.translateService.instant('DATE'), width: '15%', sortDirection: 'desc',
+                compareFunction: this.sharedService.compareFunction
+            },
             OperationalStatus: {
                 title: this.translateService.instant('OPERATIONALSTATUS'), width: '10%', type: 'html',
                 filter: {
@@ -157,27 +170,33 @@ export class NSInstancesComponent implements OnInit {
                             { value: this.operationalStateFirstStep, title: this.operationalStateFirstStep },
                             { value: this.operationalStateSecondStep, title: this.operationalStateSecondStep },
                             { value: this.operationalStateThirdStep, title: this.operationalStateThirdStep },
-                            { value: this.operationalStateFourthStep, title: this.operationalStateFourthStep }
+                            { value: this.operationalStateFourthStep, title: this.operationalStateFourthStep },
+                            { value: this.operationalStateFifthStep, title: this.operationalStateFifthStep }
                         ]
                     }
                 },
                 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
                     if (row.OperationalStatus === this.operationalStateFirstStep) {
                         return `<span class="icon-label" title="${row.OperationalStatus}">
-                        <i class="fas fa-clock text-warning"></i>
-                        </span>`;
+                           <i class="fas fa-clock text-warning"></i>
+                           </span>`;
                     } else if (row.OperationalStatus === this.operationalStateSecondStep) {
                         return `<span class="icon-label" title="${row.OperationalStatus}">
-                        <i class="fas fa-check-circle text-success"></i>
-                        </span>`;
+                           <i class="fas fa-check-circle text-success"></i>
+                           </span>`;
                     } else if (row.OperationalStatus === this.operationalStateThirdStep) {
                         return `<span class="icon-label" title="${row.OperationalStatus}">
-                        <i class="fas fa-times-circle text-danger"></i>
-                        </span>`;
+                           <i class="fas fa-times-circle text-danger"></i>
+                           </span>`;
                     } else if (row.OperationalStatus === this.operationalStateFourthStep) {
                         return `<span class="icon-label" title="${row.OperationalStatus}">
-                        <i class="fas fa-compress-alt text-success"></i>
-                        </span>`;
+                           <i class="fas fa-compress-alt text-success"></i>
+                           </span>`;
+                    }
+                    else if (row.OperationalStatus === this.operationalStateFifthStep) {
+                        return `<span class="icon-label" title="${row.OperationalStatus}">
+                           <i class="fas fa-briefcase-medical text-success"></i>
+                           </span>`;
                     } else {
                         return `<span>${row.OperationalStatus}</span>`;
                     }
@@ -199,16 +218,16 @@ export class NSInstancesComponent implements OnInit {
                 valuePrepareFunction: (cell: NSDInstanceData, row: NSDInstanceData): string => {
                     if (row.ConfigStatus === this.configStateFirstStep) {
                         return `<span class="icon-label" title="${row.ConfigStatus}">
-                        <i class="fas fa-clock text-warning"></i>
-                        </span>`;
+                           <i class="fas fa-clock text-warning"></i>
+                           </span>`;
                     } else if (row.ConfigStatus === this.configStateSecondStep) {
                         return `<span class="icon-label" title="${row.ConfigStatus}">
-                        <i class="fas fa-check-circle text-success"></i>
-                        </span>`;
+                           <i class="fas fa-check-circle text-success"></i>
+                           </span>`;
                     } else if (row.ConfigStatus === this.configStateThirdStep) {
                         return `<span class="icon-label" title="${row.ConfigStatus}">
-                        <i class="fas fa-times-circle text-danger"></i>
-                        </span>`;
+                           <i class="fas fa-times-circle text-danger"></i>
+                           </span>`;
                     } else {
                         return `<span>${row.ConfigStatus}</span>`;
                     }
@@ -243,7 +262,9 @@ export class NSInstancesComponent implements OnInit {
                     vnfID: nsdInstanceData['vnfd-id'],
                     nsd: nsdInstanceData.nsd,
                     'nsd-id': nsdInstanceData['nsd-id'],
-                    vcaStatus: nsdInstanceData.vcaStatus
+                    vcaStatus: nsdInstanceData.vcaStatus,
+                    constituent: nsdInstanceData['constituent-vnfr-ref'],
+                    'create-time': this.sharedService.convertEpochTime(Number(nsdInstanceData['create-time']))
                 };
                 this.nsInstanceData.push(nsDataObj);
             });
@@ -254,7 +275,9 @@ export class NSInstancesComponent implements OnInit {
             }
             this.dataSource.load(this.nsInstanceData).then((data: {}): void => {
                 this.isLoadingResults = false;
-            }).catch();
+            }).catch((): void => {
+                // Catch Navigation Error
+            });
         }, (error: ERRORDATA): void => {
             this.restService.handleError(error, 'get');
             this.isLoadingResults = false;
@@ -268,18 +291,53 @@ 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();
             }
-        }).catch();
+        }).catch((): void => {
+            // Catch Navigation Error
+        });
     }
 
     /**