2 Copyright 2020 TATA ELXSI
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
21 import { isNullOrUndefined } from 'util';
22 import { Component, Injector, OnInit } from '@angular/core';
23 import { ActivatedRoute, Router } from '@angular/router';
24 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
25 import { TranslateService } from '@ngx-translate/core';
26 import { NotifierService } from 'angular-notifier';
27 import { ERRORDATA } from 'CommonModel';
28 import { DataService } from 'DataService';
29 import { environment } from 'environment';
30 import * as HttpStatus from 'http-status-codes';
31 import { RestService } from 'RestService';
32 import { CONFIG, VimAccountDetails, VIMData } from 'VimAccountModel';
36 * @Component InfoVimComponent.html as template url
39 selector: 'app-info-vim',
40 templateUrl: './InfoVimComponent.html',
41 styleUrls: ['./InfoVimComponent.scss']
43 /** Exporting a class @exports InfoVimComponent */
44 export class InfoVimComponent implements OnInit {
45 /** To inject services @public */
46 public injector: Injector;
48 /** vimAccountDetails to populate in InfoVIM Page @private */
49 public vimAccountDetails: VimAccountDetails;
51 /** Information Top Left @public */
52 public configParams: {} = {};
54 /** Showing more details of collapase */
55 public isCollapsed: boolean = true;
57 /** Contains vim details @public */
58 public vimDetails: {}[];
60 /** Check the Projects loading results @public */
61 public isLoadingResults: boolean = false;
63 /** Give the message for the loading @public */
64 public message: string = 'PLEASEWAIT';
66 /** variables contains paramsID @private */
67 private paramsID: string;
69 /** Instance of the rest service @private */
70 private restService: RestService;
72 /** Holds the instance of router class @private */
73 private router: Router;
75 /** dataService to pass the data from one component to another @private */
76 private dataService: DataService;
78 /** vimId to populate in InfoVIM Page @private */
79 private vimId: string;
81 /** Holds teh instance of AuthService class of type AuthService @private */
82 private activatedRoute: ActivatedRoute;
84 /** Utilizes modal service for any modal operations @private */
85 private modalService: NgbModal;
87 /** Handle translate @public */
88 private translateService: TranslateService;
90 /** Notifier service to popup notification @private */
91 private notifierService: NotifierService;
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);
99 this.translateService = this.injector.get(TranslateService);
100 this.notifierService = this.injector.get(NotifierService);
101 this.router = this.injector.get(Router);
105 * Lifecyle Hooks the trigger before component is instantiate
107 public ngOnInit(): void {
108 this.paramsID = this.activatedRoute.snapshot.paramMap.get('id');
109 this.dataService.currentMessage.subscribe((data: VIMData) => {
110 this.vimId = data.identifier;
115 /** Routing to VIM Account Details Page @public */
116 public onVimAccountBack(): void {
117 this.router.navigate(['vim/details']).catch(() => {
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);
128 if (!isNullOrUndefined(vimAccountsData.config)) {
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];
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]);
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];
149 this.configParams = vimAccountsData.config;
151 this.isLoadingResults = false;
152 }, (error: ERRORDATA) => {
153 this.isLoadingResults = false;
154 if (error.error.status === HttpStatus.NOT_FOUND) {
155 this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
156 // Catch Navigation Error
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
164 this.restService.handleError(error, 'get');
169 /** show general vim detailed information @public */
170 public showDetails(vimAccountsData: VimAccountDetails): void {
173 title: 'PAGE.VIMDETAILS.NAME',
174 value: vimAccountsData.name
177 title: 'PAGE.VIMDETAILS.VIMUSERNAME',
178 value: vimAccountsData.vim_user
181 title: 'PAGE.VIMDETAILS.VIMURL',
182 value: vimAccountsData.vim_url
185 title: 'PAGE.VIMDETAILS.VIMTYPE',
186 value: vimAccountsData.vim_type
189 title: 'PAGE.VIMDETAILS.TENANTNAME',
190 value: vimAccountsData.vim_tenant_name
193 title: 'PAGE.VIMDETAILS.DESCRIPTION',
194 value: vimAccountsData.description
197 title: 'PAGE.VIMDETAILS.SCHEMATYPE',
198 value: vimAccountsData.schema_type
201 title: 'PAGE.VIMDETAILS.SCHEMAVERSION',
202 value: vimAccountsData.schema_version