diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index d20ca24..224c289 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use App\Models\Room; use App\Services\HomeStatus; use Livewire\Attributes\Layout; use Livewire\Component; @@ -11,12 +12,26 @@ class Dashboard extends Component { public function render(HomeStatus $home) { - $rooms = $home->load(); + $devices = $home->devices(); + + // Group by room in room order; room-less devices go into a trailing "no room" group + // so they never disappear from the overview. + $groups = []; + foreach (Room::orderBy('sort')->orderBy('name')->get() as $room) { + $roomDevices = $devices->where('room_id', $room->id)->values(); + if ($roomDevices->isNotEmpty()) { + $groups[] = ['name' => $room->name, 'devices' => $roomDevices]; + } + } + $unassigned = $devices->whereNull('room_id')->values(); + if ($unassigned->isNotEmpty()) { + $groups[] = ['name' => __('dashboard.no_room'), 'devices' => $unassigned]; + } return view('livewire.dashboard', [ - 'rooms' => $rooms, - 'summary' => $home->summary($rooms), - 'warningCount' => count($home->warnings($rooms)), + 'groups' => $groups, + 'summary' => $home->summary($devices), + 'warningCount' => count($home->warnings($devices)), ]); } } diff --git a/app/Livewire/Modals/Warnings.php b/app/Livewire/Modals/Warnings.php index 3097b34..dfc1588 100644 --- a/app/Livewire/Modals/Warnings.php +++ b/app/Livewire/Modals/Warnings.php @@ -17,7 +17,7 @@ class Warnings extends ModalComponent $home = app(HomeStatus::class); return view('livewire.modals.warnings', [ - 'warnings' => $home->warnings($home->load()), + 'warnings' => $home->warnings($home->devices()), ]); } } diff --git a/app/Services/HomeStatus.php b/app/Services/HomeStatus.php index 000825a..f9c4682 100644 --- a/app/Services/HomeStatus.php +++ b/app/Services/HomeStatus.php @@ -2,12 +2,12 @@ namespace App\Services; -use App\Models\Room; +use App\Models\Device; use Illuminate\Support\Collection; /** - * Aggregates the current home state (rooms/devices/entities) into a summary and a - * warning list. Shared by the Dashboard (grid + warning count) and the Warnings modal. + * Aggregates the current home state (all devices/entities, incl. those with no room) + * into a summary and a warning list. Shared by the Dashboard and the Warnings modal. */ class HomeStatus { @@ -15,17 +15,17 @@ class HomeStatus public function __construct(private readonly SystemHealth $health) {} - public function load(): Collection + /** Every device (including room-less ones), eager-loaded for aggregation + display. */ + public function devices(): Collection { - return Room::query() - ->with(['devices' => fn ($q) => $q->orderBy('name'), 'devices.entities.state']) - ->orderBy('sort')->orderBy('name') + return Device::query() + ->with(['entities.state', 'room']) + ->orderBy('name') ->get(); } - public function summary(Collection $rooms): array + public function summary(Collection $devices): array { - $devices = $rooms->flatMap->devices; $entities = $devices->flatMap->entities; return [ @@ -38,9 +38,8 @@ class HomeStatus } /** @return array */ - public function warnings(Collection $rooms): array + public function warnings(Collection $devices): array { - $devices = $rooms->flatMap->devices; $entities = $devices->flatMap->entities; $warnings = []; diff --git a/lang/de/dashboard.php b/lang/de/dashboard.php index 7b6f68f..0c4f0ae 100644 --- a/lang/de/dashboard.php +++ b/lang/de/dashboard.php @@ -14,6 +14,7 @@ return [ 'kpi_low_battery' => 'Niedriger Akku', 'rooms_title' => 'Räume', + 'no_room' => 'Ohne Raum', 'warn_host' => 'Systemdienst gestört', 'warn_host_meta' => 'Details im Host-Bereich', diff --git a/lang/en/dashboard.php b/lang/en/dashboard.php index 0ccdc1d..2ccfdb6 100644 --- a/lang/en/dashboard.php +++ b/lang/en/dashboard.php @@ -14,6 +14,7 @@ return [ 'kpi_low_battery' => 'Low battery', 'rooms_title' => 'Rooms', + 'no_room' => 'No room', 'warn_host' => 'System service degraded', 'warn_host_meta' => 'Details in the Host area', diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index eb73d70..4f3fd3c 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -30,10 +30,10 @@

{{ __('dashboard.rooms_title') }}