From c8b21acb368a5e261f59221b8907f7ee01c8fac1 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Tue, 18 Mar 2025 12:21:09 +0100 Subject: [PATCH] feat: override device refresh time via playlist --- app/Models/Playlist.php | 1 + ...28_add_refresh_time_to_playlists_table.php | 28 +++++++++++++++++++ .../views/livewire/playlists/index.blade.php | 24 +++++++++++++--- routes/api.php | 7 +++-- 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2025_03_18_110028_add_refresh_time_to_playlists_table.php diff --git a/app/Models/Playlist.php b/app/Models/Playlist.php index c3744e9..0945c1b 100644 --- a/app/Models/Playlist.php +++ b/app/Models/Playlist.php @@ -18,6 +18,7 @@ class Playlist extends Model 'weekdays' => 'array', 'active_from' => 'datetime:H:i', 'active_until' => 'datetime:H:i', + 'refresh_time' => 'integer', ]; public function device(): BelongsTo diff --git a/database/migrations/2025_03_18_110028_add_refresh_time_to_playlists_table.php b/database/migrations/2025_03_18_110028_add_refresh_time_to_playlists_table.php new file mode 100644 index 0000000..ad0b79d --- /dev/null +++ b/database/migrations/2025_03_18_110028_add_refresh_time_to_playlists_table.php @@ -0,0 +1,28 @@ +integer('refresh_time')->nullable()->after('active_until'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('playlists', function (Blueprint $table) { + $table->dropColumn('refresh_time'); + }); + } +}; diff --git a/resources/views/livewire/playlists/index.blade.php b/resources/views/livewire/playlists/index.blade.php index 3d34999..cfeacbd 100644 --- a/resources/views/livewire/playlists/index.blade.php +++ b/resources/views/livewire/playlists/index.blade.php @@ -11,9 +11,10 @@ new class extends Component { // Playlist form properties public $playlist_name; - public $selected_weekdays = []; + public $selected_weekdays = null; public $active_from; public $active_until; + public $refresh_time = null; public function mount() { @@ -89,29 +90,40 @@ new class extends Component { $this->validate([ 'playlist_name' => 'required|string|max:255', - 'selected_weekdays' => 'array', + 'selected_weekdays' => 'nullable|array', 'active_from' => 'nullable|date_format:H:i', 'active_until' => 'nullable|date_format:H:i', + 'refresh_time' => 'nullable|integer|min:60', ]); + if ($this->refresh_time < 60) { + $this->refresh_time = null; + } + + if (empty($this->selected_weekdays)){ + $this->selected_weekdays = null; + } + $playlist->update([ 'name' => $this->playlist_name, 'weekdays' => $this->selected_weekdays, 'active_from' => $this->active_from, 'active_until' => $this->active_until, + 'refresh_time' => $this->refresh_time, ]); $this->devices = auth()->user()->devices()->with(['playlists.items.plugin'])->get(); - $this->reset(['playlist_name', 'selected_weekdays', 'active_from', 'active_until']); + $this->reset(['playlist_name', 'selected_weekdays', 'active_from', 'active_until', 'refresh_time']); Flux::modal('edit-playlist-' . $playlist->id)->close(); } public function preparePlaylistEdit(Playlist $playlist) { $this->playlist_name = $playlist->name; - $this->selected_weekdays = $playlist->weekdays ?? []; + $this->selected_weekdays = $playlist->weekdays ?? null; $this->active_from = optional($playlist->active_from)->format('H:i'); $this->active_until = optional($playlist->active_until)->format('H:i'); + $this->refresh_time = $playlist->refresh_time; } }; ?> @@ -257,6 +269,10 @@ new class extends Component { +
+ +
+
Save Changes diff --git a/routes/api.php b/routes/api.php index ee36d76..84b4373 100644 --- a/routes/api.php +++ b/routes/api.php @@ -41,11 +41,14 @@ Route::get('/display', function (Request $request) { 'last_firmware_version' => $request->header('fw-version'), ]); + $refreshTimeOverride = null; // Skip if cloud proxy is enabled for device - if (! $device->proxy_cloud) { + if (! $device->proxy_cloud || $device->getNextPlaylistItem()) { $playlistItem = $device->getNextPlaylistItem(); if ($playlistItem) { + $refreshTimeOverride = $playlistItem->playlist()->first()->refresh_time; + $plugin = $playlistItem->plugin; // Check and update stale data if needed @@ -78,7 +81,7 @@ Route::get('/display', function (Request $request) { 'status' => 0, 'image_url' => url('storage/'.$image_path), 'filename' => $filename, - 'refresh_rate' => $device->default_refresh_interval, + 'refresh_rate' => $refreshTimeOverride ?? $device->default_refresh_interval, 'reset_firmware' => false, 'update_firmware' => $device->update_firmware, 'firmware_url' => $device->firmware_url,