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-select [(ngModel)]="dashboardSort">
<mat-option value="status">Status</mat-option> <mat-option value="status">Status</mat-option>
<mat-option value="title">Title</mat-option> <mat-option value="title">Title</mat-option>
<mat-option value="age">Age</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </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> { transform(deviceSummaries: Array<unknown>, sortBy = 'status', dashboardDisplay = "name"): Array<unknown> {
let compareFn = undefined let compareFn = undefined
@ -49,9 +56,12 @@ export class DeviceSortPipe implements PipeTransform {
case 'title': case 'title':
compareFn = this.titleCompareFn(dashboardDisplay) compareFn = this.titleCompareFn(dashboardDisplay)
break; break;
case 'age':
compareFn = this.ageCompareFn
break;
} }
//failed, unknown/empty, passed // failed, unknown/empty, passed
deviceSummaries.sort(compareFn); deviceSummaries.sort(compareFn);
return deviceSummaries; return deviceSummaries;

Loading…
Cancel
Save