2023-08-08 12:35:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Database;
|
2023-08-08 12:35:01 +00:00
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
use Exception;
|
2024-11-04 11:21:31 +00:00
|
|
|
use Livewire\Attributes\Locked;
|
|
|
|
|
use Livewire\Attributes\Rule;
|
2023-08-08 12:35:01 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class InitScript extends Component
|
|
|
|
|
{
|
2024-11-04 11:21:31 +00:00
|
|
|
#[Locked]
|
2023-08-08 12:35:01 +00:00
|
|
|
public array $script;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-04 11:21:31 +00:00
|
|
|
#[Locked]
|
2023-08-08 12:35:01 +00:00
|
|
|
public int $index;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-04 11:21:31 +00:00
|
|
|
#[Rule(['nullable', 'string'])]
|
|
|
|
|
public ?string $filename = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-04 11:21:31 +00:00
|
|
|
#[Rule(['nullable', 'string'])]
|
|
|
|
|
public ?string $content = null;
|
2023-08-08 12:35:01 +00:00
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
|
{
|
2024-11-04 11:21:31 +00:00
|
|
|
try {
|
|
|
|
|
$this->index = data_get($this->script, 'index');
|
|
|
|
|
$this->filename = data_get($this->script, 'filename');
|
|
|
|
|
$this->content = data_get($this->script, 'content');
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2023-08-08 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2024-11-04 11:21:31 +00:00
|
|
|
$this->validate();
|
2023-08-08 12:35:01 +00:00
|
|
|
$this->script['index'] = $this->index;
|
|
|
|
|
$this->script['content'] = $this->content;
|
|
|
|
|
$this->script['filename'] = $this->filename;
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('save_init_script', $this->script);
|
2023-08-08 12:35:01 +00:00
|
|
|
} catch (Exception $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-08 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
|
{
|
2024-11-04 11:21:31 +00:00
|
|
|
try {
|
|
|
|
|
$this->dispatch('delete_init_script', $this->script);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2023-08-08 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
}
|