Skip to content

Commit

Permalink
adding support for device sort in UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed May 23, 2022
1 parent 83839f7 commit 9846ba1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
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 wwn of hostId.value" [deviceWWN]="wwn" [deviceSummary]="data.data.summary[wwn]"></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 )" [deviceWWN]="deviceSummary.device.wwn" [deviceSummary]="deviceSummary"></app-dashboard-device>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
return titleParts.join(' - ')
}

deviceSummariesForHostGroup(hostGroupWWNs: string[]) {
let deviceSummaries = []
for(let wwn of hostGroupWWNs){
deviceSummaries.push(this.data.data.summary[wwn])
}
return deviceSummaries
}

openDialog() {
const dialogRef = this.dialog.open(DashboardSettingsComponent);

Expand Down
14 changes: 7 additions & 7 deletions webapp/frontend/src/app/shared/device-sort.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { Pipe, PipeTransform } from '@angular/core';
})
export class DeviceSortPipe implements PipeTransform {

numericalStatus(device): number {
if(!device.smart_results[0]){
numericalStatus(deviceSummary): number {
if(!deviceSummary.smart){
return 0
} else if (device.smart_results[0].smart_status == 'passed'){
} else if (deviceSummary.device.device_status == 0){
return 1
} else {
return -1
return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3
}
}


transform(devices: Array<unknown>, ...args: unknown[]): Array<unknown> {
transform(deviceSummaries: Array<unknown>, sortBy = ''): Array<unknown> {
//failed, unknown/empty, passed
devices.sort((a: any, b: any) => {
deviceSummaries.sort((a: any, b: any) => {

let left = this.numericalStatus(a)
let right = this.numericalStatus(b)
Expand All @@ -27,7 +27,7 @@ export class DeviceSortPipe implements PipeTransform {
});


return devices;
return deviceSummaries;
}

}

0 comments on commit 9846ba1

Please sign in to comment.