add ability to sort devices by age (powered-on-hours)

fixes #100
pull/263/head
Jason Kulatunga 3 years ago
parent da4562d308
commit 7d2daf4f6a

@ -18,6 +18,7 @@
<mat-select [(ngModel)]="dashboardSort">
<mat-option value="status">Status</mat-option>
<mat-option value="title">Title</mat-option>
<mat-option value="age">Age</mat-option>
</mat-select>
</mat-form-field>
</div>

@ -39,6 +39,13 @@ export class DeviceSortPipe implements PipeTransform {
}
}
ageCompareFn(a: any, b: any) {
const left = a.smart?.power_on_hours
const right = b.smart?.power_on_hours
return left - right;
}
transform(deviceSummaries: Array<unknown>, sortBy = 'status', dashboardDisplay = "name"): Array<unknown> {
let compareFn = undefined
@ -49,9 +56,12 @@ export class DeviceSortPipe implements PipeTransform {
case 'title':
compareFn = this.titleCompareFn(dashboardDisplay)
break;
case 'age':
compareFn = this.ageCompareFn
break;
}
//failed, unknown/empty, passed
// failed, unknown/empty, passed
deviceSummaries.sort(compareFn);
return deviceSummaries;

Loading…
Cancel
Save