blob: 14862ebeaea932af106e97b3cabf1b25801e9993 [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 AccountsAction Component
20 */
21import { Component, Injector, OnInit } from '@angular/core';
22import { Router } from '@angular/router';
23import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24import { MODALCLOSERESPONSEDATA } from 'CommonModel';
25import { DeleteComponent } from 'DeleteComponent';
26import { NSInstanceDetails } from 'NSInstanceModel';
SANDHYA.JS4a7a5422021-05-15 15:35:22 +053027import { ResourcesOverviewComponent } from 'ResourcesOverviewComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053028import { SharedService } from 'SharedService';
SANDHYA.JS4a7a5422021-05-15 15:35:22 +053029import { VimAccountDetails, VIMData } from 'VimAccountModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053030
31/**
32 * Creating component
33 * @Component takes VimAccountsActionComponent.html as template url
34 */
35@Component({
36 selector: 'app-vim-accounts-action',
37 templateUrl: './VimAccountsActionComponent.html',
38 styleUrls: ['./VimAccountsActionComponent.scss']
39})
40/** Exporting a class @exports VimAccountsActionComponent */
41export class VimAccountsActionComponent implements OnInit {
42 /** To get the value from the vimAccounts via valuePrepareFunction default Property of ng-smarttable @public */
43 public value: VIMData;
44
45 /** To inject services @public */
46 public injector: Injector;
47
48 /** To show Instances running @public */
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053049 public showMapIcon: boolean = false;
kumaran.m3b4814a2020-05-01 19:48:54 +053050
51 /** To show Details Instances running @public */
52 public showInstanceDetails: {}[];
53
54 /** Instance of the modal service @private */
55 private modalService: NgbModal;
56
57 /** Holds teh instance of AuthService class of type AuthService @private */
58 private router: Router;
59
60 /** Variables holds NS ID @private */
61 private vimID: string;
62
63 /** Contains all methods related to shared @private */
64 private sharedService: SharedService;
65
66 constructor(injector: Injector) {
67 this.injector = injector;
68 this.modalService = this.injector.get(NgbModal);
69 this.router = this.injector.get(Router);
70 this.sharedService = this.injector.get(SharedService);
71 }
72 /** Lifecyle Hooks the trigger before component is instantiate @public */
73 public ngOnInit(): void {
74 this.getInstancesDetails();
75 }
76
77 /** Delete VIM Account @public */
78 public deleteVIMAccount(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053079 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053080 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
kumaran.m3b4814a2020-05-01 19:48:54 +053081 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
82 if (result) {
83 this.sharedService.callData();
84 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053085 }).catch((): void => {
86 // Catch Navigation Error
87 });
kumaran.m3b4814a2020-05-01 19:48:54 +053088 }
89
90 /** On navigate to Info VimAccount @public */
91 public vimInfo(): void {
92 this.vimID = this.value.identifier;
93 this.router.navigate(['/vim/info', this.vimID]).catch(() => {
94 // Catch Navigation Error
SANDHYA.JSeb9c4822023-10-11 16:29:27 +053095 });
kumaran.m3b4814a2020-05-01 19:48:54 +053096 }
97
98 /** To show the Instances Info for the particular VimAccount @public */
99 public getInstancesDetails(): void {
100 this.showInstanceDetails = [];
101 this.value.instancesData.filter((item: NSInstanceDetails) => {
102 if (item.datacenter === this.value.identifier) {
103 this.showMapIcon = true;
104 this.showInstanceDetails.push(item);
105 }
106 });
107 }
SANDHYA.JS4a7a5422021-05-15 15:35:22 +0530108
109 /** Show VIM Resources Data @public */
110 public showVIMResources(vimDetails: VimAccountDetails): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530111 // eslint-disable-next-line security/detect-non-literal-fs-filename
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530112 const modalRef: NgbModalRef = this.modalService.open(ResourcesOverviewComponent, { backdrop: 'static' });
SANDHYA.JS4a7a5422021-05-15 15:35:22 +0530113 modalRef.componentInstance.resourcesData = vimDetails;
114 }
SANDHYA.JSeb9c4822023-10-11 16:29:27 +0530115
116 /** On navigate to edit VimAccount @public */
117 public editVIM(): void {
118 this.vimID = this.value.identifier;
119 this.router.navigate(['/vim/edit', this.vimID]).catch(() => {
120 // Catch Navigation Error
121 });
122 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530123}