user()->plugins->contains($this->plugin), 403); $this->blade_code = $this->plugin->render_markup; if ($this->plugin->render_markup_view) { try { $viewPath = resource_path('views/' . str_replace('.', '/', $this->plugin->render_markup_view) . '.blade.php'); $this->view_content = file_get_contents($viewPath); } catch (\Exception $e) { $this->view_content = null; } } $this->fillformFields(); } public function fillFormFields(): void { $this->name = $this->plugin->name; $this->data_stale_minutes = $this->plugin->data_stale_minutes; $this->data_strategy = $this->plugin->data_strategy; $this->polling_url = $this->plugin->polling_url; $this->polling_verb = $this->plugin->polling_verb; $this->polling_header = $this->plugin->polling_header; $this->data_payload = json_encode($this->plugin->data_payload); } public function saveMarkup(): void { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); $this->validate(); $this->plugin->update(['render_markup' => $this->blade_code]); } protected array $rules = [ 'name' => 'required|string|max:255', 'data_stale_minutes' => 'required|integer|min:1', 'data_strategy' => 'required|string|in:polling,webhook', 'polling_url' => 'required|url', 'polling_verb' => 'required|string|in:get,post', 'polling_header' => 'nullable|string|max:255', 'blade_code' => 'nullable|string', 'checked_devices' => 'array', 'playlist_name' => 'required_if:selected_playlist,new|string|max:255', 'selected_weekdays' => 'array', 'active_from' => 'nullable|date_format:H:i', 'active_until' => 'nullable|date_format:H:i', 'selected_playlist' => 'nullable|string', ]; public function editSettings() { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); $validated = $this->validate(); $this->plugin->update($validated); } public function updateData() { if ($this->plugin->data_strategy === 'polling') { $response = Http::get($this->plugin->polling_url)->json(); $this->plugin->update(['data_payload' => $response]); $this->data_payload = json_encode($response); } } public function addToPlaylist() { $this->validate([ 'checked_devices' => 'required|array|min:1', 'selected_playlist' => 'required|string', ]); foreach ($this->checked_devices as $deviceId) { $playlist = null; if ($this->selected_playlist === 'new') { // Create new playlist $this->validate([ 'playlist_name' => 'required|string|max:255', ]); $playlist = \App\Models\Playlist::create([ 'device_id' => $deviceId, 'name' => $this->playlist_name, 'weekdays' => !empty($this->selected_weekdays) ? $this->selected_weekdays : null, 'active_from' => $this->active_from ?: null, 'active_until' => $this->active_until ?: null, ]); } else { $playlist = \App\Models\Playlist::findOrFail($this->selected_playlist); } // Add plugin to playlist $maxOrder = $playlist->items()->max('order') ?? 0; $playlist->items()->create([ 'plugin_id' => $this->plugin->id, 'order' => $maxOrder + 1, ]); } $this->reset(['checked_devices', 'playlist_name', 'selected_weekdays', 'active_from', 'active_until', 'selected_playlist']); Flux::modal('add-plugin')->close(); } public function getDevicePlaylists($deviceId) { return \App\Models\Playlist::where('device_id', $deviceId)->get(); } public function renderExample(string $example) { switch ($example) { case 'layoutTitle': $markup = $this->renderLayoutWithTitleBar(); break; case 'layout': $markup = $this->renderLayoutBlank(); break; default: $markup = '