47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Livewire\Concerns\TogglesEntities;
|
|
use App\Models\Entity;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Tablet control panel — big touch tiles for lights/switches with quick on/off,
|
|
* a colour/brightness modal for lights, and drag-to-reorder (persisted per entity).
|
|
*/
|
|
#[Layout('layouts.app')]
|
|
class Panel extends Component
|
|
{
|
|
use TogglesEntities;
|
|
|
|
#[On('echo-private:home,.DeviceStateChanged')]
|
|
public function onDeviceStateChanged(): void {}
|
|
|
|
/** Persist a new tile order from the drag interaction. */
|
|
public function reorder(array $order): void
|
|
{
|
|
foreach (array_values($order) as $index => $uuid) {
|
|
Entity::where('uuid', $uuid)->update(['panel_sort' => $index]);
|
|
}
|
|
|
|
// Confirm the save so the drag doesn't feel like a no-op.
|
|
$this->dispatch('panel-reordered');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$tiles = Entity::query()
|
|
->whereIn('type', ['switch', 'light'])
|
|
->where('panel_hidden', false)
|
|
->with('device.room', 'state')
|
|
->orderByRaw('panel_sort IS NULL, panel_sort')
|
|
->orderBy('id')
|
|
->get();
|
|
|
|
return view('livewire.panel', ['tiles' => $tiles]);
|
|
}
|
|
}
|