diff --git a/app/Livewire/Windows.php b/app/Livewire/Windows.php new file mode 100644 index 0000000..c815601 --- /dev/null +++ b/app/Livewire/Windows.php @@ -0,0 +1,33 @@ +whereIn('type', ['contact', 'motion']) + ->with(['device.room', 'device.entities.state', 'state']) + ->get() + ->sortBy(fn ($e) => ($e->device->room?->name ?? 'zzz').$e->device->name) + ->values(); + + $open = $sensors->filter(fn ($e) => $e->type === 'contact' && data_get($e->state, 'state.open') === true)->count(); + + return view('livewire.windows', [ + 'groups' => $sensors->groupBy(fn ($e) => $e->device->room?->name ?? __('devices.no_room')), + 'open' => $open, + 'total' => $sensors->count(), + ]); + } +} diff --git a/lang/de/windows.php b/lang/de/windows.php new file mode 100644 index 0000000..ae58f17 --- /dev/null +++ b/lang/de/windows.php @@ -0,0 +1,9 @@ + 'Kontakte an Fenstern und Türen.', + 'empty' => 'Keine Kontaktsensoren.', + 'all_closed' => 'Alles geschlossen', + 'open_count' => '{1}1 offen|[2,*]:count offen', + 'sensor_count' => '{0}Keine Sensoren|{1}1 Sensor|[2,*]:count Sensoren', +]; diff --git a/lang/en/windows.php b/lang/en/windows.php new file mode 100644 index 0000000..1b6110a --- /dev/null +++ b/lang/en/windows.php @@ -0,0 +1,9 @@ + 'Contacts on windows and doors.', + 'empty' => 'No contact sensors.', + 'all_closed' => 'All closed', + 'open_count' => '{1}1 open|[2,*]:count open', + 'sensor_count' => '{0}No sensors|{1}1 sensor|[2,*]:count sensors', +]; diff --git a/resources/views/components/sidebar.blade.php b/resources/views/components/sidebar.blade.php index fa6b724..88a37d1 100644 --- a/resources/views/components/sidebar.blade.php +++ b/resources/views/components/sidebar.blade.php @@ -9,7 +9,7 @@ ['key' => 'persons', 'icon' => 'persons', 'route' => null, 'lock' => false], ], 'nav.section_security' => [ - ['key' => 'windows', 'icon' => 'window', 'route' => null, 'lock' => false], + ['key' => 'windows', 'icon' => 'window', 'route' => 'windows', 'lock' => false], ['key' => 'access', 'icon' => 'shield', 'route' => null, 'lock' => true], ], 'nav.section_system' => [ diff --git a/resources/views/livewire/windows.blade.php b/resources/views/livewire/windows.blade.php new file mode 100644 index 0000000..74557e6 --- /dev/null +++ b/resources/views/livewire/windows.blade.php @@ -0,0 +1,50 @@ +
+ + +
+ @if ($total === 0) +

{{ __('windows.empty') }}

+ @else + {{-- summary --}} +
+ +
+ + + +
+

+ {{ $open > 0 ? trans_choice('windows.open_count', $open, ['count' => $open]) : __('windows.all_closed') }} +

+

{{ trans_choice('windows.sensor_count', $total, ['count' => $total]) }}

+
+
+
+ + @foreach ($groups as $roomName => $sensors) + +
+ @foreach ($sensors as $sensor) + @php + $battery = $sensor->device->entities->firstWhere('type', 'battery'); + $pct = $battery ? (int) data_get($battery->state, 'state.percent', 0) : null; + @endphp +
+ + + + {{ $sensor->device->name }} +
+ @if (! is_null($pct)) + {{ __('devices.battery') }} · {{ $pct }}% + @endif + +
+
+ @endforeach +
+
+ @endforeach + @endif +
+
diff --git a/routes/web.php b/routes/web.php index 5edb949..51a1e6f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -7,6 +7,7 @@ use App\Livewire\Devices\Show as DeviceShow; use App\Livewire\Host; use App\Livewire\Rooms\Index as RoomIndex; use App\Livewire\Rooms\Show as RoomShow; +use App\Livewire\Windows; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; @@ -22,6 +23,7 @@ Route::middleware('auth')->group(function () { Route::get('/rooms/{room}', RoomShow::class)->name('rooms.show'); Route::get('/devices', DeviceIndex::class)->name('devices.index'); Route::get('/devices/{device}', DeviceShow::class)->name('devices.show'); + Route::get('/windows', Windows::class)->name('windows'); Route::get('/host', Host::class)->name('host'); Route::post('/logout', function () {