Skip to content

Commit

Permalink
fixing device sort and display title.
Browse files Browse the repository at this point in the history
fixes #194
  • Loading branch information
AnalogJ committed May 23, 2022
1 parent 9846ba1 commit 7979950
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
<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-label>Display Title</mat-label>
<mat-select [(ngModel)]="dashboardDisplay">
<mat-option value="name">Name</mat-option>
<mat-option value="serial_id">Serial ID</mat-option>
Expand All @@ -17,10 +17,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
<mat-label>Sort By</mat-label>
<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>
<mat-option value="uuid" disabled>UUID</mat-option>
<mat-option value="label" disabled>Label</mat-option>
<mat-option value="title">Title</mat-option>
</mat-select>
</mat-form-field>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h2 class="m-0">Dashboard</h2>
<div class="flex flex-wrap w-full" *ngFor="let hostId of hostGroups | keyvalue">
<h3 class="ml-4" *ngIf="hostId.key">{{hostId.key}}</h3>
<div class="flex flex-wrap w-full">
<app-dashboard-device class="flex gt-sm:w-1/2 min-w-80 p-4" *ngFor="let deviceSummary of (deviceSummariesForHostGroup(hostId.value) | deviceSort )" [deviceWWN]="deviceSummary.device.wwn" [deviceSummary]="deviceSummary"></app-dashboard-device>
<app-dashboard-device class="flex gt-sm:w-1/2 min-w-80 p-4" *ngFor="let deviceSummary of (deviceSummariesForHostGroup(hostId.value) | deviceSort:config.dashboardSort:config.dashboardDisplay )" [deviceWWN]="deviceSummary.device.wwn" [deviceSummary]="deviceSummary"></app-dashboard-device>
</div>
</div>

Expand Down
55 changes: 41 additions & 14 deletions webapp/frontend/src/app/shared/device-sort.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
import { Pipe, PipeTransform } from '@angular/core';
import {deviceDisplayTitle} from "app/layout/common/dashboard-device/dashboard-device.component";

@Pipe({
name: 'deviceSort'
})
export class DeviceSortPipe implements PipeTransform {

numericalStatus(deviceSummary): number {
if(!deviceSummary.smart){
return 0
} else if (deviceSummary.device.device_status == 0){
return 1
} else {
return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3
statusCompareFn(a: any, b: any) {
function deviceStatus(deviceSummary): number {
if(!deviceSummary.smart){
return 0
} else if (deviceSummary.device.device_status == 0){
return 1
} else {
return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3
}
}

let left = deviceStatus(a)
let right = deviceStatus(b)

return left - right;
}

titleCompareFn(dashboardDisplay: string) {
return function (a: any, b: any){
let _dashboardDisplay = dashboardDisplay
let left = deviceDisplayTitle(a.device, _dashboardDisplay) || deviceDisplayTitle(a.device, 'name')
let right = deviceDisplayTitle(b.device, _dashboardDisplay) || deviceDisplayTitle(b.device, 'name')

transform(deviceSummaries: Array<unknown>, sortBy = ''): Array<unknown> {
//failed, unknown/empty, passed
deviceSummaries.sort((a: any, b: any) => {
if( left < right )
return -1;

let left = this.numericalStatus(a)
let right = this.numericalStatus(b)
if( left > right )
return 1;

return left - right;
});
return 0;
}
}


transform(deviceSummaries: Array<unknown>, sortBy = 'status', dashboardDisplay = "name"): Array<unknown> {
let compareFn = undefined
switch (sortBy) {
case 'status':
compareFn = this.statusCompareFn
break;
case 'title':
compareFn = this.titleCompareFn(dashboardDisplay)
break;
}

//failed, unknown/empty, passed
deviceSummaries.sort(compareFn);

return deviceSummaries;
}

Expand Down

0 comments on commit 7979950

Please sign in to comment.