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