| 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 Info VIM Page |
| 20 | */ |
| 21 | import { Component, Injector, OnInit } from '@angular/core'; |
| 22 | import { ActivatedRoute, Router } from '@angular/router'; |
| 23 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
| SANDHYA.JS | 0fa417a | 2024-03-06 16:19:04 +0530 | [diff] [blame] | 24 | import { TranslateService } from '@ngx-translate/core'; |
| 25 | import { NotifierService } from 'angular-notifier'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 26 | import { ERRORDATA } from 'CommonModel'; |
| 27 | import { DataService } from 'DataService'; |
| 28 | import { environment } from 'environment'; |
| 29 | import * as HttpStatus from 'http-status-codes'; |
| 30 | import { RestService } from 'RestService'; |
| SANDHYA.JS | c84f112 | 2024-06-04 21:50:03 +0530 | [diff] [blame] | 31 | import { isNullOrUndefined } from 'SharedService'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 32 | import { CONFIG, VimAccountDetails, VIMData } from 'VimAccountModel'; |
| 33 | |
| 34 | /** |
| 35 | * Creating component |
| 36 | * @Component InfoVimComponent.html as template url |
| 37 | */ |
| 38 | @Component({ |
| 39 | selector: 'app-info-vim', |
| 40 | templateUrl: './InfoVimComponent.html', |
| 41 | styleUrls: ['./InfoVimComponent.scss'] |
| 42 | }) |
| 43 | /** Exporting a class @exports InfoVimComponent */ |
| 44 | export class InfoVimComponent implements OnInit { |
| 45 | /** To inject services @public */ |
| 46 | public injector: Injector; |
| 47 | |
| 48 | /** vimAccountDetails to populate in InfoVIM Page @private */ |
| 49 | public vimAccountDetails: VimAccountDetails; |
| 50 | |
| 51 | /** Information Top Left @public */ |
| Barath Kumar R | d477b85 | 2020-07-07 15:24:05 +0530 | [diff] [blame] | 52 | public configParams: {} = {}; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 53 | |
| 54 | /** Showing more details of collapase */ |
| 55 | public isCollapsed: boolean = true; |
| 56 | |
| 57 | /** Contains vim details @public */ |
| 58 | public vimDetails: {}[]; |
| 59 | |
| 60 | /** Check the Projects loading results @public */ |
| 61 | public isLoadingResults: boolean = false; |
| 62 | |
| 63 | /** Give the message for the loading @public */ |
| 64 | public message: string = 'PLEASEWAIT'; |
| 65 | |
| 66 | /** variables contains paramsID @private */ |
| 67 | private paramsID: string; |
| 68 | |
| 69 | /** Instance of the rest service @private */ |
| 70 | private restService: RestService; |
| 71 | |
| 72 | /** Holds the instance of router class @private */ |
| 73 | private router: Router; |
| 74 | |
| 75 | /** dataService to pass the data from one component to another @private */ |
| 76 | private dataService: DataService; |
| 77 | |
| 78 | /** vimId to populate in InfoVIM Page @private */ |
| 79 | private vimId: string; |
| 80 | |
| 81 | /** Holds teh instance of AuthService class of type AuthService @private */ |
| 82 | private activatedRoute: ActivatedRoute; |
| 83 | |
| 84 | /** Utilizes modal service for any modal operations @private */ |
| 85 | private modalService: NgbModal; |
| 86 | |
| SANDHYA.JS | 0fa417a | 2024-03-06 16:19:04 +0530 | [diff] [blame] | 87 | /** Handle translate @public */ |
| 88 | private translateService: TranslateService; |
| 89 | |
| 90 | /** Notifier service to popup notification @private */ |
| 91 | private notifierService: NotifierService; |
| 92 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 93 | constructor(injector: Injector) { |
| 94 | this.injector = injector; |
| 95 | this.restService = this.injector.get(RestService); |
| 96 | this.dataService = this.injector.get(DataService); |
| 97 | this.activatedRoute = this.injector.get(ActivatedRoute); |
| 98 | this.modalService = this.injector.get(NgbModal); |
| SANDHYA.JS | 0fa417a | 2024-03-06 16:19:04 +0530 | [diff] [blame] | 99 | this.translateService = this.injector.get(TranslateService); |
| 100 | this.notifierService = this.injector.get(NotifierService); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 101 | this.router = this.injector.get(Router); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Lifecyle Hooks the trigger before component is instantiate |
| 106 | */ |
| 107 | public ngOnInit(): void { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 108 | this.paramsID = this.activatedRoute.snapshot.paramMap.get('id'); |
| 109 | this.dataService.currentMessage.subscribe((data: VIMData) => { |
| 110 | this.vimId = data.identifier; |
| 111 | }); |
| 112 | this.generateData(); |
| 113 | } |
| 114 | |
| 115 | /** Routing to VIM Account Details Page @public */ |
| 116 | public onVimAccountBack(): void { |
| 117 | this.router.navigate(['vim/details']).catch(() => { |
| 118 | // Error Cached |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | /** Generate Data function @public */ |
| 123 | public generateData(): void { |
| 124 | this.isLoadingResults = true; |
| 125 | this.restService.getResource(environment.VIMACCOUNTS_URL + '/' + this.paramsID) |
| 126 | .subscribe((vimAccountsData: VimAccountDetails) => { |
| 127 | this.showDetails(vimAccountsData); |
| SANDHYA.JS | 40cc37e | 2023-03-07 11:01:46 +0530 | [diff] [blame] | 128 | if (!isNullOrUndefined(vimAccountsData.config)) { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 129 | if (vimAccountsData.config.location !== undefined) { |
| 130 | const locationArr: string[] = vimAccountsData.config.location.split(','); |
| 131 | if (Array.isArray(locationArr)) { |
| 132 | vimAccountsData.config.location = locationArr[0]; |
| 133 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 134 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 135 | Object.keys(vimAccountsData.config).forEach((key: string) => { |
| 136 | // eslint-disable-next-line security/detect-object-injection |
| 137 | if (Array.isArray(vimAccountsData.config[key]) || typeof vimAccountsData.config[key] === 'object') { |
| 138 | // eslint-disable-next-line security/detect-object-injection |
| 139 | vimAccountsData.config[key] = JSON.stringify(vimAccountsData.config[key]); |
| 140 | } |
| 141 | const keyArr: string[] = key.split('_'); |
| 142 | if (keyArr.length > 1) { |
| 143 | // eslint-disable-next-line security/detect-object-injection |
| 144 | vimAccountsData.config[key.split('_').join(' ')] = vimAccountsData.config[key]; |
| 145 | // eslint-disable-next-line @typescript-eslint/no-dynamic-delete, security/detect-object-injection |
| 146 | delete vimAccountsData.config[key]; |
| 147 | } |
| 148 | }); |
| 149 | this.configParams = vimAccountsData.config; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 150 | } |
| 151 | this.isLoadingResults = false; |
| 152 | }, (error: ERRORDATA) => { |
| 153 | this.isLoadingResults = false; |
| SANDHYA.JS | 0fa417a | 2024-03-06 16:19:04 +0530 | [diff] [blame] | 154 | if (error.error.status === HttpStatus.NOT_FOUND) { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 155 | this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => { |
| 156 | // Catch Navigation Error |
| 157 | }); |
| SANDHYA.JS | 0fa417a | 2024-03-06 16:19:04 +0530 | [diff] [blame] | 158 | } else if (error.error.status === HttpStatus.UNAUTHORIZED) { |
| 159 | this.notifierService.notify('error', this.translateService.instant('HTTPERROR.401')); |
| 160 | this.router.navigate(['/vim/details']).catch((): void => { |
| 161 | // Catch Navigation Error |
| 162 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 163 | } else { |
| 164 | this.restService.handleError(error, 'get'); |
| 165 | } |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | /** show general vim detailed information @public */ |
| 170 | public showDetails(vimAccountsData: VimAccountDetails): void { |
| 171 | this.vimDetails = [ |
| 172 | { |
| 173 | title: 'PAGE.VIMDETAILS.NAME', |
| 174 | value: vimAccountsData.name |
| 175 | }, |
| 176 | { |
| 177 | title: 'PAGE.VIMDETAILS.VIMUSERNAME', |
| 178 | value: vimAccountsData.vim_user |
| 179 | }, |
| 180 | { |
| 181 | title: 'PAGE.VIMDETAILS.VIMURL', |
| 182 | value: vimAccountsData.vim_url |
| 183 | }, |
| 184 | { |
| 185 | title: 'PAGE.VIMDETAILS.VIMTYPE', |
| 186 | value: vimAccountsData.vim_type |
| 187 | }, |
| 188 | { |
| 189 | title: 'PAGE.VIMDETAILS.TENANTNAME', |
| 190 | value: vimAccountsData.vim_tenant_name |
| 191 | }, |
| 192 | { |
| 193 | title: 'PAGE.VIMDETAILS.DESCRIPTION', |
| 194 | value: vimAccountsData.description |
| 195 | }, |
| 196 | { |
| 197 | title: 'PAGE.VIMDETAILS.SCHEMATYPE', |
| 198 | value: vimAccountsData.schema_type |
| 199 | }, |
| 200 | { |
| 201 | title: 'PAGE.VIMDETAILS.SCHEMAVERSION', |
| 202 | value: vimAccountsData.schema_version |
| 203 | } |
| 204 | ]; |
| 205 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 206 | } |