Skip to content

Commit

Permalink
support custom display of devices by UUID/ID/Label & Scrutiny Name. (…
Browse files Browse the repository at this point in the history
…Does not persist).

Related #225
  • Loading branch information
AnalogJ committed May 15, 2022
1 parent 01f60c8 commit 4fd40a0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 41 deletions.
2 changes: 1 addition & 1 deletion webapp/backend/pkg/config/config.go
Expand Up @@ -39,7 +39,7 @@ func (c *configuration) Init() error {

c.SetDefault("notify.urls", []string{})

c.SetDefault("web.influxdb.host", "0.0.0.0")
c.SetDefault("web.influxdb.host", "localhost")
c.SetDefault("web.influxdb.port", "8086")
c.SetDefault("web.influxdb.org", "scrutiny")
c.SetDefault("web.influxdb.bucket", "metrics")
Expand Down
@@ -1,11 +1,11 @@
<h2 mat-dialog-title>Scrutiny Settings</h2>
<mat-dialog-content class="mat-typography">

<form class="flex flex-col p-8 pb-0 overflow-hidden">
<div class="flex flex-col p-8 pb-0 overflow-hidden">
<div class="flex flex-col mt-5 gt-md:flex-row">
<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pr-3">
<mat-label>Display</mat-label>
<mat-select [value]="dashboardDisplay">
<mat-select [(ngModel)]="dashboardDisplay">
<mat-option value="name">Name</mat-option>
<mat-option value="serial_id">Serial ID</mat-option>
<mat-option value="uuid">UUID</mat-option>
Expand All @@ -15,7 +15,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>

<mat-form-field class="flex-auto gt-xs:pr-3 gt-md:pl-3">
<mat-label>Sort By</mat-label>
<mat-select [value]="dashboardSort">
<mat-select [(ngModel)]="dashboardSort">
<mat-option value="status">Status</mat-option>
<mat-option value="name" disabled>Name</mat-option>
<mat-option value="serial_id" disabled>Serial ID</mat-option>
Expand Down Expand Up @@ -80,7 +80,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
</mat-tab>
</mat-tab-group>
</div>
</form>
</div>

</mat-dialog-content>
<mat-dialog-actions align="end">
Expand Down
Expand Up @@ -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) {
Expand Down
98 changes: 63 additions & 35 deletions webapp/frontend/src/app/modules/dashboard/dashboard.component.ts
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -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
// -----------------------------------------------------------------------------------------------------
Expand All @@ -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){
Expand Down

0 comments on commit 4fd40a0

Please sign in to comment.