mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +00:00
feat: adapt device models api
This commit is contained in:
parent
a88e72b75e
commit
731d995f20
29 changed files with 2379 additions and 215 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceModel;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
|
@ -22,6 +23,8 @@ new class extends Component {
|
|||
public $is_mirror = false;
|
||||
|
||||
public $mirror_device_id = null;
|
||||
public $device_model_id = null;
|
||||
public $deviceModels;
|
||||
|
||||
public ?int $pause_duration;
|
||||
|
||||
|
|
@ -29,15 +32,29 @@ new class extends Component {
|
|||
'mac_address' => 'required',
|
||||
'api_key' => 'required',
|
||||
'default_refresh_interval' => 'required|integer',
|
||||
'device_model_id' => 'nullable|exists:device_models,id',
|
||||
'mirror_device_id' => 'required_if:is_mirror,true',
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->devices = auth()->user()->devices;
|
||||
$this->deviceModels = DeviceModel::orderBy('label')->get()->sortBy(function ($deviceModel) {
|
||||
// Put TRMNL models at the top, then sort alphabetically within each group
|
||||
$isTrmnl = str_starts_with($deviceModel->label, 'TRMNL');
|
||||
return $isTrmnl ? '0' . $deviceModel->label : '1' . $deviceModel->label;
|
||||
});
|
||||
return view('livewire.devices.manage');
|
||||
}
|
||||
|
||||
public function updatedDeviceModelId(): void
|
||||
{
|
||||
// Convert empty string to null for custom selection
|
||||
if (empty($this->device_model_id)) {
|
||||
$this->device_model_id = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function createDevice(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
|
@ -49,6 +66,9 @@ new class extends Component {
|
|||
abort_if($mirrorDevice->mirror_device_id !== null, 403, 'Cannot mirror a device that is already a mirror device');
|
||||
}
|
||||
|
||||
// Convert empty string to null for custom selection
|
||||
$deviceModelId = empty($this->device_model_id) ? null : $this->device_model_id;
|
||||
|
||||
Device::create([
|
||||
'name' => $this->name,
|
||||
'mac_address' => $this->mac_address,
|
||||
|
|
@ -56,6 +76,7 @@ new class extends Component {
|
|||
'default_refresh_interval' => $this->default_refresh_interval,
|
||||
'friendly_id' => $this->friendly_id,
|
||||
'user_id' => auth()->id(),
|
||||
'device_model_id' => $deviceModelId,
|
||||
'mirror_device_id' => $this->is_mirror ? $this->mirror_device_id : null,
|
||||
]);
|
||||
|
||||
|
|
@ -154,6 +175,19 @@ new class extends Component {
|
|||
autofocus/>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<flux:select label="Device Model" wire:model.live="device_model_id">
|
||||
<flux:select.option value="">Custom (Manual Dimensions)</flux:select.option>
|
||||
@if ($deviceModels && $deviceModels->count() > 0)
|
||||
@foreach($deviceModels as $deviceModel)
|
||||
<flux:select.option value="{{ $deviceModel->id }}">
|
||||
{{ $deviceModel->label }} ({{ $deviceModel->width }}x{{ $deviceModel->height }})
|
||||
</flux:select.option>
|
||||
@endforeach
|
||||
@endif
|
||||
</flux:select>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<flux:checkbox wire:model.live="is_mirror" label="Mirrors Device"/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue