From c7ba1f80af84ba83841c0f065a671f9e6041e9b9 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Thu, 26 Jun 2025 13:24:04 +0200 Subject: [PATCH] feat: add static data option for recipes --- .../views/livewire/plugins/index.blade.php | 52 ++++++++++--------- .../views/livewire/plugins/recipe.blade.php | 29 +++++++---- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/resources/views/livewire/plugins/index.blade.php b/resources/views/livewire/plugins/index.blade.php index d3db822..eace5ba 100644 --- a/resources/views/livewire/plugins/index.blade.php +++ b/resources/views/livewire/plugins/index.blade.php @@ -22,7 +22,7 @@ new class extends Component { protected $rules = [ 'name' => 'required|string|max:255', 'data_stale_minutes' => 'required|integer|min:1', - 'data_strategy' => 'required|string|in:polling,webhook', + 'data_strategy' => 'required|string|in:polling,webhook,static', 'polling_url' => 'required_if:data_strategy,polling|nullable|url', 'polling_verb' => 'required|string|in:get,post', 'polling_header' => 'nullable|string|max:255', @@ -53,14 +53,14 @@ new class extends Component { 'name' => $this->name, 'data_stale_minutes' => $this->data_stale_minutes, 'data_strategy' => $this->data_strategy, - 'polling_url' => $this->polling_url, + 'polling_url' => $this->polling_url ?? null, 'polling_verb' => $this->polling_verb, 'polling_header' => $this->polling_header, ]); $this->reset(['name', 'data_stale_minutes', 'data_strategy', 'polling_url', 'polling_verb', 'polling_header']); $this->refreshPlugins(); - + Flux::modal('add-plugin')->close(); } @@ -116,35 +116,37 @@ new class extends Component {
- -
- -
- + +
-
- -
+ @if($data_strategy === 'polling') +
+ +
-
- - - - -
+
+ + + + +
-
- -
+
+ +
+
+ +
+ @endif
diff --git a/resources/views/livewire/plugins/recipe.blade.php b/resources/views/livewire/plugins/recipe.blade.php index 9fd318e..fa79a88 100644 --- a/resources/views/livewire/plugins/recipe.blade.php +++ b/resources/views/livewire/plugins/recipe.blade.php @@ -77,10 +77,11 @@ new class extends Component { protected array $rules = [ 'name' => 'required|string|max:255', 'data_stale_minutes' => 'required|integer|min:1', - 'data_strategy' => 'required|string|in:polling,webhook', + 'data_strategy' => 'required|string|in:polling,webhook,static', 'polling_url' => 'required_if:data_strategy,polling|nullable|url', 'polling_verb' => 'required|string|in:get,post', 'polling_header' => 'nullable|string|max:255', + 'data_payload' => 'required_if:data_strategy,static|nullable|json', 'blade_code' => 'nullable|string', 'checked_devices' => 'array', 'playlist_name' => 'required_if:selected_playlist,new|string|max:255', @@ -94,6 +95,12 @@ new class extends Component { { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); $validated = $this->validate(); + + // If static strategy is selected, parse and save the JSON data + if ($this->data_strategy === 'static' && isset($validated['data_payload'])) { + $validated['data_payload'] = json_decode($validated['data_payload'], true); + } + $this->plugin->update($validated); } @@ -451,16 +458,11 @@ HTML; name="name" autofocus/>
-
- -
-
+
@@ -495,7 +497,12 @@ HTML; placeholder="Authorization: Bearer ey.******* Content-Type: application/json" /> - @else +
+ +
+ @elseif($data_strategy === 'webhook')
Send JSON payload with key merge_variables to the webhook URL. The payload will be merged with the plugin data.

+ @elseif($data_strategy === 'static') +
+

Enter static JSON data in the Data Payload field.

+
@endif
@@ -523,7 +534,7 @@ HTML; {{ $this->data_payload_updated_at?->diffForHumans() ?? 'Never' }} + :readonly="$data_strategy !== 'static'" rows="24"/>