X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fapp%2Fdashboard%2FDashboardComponent.ts;h=2feef7c0c567f24f59325d0a65a54ad43e6c6640;hb=4a7a542839c9ed7b6b6118c9faae0bc5d274494f;hp=8df0e7c5a1607c2798e8f59f6ac550dd8d277d36;hpb=5abb274a18081867fc491fae432c2208d3ead2df;p=osm%2FNG-UI.git diff --git a/src/app/dashboard/DashboardComponent.ts b/src/app/dashboard/DashboardComponent.ts index 8df0e7c..2feef7c 100644 --- a/src/app/dashboard/DashboardComponent.ts +++ b/src/app/dashboard/DashboardComponent.ts @@ -20,9 +20,11 @@ */ import { Component, Injector, OnInit } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; +import { NotifierService } from 'angular-notifier'; import { AuthenticationService } from 'AuthenticationService'; import { Chart } from 'chart.js'; -import { ERRORDATA } from 'CommonModel'; +import 'chartjs-plugin-labels'; +import { ERRORDATA, TYPESECTION, VIM_TYPES } from 'CommonModel'; import { environment } from 'environment'; import { NSDDetails } from 'NSDModel'; import { NSInstanceDetails } from 'NSInstanceModel'; @@ -33,8 +35,8 @@ import { Observable, Subscription } from 'rxjs'; import { SDNControllerModel } from 'SDNControllerModel'; import { SharedService } from 'SharedService'; import { ProjectRoleMappings, UserDetail } from 'UserModel'; +import { isNullOrUndefined } from 'util'; import { VimAccountDetails } from 'VimAccountModel'; -import { VNFDDetails } from 'VNFDModel'; import { VNFInstanceDetails } from 'VNFInstanceModel'; /** @@ -109,6 +111,18 @@ export class DashboardComponent implements OnInit { /** List of NS Success Instances @public */ public nsRunningInstance: string[] = []; + /** Contains VIM Account details @public */ + public vimData: VimAccountDetails[] = []; + + /** Contains Selected VIM Details @public */ + public selectedVIMDetails: VimAccountDetails = null; + + /** List of VIM_TYPES @public */ + public vimTypes: TYPESECTION[] = VIM_TYPES; + + /** Array holds Vim data filtered with selected vimtype */ + public vimList: VimAccountDetails[] = []; + /** List of color for Instances @private */ private backgroundColor: string[] = []; @@ -160,6 +174,9 @@ export class DashboardComponent implements OnInit { /** Contians hour converter @private */ private hourConverter: number = 3600; + /** Notifier service to popup notification @private */ + private notifierService: NotifierService; + constructor(injector: Injector) { this.injector = injector; this.restService = this.injector.get(RestService); @@ -167,6 +184,7 @@ export class DashboardComponent implements OnInit { this.projectService = this.injector.get(ProjectService); this.sharedService = this.injector.get(SharedService); this.translateService = this.injector.get(TranslateService); + this.notifierService = this.injector.get(NotifierService); } /** @@ -189,13 +207,13 @@ export class DashboardComponent implements OnInit { /** Get all the projects @public */ public getUserAccessedProjects(): void { - this.projectService.getUserProjects().subscribe((projects: UserDetail) => { + this.projectService.getUserProjects().subscribe((projects: UserDetail): void => { const projectList: {}[] = projects.project_role_mappings; this.projectList = projectList.filter( - (thing: ProjectRoleMappings, i: number, arr: []) => arr - .findIndex((t: ProjectRoleMappings) => t.project_name === thing.project_name) === i + (thing: ProjectRoleMappings, i: number, arr: []): boolean => arr + .findIndex((t: ProjectRoleMappings): boolean => t.project_name === thing.project_name) === i ); - }, (error: Error) => { + }, (error: Error): void => { // TODO: Handle failure }); } @@ -203,14 +221,14 @@ export class DashboardComponent implements OnInit { /** Fetching all the Project in dashboard @public */ public getAllProjects(): void { this.isProjectsLoadingResults = true; - this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectDetails[]) => { + this.restService.getResource(environment.PROJECTS_URL).subscribe((projectsData: ProjectDetails[]): void => { this.allProjectList = []; - projectsData.forEach((projectData: ProjectDetails) => { + projectsData.forEach((projectData: ProjectDetails): void => { const projectDataObj: ProjectData = this.generateProjectData(projectData); this.allProjectList.push(projectDataObj); }); this.isProjectsLoadingResults = false; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); this.isProjectsLoadingResults = false; }); @@ -230,9 +248,9 @@ export class DashboardComponent implements OnInit { /** Function to check admin privilege @public */ public checkAdminPrivilege(): void { if (!this.isAdmin) { - this.projectService.getCurrentProjectDetails().subscribe((projectDetails: {}) => { + this.projectService.getCurrentProjectDetails().subscribe((projectDetails: {}): void => { this.currentProjectDetails = projectDetails; - }, (error: Error) => { + }, (error: Error): void => { // TODO: Handle failure }); } @@ -241,9 +259,9 @@ export class DashboardComponent implements OnInit { /** Get VNFD Package details @public */ public getVnfdPackageCount(): void { this.vnfdPackageCountSub = this.restService.getResource(environment.VNFPACKAGESCONTENT_URL) - .subscribe((vnfdPackageData: VNFDDetails[]) => { + .subscribe((vnfdPackageData: []): void => { this.vnfdPackageCount = vnfdPackageData.length; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); }); } @@ -251,9 +269,9 @@ export class DashboardComponent implements OnInit { /** Get NSD Package details @public */ public getNsdPackageCount(): void { this.nsdPackageCountSub = this.restService.getResource(environment.NSDESCRIPTORSCONTENT_URL) - .subscribe((nsdPackageData: NSDDetails[]) => { + .subscribe((nsdPackageData: NSDDetails[]): void => { this.nsdPackageCount = nsdPackageData.length; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); }); } @@ -262,12 +280,12 @@ export class DashboardComponent implements OnInit { public getNsInstanceCount(): void { this.isCanvasLoadingResults = true; this.nsInstanceCountSub = this.restService.getResource(environment.NSDINSTANCES_URL) - .subscribe((nsInstancesData: NSInstanceDetails[]) => { + .subscribe((nsInstancesData: NSInstanceDetails[]): void => { this.nsInstancesDataArr = nsInstancesData; this.nsInstanceCount = nsInstancesData.length; this.nsInstanceChart(); this.isCanvasLoadingResults = false; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); this.isCanvasLoadingResults = false; }); @@ -275,7 +293,7 @@ export class DashboardComponent implements OnInit { /** Get NS Instance chart details @public */ public nsInstanceChart(): void { - this.nsInstancesDataArr.forEach((nsdInstanceData: NSDDetails) => { + this.nsInstancesDataArr.forEach((nsdInstanceData: NSDDetails): void => { const operationalStatus: string = nsdInstanceData['operational-status']; const configStatus: string = nsdInstanceData['config-status']; if (operationalStatus === 'failed' || configStatus === 'failed') { @@ -288,7 +306,7 @@ export class DashboardComponent implements OnInit { }); const now: Date = new Date(); const currentTime: number = Number((now.getTime().toString().slice(0, this.sliceLimit))); - this.createdTimes.forEach((createdTime: string) => { + this.createdTimes.forEach((createdTime: string): void => { this.noOfHours.push((Math.round((currentTime - Number(createdTime)) / this.hourConverter))); }); this.drawNsChart(); @@ -315,6 +333,12 @@ export class DashboardComponent implements OnInit { el.style.cursor = item[0] ? 'pointer' : 'default'; } }, + plugins: { + labels: { + // render 'label', 'value', 'percentage', 'image' or custom function, default is 'percentage' + render: 'value' + } + }, legend: { display: false }, scales: { xAxes: [{ @@ -342,9 +366,9 @@ export class DashboardComponent implements OnInit { /** Get VNFD instance details @public */ public getVnfInstanceCount(): void { this.vnfInstanceCountSub = this.restService.getResource(environment.NSDINSTANCES_URL) - .subscribe((vnfInstanceData: VNFInstanceDetails[]) => { + .subscribe((vnfInstanceData: VNFInstanceDetails[]): void => { this.vnfInstanceCount = vnfInstanceData.length; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); }); } @@ -352,9 +376,10 @@ export class DashboardComponent implements OnInit { /** Get VIM account details @public */ public getVimAccountCount(): void { this.vimAccountCountSub = this.restService.getResource(environment.VIMACCOUNTS_URL) - .subscribe((vimAccountData: VimAccountDetails[]) => { + .subscribe((vimAccountData: VimAccountDetails[]): void => { this.vimAccountCount = vimAccountData.length; - }, (error: ERRORDATA) => { + this.vimData = vimAccountData; + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); }); } @@ -362,13 +387,29 @@ export class DashboardComponent implements OnInit { /** Get SDN Controller Count @public */ public getSDNControllerCount(): void { this.sdnControllerCountSub = this.restService.getResource(environment.SDNCONTROLLER_URL) - .subscribe((sdnControllerData: SDNControllerModel[]) => { + .subscribe((sdnControllerData: SDNControllerModel[]): void => { this.sdnControllerCount = sdnControllerData.length; - }, (error: ERRORDATA) => { + }, (error: ERRORDATA): void => { this.restService.handleError(error, 'get'); }); } + /** Get Vim data filtered by the selected Vim Type @public */ + public getSelectedVimTypeList(selectedVIMType: string): void { + this.vimList = this.vimData.filter((vimData: VimAccountDetails): boolean => + vimData.vim_type === selectedVIMType); + + } + + /** Get Selected VIM details @public */ + public getSelectedVIMDetails(vimDetails: VimAccountDetails): void { + if (!isNullOrUndefined(vimDetails.resources)) { + this.selectedVIMDetails = vimDetails; + } else { + this.notifierService.notify('error', this.translateService.instant('RESOURCESNOTFOUND')); + } + } + /** * Lifecyle Hooks the trigger before component is deleted */