mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
feat: add static data option for recipes
This commit is contained in:
parent
3568f60b9b
commit
94c156d3c1
2 changed files with 47 additions and 34 deletions
|
|
@ -22,7 +22,7 @@ new class extends Component {
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'data_stale_minutes' => 'required|integer|min:1',
|
'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_url' => 'required_if:data_strategy,polling|nullable|url',
|
||||||
'polling_verb' => 'required|string|in:get,post',
|
'polling_verb' => 'required|string|in:get,post',
|
||||||
'polling_header' => 'nullable|string|max:255',
|
'polling_header' => 'nullable|string|max:255',
|
||||||
|
|
@ -53,14 +53,14 @@ new class extends Component {
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'data_stale_minutes' => $this->data_stale_minutes,
|
'data_stale_minutes' => $this->data_stale_minutes,
|
||||||
'data_strategy' => $this->data_strategy,
|
'data_strategy' => $this->data_strategy,
|
||||||
'polling_url' => $this->polling_url,
|
'polling_url' => $this->polling_url ?? null,
|
||||||
'polling_verb' => $this->polling_verb,
|
'polling_verb' => $this->polling_verb,
|
||||||
'polling_header' => $this->polling_header,
|
'polling_header' => $this->polling_header,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->reset(['name', 'data_stale_minutes', 'data_strategy', 'polling_url', 'polling_verb', 'polling_header']);
|
$this->reset(['name', 'data_stale_minutes', 'data_strategy', 'polling_url', 'polling_verb', 'polling_header']);
|
||||||
$this->refreshPlugins();
|
$this->refreshPlugins();
|
||||||
|
|
||||||
Flux::modal('add-plugin')->close();
|
Flux::modal('add-plugin')->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,35 +116,37 @@ new class extends Component {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:input label="Data is stale after minutes" wire:model="data_stale_minutes"
|
<flux:radio.group wire:model.live="data_strategy" label="Data Strategy" variant="segmented">
|
||||||
id="data_stale_minutes"
|
|
||||||
class="block mt-1 w-full" type="number" name="data_stale_minutes" autofocus/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-4">
|
|
||||||
<flux:radio.group wire:model="data_strategy" label="Data Strategy" variant="segmented">
|
|
||||||
<flux:radio value="polling" label="Polling"/>
|
<flux:radio value="polling" label="Polling"/>
|
||||||
<flux:radio value="webhook" label="Webhook"/>
|
<flux:radio value="webhook" label="Webhook"/>
|
||||||
|
<flux:radio value="static" label="Static"/>
|
||||||
</flux:radio.group>
|
</flux:radio.group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
@if($data_strategy === 'polling')
|
||||||
<flux:input label="Polling URL" wire:model="polling_url" id="polling_url"
|
<div class="mb-4">
|
||||||
placeholder="https://example.com/api"
|
<flux:input label="Polling URL" wire:model="polling_url" id="polling_url"
|
||||||
class="block mt-1 w-full" type="text" name="polling_url" autofocus/>
|
placeholder="https://example.com/api"
|
||||||
</div>
|
class="block mt-1 w-full" type="text" name="polling_url" autofocus/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:radio.group wire:model="polling_verb" label="Polling Verb" variant="segmented">
|
<flux:radio.group wire:model="polling_verb" label="Polling Verb" variant="segmented">
|
||||||
<flux:radio value="get" label="GET"/>
|
<flux:radio value="get" label="GET"/>
|
||||||
<flux:radio value="post" label="POST"/>
|
<flux:radio value="post" label="POST"/>
|
||||||
</flux:radio.group>
|
</flux:radio.group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:input label="Polling Header" wire:model="polling_header" id="polling_header"
|
<flux:input label="Polling Header" wire:model="polling_header" id="polling_header"
|
||||||
class="block mt-1 w-full" type="text" name="polling_header" autofocus/>
|
class="block mt-1 w-full" type="text" name="polling_header" autofocus/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<flux:input label="Data is stale after minutes" wire:model.live="data_stale_minutes"
|
||||||
|
id="data_stale_minutes"
|
||||||
|
class="block mt-1 w-full" type="number" name="data_stale_minutes" autofocus/>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<flux:spacer/>
|
<flux:spacer/>
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,11 @@ new class extends Component {
|
||||||
protected array $rules = [
|
protected array $rules = [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'data_stale_minutes' => 'required|integer|min:1',
|
'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_url' => 'required_if:data_strategy,polling|nullable|url',
|
||||||
'polling_verb' => 'required|string|in:get,post',
|
'polling_verb' => 'required|string|in:get,post',
|
||||||
'polling_header' => 'nullable|string|max:255',
|
'polling_header' => 'nullable|string|max:255',
|
||||||
|
'data_payload' => 'required_if:data_strategy,static|nullable|json',
|
||||||
'blade_code' => 'nullable|string',
|
'blade_code' => 'nullable|string',
|
||||||
'checked_devices' => 'array',
|
'checked_devices' => 'array',
|
||||||
'playlist_name' => 'required_if:selected_playlist,new|string|max:255',
|
'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);
|
abort_unless(auth()->user()->plugins->contains($this->plugin), 403);
|
||||||
$validated = $this->validate();
|
$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);
|
$this->plugin->update($validated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -451,16 +458,11 @@ HTML;
|
||||||
name="name" autofocus/>
|
name="name" autofocus/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-4">
|
|
||||||
<flux:input label="Data is stale after minutes" wire:model="data_stale_minutes"
|
|
||||||
id="data_stale_minutes"
|
|
||||||
class="block mt-1 w-full" type="number" name="data_stale_minutes" autofocus/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:radio.group wire:model.live="data_strategy" label="Data Strategy" variant="segmented">
|
<flux:radio.group wire:model.live="data_strategy" label="Data Strategy" variant="segmented">
|
||||||
<flux:radio value="polling" label="Polling"/>
|
<flux:radio value="polling" label="Polling"/>
|
||||||
<flux:radio value="webhook" label="Webhook"/>
|
<flux:radio value="webhook" label="Webhook"/>
|
||||||
|
<flux:radio value="static" label="Static"/>
|
||||||
</flux:radio.group>
|
</flux:radio.group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -495,7 +497,12 @@ HTML;
|
||||||
placeholder="Authorization: Bearer ey.******* Content-Type: application/json"
|
placeholder="Authorization: Bearer ey.******* Content-Type: application/json"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@else
|
<div class="mb-4">
|
||||||
|
<flux:input label="Data is stale after minutes" wire:model="data_stale_minutes"
|
||||||
|
id="data_stale_minutes"
|
||||||
|
class="block mt-1 w-full" type="number" name="data_stale_minutes" autofocus/>
|
||||||
|
</div>
|
||||||
|
@elseif($data_strategy === 'webhook')
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<flux:input
|
<flux:input
|
||||||
label="Webhook URL"
|
label="Webhook URL"
|
||||||
|
|
@ -510,6 +517,10 @@ HTML;
|
||||||
<p>Send JSON payload with key <code>merge_variables</code> to the webhook URL. The payload
|
<p>Send JSON payload with key <code>merge_variables</code> to the webhook URL. The payload
|
||||||
will be merged with the plugin data.</p>
|
will be merged with the plugin data.</p>
|
||||||
</div>
|
</div>
|
||||||
|
@elseif($data_strategy === 'static')
|
||||||
|
<div>
|
||||||
|
<p>Enter static JSON data in the Data Payload field.</p>
|
||||||
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|
@ -523,7 +534,7 @@ HTML;
|
||||||
<flux:badge icon="clock" size="sm" variant="pill" class="ml-2">{{ $this->data_payload_updated_at?->diffForHumans() ?? 'Never' }}</flux:badge>
|
<flux:badge icon="clock" size="sm" variant="pill" class="ml-2">{{ $this->data_payload_updated_at?->diffForHumans() ?? 'Never' }}</flux:badge>
|
||||||
<flux:textarea wire:model="data_payload" id="data_payload"
|
<flux:textarea wire:model="data_payload" id="data_payload"
|
||||||
class="block mt-1 w-full font-mono" type="text" name="data_payload"
|
class="block mt-1 w-full font-mono" type="text" name="data_payload"
|
||||||
readonly rows="24"/>
|
:readonly="$data_strategy !== 'static'" rows="24"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<flux:separator/>
|
<flux:separator/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue