blob: c709672a183b343d6d731a89385857e57479fdd4 [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 Delete Model
20 */
21import { HttpHeaders } from '@angular/common/http';
22import { Component, Injector, Input } from '@angular/core';
23import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24import { TranslateService } from '@ngx-translate/core';
25import { NotifierService } from 'angular-notifier';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053026import { APIURLHEADER, DELETEPARAMS, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { DataService } from 'DataService';
28import { environment } from 'environment';
29import { RestService } from 'RestService';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053030import { isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053031
32/**
33 * Creating component
34 * @Component takes DeleteComponent.html as template url
35 */
36@Component({
37 selector: 'app-delete',
38 templateUrl: './DeleteComponent.html',
39 styleUrls: ['./DeleteComponent.scss']
40})
41/** Exporting a class @exports DeleteComponent */
42export class DeleteComponent {
43 /** To inject services @public */
44 public injector: Injector;
45
46 /** Instance for active modal service @public */
47 public activeModal: NgbActiveModal;
48
49 /** Instance of the modal service @public */
50 public title: string;
51
52 /** Show the Delete Ok button to trigger the terminate and delete */
53 public forceDelete: boolean = false;
54
55 /** Check the loading results @public */
56 public isLoadingResults: Boolean = false;
57
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053058 /** Check the page @public */
SANDHYA.JS26570112024-07-05 21:35:46 +053059 public isPage = false;
60
61 /** Check the register page @public */
62 public isRegisterPage = false;
63
64 /** contain page @public */
65 public page: string;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +053066
67 /** Number of instances @public */
68 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
69 public noOfInstances: Number = 25;
70
kumaran.m3b4814a2020-05-01 19:48:54 +053071 /** Give the message for the loading @public */
72 public notifyMessage: string = 'DELETELOADERMESSAGE';
73
74 /** Give the message for the loading @public */
75 public message: string = 'PLEASEWAIT';
76
77 /** DataService to pass the data from one component to another @private */
78 private dataService: DataService;
79
80 /** Instance of the rest service @private */
81 private restService: RestService;
82
83 /** Instance of the modal service @private */
84 private id: string;
85
86 /** Variables holds url to be delete @private */
87 private deleteURL: string;
88
89 /** Controls the header form @private */
90 private headers: HttpHeaders;
91
92 /** Input contains component objects @private */
93 @Input() private params: URLPARAMS;
94
95 /** Notifier service to popup notification @private */
96 private notifierService: NotifierService;
97
98 /** Contains tranlsate instance @private */
99 private translateService: TranslateService;
100
101 constructor(injector: Injector) {
102 this.injector = injector;
103 this.restService = this.injector.get(RestService);
104 this.dataService = this.injector.get(DataService);
105 this.activeModal = this.injector.get(NgbActiveModal);
106 this.notifierService = this.injector.get(NotifierService);
107 this.translateService = this.injector.get(TranslateService);
108 }
109
110 /**
111 * Lifecyle Hooks the trigger before component is instantiate
112 */
113 public ngOnInit(): void {
114 this.headers = new HttpHeaders({
115 'Content-Type': 'application/json',
116 Accept: 'application/json',
117 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
118 });
119 this.dataService.currentMessage.subscribe((data: DELETEPARAMS) => {
120 if (data.identifier !== undefined || data.identifier !== '' || data.identifier !== null) {
121 this.id = data.identifier;
122 }
SANDHYA.JS26570112024-07-05 21:35:46 +0530123 if (sessionStorage.getItem('clusterType') === 'Registered') {
124 this.isRegisterPage = true;
125 }
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530126 if (!isNullOrUndefined(this.params)) {
127 if (this.params.page === 'instantiateNS') {
128 this.isPage = true;
129 this.title = '';
130 this.createDeleteUrl(data);
131 } else if (this.params.page === 'ns-instance') {
132 this.createDeleteUrl(data);
133 this.isPage = false;
SANDHYA.JS26570112024-07-05 21:35:46 +0530134 } else {
135 this.createTitleandID(data);
136 this.createDeleteUrl(data);
137 this.isPage = false;
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530138 }
139 } else {
140 this.createTitleandID(data);
141 this.createDeleteUrl(data);
142 this.isPage = false;
143 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530144 });
145 }
146 /** Generate Title and Id from data @public */
147 public createTitleandID(data: DELETEPARAMS): void {
148 this.title = '';
149 if (data.name !== undefined) {
150 this.title = data.name;
kumaran.m3b4814a2020-05-01 19:48:54 +0530151 } else if (data.projectName !== undefined) {
152 this.title = data.projectName;
153 this.id = this.title;
154 } else if (data.userName !== undefined) {
155 this.title = data.userName;
156 } else if (data.username !== undefined) {
157 this.title = data.username;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530158 } else if (data.productName !== undefined) {
159 this.title = data.productName;
kumaran.m3b4814a2020-05-01 19:48:54 +0530160 }
161 }
162 /** Generate Delete url from data @public */
SANDHYA.JS26570112024-07-05 21:35:46 +0530163 // eslint-disable-next-line complexity
kumaran.m3b4814a2020-05-01 19:48:54 +0530164 public createDeleteUrl(data: DELETEPARAMS): void {
165 this.deleteURL = '';
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530166 if (!isNullOrUndefined(this.params)) {
167 if (this.params.page === 'ns-instance') {
168 this.deleteURL = environment.NSINSTANCESCONTENT_URL;
169 this.forceDelete = this.params.forceDeleteType;
170 this.title = this.params.name;
171 this.id = this.params.id;
172 } else if (this.params.page === 'instantiateNS') {
173 this.deleteURL = environment.NSINSTANCESTERMINATE_URL;
174 this.notifyMessage = 'DELETEDSUCCESSFULLY';
175 }
176 }
177 if (data.page === 'ns-package') {
kumaran.m3b4814a2020-05-01 19:48:54 +0530178 this.deleteURL = environment.NSDESCRIPTORSCONTENT_URL;
179 this.notifyMessage = 'DELETEDSUCCESSFULLY';
180 } else if (data.page === 'vnf-package') {
181 this.deleteURL = environment.VNFPACKAGESCONTENT_URL;
182 this.notifyMessage = 'DELETEDSUCCESSFULLY';
183 } else if (data.page === 'vim-account') {
184 this.deleteURL = environment.VIMACCOUNTS_URL;
185 this.notifyMessage = 'DELETEDSUCCESSFULLY';
186 } else if (data.page === 'wim-account') {
187 this.deleteURL = environment.WIMACCOUNTS_URL;
188 this.notifyMessage = 'DELETEDSUCCESSFULLY';
189 } else if (data.page === 'projects') {
190 this.deleteURL = environment.PROJECTS_URL;
191 this.notifyMessage = 'DELETEDSUCCESSFULLY';
192 this.id = data.id;
193 } else if (data.page === 'users') {
194 this.deleteURL = environment.USERS_URL;
195 this.notifyMessage = 'DELETEDSUCCESSFULLY';
196 } else if (data.page === 'network-slice') {
197 this.deleteURL = environment.NETWORKSLICETEMPLATECONTENT_URL;
198 this.notifyMessage = 'DELETEDSUCCESSFULLY';
199 } else if (data.page === 'net-slice-instance') {
200 this.deleteURL = environment.NETWORKSLICEINSTANCESCONTENT_URL;
201 this.forceDelete = this.params.forceDeleteType;
202 } else if (data.page === 'roles') {
203 this.deleteURL = environment.ROLES_URL;
204 this.notifyMessage = 'DELETEDSUCCESSFULLY';
205 } else if (data.page === 'pdu-instances') {
206 this.deleteURL = environment.PDUINSTANCE_URL;
207 } else if (data.page === 'sdn-controller') {
208 this.deleteURL = environment.SDNCONTROLLER_URL;
209 this.notifyMessage = 'DELETEDSUCCESSFULLY';
kumaran.m3b4814a2020-05-01 19:48:54 +0530210 } else if (data.page === 'k8-repo') {
211 this.deleteURL = environment.K8REPOS_URL;
212 this.notifyMessage = 'DELETEDSUCCESSFULLY';
Barath Kumar R403234e2020-07-07 15:48:58 +0530213 } else if (data.page === 'osmrepo') {
214 this.deleteURL = environment.OSMREPOS_URL;
215 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS07decc02024-07-01 21:50:48 +0530216 } else if (data.page === 'ns-config-template') {
217 this.deleteURL = environment.NSCONFIGTEMPLATE_URL;
218 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS26570112024-07-05 21:35:46 +0530219 } else if (data.page === 'k8-infra-profile') {
220 this.deleteURL = environment.K8SINFRACONFIGPROFILE_URL;
221 } else if (data.page === 'k8-infra-controller') {
222 this.deleteURL = environment.K8SINFRACONTROLLERPROFILE_URL;
223 } else if (data.page === 'k8-app-profile') {
224 this.deleteURL = environment.K8SAPPPROFILE_URL;
225 } else if (data.page === 'k8-resource-profile') {
226 this.deleteURL = environment.K8SRESOURCEPROFILE_URL;
227 } else if (data.page === 'oka-packages') {
228 this.deleteURL = environment.OKAPACKAGES_URL;
229 } else if (data.page === 'k8-ksu') {
230 this.deleteURL = environment.KSU_URL;
231 } else if (data.page === 'k8-cluster') {
232 this.page = data.page;
233 if (sessionStorage.getItem('clusterType') === 'Managed' || sessionStorage.getItem('clusterType') === 'Registered') {
234 this.deleteURL = environment.K8SCREATECLUSTER_URL;
235 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530236 }
237 }
238 /** Generate Data function @public */
239 public deleteData(): void {
240 this.isLoadingResults = true;
241 const modalData: MODALCLOSERESPONSEDATA = {
242 message: 'Done'
243 };
244 let deletingURl: string = '';
245 if (this.forceDelete) {
246 deletingURl = this.deleteURL + '/' + this.id + '?FORCE=true';
247 this.notifyMessage = 'DELETEDSUCCESSFULLY';
SANDHYA.JS26570112024-07-05 21:35:46 +0530248 } else if (this.page === 'k8-cluster' && sessionStorage.getItem('clusterType') === 'Registered') {
249 deletingURl = this.deleteURL + '/' + this.id + '/deregister';
kumaran.m3b4814a2020-05-01 19:48:54 +0530250 } else {
251 deletingURl = this.deleteURL + '/' + this.id;
252 }
253 this.restService.deleteResource(deletingURl).subscribe((res: {}) => {
254 this.activeModal.close(modalData);
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530255 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage, { title: this.title }));
kumaran.m3b4814a2020-05-01 19:48:54 +0530256 }, (error: ERRORDATA) => {
257 this.isLoadingResults = false;
258 this.restService.handleError(error, 'delete');
259 }, () => {
260 this.isLoadingResults = false;
261 });
262 }
SANDHYA.JS8ead52b2024-06-10 18:23:41 +0530263
264 /** terminate multiple ns instances function @public */
265 public terminate(): void {
266 this.isLoadingResults = true;
267 const modalData: MODALCLOSERESPONSEDATA = {
268 message: 'Done'
269 };
270 const idData: string[] = [];
271 this.params.identifierList.forEach((data: DELETEPARAMS) => {
272 idData.push(data.identifier);
273 });
274 if (idData.length > this.noOfInstances) {
275 this.activeModal.close(modalData);
276 this.notifierService.notify('warning', this.translateService.instant('WARNINGMESSAGE'));
277 } else {
278 const postData: {} = {
279 ns_ids: idData
280 };
281 let deletingURl: string = '';
282 deletingURl = this.deleteURL;
283 this.notifyMessage = 'DELETELOADMESSAGE';
284 const apiURLHeader: APIURLHEADER = {
285 url: deletingURl,
286 httpOptions: { headers: this.headers }
287 };
288 this.restService.postResource(apiURLHeader, postData).subscribe(() => {
289 this.activeModal.close(modalData);
290 this.isLoadingResults = false;
291 this.notifierService.notify('success', this.translateService.instant(this.notifyMessage));
292 }, (error: ERRORDATA) => {
293 this.isLoadingResults = false;
294 this.restService.handleError(error, 'post');
295 }, () => {
296 this.isLoadingResults = false;
297 });
298 }
299 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530300}