Skip to content

Commit

Permalink
add ability to sort devices by age (powered-on-hours)
Browse files Browse the repository at this point in the history
fixes #100
  • Loading branch information
AnalogJ committed May 26, 2022
1 parent da4562d commit 7d2daf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h2 mat-dialog-title>Scrutiny Settings</h2>
<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>
Expand Down
12 changes: 11 additions & 1 deletion webapp/frontend/src/app/shared/device-sort.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 7d2daf4

Please sign in to comment.