- Poll only rooms returned by /api/v1/rooms so calls are never wasted on sensor-less rooms; new rooms are picked up automatically after deploy - Replace timer(0, interval) with concat() for synchronous initial emission - Remove mock fallback from getLatestReadingForRoom / getHistoryForRoom so the UI reflects real API state instead of hiding errors with fake data - Add Basic-Auth interceptor and dev proxy (proxy.conf.json) for local dev - Replace hardcoded API credentials with __API_USERNAME__ / __API_PASSWORD__ placeholders for CI-time injection from GitHub Secrets - Add "Very Poor" CO2 level (1500-2000 ppm) to the 6-level scale - Update "No sensor installed" copy to "No data available currently" - Handle empty history state in room-details-panel Closes #30
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { Observable, catchError, map, of } from 'rxjs';
|
|
import { ROOM_LAYOUTS, RoomLayout } from '../config/rooms-layout.config';
|
|
import { environment } from '../../environments/environment';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class RoomService {
|
|
private http = inject(HttpClient);
|
|
private apiUrl = environment.apiUrl;
|
|
|
|
/**
|
|
* Returns rooms that exist both in ROOM_LAYOUTS (with layout/sensor metadata)
|
|
* and in the backend (confirmed to have data). Falls back to all layouts.
|
|
*/
|
|
getRooms(): Observable<RoomLayout[]> {
|
|
return this.http.get<string[]>(`${this.apiUrl}/rooms`).pipe(
|
|
map(ids => {
|
|
const matched = ids
|
|
.map(id => ROOM_LAYOUTS.find(r => r.id === id))
|
|
.filter((r): r is RoomLayout => r !== undefined);
|
|
return matched.length > 0 ? matched : ROOM_LAYOUTS;
|
|
}),
|
|
catchError(() => of(ROOM_LAYOUTS)),
|
|
);
|
|
}
|
|
|
|
getRoomById(id: string): Observable<RoomLayout | undefined> {
|
|
return of(ROOM_LAYOUTS.find(r => r.id === id));
|
|
}
|
|
}
|