| 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 Dashboard Component |
| 20 | */ |
| 21 | import { Component, Injector, OnInit } from '@angular/core'; |
| 22 | import { TranslateService } from '@ngx-translate/core'; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 23 | import { NotifierService } from 'angular-notifier'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 24 | import { AuthenticationService } from 'AuthenticationService'; |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 25 | import { Chart, ChartType, LineController, LineElement, PointElement, LinearScale, Title, ChartEvent, ActiveElement } from 'chart.js'; |
| 26 | import ChartDataLabels from 'chartjs-plugin-datalabels'; |
| 27 | Chart.register(LineController, LineElement, PointElement, LinearScale, Title, ChartDataLabels); |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 28 | import { ERRORDATA, TYPESECTION, VIM_TYPES } from 'CommonModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 29 | import { environment } from 'environment'; |
| 30 | import { NSDDetails } from 'NSDModel'; |
| 31 | import { NSInstanceDetails } from 'NSInstanceModel'; |
| 32 | import { ProjectData, ProjectDetails } from 'ProjectModel'; |
| 33 | import { ProjectService } from 'ProjectService'; |
| 34 | import { RestService } from 'RestService'; |
| 35 | import { Observable, Subscription } from 'rxjs'; |
| 36 | import { SDNControllerModel } from 'SDNControllerModel'; |
| SANDHYA.JS | c84f112 | 2024-06-04 21:50:03 +0530 | [diff] [blame] | 37 | import { SharedService, isNullOrUndefined } from 'SharedService'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 38 | import { ProjectRoleMappings, UserDetail } from 'UserModel'; |
| 39 | import { VimAccountDetails } from 'VimAccountModel'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 40 | import { VNFInstanceDetails } from 'VNFInstanceModel'; |
| 41 | |
| 42 | /** |
| 43 | * Creating component |
| 44 | * @Component takes DashboardComponent.html as template url |
| 45 | */ |
| 46 | @Component({ |
| 47 | styleUrls: ['./DashboardComponent.scss'], |
| 48 | templateUrl: './DashboardComponent.html' |
| 49 | }) |
| 50 | |
| 51 | /** |
| 52 | * This file created during the angular project creation |
| 53 | */ |
| 54 | |
| 55 | /** Exporting a class @exports DashboardComponent */ |
| 56 | export class DashboardComponent implements OnInit { |
| 57 | /** Invoke service injectors @public */ |
| 58 | public injector: Injector; |
| 59 | |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 60 | /** Handle translate @public */ |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 61 | public translateService: TranslateService; |
| 62 | |
| 63 | /** Observable holds logined value @public */ |
| 64 | public username$: Observable<string>; |
| 65 | |
| 66 | /** Variables holds admin is logged or not @public */ |
| 67 | public isAdmin: boolean; |
| 68 | |
| 69 | /** List of NS failed Instances @public */ |
| 70 | public nsFailedInstances: {}[] = []; |
| 71 | |
| 72 | /** Setting up count for vnfdPackages @public */ |
| 73 | public vnfdPackageCount: number; |
| 74 | |
| 75 | /** Setting up count for nsdPackage @public */ |
| 76 | public nsdPackageCount: number; |
| 77 | |
| 78 | /** Setting up count for nsInstance @public */ |
| 79 | public nsInstanceCount: number; |
| 80 | |
| 81 | /** Setting up count for vnfInstance @public */ |
| 82 | public vnfInstanceCount: number; |
| 83 | |
| 84 | /** Setting up count for vimAccount @public */ |
| 85 | public vimAccountCount: number; |
| 86 | |
| 87 | /** Setting up count for sdnController @public */ |
| 88 | public sdnControllerCount: number; |
| 89 | |
| 90 | /** Variables holds current project details @public */ |
| 91 | public currentProjectDetails: {}; |
| 92 | |
| 93 | /** Array holds all the projects @public */ |
| 94 | public projectList: {}[] = []; |
| 95 | |
| 96 | /** Array holds all the projects @public */ |
| 97 | public allProjectList: {}[] = []; |
| 98 | |
| 99 | /** Variables holds the selected project @public */ |
| 100 | public selectedProject: Observable<string>; |
| 101 | |
| 102 | /** Check the Instances loading results @public */ |
| 103 | public isCanvasLoadingResults: boolean = true; |
| 104 | |
| 105 | /** Check the Projects loading results @public */ |
| 106 | public isProjectsLoadingResults: boolean = true; |
| 107 | |
| 108 | /** Give the message for the loading @public */ |
| 109 | public message: string = 'PLEASEWAIT'; |
| 110 | |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 111 | /** List of NS Success Instances @public */ |
| Barath Kumar R | 5abb274 | 2020-11-22 20:15:10 +0530 | [diff] [blame] | 112 | public nsRunningInstance: string[] = []; |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 113 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 114 | /** Contains VIM Account details @public */ |
| 115 | public vimData: VimAccountDetails[] = []; |
| 116 | |
| 117 | /** Contains Selected VIM Details @public */ |
| 118 | public selectedVIMDetails: VimAccountDetails = null; |
| 119 | |
| 120 | /** List of VIM_TYPES @public */ |
| 121 | public vimTypes: TYPESECTION[] = VIM_TYPES; |
| 122 | |
| 123 | /** Array holds Vim data filtered with selected vimtype */ |
| 124 | public vimList: VimAccountDetails[] = []; |
| 125 | |
| SANDHYA.JS | 0e9c0a4 | 2022-04-04 18:44:53 +0530 | [diff] [blame] | 126 | /** Model value used to hold selected vimtype Data @public */ |
| 127 | public vimListData: string; |
| 128 | |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 129 | /** List of color for Instances @private */ |
| 130 | private backgroundColor: string[] = []; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 131 | |
| 132 | /** Utilizes rest service for any CRUD operations @private */ |
| 133 | private restService: RestService; |
| 134 | |
| 135 | /** Utilizes auth service for any auth operations @private */ |
| 136 | private authService: AuthenticationService; |
| 137 | |
| 138 | /** Used to subscribe vnfdPackage @private */ |
| 139 | private vnfdPackageCountSub: Subscription; |
| 140 | |
| 141 | /** Used to subscribe nsdPackage @private */ |
| 142 | private nsdPackageCountSub: Subscription; |
| 143 | |
| 144 | /** Used to subscribe nsInstance @private */ |
| 145 | private nsInstanceCountSub: Subscription; |
| 146 | |
| 147 | /** Used to subscribe vnfInstance @private */ |
| 148 | private vnfInstanceCountSub: Subscription; |
| 149 | |
| 150 | /** Used to subscribe vimAccount @private */ |
| 151 | private vimAccountCountSub: Subscription; |
| 152 | |
| 153 | /** Used to subscribe sdnController @private */ |
| 154 | private sdnControllerCountSub: Subscription; |
| 155 | |
| 156 | /** No of Hours of NS Success Instances @private */ |
| 157 | private noOfHours: number[] = []; |
| 158 | |
| 159 | /** collects charts objects @private */ |
| 160 | private charts: object = []; |
| 161 | |
| 162 | /** Contains all methods related to projects @private */ |
| 163 | private projectService: ProjectService; |
| 164 | |
| 165 | /** Contains all methods related to shared @private */ |
| 166 | private sharedService: SharedService; |
| 167 | |
| 168 | /** Contains NS Instance Details */ |
| 169 | private nsInstancesDataArr: {}[]; |
| 170 | |
| 171 | /** Container created time array @private */ |
| 172 | private createdTimes: string[] = []; |
| 173 | |
| 174 | /** Contains slice limit const @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 175 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 176 | private sliceLimit: number = 10; |
| 177 | |
| 178 | /** Contians hour converter @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 179 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 180 | private hourConverter: number = 3600; |
| 181 | |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 182 | /** Converter used to round off time to one decimal point @private */ |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 183 | // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 184 | private converter: number = 10; |
| 185 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 186 | /** Notifier service to popup notification @private */ |
| 187 | private notifierService: NotifierService; |
| 188 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 189 | constructor(injector: Injector) { |
| 190 | this.injector = injector; |
| 191 | this.restService = this.injector.get(RestService); |
| 192 | this.authService = this.injector.get(AuthenticationService); |
| 193 | this.projectService = this.injector.get(ProjectService); |
| 194 | this.sharedService = this.injector.get(SharedService); |
| 195 | this.translateService = this.injector.get(TranslateService); |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 196 | this.notifierService = this.injector.get(NotifierService); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Lifecyle Hooks the trigger before component is instantiate |
| 201 | */ |
| 202 | public ngOnInit(): void { |
| 203 | this.username$ = this.authService.username; |
| SANDHYA.JS | 5b35bcd | 2023-04-27 15:11:06 +0530 | [diff] [blame] | 204 | this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 205 | this.selectedProject = this.authService.ProjectName; |
| 206 | this.checkAdminPrivilege(); |
| 207 | this.getUserAccessedProjects(); |
| 208 | this.getAllProjects(); |
| 209 | this.getVnfdPackageCount(); |
| 210 | this.getNsdPackageCount(); |
| 211 | this.getNsInstanceCount(); |
| 212 | this.getVnfInstanceCount(); |
| 213 | this.getVimAccountCount(); |
| 214 | this.getSDNControllerCount(); |
| 215 | } |
| 216 | |
| 217 | /** Get all the projects @public */ |
| 218 | public getUserAccessedProjects(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 219 | this.projectService.getUserProjects().subscribe((projects: UserDetail): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 220 | const projectList: {}[] = projects.project_role_mappings; |
| 221 | this.projectList = projectList.filter( |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 222 | (thing: ProjectRoleMappings, i: number, arr: []): boolean => arr |
| 223 | .findIndex((t: ProjectRoleMappings): boolean => t.project_name === thing.project_name) === i |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 224 | ); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 225 | }, (error: Error): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 226 | // TODO: Handle failure |
| 227 | }); |
| 228 | } |
| 229 | |
| 230 | /** Fetching all the Project in dashboard @public */ |
| 231 | public getAllProjects(): void { |
| 232 | this.isProjectsLoadingResults = true; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 233 | this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 234 | this.allProjectList = []; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 235 | projectsData.forEach((projectData: ProjectDetails): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 236 | const projectDataObj: ProjectData = this.generateProjectData(projectData); |
| 237 | this.allProjectList.push(projectDataObj); |
| 238 | }); |
| 239 | this.isProjectsLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 240 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 241 | this.restService.handleError(error, 'get'); |
| 242 | this.isProjectsLoadingResults = false; |
| 243 | }); |
| 244 | } |
| 245 | |
| 246 | /** Generate Projects object from loop and return for the datasource @public */ |
| 247 | public generateProjectData(projectData: ProjectDetails): ProjectData { |
| 248 | return { |
| 249 | projectName: projectData.name, |
| 250 | modificationDate: this.sharedService.convertEpochTime(projectData._admin.modified), |
| 251 | creationDate: this.sharedService.convertEpochTime(projectData._admin.created), |
| 252 | id: projectData._id, |
| 253 | project: projectData._id |
| 254 | }; |
| 255 | } |
| 256 | |
| 257 | /** Function to check admin privilege @public */ |
| 258 | public checkAdminPrivilege(): void { |
| 259 | if (!this.isAdmin) { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 260 | this.projectService.getCurrentProjectDetails().subscribe((projectDetails: {}): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 261 | this.currentProjectDetails = projectDetails; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 262 | }, (error: Error): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 263 | // TODO: Handle failure |
| 264 | }); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /** Get VNFD Package details @public */ |
| 269 | public getVnfdPackageCount(): void { |
| 270 | this.vnfdPackageCountSub = this.restService.getResource(environment.VNFPACKAGESCONTENT_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 271 | .subscribe((vnfdPackageData: []): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 272 | this.vnfdPackageCount = vnfdPackageData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 273 | }, (error: ERRORDATA): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 274 | this.restService.handleError(error, 'get'); |
| 275 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** Get NSD Package details @public */ |
| 279 | public getNsdPackageCount(): void { |
| 280 | this.nsdPackageCountSub = this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 281 | .subscribe((nsdPackageData: NSDDetails[]): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 282 | this.nsdPackageCount = nsdPackageData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 283 | }, (error: ERRORDATA): void => { |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 284 | this.restService.handleError(error, 'get'); |
| 285 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /** Get NS Instance details @public */ |
| 289 | public getNsInstanceCount(): void { |
| 290 | this.isCanvasLoadingResults = true; |
| 291 | this.nsInstanceCountSub = this.restService.getResource(environment.NSDINSTANCES_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 292 | .subscribe((nsInstancesData: NSInstanceDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 293 | this.nsInstancesDataArr = nsInstancesData; |
| 294 | this.nsInstanceCount = nsInstancesData.length; |
| 295 | this.nsInstanceChart(); |
| 296 | this.isCanvasLoadingResults = false; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 297 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 298 | this.restService.handleError(error, 'get'); |
| 299 | this.isCanvasLoadingResults = false; |
| 300 | }); |
| 301 | } |
| 302 | |
| 303 | /** Get NS Instance chart details @public */ |
| 304 | public nsInstanceChart(): void { |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 305 | this.nsInstancesDataArr.forEach((nsdInstanceData: NSDDetails): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 306 | const operationalStatus: string = nsdInstanceData['operational-status']; |
| 307 | const configStatus: string = nsdInstanceData['config-status']; |
| 308 | if (operationalStatus === 'failed' || configStatus === 'failed') { |
| 309 | this.nsFailedInstances.push(nsdInstanceData); |
| 310 | } else if (operationalStatus === 'running' && configStatus === 'configured') { |
| Barath Kumar R | 5abb274 | 2020-11-22 20:15:10 +0530 | [diff] [blame] | 311 | this.nsRunningInstance.push(nsdInstanceData.name); |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 312 | this.backgroundColor.push(this.sharedService.generateColor()); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 313 | this.createdTimes.push(((nsdInstanceData._admin.created).toString()).slice(0, this.sliceLimit)); |
| 314 | } |
| 315 | }); |
| 316 | const now: Date = new Date(); |
| 317 | const currentTime: number = Number((now.getTime().toString().slice(0, this.sliceLimit))); |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 318 | this.createdTimes.forEach((createdTime: string): void => { |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 319 | this.noOfHours.push(Math.floor(((currentTime - Number(createdTime)) / this.hourConverter) * (this.converter)) / this.converter); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 320 | }); |
| 321 | this.drawNsChart(); |
| 322 | } |
| 323 | |
| 324 | /** Prepare and sketch NS instance chart */ |
| 325 | public drawNsChart(): void { |
| 326 | this.charts = new Chart('canvas', { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 327 | type: 'bar' as ChartType, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 328 | data: { |
| 329 | labels: this.nsRunningInstance, |
| 330 | datasets: [{ |
| 331 | data: this.noOfHours, |
| 332 | label: this.translateService.instant('NOOFHOURS'), |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 333 | borderColor: this.backgroundColor, |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 334 | fill: false, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 335 | backgroundColor: this.backgroundColor, |
| 336 | hoverBackgroundColor: this.backgroundColor |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 337 | }] |
| 338 | }, |
| 339 | options: { |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 340 | layout: { |
| 341 | padding: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 342 | top: 25 |
| SANDHYA.JS | 9bae460 | 2022-04-05 07:28:32 +0530 | [diff] [blame] | 343 | } |
| 344 | }, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 345 | animation: false, |
| 346 | // eslint-disable-next-line prefer-arrow/prefer-arrow-functions |
| 347 | onHover(event: ChartEvent, item: ActiveElement[], chart: Chart): void { |
| 348 | const el: HTMLElement = document.getElementById('canvas'); |
| 349 | el.style.cursor = item[0] ? 'pointer' : 'default'; |
| Barath Kumar R | 208bef2 | 2020-07-07 12:28:04 +0530 | [diff] [blame] | 350 | }, |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 351 | plugins: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 352 | legend: { display: false }, |
| 353 | datalabels: { |
| 354 | anchor: 'end', |
| 355 | align: 'top', |
| 356 | font: { |
| 357 | weight: 'bold' |
| 358 | } |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 359 | } |
| 360 | }, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 361 | scales: { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 362 | x: { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 363 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 364 | title: { |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 365 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 366 | text: this.translateService.instant('NSINSTANCES') |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 367 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 368 | }, |
| 369 | y: { |
| 370 | beginAtZero: true, |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 371 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 372 | title: { |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 373 | display: true, |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 374 | text: this.translateService.instant('NOOFHOURS') |
| Barath Kumar R | e53dbb6 | 2021-06-08 11:06:38 +0530 | [diff] [blame] | 375 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 376 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | }); |
| 380 | } |
| 381 | |
| 382 | /** Get VNFD instance details @public */ |
| 383 | public getVnfInstanceCount(): void { |
| harshini.r | 3649a5c | 2022-04-28 12:43:12 +0530 | [diff] [blame] | 384 | this.vnfInstanceCountSub = this.restService.getResource(environment.VNFINSTANCES_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 385 | .subscribe((vnfInstanceData: VNFInstanceDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 386 | this.vnfInstanceCount = vnfInstanceData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 387 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 388 | this.restService.handleError(error, 'get'); |
| 389 | }); |
| 390 | } |
| 391 | |
| 392 | /** Get VIM account details @public */ |
| 393 | public getVimAccountCount(): void { |
| 394 | this.vimAccountCountSub = this.restService.getResource(environment.VIMACCOUNTS_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 395 | .subscribe((vimAccountData: VimAccountDetails[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 396 | this.vimAccountCount = vimAccountData.length; |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 397 | this.vimData = vimAccountData; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 398 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 399 | this.restService.handleError(error, 'get'); |
| 400 | }); |
| 401 | } |
| 402 | |
| 403 | /** Get SDN Controller Count @public */ |
| 404 | public getSDNControllerCount(): void { |
| 405 | this.sdnControllerCountSub = this.restService.getResource(environment.SDNCONTROLLER_URL) |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 406 | .subscribe((sdnControllerData: SDNControllerModel[]): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 407 | this.sdnControllerCount = sdnControllerData.length; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame] | 408 | }, (error: ERRORDATA): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 409 | this.restService.handleError(error, 'get'); |
| 410 | }); |
| 411 | } |
| 412 | |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 413 | /** Get Vim data filtered by the selected Vim Type @public */ |
| 414 | public getSelectedVimTypeList(selectedVIMType: string): void { |
| 415 | this.vimList = this.vimData.filter((vimData: VimAccountDetails): boolean => |
| 416 | vimData.vim_type === selectedVIMType); |
| SANDHYA.JS | 0e9c0a4 | 2022-04-04 18:44:53 +0530 | [diff] [blame] | 417 | if (this.vimList.length === 0) { |
| 418 | this.vimListData = null; |
| 419 | } |
| SANDHYA.JS | 4a7a542 | 2021-05-15 15:35:22 +0530 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** Get Selected VIM details @public */ |
| 423 | public getSelectedVIMDetails(vimDetails: VimAccountDetails): void { |
| 424 | if (!isNullOrUndefined(vimDetails.resources)) { |
| 425 | this.selectedVIMDetails = vimDetails; |
| 426 | } else { |
| 427 | this.notifierService.notify('error', this.translateService.instant('RESOURCESNOTFOUND')); |
| 428 | } |
| 429 | } |
| 430 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 431 | /** |
| 432 | * Lifecyle Hooks the trigger before component is deleted |
| 433 | */ |
| 434 | public ngOnDestroy(): void { |
| 435 | this.vnfdPackageCountSub.unsubscribe(); |
| 436 | this.nsdPackageCountSub.unsubscribe(); |
| 437 | this.nsInstanceCountSub.unsubscribe(); |
| 438 | this.vnfInstanceCountSub.unsubscribe(); |
| 439 | this.vimAccountCountSub.unsubscribe(); |
| 440 | this.sdnControllerCountSub.unsubscribe(); |
| 441 | } |
| 442 | } |