mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 15:37:53 +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
|
<?php
|
||||||
|
|
||||||
use App\Jobs\GenerateScreenJob;
|
use App\Jobs\GenerateScreenJob;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
new class extends Component {
|
new class extends Component {
|
||||||
|
|
@ -8,24 +9,32 @@ new class extends Component {
|
||||||
public string $blade_code = '';
|
public string $blade_code = '';
|
||||||
public bool $isLoading = false;
|
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()
|
public function submit()
|
||||||
{
|
{
|
||||||
$this->isLoading = true;
|
$this->isLoading = true;
|
||||||
|
|
||||||
$this->validate([
|
$this->validate([
|
||||||
|
'checked_devices' => 'required|array',
|
||||||
'blade_code' => 'required|string'
|
'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 {
|
try {
|
||||||
$rendered = Blade::render($this->blade_code);
|
$rendered = Blade::render($this->blade_code);
|
||||||
|
foreach ($this->checked_devices as $device) {
|
||||||
// if (config('app.puppeteer_docker')) {
|
GenerateScreenJob::dispatchSync($device, $rendered);
|
||||||
// GenerateScreenJob::dispatch(auth()->user()->devices()->first()->id, $rendered);
|
}
|
||||||
// } else {
|
|
||||||
GenerateScreenJob::dispatchSync(auth()->user()->devices()->first()->id, $rendered);
|
|
||||||
// }
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->addError('error', $e->getMessage());
|
$this->addError('error', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +168,14 @@ HTML;
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex">
|
<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:spacer/>
|
||||||
|
|
||||||
<flux:button type="submit" variant="primary">
|
<flux:button type="submit" variant="primary">
|
||||||
Generate Screen
|
Generate Screen
|
||||||
</flux:button>
|
</flux:button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue