blob: a942e9e64c8c0bf7b0395ac484eb6d8364e3580f [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 Vim Account Component.
20 */
21import { HttpHeaders } from '@angular/common/http';
22import { Component, ElementRef, Injector, OnInit, ViewChild } from '@angular/core';
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053023import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
24import { ActivatedRoute, Router } from '@angular/router';
25import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
kumaran.m3b4814a2020-05-01 19:48:54 +053026import { TranslateService } from '@ngx-translate/core';
27import { NotifierService } from 'angular-notifier';
Barath Kumar Rd477b852020-07-07 15:24:05 +053028import 'codemirror/addon/dialog/dialog';
29import 'codemirror/addon/display/autorefresh';
30import 'codemirror/addon/display/fullscreen';
31import 'codemirror/addon/edit/closebrackets';
32import 'codemirror/addon/edit/matchbrackets';
33import 'codemirror/addon/fold/brace-fold';
34import 'codemirror/addon/fold/foldcode';
35import 'codemirror/addon/fold/foldgutter';
36import 'codemirror/addon/search/search';
37import 'codemirror/addon/search/searchcursor';
38import 'codemirror/keymap/sublime';
39import 'codemirror/lib/codemirror';
40import 'codemirror/mode/javascript/javascript';
41import 'codemirror/mode/markdown/markdown';
42import 'codemirror/mode/yaml/yaml';
43import {
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053044 APIURLHEADER, CONFIGCONSTANT, ERRORDATA, MODALCLOSERESPONSEDATA, TYPEAWS, TYPEAZURE, TYPEOPENSTACK, TYPEOPENVIMNEBULA, TYPEOTERS,
lloretgalleg3e906e22025-03-21 10:27:22 +000045 TYPESECTION, TYPEVMWARE, TYPEVCENTER, VIM_TYPES
Barath Kumar Rd477b852020-07-07 15:24:05 +053046} from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053047import { environment } from 'environment';
48import * as jsyaml from 'js-yaml';
49import { RestService } from 'RestService';
SANDHYA.JSc84f1122024-06-04 21:50:03 +053050import { SharedService, isNullOrUndefined } from 'SharedService';
SANDHYA.JS4a7a5422021-05-15 15:35:22 +053051import { VimAccountDetails } from 'VimAccountModel';
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053052import { WarningComponent } from 'WarningComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053053/**
54 * Creating component
55 * @Component takes NewVimaccountComponent.html as template url
56 */
57@Component({
58 selector: 'app-new-vimaccount',
59 templateUrl: './NewVimaccountComponent.html',
60 styleUrls: ['./NewVimaccountComponent.scss']
61})
62/** Exporting a class @exports NewVimaccountComponent */
63export class NewVimaccountComponent implements OnInit {
64 /** To inject services @public */
65 public injector: Injector;
66
67 /** FormGroup vim New Account added to the form @ html @public */
68 public vimNewAccountForm: FormGroup;
69
70 /** Supported Vim type for the dropdown */
71 public vimType: TYPESECTION[];
72
73 /** Supported Vim type for the dropdown */
74 public selectedVimType: string;
75
kumaran.m3b4814a2020-05-01 19:48:54 +053076 /** Form submission Add */
77 public submitted: boolean = false;
78
79 /** Showing more details of collapase */
80 public isCollapsed: boolean = false;
81
kumaran.m3b4814a2020-05-01 19:48:54 +053082 /** Check the Projects loading results @public */
83 public isLocationLoadingResults: boolean = false;
84
85 /** Give the message for the loading @public */
86 public message: string = 'PLEASEWAIT';
87
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053088 /** Set the check value @public */
89 public check: boolean = false;
90
Barath Kumar Rd477b852020-07-07 15:24:05 +053091 /** Handle the formate Change @public */
92 public defaults: {} = {
93 'text/x-yaml': ''
94 };
95
96 /** To Set Mode @public */
97 public mode: string = 'text/x-yaml';
98
99 /** To Set Mode @public */
100 public modeDefault: string = 'yaml';
101
102 /** options @public */
103 public options: {} = {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530104 // eslint-disable-next-line no-invalid-this
Barath Kumar Rd477b852020-07-07 15:24:05 +0530105 mode: this.modeDefault,
106 showCursorWhenSelecting: true,
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530107 autofocus: false,
Barath Kumar Rd477b852020-07-07 15:24:05 +0530108 autoRefresh: true,
109 lineNumbers: true,
110 lineWrapping: true,
111 foldGutter: true,
112 gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
113 autoCloseBrackets: true,
114 matchBrackets: true,
115 theme: 'neat',
116 keyMap: 'sublime'
117 };
118
119 /** Data @public */
120 public data: string = '';
121
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530122 /** contains vim ID @public */
123 public vimID: string;
124
kumaran.m3b4814a2020-05-01 19:48:54 +0530125 /** Element ref for fileInput @public */
126 @ViewChild('fileInput', { static: true }) public fileInput: ElementRef;
127
128 /** Element ref for fileInput @public */
129 @ViewChild('fileInputLabel', { static: true }) public fileInputLabel: ElementRef;
130
SANDHYA.JSdb033b52024-09-20 12:17:59 +0530131 /** Element ref for filecredsInput @public */
132 @ViewChild('fileInputcreds', { static: true }) public fileInputcreds: ElementRef;
133
134 /** Element ref for filecredsInput @public */
135 @ViewChild('fileInputcredsLabel', { static: true }) public fileInputcredsLabel: ElementRef;
136
Barath Kumar Rd477b852020-07-07 15:24:05 +0530137 /** Contains all methods related to shared @private */
138 public sharedService: SharedService;
139
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530140 /** Check key for the Edit form @public */
141 public checkFormKeys: string[] =
142 [
143 'name',
144 'vim_type',
145 'vim_tenant_name',
146 'description',
147 'vim_url',
148 'schema_type',
149 'vim_user',
150 'vim_password',
151 'locationName',
152 'latitude',
153 'longitude',
154 'config'
155 ];
156
157 /** Contains config details in edit @public */
158 public config: {};
159
160 /** Contains latitude value @public */
161 public latitude: string;
162
163 /** Contains longitude value @public */
164 public longitude: string;
165
SANDHYA.JSdb033b52024-09-20 12:17:59 +0530166 /** Contains credentials value in base64 @public */
167 public credentialsAs64: string;
168
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530169 /** Contains location value @public */
170 public locationName: string;
171
172 /** Contains VIMAccount Details @private */
173 private details: VimAccountDetails;
174
175 /** Contains config with location @private */
176 private configLocation: string;
177
178 /** Check for config length @private */
179 // eslint-disable-next-line @typescript-eslint/no-magic-numbers
180 private configLength: number = 3;
181
SANDHYA.JS46ea49d2023-11-09 12:50:28 +0530182 /** Contains config length from get api @private */
183 private getConfigLength: number;
184
185 /** Contains config when update @private */
186 private updateConfig: object;
187
188 /** Contains config length when update @private */
189 private updateConfigLength: number;
190
kumaran.m3b4814a2020-05-01 19:48:54 +0530191 /** Instance of the rest service @private */
192 private restService: RestService;
193
194 /** Holds the instance of router class @private */
195 private router: Router;
196
197 /** Controls the header form @private */
198 private headers: HttpHeaders;
199
200 /** FormBuilder instance added to the formBuilder @private */
201 private formBuilder: FormBuilder;
202
203 /** Notifier service to popup notification @private */
204 private notifierService: NotifierService;
205
206 /** Contains tranlsate instance @private */
207 private translateService: TranslateService;
208
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530209 /** Holds teh instance of AuthService class of type AuthService @private */
210 private activatedRoute: ActivatedRoute;
211
212 /** Instance of the modal service @private */
213 private modalService: NgbModal;
kumaran.m3b4814a2020-05-01 19:48:54 +0530214
kumaran.m3b4814a2020-05-01 19:48:54 +0530215 constructor(injector: Injector) {
216 this.injector = injector;
217 this.restService = this.injector.get(RestService);
218 this.formBuilder = this.injector.get(FormBuilder);
219 this.router = this.injector.get(Router);
220 this.notifierService = this.injector.get(NotifierService);
221 this.translateService = this.injector.get(TranslateService);
222 this.sharedService = this.injector.get(SharedService);
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530223 this.activatedRoute = this.injector.get(ActivatedRoute);
224 this.modalService = this.injector.get(NgbModal);
Barath Kumar R1245fc82021-04-16 13:34:06 +0530225 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530226
Barath Kumar R1245fc82021-04-16 13:34:06 +0530227 /** convenience getter for easy access to form fields */
228 get f(): FormGroup['controls'] { return this.vimNewAccountForm.controls; }
229
230 /**
231 * Lifecyle Hooks the trigger before component is instantiate
232 */
233 public ngOnInit(): void {
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530234 this.vimID = this.activatedRoute.snapshot.paramMap.get('id');
Barath Kumar R1245fc82021-04-16 13:34:06 +0530235 this.vimType = VIM_TYPES;
236 this.headers = new HttpHeaders({
237 Accept: 'application/json',
238 'Content-Type': 'application/json',
239 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
240 });
241 this.initializeForm();
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530242 if (!isNullOrUndefined(this.vimID)) {
243 this.getVIMDetails(this.vimID);
244 }
Barath Kumar R1245fc82021-04-16 13:34:06 +0530245 }
246
247 /** VIM Initialize Forms @public */
248 public initializeForm(): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530249 this.vimNewAccountForm = this.formBuilder.group({
250 name: [null, Validators.required],
251 vim_type: [null, Validators.required],
252 vim_tenant_name: [null, Validators.required],
253 description: [null],
254 vim_url: [null, [Validators.required, Validators.pattern(this.sharedService.REGX_URL_PATTERN)]],
255 schema_type: [''],
256 vim_user: [null, Validators.required],
257 vim_password: [null, Validators.required],
Barath Kumar R1245fc82021-04-16 13:34:06 +0530258 locationName: [''],
259 latitude: ['', Validators.pattern(this.sharedService.REGX_LAT_PATTERN)],
260 longitude: ['', Validators.pattern(this.sharedService.REGX_LONG_PATTERN)],
Barath Kumar Rd477b852020-07-07 15:24:05 +0530261 config: this.paramsBuilder()
kumaran.m3b4814a2020-05-01 19:48:54 +0530262 });
263 }
264
265 /** Generate params for config @public */
266 public paramsBuilder(): FormGroup {
267 return this.formBuilder.group({
Barath Kumar Rd477b852020-07-07 15:24:05 +0530268 location: [null]
kumaran.m3b4814a2020-05-01 19:48:54 +0530269 });
270 }
271
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530272 /** Fetching the vim details from get api @protected */
273 private getVIMDetails(id: string): void {
274 this.isLocationLoadingResults = true;
275 this.restService.getResource(environment.VIMACCOUNTS_URL + '/' + id).subscribe((vimAccountsData: VimAccountDetails) => {
276 this.details = vimAccountsData;
277 if (!isNullOrUndefined(this.details.config.location)) {
278 this.configLocation = this.details.config.location;
279 if (this.configLocation.indexOf(',') !== -1) {
280 this.locationName = this.configLocation.split(',')[0];
281 this.latitude = this.configLocation.split(',')[1];
282 this.longitude = this.configLocation.split(',')[2];
283 }
284 }
285 delete this.details.config.location;
SANDHYA.JS46ea49d2023-11-09 12:50:28 +0530286 this.getConfigLength = Object.keys(this.details.config).length;
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530287 this.getFormControl('schema_type').disable();
288 this.getFormControl('vim_url').disable();
289 this.getFormControl('vim_type').disable();
290 this.config = { ...this.details.config };
291 this.details.vim_password = '';
292 this.setEditValue(this.details, this.checkFormKeys);
293 this.isLocationLoadingResults = false;
294 }, (error: ERRORDATA) => {
295 this.restService.handleError(error, 'get');
296 this.isLocationLoadingResults = false;
297 });
298 }
299
300 /** Set the value for the Edit Section @public */
301 public setEditValue(formValues: VimAccountDetails, checkKey: string[]): void {
302 Object.keys(formValues).forEach((name: string): void => {
303 if (checkKey.includes(name)) {
304 if (name === 'config') {
305 this.loadConfig();
306 this.getFormControl('locationName').patchValue(this.locationName);
307 this.getFormControl('latitude').patchValue(this.latitude);
308 this.getFormControl('longitude').patchValue(this.longitude);
309 }
310 else {
311 // eslint-disable-next-line security/detect-object-injection
312 this.getFormControl(name).setValue(formValues[name], { onlySelf: true });
313 this.getFormControl(name).updateValueAndValidity();
314 }
315 }
316 });
317 }
318
kumaran.m3b4814a2020-05-01 19:48:54 +0530319 /** On modal submit newVimAccountSubmit will called @public */
320 public newVimAccountSubmit(): void {
321 this.submitted = true;
Barath Kumar R1245fc82021-04-16 13:34:06 +0530322
kumaran.m3b4814a2020-05-01 19:48:54 +0530323 if (!this.vimNewAccountForm.invalid) {
324 this.isLocationLoadingResults = true;
Barath Kumar Rd477b852020-07-07 15:24:05 +0530325 this.sharedService.cleanForm(this.vimNewAccountForm, 'vim');
326 if (!isNullOrUndefined(this.data) && this.data !== '') {
327 Object.assign(this.vimNewAccountForm.value.config, jsyaml.load(this.data.toString(), { json: true }));
328 } else {
Barath Kumar R1245fc82021-04-16 13:34:06 +0530329 Object.keys(this.vimNewAccountForm.value.config).forEach((res: string): void => {
Barath Kumar Rd477b852020-07-07 15:24:05 +0530330 if (res !== 'location') {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530331 // eslint-disable-next-line @typescript-eslint/no-dynamic-delete, security/detect-object-injection
Barath Kumar Rd477b852020-07-07 15:24:05 +0530332 delete this.vimNewAccountForm.value.config[res];
333 }
334 });
335 }
Barath Kumar R1245fc82021-04-16 13:34:06 +0530336 if (!isNullOrUndefined(this.vimNewAccountForm.value.latitude) && !isNullOrUndefined(this.vimNewAccountForm.value.longitude)) {
337 this.vimNewAccountForm.value.config.location = this.vimNewAccountForm.value.locationName + ',' +
338 this.vimNewAccountForm.value.longitude + ',' +
339 this.vimNewAccountForm.value.latitude;
340 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530341
SANDHYA.JSdb033b52024-09-20 12:17:59 +0530342 if (!isNullOrUndefined(this.credentialsAs64)) {
343 this.vimNewAccountForm.value.config.credentials_base64 = this.credentialsAs64;
344 }
345
Barath Kumar Rd477b852020-07-07 15:24:05 +0530346 if (isNullOrUndefined(this.vimNewAccountForm.value.config.location)) {
347 delete this.vimNewAccountForm.value.config.location;
348 }
Barath Kumar R1245fc82021-04-16 13:34:06 +0530349
350 Object.keys(this.vimNewAccountForm.value.config).forEach((res: string): void => {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530351 // eslint-disable-next-line security/detect-object-injection
Barath Kumar Rd477b852020-07-07 15:24:05 +0530352 if (isNullOrUndefined(this.vimNewAccountForm.value.config[res]) || this.vimNewAccountForm.value.config[res] === '') {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530353 // eslint-disable-next-line @typescript-eslint/no-dynamic-delete, security/detect-object-injection
Barath Kumar Rd477b852020-07-07 15:24:05 +0530354 delete this.vimNewAccountForm.value.config[res];
kumaran.m3b4814a2020-05-01 19:48:54 +0530355 }
356 });
SANDHYA.JS46ea49d2023-11-09 12:50:28 +0530357 delete this.vimNewAccountForm.value.config.location;
358 if (!isNullOrUndefined(this.data)) {
359 this.updateConfig = jsyaml.load(this.data, { json: true });
360 if (!isNullOrUndefined(this.updateConfig)) {
361 this.updateConfigLength = Object.keys(this.updateConfig).length;
362 }
363 }
364 if (this.updateConfig === undefined) {
365 this.notifierService.notify('warning', this.translateService.instant('PAGE.VIMDETAILS.VIMDELETE'));
366 this.isLocationLoadingResults = false;
367 } else if (this.getConfigLength > this.updateConfigLength) {
368 this.notifierService.notify('warning', this.translateService.instant('PAGE.VIMDETAILS.VIMEMPTY'));
369 this.isLocationLoadingResults = false;
370 }
371 if (!isNullOrUndefined(this.vimID) && ((this.getConfigLength <= this.updateConfigLength))) {
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530372 this.editVIM();
SANDHYA.JS46ea49d2023-11-09 12:50:28 +0530373 } else if (isNullOrUndefined(this.vimID)) {
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530374 this.createNewVIM();
375 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530376 }
377 }
378
Barath Kumar R1245fc82021-04-16 13:34:06 +0530379 /** Create a new VIM Account @public */
380 public createNewVIM(): void {
381 const apiURLHeader: APIURLHEADER = {
382 url: environment.VIMACCOUNTS_URL,
383 httpOptions: { headers: this.headers }
384 };
385 delete this.vimNewAccountForm.value.locationName;
386 delete this.vimNewAccountForm.value.latitude;
387 delete this.vimNewAccountForm.value.longitude;
388 this.restService.postResource(apiURLHeader, this.vimNewAccountForm.value)
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530389 .subscribe((result: { id: string }): void => {
Barath Kumar R1245fc82021-04-16 13:34:06 +0530390 this.notifierService.notify('success', this.translateService.instant('PAGE.VIM.CREATEDSUCCESSFULLY'));
391 this.isLocationLoadingResults = false;
392 this.router.navigate(['vim/info/' + result.id]).catch((): void => {
393 // Error Cached;
394 });
395 }, (error: ERRORDATA): void => {
396 this.restService.handleError(error, 'post');
397 this.isLocationLoadingResults = false;
398 });
399 }
400
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530401 /** Create a edit VIM Account @public */
402 public editVIM(): void {
403 const apiURLHeader: APIURLHEADER = {
404 url: environment.VIMACCOUNTS_URL + '/' + this.vimID,
405 httpOptions: { headers: this.headers }
406 };
407 delete this.vimNewAccountForm.value.locationName;
408 delete this.vimNewAccountForm.value.latitude;
409 delete this.vimNewAccountForm.value.longitude;
410 this.restService.patchResource(apiURLHeader, this.vimNewAccountForm.value)
411 .subscribe((result: { id: string }): void => {
412 this.notifierService.notify('success', this.translateService.instant('PAGE.VIM.UPDATEDSUCCESSFULLY'));
413 this.isLocationLoadingResults = false;
414 this.router.navigate(['vim/info/' + this.vimID]).catch((): void => {
415 // Error Cached;
416 });
417 }, (error: ERRORDATA): void => {
418 this.restService.handleError(error, 'post');
419 this.isLocationLoadingResults = false;
420 });
421 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530422 /** HandleChange function @public */
423 public handleChange($event: string): void {
424 this.data = $event;
425 }
426
kumaran.m3b4814a2020-05-01 19:48:54 +0530427 /** Routing to VIM Account Details Page @public */
428 public onVimAccountBack(): void {
Barath Kumar R1245fc82021-04-16 13:34:06 +0530429 this.router.navigate(['vim/details']).catch((): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530430 // Error Cached
431 });
432 }
433
kumaran.m3b4814a2020-05-01 19:48:54 +0530434 /** Drag and drop feature and fetchind the details of files @private */
435 public filesDropped(files: FileList): void {
kumaran.m3b4814a2020-05-01 19:48:54 +0530436 if (files && files.length === 1) {
437 this.sharedService.getFileString(files, 'yaml').then((fileContent: string): void => {
438 const getJson: string = jsyaml.load(fileContent, { json: true });
Barath Kumar Rd477b852020-07-07 15:24:05 +0530439 this.defaults['text/x-yaml'] = fileContent;
440 this.data = fileContent;
kumaran.m3b4814a2020-05-01 19:48:54 +0530441 }).catch((err: string): void => {
442 if (err === 'typeError') {
443 this.notifierService.notify('error', this.translateService.instant('YAMLFILETYPEERRROR'));
444 } else {
445 this.notifierService.notify('error', this.translateService.instant('ERROR'));
446 }
447 this.fileInputLabel.nativeElement.innerText = this.translateService.instant('CHOOSEFILE');
448 this.fileInput.nativeElement.value = null;
449 });
450 } else if (files && files.length > 1) {
451 this.notifierService.notify('error', this.translateService.instant('DROPFILESVALIDATION'));
452 }
453 this.fileInputLabel.nativeElement.innerText = files[0].name;
454 this.fileInput.nativeElement.value = null;
455 }
Barath Kumar Rd477b852020-07-07 15:24:05 +0530456
SANDHYA.JSdb033b52024-09-20 12:17:59 +0530457 /** Drag and drop feature and fetchind the details of credential files @private */
458 public onFileSelected(event: Event): void {
459 const input = event.target as HTMLInputElement;
460 if (input && input.files && input.files.length > 0) {
461 const file: File = input.files[0];
462 const reader: FileReader = new FileReader();
463 reader.onload = (e: ProgressEvent<FileReader>) => {
464 const tomlContent = e.target?.result as string;
465 this.credentialsAs64 = btoa(tomlContent);
466 };
467 reader.readAsText(file);
468 }
469 this.fileInputcredsLabel.nativeElement.innerText = input.files[0].name;
470 this.fileInputcreds.nativeElement.value = null;
471 }
472
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530473 /** Check data is empty or not to load config @public */
474 public checkData(): void {
475 if (this.data !== '' && this.data.length > this.configLength) {
476 // eslint-disable-next-line security/detect-non-literal-fs-filename
477 const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' });
478 modalRef.componentInstance.heading = this.translateService.instant('PAGE.VIMDETAILS.VIMHEADER');
479 modalRef.componentInstance.confirmationMessage = this.translateService.instant('PAGE.VIMDETAILS.VIMCONTENT');
480 modalRef.componentInstance.submitMessage = this.translateService.instant('PAGE.VIMDETAILS.VIMSUBMIT');
481 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
482 if (result.message === CONFIGCONSTANT.done) {
483 this.loadSampleConfig();
484 }
485 }).catch((): void => {
486 // Catch Navigation Error
487 });
488 } else if (this.data.length < this.configLength || this.data === '') {
489 this.loadSampleConfig();
490 }
491 }
492
Barath Kumar Rd477b852020-07-07 15:24:05 +0530493 /** Load sample config based on VIM type @public */
494 public loadSampleConfig(): void {
Barath Kumar Rd477b852020-07-07 15:24:05 +0530495 if (this.selectedVimType === 'openstack') {
496 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEOPENSTACK);
497 this.data = JSON.stringify(TYPEOPENSTACK, null, '\t');
498 } else if (this.selectedVimType === 'aws') {
499 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEAWS);
500 this.data = JSON.stringify(TYPEAWS, null, '\t');
lloretgalleg3e906e22025-03-21 10:27:22 +0000501 } else if (this.selectedVimType === 'vcenter') {
502 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEVCENTER);
503 this.data = JSON.stringify(TYPEVCENTER, null, '\t');
Barath Kumar Rd477b852020-07-07 15:24:05 +0530504 } else if (this.selectedVimType === 'vmware') {
505 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEVMWARE);
506 this.data = JSON.stringify(TYPEVMWARE, null, '\t');
507 } else if (this.selectedVimType === 'openvim' || this.selectedVimType === 'opennebula') {
508 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEOPENVIMNEBULA);
509 this.data = JSON.stringify(TYPEOPENVIMNEBULA, null, '\t');
510 } else if (this.selectedVimType === 'azure' || this.selectedVimType === 'opennebula') {
511 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEAZURE);
512 this.data = JSON.stringify(TYPEAZURE, null, '\t');
513 } else {
514 this.defaults['text/x-yaml'] = jsyaml.dump(TYPEOTERS);
515 this.data = JSON.stringify(TYPEOTERS, null, '\t');
516 }
517 }
518
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530519 /** Load sample config based on VIM type in edit @public */
520 public loadConfig(): void {
521 this.clearConfig();
522 if (this.details.vim_type === 'openstack') {
523 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
524 this.data = JSON.stringify(this.config, null, '\t');
525 } else if (this.details.vim_type === 'aws') {
526 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
527 this.data = JSON.stringify(this.config, null, '\t');
528 } else if (this.details.vim_type === 'vmware') {
529 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
530 this.data = JSON.stringify(this.config, null, '\t');
531 } else if (this.details.vim_type === 'openvim' || this.details.vim_type === 'opennebula') {
532 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
533 this.data = JSON.stringify(this.config, null, '\t');
534 } else if (this.details.vim_type === 'azure' || this.details.vim_type === 'opennebula') {
535 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
536 this.data = JSON.stringify(this.config, null, '\t');
537 } else {
538 this.defaults['text/x-yaml'] = jsyaml.dump(this.config);
539 this.data = JSON.stringify(this.config, null, '\t');
540 }
541 }
542
Barath Kumar Rd477b852020-07-07 15:24:05 +0530543 /** Clear config parameters @public */
544 public clearConfig(): void {
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530545 this.check = true;
546 if (this.data !== '' && this.data.length > this.configLength) {
547 // eslint-disable-next-line security/detect-non-literal-fs-filename
548 const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' });
549 modalRef.componentInstance.heading = this.translateService.instant('PAGE.VIMDETAILS.VIMHEADER');
550 modalRef.componentInstance.confirmationMessage = this.translateService.instant('PAGE.VIMDETAILS.CLEARCONTENT');
551 modalRef.componentInstance.submitMessage = this.translateService.instant('PAGE.VIMDETAILS.VIMSUBMIT');
552 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
553 if (result.message === CONFIGCONSTANT.done) {
554 this.defaults['text/x-yaml'] = '';
555 this.data = '';
556 this.fileInput.nativeElement.value = null;
557 }
558 }).catch((): void => {
559 // Catch Navigation Error
560 });
561 } else {
562 this.defaults['text/x-yaml'] = '';
563 this.data = '';
564 this.fileInput.nativeElement.value = null;
565 }
566 }
567
568 /** Used to get the AbstractControl of controlName passed @private */
569 private getFormControl(controlName: string): AbstractControl {
570 // eslint-disable-next-line security/detect-object-injection
571 return this.vimNewAccountForm.controls[controlName];
Barath Kumar Rd477b852020-07-07 15:24:05 +0530572 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530573}