mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat(#17): add commands and jobs to poll, download and update firmware
feat(#17): add commands and jobs to poll, download and update firmware feat(#17): update firmware modal feat(#17): add tests
This commit is contained in:
parent
93aac51182
commit
87b9b57c3d
13 changed files with 567 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\FirmwareDownloadJob;
|
||||
use App\Models\Firmware;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\PlaylistItem;
|
||||
use Livewire\Volt\Component;
|
||||
|
|
@ -26,6 +28,11 @@ new class extends Component {
|
|||
public $active_until;
|
||||
public $refresh_time = null;
|
||||
|
||||
// Firmware properties
|
||||
public $firmwares;
|
||||
public $selected_firmware_id;
|
||||
public $download_firmware;
|
||||
|
||||
public function mount(\App\Models\Device $device)
|
||||
{
|
||||
abort_unless(auth()->user()->devices->contains($device), 403);
|
||||
|
|
@ -44,6 +51,8 @@ new class extends Component {
|
|||
$this->rotate = $device->rotate;
|
||||
$this->image_format = $device->image_format;
|
||||
$this->playlists = $device->playlists()->with('items.plugin')->orderBy('created_at')->get();
|
||||
$this->firmwares = \App\Models\Firmware::orderBy('latest', 'desc')->orderBy('created_at', 'desc')->get();
|
||||
$this->selected_firmware_id = $this->firmwares->where('latest', true)->first()?->id;
|
||||
|
||||
return view('livewire.devices.configure', [
|
||||
'image' => ($current_image_uuid) ? url($current_image_path) : null,
|
||||
|
|
@ -216,6 +225,26 @@ new class extends Component {
|
|||
$this->active_until = optional($playlist->active_until)->format('H:i');
|
||||
$this->refresh_time = $playlist->refresh_time;
|
||||
}
|
||||
|
||||
public function updateFirmware()
|
||||
{
|
||||
abort_unless(auth()->user()->devices->contains($this->device), 403);
|
||||
|
||||
$this->validate([
|
||||
'selected_firmware_id' => 'required|exists:firmware,id',
|
||||
]);
|
||||
|
||||
|
||||
if ($this->download_firmware) {
|
||||
FirmwareDownloadJob::dispatchSync(Firmware::find($this->selected_firmware_id));
|
||||
}
|
||||
|
||||
$this->device->update([
|
||||
'update_firmware_id' => $this->selected_firmware_id,
|
||||
]);
|
||||
|
||||
Flux::modal('update-firmware')->close();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
|
@ -266,9 +295,18 @@ new class extends Component {
|
|||
<flux:modal.trigger name="edit-device">
|
||||
<flux:button icon="pencil-square" />
|
||||
</flux:modal.trigger>
|
||||
<flux:modal.trigger name="delete-device">
|
||||
<flux:button icon="trash" variant="subtle"/>
|
||||
</flux:modal.trigger>
|
||||
|
||||
<flux:dropdown>
|
||||
<flux:button icon="ellipsis-horizontal" variant="subtle"></flux:button>
|
||||
<flux:menu>
|
||||
<flux:modal.trigger name="update-firmware">
|
||||
<flux:menu.item icon="arrow-up-circle">Update Firmware</flux:menu.item>
|
||||
</flux:modal.trigger>
|
||||
<flux:modal.trigger name="delete-device">
|
||||
<flux:menu.item icon="trash" variant="danger">Delete Device</flux:menu.item>
|
||||
</flux:modal.trigger>
|
||||
</flux:menu>
|
||||
</flux:dropdown>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -309,6 +347,39 @@ new class extends Component {
|
|||
</div>
|
||||
</flux:modal>
|
||||
|
||||
<flux:modal name="update-firmware" class="md:w-96">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">Update Firmware</flux:heading>
|
||||
<flux:subheading>Select a firmware version to update to</flux:subheading>
|
||||
</div>
|
||||
|
||||
<form wire:submit="updateFirmware">
|
||||
<div class="mb-4">
|
||||
<flux:select label="Firmware Version" wire:model="selected_firmware_id" required>
|
||||
@foreach($firmwares as $firmware)
|
||||
<flux:select.option value="{{ $firmware->id }}">
|
||||
{{ $firmware->version_tag }} {{ $firmware->latest ? '(Latest)' : '' }}
|
||||
</flux:select.option>
|
||||
@endforeach
|
||||
</flux:select>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<flux:checkbox wire:model="download_firmware" label="Cache Firmware on BYOS">
|
||||
</flux:checkbox>
|
||||
<flux:text class="text-xs mt-2">Check if the Device has no internet connection.
|
||||
</flux:text>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<flux:spacer/>
|
||||
<flux:button type="submit" variant="primary">Update Firmware</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</flux:modal>
|
||||
|
||||
<flux:modal name="delete-device" class="min-w-[22rem] space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">Delete {{$device->name}}?</flux:heading>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue