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
/** 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';
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 */
/** 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') {
}
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');
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;
+ });
+ }
+ }
}