-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-129747 / 24.10 / Implement
MiniDriveTemperaturesComponent
(#10304)
* NAS-129747: Implement `MiniDriveTemperaturesComponent` * NAS-129747: Add tests * NAS-129747: Implement MiniDriveTemperaturesComponent --------- Co-authored-by: Boris Vasilenko <[email protected]> Co-authored-by: Evgeny Stepanovych <[email protected]>
- Loading branch information
1 parent
97b0217
commit 8d74386
Showing
93 changed files
with
320 additions
and
5 deletions.
There are no files selected for viewing
18 changes: 17 additions & 1 deletion
18
...components/pages/mini-page/mini-drive-temperatures/mini-drive-temperatures.component.html
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 |
---|---|---|
@@ -1,3 +1,19 @@ | ||
<h3>{{ 'Drive Temperatures' | translate }}</h3> | ||
|
||
Not implemented. | ||
@if (disks()) { | ||
<ul> | ||
@for (disk of disks(); track disk) { | ||
<li class="disk"> | ||
<strong class="dev">{{ disk.dev }}:</strong> | ||
<span class="temperature">{{ disk.temperature || ('Temperature not available.' | translate) }}</span> | ||
|
||
@if (!disk.temperature) { | ||
<ix-tooltip | ||
[header]="'Temperature data missing.' | translate" | ||
[message]="'No temperature data was reported by the system. There can be a number of reasons why this might occur.' | translate" | ||
></ix-tooltip> | ||
} | ||
</li> | ||
} | ||
</ul> | ||
} |
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 |
---|---|---|
|
@@ -3,3 +3,11 @@ | |
h3 { | ||
@include section-title; | ||
} | ||
|
||
.disk { | ||
margin: 8px 0 6px; | ||
|
||
.dev { | ||
margin-right: 6px; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...ponents/pages/mini-page/mini-drive-temperatures/mini-drive-temperatures.component.spec.ts
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,79 @@ | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { of } from 'rxjs'; | ||
import { EnclosureElementType, EnclosureStatus } from 'app/enums/enclosure-slot-status.enum'; | ||
import { | ||
DashboardEnclosure, | ||
DashboardEnclosureElements, | ||
DashboardEnclosureSlot, | ||
} from 'app/interfaces/enclosure.interface'; | ||
import { TooltipComponent } from 'app/modules/tooltip/tooltip.component'; | ||
import { MiniDriveTemperaturesComponent } from 'app/pages/system/enclosure/components/pages/mini-page/mini-drive-temperatures/mini-drive-temperatures.component'; | ||
import { EnclosureStore } from 'app/pages/system/enclosure/services/enclosure.store'; | ||
import { DiskTemperatureService, Temperature } from 'app/services/disk-temperature.service'; | ||
|
||
describe('MiniDriveTemperaturesComponent', () => { | ||
let spectator: Spectator<MiniDriveTemperaturesComponent>; | ||
const enclosure = { | ||
elements: { | ||
[EnclosureElementType.ArrayDeviceSlot]: { | ||
1: { | ||
dev: 'ada1', | ||
status: EnclosureStatus.Ok, | ||
is_front: true, | ||
} as DashboardEnclosureSlot, | ||
2: { | ||
dev: 'ada2', | ||
status: EnclosureStatus.Crit, | ||
is_front: true, | ||
} as DashboardEnclosureSlot, | ||
3: { | ||
dev: null, | ||
status: EnclosureStatus.Ok, | ||
is_front: true, | ||
} as DashboardEnclosureSlot, | ||
}, | ||
} as DashboardEnclosureElements, | ||
} as DashboardEnclosure; | ||
const createComponent = createComponentFactory({ | ||
component: MiniDriveTemperaturesComponent, | ||
imports: [ | ||
TooltipComponent, | ||
], | ||
providers: [ | ||
mockProvider(EnclosureStore, { | ||
selectedEnclosure: () => enclosure, | ||
selectedSlot: () => null as DashboardEnclosureSlot, | ||
selectSlot: jest.fn(), | ||
}), | ||
mockProvider(DiskTemperatureService, { | ||
temperature$: of({ | ||
values: { ada1: 37 }, | ||
keys: ['ada1'], | ||
unit: 'Celsius', | ||
symbolText: '°', | ||
} as Temperature), | ||
}), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
}); | ||
|
||
it('renders lines with temperature values', () => { | ||
const lines = spectator.queryAll('.disk'); | ||
expect(lines).toHaveLength(2); | ||
|
||
const contents = lines.map((line) => { | ||
return { | ||
label: line.querySelector('.dev').textContent.trim(), | ||
temperature: line.querySelector('.temperature').textContent.trim(), | ||
hideTooltip: !line.querySelector('ix-tooltip'), | ||
}; | ||
}); | ||
expect(contents).toEqual([ | ||
{ label: 'ada1:', temperature: '37 °C', hideTooltip: true }, | ||
{ label: 'ada2:', temperature: 'Temperature not available.', hideTooltip: false }, | ||
]); | ||
}); | ||
}); |
40 changes: 38 additions & 2 deletions
40
...e/components/pages/mini-page/mini-drive-temperatures/mini-drive-temperatures.component.ts
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 |
---|---|---|
@@ -1,11 +1,47 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, Component, OnDestroy, computed, | ||
} from '@angular/core'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
import { EnclosureStore } from 'app/pages/system/enclosure/services/enclosure.store'; | ||
import { getSlotsOfSide } from 'app/pages/system/enclosure/utils/get-slots-of-side.utils'; | ||
import { EnclosureSide } from 'app/pages/system/enclosure/utils/supported-enclosures'; | ||
import { DiskTemperatureService } from 'app/services/disk-temperature.service'; | ||
|
||
@Component({ | ||
selector: 'ix-mini-drive-temperatures', | ||
templateUrl: './mini-drive-temperatures.component.html', | ||
styleUrl: './mini-drive-temperatures.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MiniDriveTemperaturesComponent { | ||
export class MiniDriveTemperaturesComponent implements OnDestroy { | ||
private temperature = toSignal(this.diskTemperatureService.temperature$); | ||
|
||
private readonly slots = computed(() => { | ||
return getSlotsOfSide(this.store.selectedEnclosure(), EnclosureSide.Front); | ||
}); | ||
|
||
protected readonly disks = computed(() => { | ||
return this.slots() | ||
.filter((slot) => slot.dev) | ||
.map((slot) => { | ||
const value = this.temperature()?.values?.[slot.dev] || null; | ||
const symbolText = `${this.temperature()?.symbolText}C`; | ||
return { | ||
dev: slot.dev, | ||
temperature: value !== null ? `${value} ${symbolText}` : undefined, | ||
}; | ||
}); | ||
}); | ||
|
||
constructor( | ||
private store: EnclosureStore, | ||
private diskTemperatureService: DiskTemperatureService, | ||
) { | ||
this.diskTemperatureService.listenForTemperatureUpdates(); | ||
this.diskTemperatureService.diskTemperaturesSubscribe(); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.diskTemperatureService.diskTemperaturesUnsubscribe(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.