mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 23:18:10 +00:00
feat: select (multiple) devices in markup view to render
This commit is contained in:
parent
05b5b206dd
commit
1597b70a4b
1 changed files with 23 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
|
@ -8,24 +9,32 @@ new class extends Component {
|
|||
public string $blade_code = '';
|
||||
public bool $isLoading = false;
|
||||
|
||||
public Collection $devices;
|
||||
public array $checked_devices;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->devices = auth()->user()->devices->pluck('id', 'name');
|
||||
}
|
||||
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->isLoading = true;
|
||||
|
||||
$this->validate([
|
||||
'checked_devices' => 'required|array',
|
||||
'blade_code' => 'required|string'
|
||||
]);
|
||||
|
||||
//only devices that are owned by the user
|
||||
$this->checked_devices = array_intersect($this->checked_devices, auth()->user()->devices->pluck('id')->toArray());
|
||||
|
||||
try {
|
||||
$rendered = Blade::render($this->blade_code);
|
||||
|
||||
// if (config('app.puppeteer_docker')) {
|
||||
// GenerateScreenJob::dispatch(auth()->user()->devices()->first()->id, $rendered);
|
||||
// } else {
|
||||
GenerateScreenJob::dispatchSync(auth()->user()->devices()->first()->id, $rendered);
|
||||
// }
|
||||
|
||||
foreach ($this->checked_devices as $device) {
|
||||
GenerateScreenJob::dispatchSync($device, $rendered);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('error', $e->getMessage());
|
||||
}
|
||||
|
|
@ -159,7 +168,14 @@ HTML;
|
|||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<flux:checkbox.group wire:model="checked_devices" label="Devices">
|
||||
@foreach($devices as $name => $id)
|
||||
<flux:checkbox label="{{ $name }}" value="{{ $id }}"/>
|
||||
@endforeach
|
||||
</flux:checkbox.group>
|
||||
|
||||
<flux:spacer/>
|
||||
|
||||
<flux:button type="submit" variant="primary">
|
||||
Generate Screen
|
||||
</flux:button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue