mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-16 16:37:47 +00:00
chore: pint
This commit is contained in:
parent
a15645ad88
commit
d19a079b8a
30 changed files with 295 additions and 188 deletions
|
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public $token;
|
||||
|
||||
public $devices;
|
||||
|
||||
public $selected_device;
|
||||
|
||||
public function mount(): void
|
||||
|
|
|
|||
|
|
@ -1,26 +1,30 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plugin;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Component;
|
||||
|
||||
/*
|
||||
* This component contains the configuation modal
|
||||
*/
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public Plugin $plugin;
|
||||
|
||||
public array $configuration_template = [];
|
||||
|
||||
public array $configuration = []; // holds config data
|
||||
|
||||
public array $multiValues = []; // UI boxes for multi_string
|
||||
|
||||
public array $xhrSelectOptions = [];
|
||||
|
||||
public array $searchQueries = [];
|
||||
|
||||
// ------------------------------------This section contains one-off functions for the form------------------------------------------------
|
||||
public function mount(): void
|
||||
{
|
||||
$this -> loadData();
|
||||
$this->loadData();
|
||||
}
|
||||
|
||||
public function loadData(): void
|
||||
|
|
@ -38,7 +42,7 @@ new class extends Component {
|
|||
$fieldKey = $field['keyname'];
|
||||
$rawValue = $this->configuration[$fieldKey] ?? ($field['default'] ?? '');
|
||||
|
||||
$currentValue = is_array($rawValue) ? '' : (string)$rawValue;
|
||||
$currentValue = is_array($rawValue) ? '' : (string) $rawValue;
|
||||
|
||||
$this->multiValues[$fieldKey] = $currentValue !== ''
|
||||
? array_values(array_filter(explode(',', $currentValue)))
|
||||
|
|
@ -51,10 +55,11 @@ new class extends Component {
|
|||
* Triggered by @close on the modal to discard any typed but unsaved changes
|
||||
*/
|
||||
public int $resetIndex = 0; // Add this property
|
||||
|
||||
public function resetForm(): void
|
||||
{
|
||||
$this->loadData();
|
||||
$this->resetIndex++; // Increment to force DOM refresh
|
||||
++$this->resetIndex; // Increment to force DOM refresh
|
||||
}
|
||||
|
||||
public function saveConfiguration()
|
||||
|
|
@ -131,7 +136,7 @@ new class extends Component {
|
|||
if ($query !== null) {
|
||||
$requestData = [
|
||||
'function' => $fieldKey,
|
||||
'query' => $query
|
||||
'query' => $query,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +149,7 @@ new class extends Component {
|
|||
} else {
|
||||
$this->xhrSelectOptions[$fieldKey] = [];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->xhrSelectOptions[$fieldKey] = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -152,11 +157,11 @@ new class extends Component {
|
|||
public function searchXhrSelect(string $fieldKey, string $endpoint): void
|
||||
{
|
||||
$query = $this->searchQueries[$fieldKey] ?? '';
|
||||
if (!empty($query)) {
|
||||
if (! empty($query)) {
|
||||
$this->loadXhrSelectOptions($fieldKey, $endpoint, $query);
|
||||
}
|
||||
}
|
||||
};?>
|
||||
}; ?>
|
||||
|
||||
<flux:modal name="configuration-modal" @close="resetForm" class="md:w-96">
|
||||
<div wire:key="config-form-{{ $resetIndex }}" class="space-y-6">
|
||||
|
|
|
|||
|
|
@ -3,14 +3,22 @@
|
|||
use App\Models\Plugin;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public Plugin $plugin;
|
||||
|
||||
public string $name;
|
||||
|
||||
public array $checked_devices = [];
|
||||
|
||||
public array $device_playlists = [];
|
||||
|
||||
public array $device_playlist_names = [];
|
||||
|
||||
public array $device_weekdays = [];
|
||||
|
||||
public array $device_active_from = [];
|
||||
|
||||
public array $device_active_until = [];
|
||||
|
||||
public function mount(): void
|
||||
|
|
@ -38,7 +46,6 @@ new class extends Component {
|
|||
$this->plugin->update(['name' => $this->name]);
|
||||
}
|
||||
|
||||
|
||||
public function addToPlaylist()
|
||||
{
|
||||
$this->validate([
|
||||
|
|
@ -46,14 +53,16 @@ new class extends Component {
|
|||
]);
|
||||
|
||||
foreach ($this->checked_devices as $deviceId) {
|
||||
if (!isset($this->device_playlists[$deviceId]) || empty($this->device_playlists[$deviceId])) {
|
||||
$this->addError('device_playlists.' . $deviceId, 'Please select a playlist for each device.');
|
||||
if (! isset($this->device_playlists[$deviceId]) || empty($this->device_playlists[$deviceId])) {
|
||||
$this->addError('device_playlists.'.$deviceId, 'Please select a playlist for each device.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->device_playlists[$deviceId] === 'new') {
|
||||
if (!isset($this->device_playlist_names[$deviceId]) || empty($this->device_playlist_names[$deviceId])) {
|
||||
$this->addError('device_playlist_names.' . $deviceId, 'Playlist name is required when creating a new playlist.');
|
||||
if (! isset($this->device_playlist_names[$deviceId]) || empty($this->device_playlist_names[$deviceId])) {
|
||||
$this->addError('device_playlist_names.'.$deviceId, 'Playlist name is required when creating a new playlist.');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -63,15 +72,15 @@ new class extends Component {
|
|||
$playlist = null;
|
||||
|
||||
if ($this->device_playlists[$deviceId] === 'new') {
|
||||
$playlist = \App\Models\Playlist::create([
|
||||
$playlist = App\Models\Playlist::create([
|
||||
'device_id' => $deviceId,
|
||||
'name' => $this->device_playlist_names[$deviceId],
|
||||
'weekdays' => !empty($this->device_weekdays[$deviceId] ?? null) ? $this->device_weekdays[$deviceId] : null,
|
||||
'weekdays' => ! empty($this->device_weekdays[$deviceId] ?? null) ? $this->device_weekdays[$deviceId] : null,
|
||||
'active_from' => $this->device_active_from[$deviceId] ?? null,
|
||||
'active_until' => $this->device_active_until[$deviceId] ?? null,
|
||||
]);
|
||||
} else {
|
||||
$playlist = \App\Models\Playlist::findOrFail($this->device_playlists[$deviceId]);
|
||||
$playlist = App\Models\Playlist::findOrFail($this->device_playlists[$deviceId]);
|
||||
}
|
||||
|
||||
$maxOrder = $playlist->items()->max('order') ?? 0;
|
||||
|
|
@ -96,16 +105,17 @@ new class extends Component {
|
|||
|
||||
public function getDevicePlaylists($deviceId)
|
||||
{
|
||||
return \App\Models\Playlist::where('device_id', $deviceId)->get();
|
||||
return App\Models\Playlist::where('device_id', $deviceId)->get();
|
||||
}
|
||||
|
||||
public function hasAnyPlaylistSelected(): bool
|
||||
{
|
||||
foreach ($this->checked_devices as $deviceId) {
|
||||
if (isset($this->device_playlists[$deviceId]) && !empty($this->device_playlists[$deviceId])) {
|
||||
if (isset($this->device_playlists[$deviceId]) && ! empty($this->device_playlists[$deviceId])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -118,14 +128,14 @@ new class extends Component {
|
|||
|
||||
public function getImagePath(): ?string
|
||||
{
|
||||
if (!$this->plugin->current_image) {
|
||||
if (! $this->plugin->current_image) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$extensions = ['png', 'bmp'];
|
||||
foreach ($extensions as $ext) {
|
||||
$path = 'images/generated/'.$this->plugin->current_image.'.'.$ext;
|
||||
if (\Illuminate\Support\Facades\Storage::disk('public')->exists($path)) {
|
||||
if (Illuminate\Support\Facades\Storage::disk('public')->exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plugin;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public array $instances = [];
|
||||
|
||||
protected $rules = [
|
||||
|
|
|
|||
|
|
@ -2,32 +2,38 @@
|
|||
|
||||
use App\Console\Commands\ExampleRecipesSeederCommand;
|
||||
use App\Services\PluginImportService;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public string $name;
|
||||
|
||||
public int $data_stale_minutes = 60;
|
||||
public string $data_strategy = "polling";
|
||||
|
||||
public string $data_strategy = 'polling';
|
||||
|
||||
public string $polling_url;
|
||||
public string $polling_verb = "get";
|
||||
|
||||
public string $polling_verb = 'get';
|
||||
|
||||
public $polling_header;
|
||||
|
||||
public $polling_body;
|
||||
|
||||
public array $plugins;
|
||||
|
||||
public $zipFile;
|
||||
|
||||
public string $sortBy = 'date_asc';
|
||||
|
||||
public array $native_plugins = [
|
||||
'markup' =>
|
||||
['name' => 'Markup', 'flux_icon_name' => 'code-bracket', 'detail_view_route' => 'plugins.markup'],
|
||||
'api' =>
|
||||
['name' => 'API', 'flux_icon_name' => 'braces', 'detail_view_route' => 'plugins.api'],
|
||||
'image-webhook' =>
|
||||
['name' => 'Image Webhook', 'flux_icon_name' => 'photo', 'detail_view_route' => 'plugins.image-webhook'],
|
||||
'markup' => ['name' => 'Markup', 'flux_icon_name' => 'code-bracket', 'detail_view_route' => 'plugins.markup'],
|
||||
'api' => ['name' => 'API', 'flux_icon_name' => 'braces', 'detail_view_route' => 'plugins.api'],
|
||||
'image-webhook' => ['name' => 'Image Webhook', 'flux_icon_name' => 'photo', 'detail_view_route' => 'plugins.image-webhook'],
|
||||
];
|
||||
|
||||
protected $rules = [
|
||||
|
|
@ -60,29 +66,31 @@ new class extends Component {
|
|||
|
||||
switch ($this->sortBy) {
|
||||
case 'name_asc':
|
||||
usort($pluginsToSort, function($a, $b) {
|
||||
usort($pluginsToSort, function ($a, $b) {
|
||||
return strcasecmp($a['name'] ?? '', $b['name'] ?? '');
|
||||
});
|
||||
break;
|
||||
|
||||
case 'name_desc':
|
||||
usort($pluginsToSort, function($a, $b) {
|
||||
usort($pluginsToSort, function ($a, $b) {
|
||||
return strcasecmp($b['name'] ?? '', $a['name'] ?? '');
|
||||
});
|
||||
break;
|
||||
|
||||
case 'date_desc':
|
||||
usort($pluginsToSort, function($a, $b) {
|
||||
usort($pluginsToSort, function ($a, $b) {
|
||||
$aDate = $a['created_at'] ?? '1970-01-01';
|
||||
$bDate = $b['created_at'] ?? '1970-01-01';
|
||||
|
||||
return strcmp($bDate, $aDate);
|
||||
});
|
||||
break;
|
||||
|
||||
case 'date_asc':
|
||||
usort($pluginsToSort, function($a, $b) {
|
||||
usort($pluginsToSort, function ($a, $b) {
|
||||
$aDate = $a['created_at'] ?? '1970-01-01';
|
||||
$bDate = $b['created_at'] ?? '1970-01-01';
|
||||
|
||||
return strcmp($aDate, $bDate);
|
||||
});
|
||||
break;
|
||||
|
|
@ -113,7 +121,7 @@ new class extends Component {
|
|||
abort_unless(auth()->user() !== null, 403);
|
||||
$this->validate();
|
||||
|
||||
\App\Models\Plugin::create([
|
||||
App\Models\Plugin::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'user_id' => auth()->id(),
|
||||
'name' => $this->name,
|
||||
|
|
@ -137,7 +145,6 @@ new class extends Component {
|
|||
$this->refreshPlugins();
|
||||
}
|
||||
|
||||
|
||||
public function importZip(PluginImportService $pluginImportService): void
|
||||
{
|
||||
abort_unless(auth()->user() !== null, 403);
|
||||
|
|
@ -153,11 +160,10 @@ new class extends Component {
|
|||
$this->reset(['zipFile']);
|
||||
|
||||
Flux::modal('import-zip')->close();
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('zipFile', 'Error installing plugin: ' . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->addError('zipFile', 'Error installing plugin: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
?>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ use App\Jobs\GenerateScreenJob;
|
|||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public string $blade_code = '';
|
||||
|
||||
public bool $isLoading = false;
|
||||
|
||||
public Collection $devices;
|
||||
|
||||
public array $checked_devices;
|
||||
|
||||
public function mount()
|
||||
|
|
@ -17,17 +19,16 @@ new class extends Component {
|
|||
$this->devices = auth()->user()->devices->pluck('id', 'name');
|
||||
}
|
||||
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->isLoading = true;
|
||||
|
||||
$this->validate([
|
||||
'checked_devices' => 'required|array',
|
||||
'blade_code' => 'required|string'
|
||||
'blade_code' => 'required|string',
|
||||
]);
|
||||
|
||||
//only devices that are owned by the user
|
||||
// only devices that are owned by the user
|
||||
$this->checked_devices = array_intersect($this->checked_devices, auth()->user()->devices->pluck('id')->toArray());
|
||||
|
||||
try {
|
||||
|
|
@ -35,7 +36,7 @@ new class extends Component {
|
|||
foreach ($this->checked_devices as $device) {
|
||||
GenerateScreenJob::dispatchSync($device, null, $rendered);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->addError('generate_screen', $e->getMessage());
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ new class extends Component {
|
|||
|
||||
public function renderHelloWorld(): string
|
||||
{
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<x-trmnl::screen>
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout>
|
||||
|
|
@ -84,7 +85,7 @@ HTML;
|
|||
|
||||
public function renderQuote(): string
|
||||
{
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<x-trmnl::screen>
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout>
|
||||
|
|
@ -102,7 +103,7 @@ HTML;
|
|||
|
||||
public function renderTrainMonitor()
|
||||
{
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<x-trmnl::screen>
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout>
|
||||
|
|
@ -136,7 +137,7 @@ HTML;
|
|||
|
||||
public function renderHomeAssistant()
|
||||
{
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<x-trmnl::screen>
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout class="layout--col gap--space-between">
|
||||
|
|
@ -162,8 +163,6 @@ HTML;
|
|||
HTML;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
?>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +1,68 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Plugin;
|
||||
use App\Models\DeviceModel;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Keepsuit\Liquid\Exceptions\LiquidException;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use App\Models\Plugin;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Attributes\On;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Keepsuit\Liquid\Exceptions\LiquidException;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public Plugin $plugin;
|
||||
public string|null $markup_code;
|
||||
public string|null $view_content;
|
||||
public string|null $markup_language;
|
||||
|
||||
public ?string $markup_code;
|
||||
|
||||
public ?string $view_content;
|
||||
|
||||
public ?string $markup_language;
|
||||
|
||||
public string $name;
|
||||
|
||||
public bool $no_bleed = false;
|
||||
|
||||
public bool $dark_mode = false;
|
||||
|
||||
public int $data_stale_minutes;
|
||||
|
||||
public string $data_strategy;
|
||||
public string|null $polling_url;
|
||||
|
||||
public ?string $polling_url;
|
||||
|
||||
public string $polling_verb;
|
||||
public string|null $polling_header;
|
||||
public string|null $polling_body;
|
||||
|
||||
public ?string $polling_header;
|
||||
|
||||
public ?string $polling_body;
|
||||
|
||||
public $data_payload;
|
||||
|
||||
public ?Carbon $data_payload_updated_at;
|
||||
|
||||
public array $checked_devices = [];
|
||||
|
||||
public array $device_playlists = [];
|
||||
|
||||
public array $device_playlist_names = [];
|
||||
|
||||
public array $device_weekdays = [];
|
||||
|
||||
public array $device_active_from = [];
|
||||
|
||||
public array $device_active_until = [];
|
||||
|
||||
public string $mashup_layout = 'full';
|
||||
|
||||
public array $mashup_plugins = [];
|
||||
|
||||
public array $configuration_template = [];
|
||||
|
||||
public ?int $preview_device_model_id = null;
|
||||
|
||||
public string $preview_size = 'full';
|
||||
|
||||
public function mount(): void
|
||||
|
|
@ -50,10 +74,10 @@ new class extends Component {
|
|||
|
||||
if ($this->plugin->render_markup_view) {
|
||||
try {
|
||||
$basePath = resource_path('views/' . str_replace('.', '/', $this->plugin->render_markup_view));
|
||||
$basePath = resource_path('views/'.str_replace('.', '/', $this->plugin->render_markup_view));
|
||||
$paths = [
|
||||
$basePath . '.blade.php',
|
||||
$basePath . '.liquid',
|
||||
$basePath.'.blade.php',
|
||||
$basePath.'.liquid',
|
||||
];
|
||||
|
||||
$this->view_content = null;
|
||||
|
|
@ -63,7 +87,7 @@ new class extends Component {
|
|||
break;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->view_content = null;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -103,7 +127,7 @@ new class extends Component {
|
|||
$this->validate();
|
||||
$this->plugin->update([
|
||||
'render_markup' => $this->markup_code ?? null,
|
||||
'markup_language' => $this->markup_language ?? null
|
||||
'markup_language' => $this->markup_language ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +160,7 @@ new class extends Component {
|
|||
$this->validatePollingUrl();
|
||||
|
||||
$validated = $this->validate();
|
||||
$validated['data_payload'] = json_decode(Arr::get($validated,'data_payload'), true);
|
||||
$validated['data_payload'] = json_decode(Arr::get($validated, 'data_payload'), true);
|
||||
$this->plugin->update($validated);
|
||||
|
||||
foreach ($this->configuration_template as $fieldKey => $field) {
|
||||
|
|
@ -144,7 +168,7 @@ new class extends Component {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!isset($this->multiValues[$fieldKey])) {
|
||||
if (! isset($this->multiValues[$fieldKey])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -155,15 +179,15 @@ new class extends Component {
|
|||
|
||||
protected function validatePollingUrl(): void
|
||||
{
|
||||
if ($this->data_strategy === 'polling' && !empty($this->polling_url)) {
|
||||
if ($this->data_strategy === 'polling' && ! empty($this->polling_url)) {
|
||||
try {
|
||||
$resolvedUrl = $this->plugin->resolveLiquidVariables($this->polling_url);
|
||||
|
||||
if (!filter_var($resolvedUrl, FILTER_VALIDATE_URL)) {
|
||||
if (! filter_var($resolvedUrl, FILTER_VALIDATE_URL)) {
|
||||
$this->addError('polling_url', 'The polling URL must be a valid URL after resolving configuration variables.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('polling_url', 'Error resolving Liquid variables: ' . $e->getMessage() . $e->getPrevious()?->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->addError('polling_url', 'Error resolving Liquid variables: '.$e->getMessage().$e->getPrevious()?->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -177,8 +201,8 @@ new class extends Component {
|
|||
$this->data_payload = json_encode($this->plugin->data_payload, JSON_PRETTY_PRINT);
|
||||
$this->data_payload_updated_at = $this->plugin->data_payload_updated_at;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->dispatch('data-update-error', message: $e->getMessage() . $e->getPrevious()?->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->dispatch('data-update-error', message: $e->getMessage().$e->getPrevious()?->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,15 +236,17 @@ new class extends Component {
|
|||
|
||||
// Validate that each checked device has a playlist selected
|
||||
foreach ($this->checked_devices as $deviceId) {
|
||||
if (!isset($this->device_playlists[$deviceId]) || empty($this->device_playlists[$deviceId])) {
|
||||
$this->addError('device_playlists.' . $deviceId, 'Please select a playlist for each device.');
|
||||
if (! isset($this->device_playlists[$deviceId]) || empty($this->device_playlists[$deviceId])) {
|
||||
$this->addError('device_playlists.'.$deviceId, 'Please select a playlist for each device.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If creating new playlist, validate required fields
|
||||
if ($this->device_playlists[$deviceId] === 'new') {
|
||||
if (!isset($this->device_playlist_names[$deviceId]) || empty($this->device_playlist_names[$deviceId])) {
|
||||
$this->addError('device_playlist_names.' . $deviceId, 'Playlist name is required when creating a new playlist.');
|
||||
if (! isset($this->device_playlist_names[$deviceId]) || empty($this->device_playlist_names[$deviceId])) {
|
||||
$this->addError('device_playlist_names.'.$deviceId, 'Playlist name is required when creating a new playlist.');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -231,15 +257,15 @@ new class extends Component {
|
|||
|
||||
if ($this->device_playlists[$deviceId] === 'new') {
|
||||
// Create new playlist
|
||||
$playlist = \App\Models\Playlist::create([
|
||||
$playlist = App\Models\Playlist::create([
|
||||
'device_id' => $deviceId,
|
||||
'name' => $this->device_playlist_names[$deviceId],
|
||||
'weekdays' => !empty($this->device_weekdays[$deviceId] ?? null) ? $this->device_weekdays[$deviceId] : null,
|
||||
'weekdays' => ! empty($this->device_weekdays[$deviceId] ?? null) ? $this->device_weekdays[$deviceId] : null,
|
||||
'active_from' => $this->device_active_from[$deviceId] ?? null,
|
||||
'active_until' => $this->device_active_until[$deviceId] ?? null,
|
||||
]);
|
||||
} else {
|
||||
$playlist = \App\Models\Playlist::findOrFail($this->device_playlists[$deviceId]);
|
||||
$playlist = App\Models\Playlist::findOrFail($this->device_playlists[$deviceId]);
|
||||
}
|
||||
|
||||
// Add plugin to playlist
|
||||
|
|
@ -253,11 +279,11 @@ new class extends Component {
|
|||
} else {
|
||||
// Create mashup
|
||||
$pluginIds = array_merge([$this->plugin->id], array_map('intval', $this->mashup_plugins));
|
||||
\App\Models\PlaylistItem::createMashup(
|
||||
App\Models\PlaylistItem::createMashup(
|
||||
$playlist,
|
||||
$this->mashup_layout,
|
||||
$pluginIds,
|
||||
$this->plugin->name . ' Mashup',
|
||||
$this->plugin->name.' Mashup',
|
||||
$maxOrder + 1
|
||||
);
|
||||
}
|
||||
|
|
@ -271,23 +297,24 @@ new class extends Component {
|
|||
'device_active_from',
|
||||
'device_active_until',
|
||||
'mashup_layout',
|
||||
'mashup_plugins'
|
||||
'mashup_plugins',
|
||||
]);
|
||||
Flux::modal('add-to-playlist')->close();
|
||||
}
|
||||
|
||||
public function getDevicePlaylists($deviceId)
|
||||
{
|
||||
return \App\Models\Playlist::where('device_id', $deviceId)->get();
|
||||
return App\Models\Playlist::where('device_id', $deviceId)->get();
|
||||
}
|
||||
|
||||
public function hasAnyPlaylistSelected(): bool
|
||||
{
|
||||
foreach ($this->checked_devices as $deviceId) {
|
||||
if (isset($this->device_playlists[$deviceId]) && !empty($this->device_playlists[$deviceId])) {
|
||||
if (isset($this->device_playlists[$deviceId]) && ! empty($this->device_playlists[$deviceId])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -315,7 +342,7 @@ new class extends Component {
|
|||
public function renderLayoutWithTitleBar(): string
|
||||
{
|
||||
if ($this->markup_language === 'liquid') {
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<div class="view view--{{ size }}">
|
||||
<div class="layout">
|
||||
<!-- ADD YOUR CONTENT HERE-->
|
||||
|
|
@ -327,9 +354,9 @@ new class extends Component {
|
|||
HTML;
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
@props(['size' => 'full'])
|
||||
<x-trmnl::view size="{{\$size}}">
|
||||
<x-trmnl::view size="{{$size}}">
|
||||
<x-trmnl::layout>
|
||||
<!-- ADD YOUR CONTENT HERE-->
|
||||
</x-trmnl::layout>
|
||||
|
|
@ -341,7 +368,7 @@ HTML;
|
|||
public function renderLayoutBlank(): string
|
||||
{
|
||||
if ($this->markup_language === 'liquid') {
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
<div class="view view--{{ size }}">
|
||||
<div class="layout">
|
||||
<!-- ADD YOUR CONTENT HERE-->
|
||||
|
|
@ -350,9 +377,9 @@ HTML;
|
|||
HTML;
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
return <<<'HTML'
|
||||
@props(['size' => 'full'])
|
||||
<x-trmnl::view size="{{\$size}}">
|
||||
<x-trmnl::view size="{{$size}}">
|
||||
<x-trmnl::layout>
|
||||
<!-- ADD YOUR CONTENT HERE-->
|
||||
</x-trmnl::layout>
|
||||
|
|
@ -378,12 +405,12 @@ HTML;
|
|||
$this->dispatch('preview-updated', preview: $previewMarkup);
|
||||
} catch (LiquidException $e) {
|
||||
$this->dispatch('preview-error', message: $e->toLiquidErrorMessage());
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->dispatch('preview-error', message: $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function createPreviewDevice(): \App\Models\Device
|
||||
private function createPreviewDevice(): Device
|
||||
{
|
||||
$deviceModel = DeviceModel::with(['palette'])->find($this->preview_device_model_id)
|
||||
?? DeviceModel::with(['palette'])->first();
|
||||
|
|
@ -434,18 +461,17 @@ HTML;
|
|||
#[Computed]
|
||||
private function parsedUrls()
|
||||
{
|
||||
if (!isset($this->polling_url)) {
|
||||
if (! isset($this->polling_url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->plugin->resolveLiquidVariables($this->polling_url);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return 'PARSE_ERROR: ' . $e->getMessage();
|
||||
} catch (Exception $e) {
|
||||
return 'PARSE_ERROR: '.$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,14 @@ use Livewire\Component;
|
|||
/*
|
||||
* This component contains the TRMNL Plugin Settings modal
|
||||
*/
|
||||
new class extends Component {
|
||||
new class extends Component
|
||||
{
|
||||
public Plugin $plugin;
|
||||
public string|null $trmnlp_id = null;
|
||||
public string|null $uuid = null;
|
||||
|
||||
public ?string $trmnlp_id = null;
|
||||
|
||||
public ?string $uuid = null;
|
||||
|
||||
public bool $alias = false;
|
||||
|
||||
public int $resetIndex = 0;
|
||||
|
|
@ -53,7 +57,7 @@ new class extends Component {
|
|||
{
|
||||
return url("/api/display/{$this->uuid}/alias");
|
||||
}
|
||||
};?>
|
||||
}; ?>
|
||||
|
||||
<flux:modal name="trmnlp-settings" class="min-w-[400px] space-y-6">
|
||||
<div wire:key="trmnlp-settings-form-{{ $resetIndex }}" class="space-y-6">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue