Skip to content

Commit 894e264

Browse files
Mikersdmike
authored andcommitted
feat: add power state to device details
fixes issue with tag editing as well closes Show current power status on device details page #2283
1 parent 0a03ee4 commit 894e264

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed
Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
<mat-toolbar>
22
@if (device?.useTLS && !isCloudMode) {
3-
<div style="padding-right: 12px">
4-
<button
5-
[color]="isPinned() ? 'primary' : 'warn'"
6-
mat-icon-button
7-
[matTooltip]="isPinned() ? 'TLS w/ Pinned Certificate' : 'TLS (not pinned)'"
8-
(click)="getDeviceCert()">
9-
<mat-icon>lock</mat-icon>
10-
</button>
11-
</div>
3+
<div style="padding-right: 12px">
4+
<button [color]="isPinned() ? 'primary' : 'warn'" mat-icon-button [matTooltip]="isPinned() ? 'TLS w/ Pinned Certificate' : 'TLS (not pinned)'" (click)="getDeviceCert()">
5+
<mat-icon>lock</mat-icon>
6+
</button>
7+
</div>
128
}
139
<span>
1410
@if (device?.friendlyName) {
15-
<span>{{ device?.friendlyName }}</span>
11+
<span>{{ device?.friendlyName }}</span>
1612
} @else {
17-
<span>{{ device?.hostname }}</span>
13+
<span>{{ device?.hostname }}</span>
1814
}
1915
<div class="mat-caption">
2016
@if (isCloudMode) {
21-
{{ deviceId }}
17+
{{ deviceId }}
2218
}
2319
@if (device?.friendlyName) {
24-
<span>
25-
@if (isCloudMode) {
26-
-
27-
}
28-
{{ device?.hostname }}</span
29-
>
20+
<span>
21+
@if (isCloudMode) {
22+
-
23+
}
24+
{{ device?.hostname }}</span>
3025
}
3126
</div>
3227
</span>
3328
<mat-chip-set class="flex-1 pad-15">
3429
@for (tag of device?.tags; track tag) {
35-
<mat-chip>{{ tag }}</mat-chip>
30+
<mat-chip>{{ tag }}</mat-chip>
3631
}
3732
</mat-chip-set>
3833
<button mat-icon-button matTooltip="Edit device" (click)="editDevice()">
@@ -42,7 +37,9 @@
4237
<mat-icon>delete</mat-icon>
4338
</button>
4439
<mat-divider style="height: 40px" vertical="true"></mat-divider>
45-
40+
@if(!isLoading){
41+
<mat-icon (click)="getPowerState()" style="padding:0 18px 0 12px;cursor: pointer;" [style.color]="powerState === 'Power: On' ? 'green' : powerState === 'Power: Sleep' ? 'yellow' : 'red'" [matTooltip]="powerState">mode_standby</mat-icon>
42+
}
4643
<mat-divider style="height: 40px" vertical="true"></mat-divider>
4744
<button mat-icon-button matTooltip="Power up the device" (click)="sendPowerAction(2)">
4845
<mat-icon>power</mat-icon>
@@ -58,12 +55,12 @@
5855
</button>
5956
<mat-menu #menu="matMenu">
6057
@for (option of powerOptions; track option) {
61-
<button mat-menu-item (click)="sendPowerAction(option.action)">
62-
<span>{{ option.label }}</span>
63-
</button>
58+
<button mat-menu-item (click)="sendPowerAction(option.action)">
59+
<span>{{ option.label }}</span>
60+
</button>
6461
}
6562
</mat-menu>
6663
</mat-toolbar>
6764
@if (isLoading) {
68-
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
65+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
6966
}

src/app/devices/device-toolbar/device-toolbar.component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class DeviceToolbarComponent implements OnInit {
5555
amtFeatures?: AMTFeaturesResponse
5656
public isCloudMode = environment.cloud
5757
public device: Device | null = null
58+
public powerState = ''
5859
public powerOptions = [
5960
{
6061
label: 'Hibernate',
@@ -110,9 +111,21 @@ export class DeviceToolbarComponent implements OnInit {
110111
this.devicesService.getDevice(this.deviceId).subscribe((data) => {
111112
this.device = data
112113
this.devicesService.device.next(this.device)
114+
this.getPowerState()
115+
})
116+
}
117+
getPowerState(): void {
118+
this.isLoading = true
119+
this.devicesService.getPowerState(this.deviceId).subscribe((powerState) => {
120+
this.powerState =
121+
powerState.powerstate.toString() === '2'
122+
? 'Power: On'
123+
: powerState.powerstate.toString() === '3' || powerState.powerstate.toString() === '4'
124+
? 'Power: Sleep'
125+
: 'Power: Off'
126+
this.isLoading = false
113127
})
114128
}
115-
116129
isPinned(): boolean {
117130
return this.device?.certHash != null && this.device?.certHash !== ''
118131
}

src/app/devices/devices.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ <h3 class="flex justify-center">
119119
Tags
120120
</mat-header-cell>
121121
<mat-cell class="tags" *matCellDef="let element">
122-
<span>
122+
123123
<mat-icon class="addTag" (click)="$event.stopPropagation(); editTagsForDevice(element.guid)">edit</mat-icon>
124-
</span>
124+
125125
<mat-chip-set>
126126
@for (tag of element?.tags; track tag) {
127127
<mat-chip [disableRipple]="true">{{ tag }}</mat-chip>

src/app/devices/devices.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class DevicesComponent implements OnInit, AfterViewInit {
276276
editTagsForDevice(deviceId: string): void {
277277
const device = this.devices.data.find((d) => d.guid === deviceId)
278278
if (!device) return // device not found
279-
const editedTags = [...device.tags]
279+
const editedTags = device.tags == null ? [] : [...device.tags]
280280
const dialogRef = this.dialog.open(DeviceEditTagsComponent, { data: editedTags })
281281
dialogRef.afterClosed().subscribe((tagsChanged) => {
282282
if (tagsChanged) {

0 commit comments

Comments
 (0)