-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using device title pipe to consistently set the device name based on …
…configuration setting. adding device status pipe to set the device status in a more readable way.
- Loading branch information
Showing
10 changed files
with
113 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DeviceStatusPipe } from './device-status.pipe'; | ||
|
||
describe('DeviceStatusPipe', () => { | ||
it('create an instance', () => { | ||
const pipe = new DeviceStatusPipe(); | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DeviceTitlePipe } from './device-title.pipe'; | ||
|
||
describe('DeviceTitlePipe', () => { | ||
it('create an instance', () => { | ||
const pipe = new DeviceTitlePipe(); | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters