Skip to content

Commit

Permalink
NAS-129747 / 24.10 / Implement MiniDriveTemperaturesComponent (#10304)
Browse files Browse the repository at this point in the history
* 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
3 people authored Jul 16, 2024
1 parent 97b0217 commit 8d74386
Show file tree
Hide file tree
Showing 93 changed files with 320 additions and 5 deletions.
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>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
h3 {
@include section-title;
}

.disk {
margin: 8px 0 6px;

.dev {
margin-right: 6px;
}
}
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 },
]);
});
});
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();
}
}
2 changes: 2 additions & 0 deletions src/app/pages/system/enclosure/enclosure.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AppLoaderModule } from 'app/modules/loader/app-loader.module';
import { FileSizePipe } from 'app/modules/pipes/file-size/file-size.pipe';
import { MapValuePipe } from 'app/modules/pipes/map-value/map-value.pipe';
import { TestIdModule } from 'app/modules/test-id/test-id.module';
import { TooltipComponent } from 'app/modules/tooltip/tooltip.component';
import { EnclosureDashboardComponent } from 'app/pages/system/enclosure/components/enclosure-dashboard/enclosure-dashboard.component';
import {
EnclosureHeaderComponent,
Expand Down Expand Up @@ -112,6 +113,7 @@ import { SvgCacheService } from 'app/pages/system/enclosure/services/svg-cache.s
NgxSkeletonLoaderModule,
AppLoaderModule,
DiskIconComponent,
TooltipComponent,
],
declarations: [
EnclosureDashboardComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -3870,6 +3871,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -2862,6 +2862,7 @@
"No results found in {section}": "",
"No similar apps found.": "",
"No snapshots sent yet": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur.": "",
"No temperature data was reported by the system. There can be a number of reasons why this might occur. For troubleshooting tips please go here": "",
"No unused disks": "",
"No update found.": "",
Expand Down Expand Up @@ -4263,6 +4264,7 @@
"Temperature Alerts": "",
"Temperature Sensors": "",
"Temperature data missing.": "",
"Temperature not available.": "",
"Template": "",
"Tenant Domain": "",
"Tenant ID": "",
Expand Down
Loading

0 comments on commit 8d74386

Please sign in to comment.