|
|
@ -1,32 +1,59 @@
|
|
|
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
|
|
|
|
import {deviceDisplayTitle} from "app/layout/common/dashboard-device/dashboard-device.component";
|
|
|
|
|
|
|
|
|
|
|
|
@Pipe({
|
|
|
|
@Pipe({
|
|
|
|
name: 'deviceSort'
|
|
|
|
name: 'deviceSort'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class DeviceSortPipe implements PipeTransform {
|
|
|
|
export class DeviceSortPipe implements PipeTransform {
|
|
|
|
|
|
|
|
|
|
|
|
numericalStatus(deviceSummary): number {
|
|
|
|
statusCompareFn(a: any, b: any) {
|
|
|
|
if(!deviceSummary.smart){
|
|
|
|
function deviceStatus(deviceSummary): number {
|
|
|
|
return 0
|
|
|
|
if(!deviceSummary.smart){
|
|
|
|
} else if (deviceSummary.device.device_status == 0){
|
|
|
|
return 0
|
|
|
|
return 1
|
|
|
|
} else if (deviceSummary.device.device_status == 0){
|
|
|
|
} else {
|
|
|
|
return 1
|
|
|
|
return deviceSummary.device.device_status * -1 // will return range from -1, -2, -3
|
|
|
|
} 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> {
|
|
|
|
if( left < right )
|
|
|
|
//failed, unknown/empty, passed
|
|
|
|
return -1;
|
|
|
|
deviceSummaries.sort((a: any, b: any) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let left = this.numericalStatus(a)
|
|
|
|
if( left > right )
|
|
|
|
let right = this.numericalStatus(b)
|
|
|
|
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;
|
|
|
|
return deviceSummaries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|