| 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 K8 Action Component |
| 20 | */ |
| 21 | import { Component, Injector } from '@angular/core'; |
| 22 | import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; |
| 23 | import { TranslateService } from '@ngx-translate/core'; |
| 24 | import { MODALCLOSERESPONSEDATA } from 'CommonModel'; |
| 25 | import { DeleteComponent } from 'DeleteComponent'; |
| 26 | import { K8SCLUSTERDATADISPLAY, K8SREPODATADISPLAY } from 'K8sModel'; |
| 27 | import { SharedService } from 'SharedService'; |
| 28 | import { ShowInfoComponent } from 'ShowInfoComponent'; |
| 29 | /** |
| 30 | * Creating component |
| 31 | * @Component takes K8sActionComponent.html as template url |
| 32 | */ |
| 33 | @Component({ |
| 34 | selector: 'app-k8s-action', |
| 35 | templateUrl: './K8sActionComponent.html', |
| 36 | styleUrls: ['./K8sActionComponent.scss'] |
| 37 | }) |
| 38 | /** Exporting a class @exports K8sActionComponent */ |
| 39 | export class K8sActionComponent{ |
| 40 | /** To inject services @public */ |
| 41 | public injector: Injector; |
| 42 | |
| 43 | /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */ |
| 44 | public value: K8SCLUSTERDATADISPLAY | K8SREPODATADISPLAY; |
| 45 | |
| 46 | /** handle translate @public */ |
| 47 | public translateService: TranslateService; |
| 48 | |
| 49 | /** Contains K8s Type @private */ |
| 50 | public getK8sType: string; |
| 51 | |
| 52 | /** Instance of the modal service @private */ |
| 53 | private modalService: NgbModal; |
| 54 | |
| 55 | /** Contains all methods related to shared @private */ |
| 56 | private sharedService: SharedService; |
| 57 | |
| 58 | /** Contains instance ID @private */ |
| 59 | private instanceID: string; |
| 60 | |
| 61 | constructor(injector: Injector) { |
| 62 | this.injector = injector; |
| 63 | this.modalService = this.injector.get(NgbModal); |
| 64 | this.sharedService = this.injector.get(SharedService); |
| 65 | this.translateService = this.injector.get(TranslateService); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Lifecyle Hooks the trigger before component is instantiate |
| 70 | */ |
| 71 | public ngOnInit(): void { |
| 72 | this.instanceID = this.value.identifier; |
| 73 | this.getK8sType = this.value.pageType; |
| 74 | } |
| 75 | |
| 76 | /** Delete User Account @public */ |
| 77 | public deleteK8s(pageType: string): 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 | /** Shows information using modalservice @public */ |
| 87 | public infoK8s(pageType: string): void { |
| 88 | let pageName: string = ''; |
| 89 | let title: string = ''; |
| 90 | if (pageType === 'repo') { |
| 91 | pageName = 'k8s-repo'; |
| 92 | title = 'PAGE.K8S.K8SREPODETAILS'; |
| 93 | } else { |
| 94 | pageName = 'k8s-cluster'; |
| 95 | title = 'PAGE.K8S.K8SCLUSTERDETAILS'; |
| 96 | } |
| 97 | this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = { |
| 98 | id: this.instanceID, |
| 99 | page: pageName, |
| 100 | titleName: title |
| 101 | }; |
| 102 | } |
| 103 | } |