| 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'; |
| 27 | import { SharedService } from 'SharedService'; |
| 28 | import { VIMData } from 'VimAccountModel'; |
| 29 | |
| 30 | /** |
| 31 | * Creating component |
| 32 | * @Component takes VimAccountsActionComponent.html as template url |
| 33 | */ |
| 34 | @Component({ |
| 35 | selector: 'app-vim-accounts-action', |
| 36 | templateUrl: './VimAccountsActionComponent.html', |
| 37 | styleUrls: ['./VimAccountsActionComponent.scss'] |
| 38 | }) |
| 39 | /** Exporting a class @exports VimAccountsActionComponent */ |
| 40 | export class VimAccountsActionComponent implements OnInit { |
| 41 | /** To get the value from the vimAccounts via valuePrepareFunction default Property of ng-smarttable @public */ |
| 42 | public value: VIMData; |
| 43 | |
| 44 | /** To inject services @public */ |
| 45 | public injector: Injector; |
| 46 | |
| 47 | /** To show Instances running @public */ |
| 48 | public showMapIcon: boolean = false; |
| 49 | |
| 50 | /** To show Details Instances running @public */ |
| 51 | public showInstanceDetails: {}[]; |
| 52 | |
| 53 | /** Instance of the modal service @private */ |
| 54 | private modalService: NgbModal; |
| 55 | |
| 56 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 57 | private router: Router; |
| 58 | |
| 59 | /** Variables holds NS ID @private */ |
| 60 | private vimID: string; |
| 61 | |
| 62 | /** Contains all methods related to shared @private */ |
| 63 | private sharedService: SharedService; |
| 64 | |
| 65 | constructor(injector: Injector) { |
| 66 | this.injector = injector; |
| 67 | this.modalService = this.injector.get(NgbModal); |
| 68 | this.router = this.injector.get(Router); |
| 69 | this.sharedService = this.injector.get(SharedService); |
| 70 | } |
| 71 | /** Lifecyle Hooks the trigger before component is instantiate @public */ |
| 72 | public ngOnInit(): void { |
| 73 | this.getInstancesDetails(); |
| 74 | } |
| 75 | |
| 76 | /** Delete VIM Account @public */ |
| 77 | public deleteVIMAccount(): void { |
| 78 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, {backdrop: 'static'}); |
| 79 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 80 | if (result) { |
| 81 | this.sharedService.callData(); |
| 82 | } |
| 83 | }).catch(); |
| 84 | } |
| 85 | |
| 86 | /** On navigate to Info VimAccount @public */ |
| 87 | public vimInfo(): void { |
| 88 | this.vimID = this.value.identifier; |
| 89 | this.router.navigate(['/vim/info', this.vimID]).catch(() => { |
| 90 | // Catch Navigation Error |
| 91 | }); |
| 92 | } |
| 93 | |
| 94 | /** To show the Instances Info for the particular VimAccount @public */ |
| 95 | public getInstancesDetails(): void { |
| 96 | this.showInstanceDetails = []; |
| 97 | this.value.instancesData.filter((item: NSInstanceDetails) => { |
| 98 | if (item.datacenter === this.value.identifier) { |
| 99 | this.showMapIcon = true; |
| 100 | this.showInstanceDetails.push(item); |
| 101 | } |
| 102 | }); |
| 103 | } |
| 104 | } |