X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Futilities%2Fdelete%2FDeleteComponent.ts;h=b403e9bd46d1d00337173ba81573a2f7968cef2a;hb=refs%2Fheads%2Fmaster;hp=4baee646f1be3ccca4bdf42808234dcc8a7d844f;hpb=3b4814aa2d3dec621dadb52f058ba95a3dc3a86a;p=osm%2FNG-UI.git diff --git a/src/app/utilities/delete/DeleteComponent.ts b/src/app/utilities/delete/DeleteComponent.ts index 4baee64..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 */ @@ -115,8 +135,6 @@ export class DeleteComponent { this.title = ''; if (data.name !== undefined) { this.title = data.name; - } else if (data.shortName !== undefined) { - this.title = data.shortName; } else if (data.projectName !== undefined) { this.title = data.projectName; this.id = this.title; @@ -124,15 +142,25 @@ export class DeleteComponent { this.title = data.userName; } else if (data.username !== undefined) { this.title = data.username; + } else if (data.productName !== undefined) { + this.title = data.productName; } } /** 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') { @@ -171,6 +199,9 @@ export class DeleteComponent { } else if (data.page === 'k8-repo') { this.deleteURL = environment.K8REPOS_URL; this.notifyMessage = 'DELETEDSUCCESSFULLY'; + } else if (data.page === 'osmrepo') { + this.deleteURL = environment.OSMREPOS_URL; + this.notifyMessage = 'DELETEDSUCCESSFULLY'; } } /** Generate Data function @public */ @@ -188,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'); @@ -196,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; + }); + } + } }