Fix Bug 2291: No option to update VIM Account in NG-UI
[osm/NG-UI.git] / src / app / utilities / vim-accounts-action / VimAccountsActionComponent.ts
1 /*
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  */
21 import { Component, Injector, OnInit } from '@angular/core';
22 import { Router } from '@angular/router';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
25 import { DeleteComponent } from 'DeleteComponent';
26 import { NSInstanceDetails } from 'NSInstanceModel';
27 import { ResourcesOverviewComponent } from 'ResourcesOverviewComponent';
28 import { SharedService } from 'SharedService';
29 import { VimAccountDetails, VIMData } from 'VimAccountModel';
30
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 */
41 export 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 */
49     public showMapIcon: boolean = false;
50
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 {
79         // eslint-disable-next-line security/detect-non-literal-fs-filename
80         const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
81         modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
82             if (result) {
83                 this.sharedService.callData();
84             }
85         }).catch((): void => {
86             // Catch Navigation Error
87         });
88     }
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
95         });
96     }
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     }
108
109     /** Show VIM Resources Data @public */
110     public showVIMResources(vimDetails: VimAccountDetails): void {
111         // eslint-disable-next-line security/detect-non-literal-fs-filename
112         const modalRef: NgbModalRef = this.modalService.open(ResourcesOverviewComponent, { backdrop: 'static' });
113         modalRef.componentInstance.resourcesData = vimDetails;
114     }
115
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     }
123 }