From 0aeb13c181df3d359e20cfd1cb4833c9ad2ebc27 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sat, 14 May 2022 17:54:19 -0700 Subject: [PATCH] support custom display of devices by UUID/ID/Label & Scrutiny Name. (Does not persist). Related #225 --- .../dashboard-settings.component.html | 8 +- .../dashboard-settings.component.ts | 4 +- .../modules/dashboard/dashboard.component.ts | 98 ++++++++++++------- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html index 773ed26..a90786b 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html +++ b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.html @@ -1,11 +1,11 @@

Scrutiny Settings

-
+
Display - + Name Serial ID UUID @@ -15,7 +15,7 @@ Sort By - + Status Name Serial ID @@ -80,7 +80,7 @@
- +
diff --git a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts index dab49f7..dc259fe 100644 --- a/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts +++ b/webapp/frontend/src/app/layout/common/dashboard-settings/dashboard-settings.component.ts @@ -38,10 +38,12 @@ export class DashboardSettingsComponent implements OnInit { } saveSettings(): void { - this._configService.config = { + var newSettings = { dashboardDisplay: this.dashboardDisplay, dashboardSort: this.dashboardSort } + this._configService.config = newSettings + console.log(`Saved Settings: ${JSON.stringify(newSettings)}`) } formatLabel(value: number) { diff --git a/webapp/frontend/src/app/modules/dashboard/dashboard.component.ts b/webapp/frontend/src/app/modules/dashboard/dashboard.component.ts index 4cc9b0a..21e7523 100644 --- a/webapp/frontend/src/app/modules/dashboard/dashboard.component.ts +++ b/webapp/frontend/src/app/modules/dashboard/dashboard.component.ts @@ -11,6 +11,7 @@ import { DashboardSettingsComponent } from 'app/layout/common/dashboard-settings import humanizeDuration from 'humanize-duration' import {AppConfig} from 'app/core/config/app.config'; import { TreoConfigService } from '@treo/services/config'; +import {Router, NavigationEnd,ActivatedRoute} from '@angular/router'; @Component({ selector : 'example', @@ -37,6 +38,9 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy private _smartService: DashboardService, public dialog: MatDialog, private _configService: TreoConfigService, + private router: Router, + private activatedRoute: ActivatedRoute + ) { // Set the private defaults @@ -57,10 +61,21 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy this._configService.config$ .pipe(takeUntil(this._unsubscribeAll)) .subscribe((config: AppConfig) => { - console.log('Configuration updated...') - // Store the config - this.config = config; + //check if the old config and the new config do not match. + let oldConfig = JSON.stringify(this.config) + let newConfig = JSON.stringify(config) + + if(oldConfig != newConfig){ + console.log(`Configuration updated: ${newConfig} vs ${oldConfig}`) + // Store the config + this.config = config; + + if(oldConfig){ + console.log("reloading component...") + this.refreshComponent() + } + } }); // Get the data @@ -95,6 +110,14 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy // ----------------------------------------------------------------------------------------------------- // @ Private methods // ----------------------------------------------------------------------------------------------------- + private refreshComponent(){ + + let currentUrl = this.router.url; + this.router.routeReuseStrategy.shouldReuseRoute = () => false; + this.router.onSameUrlNavigation = 'reload'; + this.router.navigate([currentUrl]); + } + private _deviceDataTemperatureSeries() { var deviceTemperatureSeries = [] @@ -180,6 +203,37 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy }; } + private _deviceDisplayTitle(disk, titleType: string){ + let deviceDisplay = '' + let titleParts = [] + switch(titleType){ + case 'name': + titleParts.push(`/dev/${disk.device_name}`) + if (disk.device_type && disk.device_type != 'scsi' && disk.device_type != 'ata'){ + titleParts.push(disk.device_type) + } + titleParts.push(disk.model_name) + + break; + case 'serial_id': + if(!disk.device_serial_id) return '' + titleParts.push(`/by-id/${disk.device_serial_id}`) + break; + case 'uuid': + if(!disk.device_uuid) return '' + titleParts.push(`/by-uuid/${disk.device_uuid}`) + break; + case 'label': + if(disk.label){ + titleParts.push(disk.label) + } else if(disk.device_label){ + titleParts.push(`/by-label/${disk.device_label}`) + } + break; + } + return titleParts.join(' - ') + } + // ----------------------------------------------------------------------------------------------------- // @ Public methods // ----------------------------------------------------------------------------------------------------- @@ -193,41 +247,15 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy } deviceTitle(disk){ - let title = [] - let showModelName = false - if (disk.host_id) title.push(disk.host_id) - let deviceDisplay = '' - switch(this.config.dashboardDisplay){ - case 'name': - deviceDisplay = `/dev/${disk.device_name}` - if (disk.device_type && disk.device_type != 'scsi' && disk.device_type != 'ata'){ - title.push(disk.device_type) - } - showModelName = true + console.log(`Displaying Dashboard with: ${this.config.dashboardDisplay}`) + let titleParts = [] + if (disk.host_id) titleParts.push(disk.host_id) - break; - case 'serial_id': - deviceDisplay = disk.device_serial_id - break; - case 'uuid': - deviceDisplay = disk.device_uuid - break; - case 'label': - deviceDisplay = disk.label || disk.device_label - } - - if(!deviceDisplay) { - // fallback - deviceDisplay = `/dev/${disk.device_name}` - } - - title.push(deviceDisplay) - if(showModelName){ - title.push(disk.model_name) - } + //add device identifier (fallback to generated device name) + titleParts.push(this._deviceDisplayTitle(disk, this.config.dashboardDisplay) || this._deviceDisplayTitle(disk, 'name')) - return title.join(' - ') + return titleParts.join(' - ') } deviceStatusString(deviceStatus){