Coverity-CWE 922: Insecure Storage of Sensitive Information(localStorage write)
[osm/NG-UI.git] / src / app / dashboard / DashboardComponent.ts
index 56b79a4..3c856dd 100644 (file)
  */
 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,6 +35,7 @@ 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 { VNFInstanceDetails } from 'VNFInstanceModel';
 
@@ -54,7 +57,7 @@ export class DashboardComponent implements OnInit {
     /** Invoke service injectors @public */
     public injector: Injector;
 
-    /** handle translate @public */
+    /** Handle translate @public */
     public translateService: TranslateService;
 
     /** Observable holds logined value  @public */
@@ -108,6 +111,21 @@ 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[] = [];
+
+    /** Model value used to hold selected vimtype Data @public */
+    public vimListData: string;
+
     /** List of color for Instances @private */
     private backgroundColor: string[] = [];
 
@@ -159,6 +177,12 @@ export class DashboardComponent implements OnInit {
     /** Contians hour converter @private */
     private hourConverter: number = 3600;
 
+    /** Converter used to round off time to one decimal point @private */
+    private converter: number = 10;
+
+    /** Notifier service to popup notification @private */
+    private notifierService: NotifierService;
+
     constructor(injector: Injector) {
         this.injector = injector;
         this.restService = this.injector.get(RestService);
@@ -166,6 +190,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);
     }
 
     /**
@@ -173,7 +198,7 @@ export class DashboardComponent implements OnInit {
      */
     public ngOnInit(): void {
         this.username$ = this.authService.username;
-        this.isAdmin = (localStorage.getItem('isAdmin') === 'true') ? true : false;
+        this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
         this.selectedProject = this.authService.ProjectName;
         this.checkAdminPrivilege();
         this.getUserAccessedProjects();
@@ -288,7 +313,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): void => {
-            this.noOfHours.push((Math.round((currentTime - Number(createdTime)) / this.hourConverter)));
+            this.noOfHours.push(Math.floor(((currentTime - Number(createdTime)) / this.hourConverter) * (this.converter)) / this.converter);
         });
         this.drawNsChart();
     }
@@ -308,19 +333,30 @@ export class DashboardComponent implements OnInit {
                 }]
             },
             options: {
+                layout: {
+                    padding: {
+                        top: 20
+                    }
+                },
                 hover: {
                     onHover(evt: Event, item: {}): void {
                         const el: HTMLElement = document.getElementById('canvas');
                         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: [{
                         display: true,
                         scaleLabel: {
                             display: true,
-                            labelString: this.translateService.instant('INSTANCES')
+                            labelString: this.translateService.instant('NSINSTANCES')
                         }
                     }],
                     yAxes: [{
@@ -340,7 +376,7 @@ export class DashboardComponent implements OnInit {
 
     /** Get VNFD instance details @public */
     public getVnfInstanceCount(): void {
-        this.vnfInstanceCountSub = this.restService.getResource(environment.NSDINSTANCES_URL)
+        this.vnfInstanceCountSub = this.restService.getResource(environment.VNFINSTANCES_URL)
             .subscribe((vnfInstanceData: VNFInstanceDetails[]): void => {
                 this.vnfInstanceCount = vnfInstanceData.length;
             }, (error: ERRORDATA): void => {
@@ -353,6 +389,7 @@ export class DashboardComponent implements OnInit {
         this.vimAccountCountSub = this.restService.getResource(environment.VIMACCOUNTS_URL)
             .subscribe((vimAccountData: VimAccountDetails[]): void => {
                 this.vimAccountCount = vimAccountData.length;
+                this.vimData = vimAccountData;
             }, (error: ERRORDATA): void => {
                 this.restService.handleError(error, 'get');
             });
@@ -368,6 +405,25 @@ export class DashboardComponent implements OnInit {
             });
     }
 
+    /** 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);
+        if (this.vimList.length === 0) {
+            this.vimListData = null;
+        }
+
+    }
+
+    /** 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
      */