| 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 | |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 10 | Unless required by applicable law or agreed to in writing, software |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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'; |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 26 | import { K8sAddClusterComponent } from 'K8sAddClusterComponent'; |
| 27 | import { K8sAttachProfileComponent } from 'K8sAttachProfileComponent'; |
| 28 | import { K8sInfraConfigAddComponent } from 'K8sInfraConfigAddComponent'; |
| 29 | import { INFRACONFIGPAYLOAD, K8SCLUSTERDATADISPLAY, K8SPayload, K8SREPODATADISPLAY } from 'K8sModel'; |
| 30 | import { KSUAddComponent } from 'KSUAddComponent'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 31 | import { SharedService } from 'SharedService'; |
| 32 | import { ShowInfoComponent } from 'ShowInfoComponent'; |
| 33 | /** |
| 34 | * Creating component |
| 35 | * @Component takes K8sActionComponent.html as template url |
| 36 | */ |
| 37 | @Component({ |
| 38 | selector: 'app-k8s-action', |
| 39 | templateUrl: './K8sActionComponent.html', |
| 40 | styleUrls: ['./K8sActionComponent.scss'] |
| 41 | }) |
| 42 | /** Exporting a class @exports K8sActionComponent */ |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 43 | export class K8sActionComponent { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 44 | /** To inject services @public */ |
| 45 | public injector: Injector; |
| 46 | |
| 47 | /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */ |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 48 | public value: K8SCLUSTERDATADISPLAY | K8SREPODATADISPLAY | INFRACONFIGPAYLOAD; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 49 | |
| 50 | /** handle translate @public */ |
| 51 | public translateService: TranslateService; |
| 52 | |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 53 | /** Contains K8s Type @public */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 54 | public getK8sType: string; |
| 55 | |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 56 | /** Check register page @public */ |
| 57 | public checkRegister = false; |
| 58 | |
| 59 | /** Contains state @public */ |
| 60 | public state: string; |
| 61 | |
| 62 | /** Check profile or not @public */ |
| 63 | public isProfile = false; |
| 64 | |
| 65 | /** Check ksu or not @public */ |
| 66 | public isKSU = false; |
| 67 | |
| 68 | /** Check cluster or not @public */ |
| 69 | public isCluster = false; |
| 70 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 71 | /** Instance of the modal service @private */ |
| 72 | private modalService: NgbModal; |
| 73 | |
| 74 | /** Contains all methods related to shared @private */ |
| 75 | private sharedService: SharedService; |
| 76 | |
| 77 | /** Contains instance ID @private */ |
| 78 | private instanceID: string; |
| 79 | |
| 80 | constructor(injector: Injector) { |
| 81 | this.injector = injector; |
| 82 | this.modalService = this.injector.get(NgbModal); |
| 83 | this.sharedService = this.injector.get(SharedService); |
| 84 | this.translateService = this.injector.get(TranslateService); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Lifecyle Hooks the trigger before component is instantiate |
| 89 | */ |
| 90 | public ngOnInit(): void { |
| 91 | this.instanceID = this.value.identifier; |
| 92 | this.getK8sType = this.value.pageType; |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 93 | this.state = this.value.state; |
| 94 | if (sessionStorage.getItem('clusterType') === 'Registered') { |
| 95 | this.checkRegister = true; |
| 96 | } |
| 97 | if (this.getK8sType === 'infra-config' || this.getK8sType === 'infra-controller' || this.getK8sType === 'app-profile' || this.getK8sType === 'resource-profile') { |
| 98 | this.isCluster = false; |
| 99 | this.isProfile = true; |
| 100 | this.isKSU = false; |
| 101 | } else if (sessionStorage.getItem('clusterType') === 'Managed') { |
| 102 | this.isCluster = true; |
| 103 | this.isProfile = false; |
| 104 | this.isKSU = false; |
| 105 | } |
| 106 | if (this.getK8sType === 'k8-ksu') { |
| 107 | this.isKSU = true; |
| 108 | this.isCluster = false; |
| 109 | this.isProfile = false; |
| 110 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** Delete User Account @public */ |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 114 | public deleteK8s(): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 115 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 116 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); |
| 117 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 118 | if (result) { |
| 119 | this.sharedService.callData(); |
| 120 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 121 | }).catch((): void => { |
| 122 | // Catch Navigation Error |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 123 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** Shows information using modalservice @public */ |
| 127 | public infoK8s(pageType: string): void { |
| 128 | let pageName: string = ''; |
| 129 | let title: string = ''; |
| 130 | if (pageType === 'repo') { |
| 131 | pageName = 'k8s-repo'; |
| 132 | title = 'PAGE.K8S.K8SREPODETAILS'; |
| 133 | } else { |
| 134 | pageName = 'k8s-cluster'; |
| 135 | title = 'PAGE.K8S.K8SCLUSTERDETAILS'; |
| 136 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 137 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 138 | this.modalService.open(ShowInfoComponent, { backdrop: 'static' }).componentInstance.params = { |
| 139 | id: this.instanceID, |
| 140 | page: pageName, |
| 141 | titleName: title |
| 142 | }; |
| 143 | } |
| SANDHYA.JS | 2657011 | 2024-07-05 21:35:46 +0530 | [diff] [blame^] | 144 | /** Edit profile @public */ |
| 145 | public editProfile(editType: string): void { |
| 146 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 147 | const modalRef: NgbModalRef = this.modalService.open(K8sInfraConfigAddComponent, { backdrop: 'static' }); |
| 148 | modalRef.componentInstance.profileID = this.value.identifier; |
| 149 | modalRef.componentInstance.profileType = editType; |
| 150 | modalRef.componentInstance.profileName = this.value.name; |
| 151 | modalRef.componentInstance.profileDescription = this.value.description; |
| 152 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 153 | if (result) { |
| 154 | this.sharedService.callData(); |
| 155 | } |
| 156 | }).catch((): void => { |
| 157 | // Catch Navigation Error |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** Edit cluster @public */ |
| 162 | public editCluster(editType: string): void { |
| 163 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 164 | const modalRef: NgbModalRef = this.modalService.open(K8sAddClusterComponent, { backdrop: 'static' }); |
| 165 | modalRef.componentInstance.profileID = this.value.identifier; |
| 166 | modalRef.componentInstance.profileType = editType; |
| 167 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 168 | if (result) { |
| 169 | this.sharedService.callData(); |
| 170 | } |
| 171 | }).catch((): void => { |
| 172 | // Catch Navigation Error |
| 173 | }); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | /** Edit profile under cluster @public */ |
| 178 | public editClusterProfile(editType: string): void { |
| 179 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 180 | const modalRef: NgbModalRef = this.modalService.open(K8sAttachProfileComponent, { backdrop: 'static' }); |
| 181 | modalRef.componentInstance.profileID = this.value.identifier; |
| 182 | modalRef.componentInstance.profileType = editType; |
| 183 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 184 | if (result) { |
| 185 | this.sharedService.callData(); |
| 186 | } |
| 187 | }).catch((): void => { |
| 188 | // Catch Navigation Error |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | /** Move KSU @public */ |
| 193 | public moveKsu(): void { |
| 194 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 195 | const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' }); |
| 196 | modalRef.componentInstance.profileID = this.value.identifier; |
| 197 | modalRef.componentInstance.profileType = 'move'; |
| 198 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 199 | if (result) { |
| 200 | this.sharedService.callData(); |
| 201 | } |
| 202 | }).catch((): void => { |
| 203 | // Catch Navigation Error |
| 204 | }); |
| 205 | } |
| 206 | |
| 207 | /** Edit KSU @public */ |
| 208 | public editKsu(): void { |
| 209 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 210 | const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' }); |
| 211 | modalRef.componentInstance.profileID = this.value.identifier; |
| 212 | modalRef.componentInstance.profileType = 'edit'; |
| 213 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 214 | if (result) { |
| 215 | this.sharedService.callData(); |
| 216 | } |
| 217 | }).catch((): void => { |
| 218 | // Catch Navigation Error |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | /** Clone KSU @public */ |
| 223 | public cloneKsu(): void { |
| 224 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| 225 | const modalRef: NgbModalRef = this.modalService.open(KSUAddComponent, { backdrop: 'static' }); |
| 226 | modalRef.componentInstance.profileID = this.value.identifier; |
| 227 | modalRef.componentInstance.profileType = 'clone'; |
| 228 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 229 | if (result) { |
| 230 | this.sharedService.callData(); |
| 231 | } |
| 232 | }).catch((): void => { |
| 233 | // Catch Navigation Error |
| 234 | }); |
| 235 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 236 | } |