| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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'; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 27 | import { ResourcesOverviewComponent } from 'ResourcesOverviewComponent'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 28 | import { SharedService } from 'SharedService'; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 29 | import { VimAccountDetails, VIMData } from 'VimAccountModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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 { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame^] | 79 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 80 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, {backdrop: 'static'}); |
| 81 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 82 | if (result) { |
| 83 | this.sharedService.callData(); |
| 84 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame^] | 85 | }).catch((): void => { |
| 86 | // Catch Navigation Error |
| 87 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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 | } |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 108 | |
| 109 | /** Show VIM Resources Data @public */ |
| 110 | public showVIMResources(vimDetails: VimAccountDetails): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame^] | 111 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 112 | const modalRef: NgbModalRef = this.modalService.open(ResourcesOverviewComponent, {backdrop: 'static'}); |
| 113 | modalRef.componentInstance.resourcesData = vimDetails; |
| 114 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 115 | } |