adding device status pipe to set the device status in a more readable way.pull/263/head
parent
e1e1d321dd
commit
4aa1485246
@ -0,0 +1,8 @@
|
||||
import { DeviceStatusPipe } from './device-status.pipe';
|
||||
|
||||
describe('DeviceStatusPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new DeviceStatusPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'deviceStatus'
|
||||
})
|
||||
export class DeviceStatusPipe implements PipeTransform {
|
||||
|
||||
transform(deviceStatusFlag: number): string {
|
||||
if(deviceStatusFlag === 0){
|
||||
return 'passed'
|
||||
} else if(deviceStatusFlag === 3){
|
||||
return 'failed: both'
|
||||
} else if(deviceStatusFlag === 2) {
|
||||
return 'failed: scrutiny'
|
||||
} else if(deviceStatusFlag === 1) {
|
||||
return 'failed: smart'
|
||||
}
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { DeviceTitlePipe } from './device-title.pipe';
|
||||
|
||||
describe('DeviceTitlePipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new DeviceTitlePipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,54 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'deviceTitle'
|
||||
})
|
||||
export class DeviceTitlePipe implements PipeTransform {
|
||||
|
||||
static deviceTitleForType(device: any, titleType: string): string {
|
||||
const titleParts = []
|
||||
switch(titleType){
|
||||
case 'name':
|
||||
titleParts.push(`/dev/${device.device_name}`)
|
||||
if (device.device_type && device.device_type !== 'scsi' && device.device_type !== 'ata'){
|
||||
titleParts.push(device.device_type)
|
||||
}
|
||||
titleParts.push(device.model_name)
|
||||
|
||||
break;
|
||||
case 'serial_id':
|
||||
if(!device.device_serial_id) return ''
|
||||
titleParts.push(`/by-id/${device.device_serial_id}`)
|
||||
break;
|
||||
case 'uuid':
|
||||
if(!device.device_uuid) return ''
|
||||
titleParts.push(`/by-uuid/${device.device_uuid}`)
|
||||
break;
|
||||
case 'label':
|
||||
if(device.label){
|
||||
titleParts.push(device.label)
|
||||
} else if(device.device_label){
|
||||
titleParts.push(`/by-label/${device.device_label}`)
|
||||
}
|
||||
break;
|
||||
}
|
||||
return titleParts.join(' - ')
|
||||
}
|
||||
|
||||
static deviceTitleWithFallback(device, titleType: string): string {
|
||||
console.log(`Displaying Device ${device.wwn} with: ${titleType}`)
|
||||
const titleParts = []
|
||||
if (device.host_id) titleParts.push(device.host_id)
|
||||
|
||||
// add device identifier (fallback to generated device name)
|
||||
titleParts.push(DeviceTitlePipe.deviceTitleForType(device, titleType) || DeviceTitlePipe.deviceTitleForType(device, 'name'))
|
||||
|
||||
return titleParts.join(' - ')
|
||||
}
|
||||
|
||||
|
||||
transform(device: any, titleType: string = 'name'): string {
|
||||
return DeviceTitlePipe.deviceTitleWithFallback(device, titleType)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue