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;
|
2023-08-08 12:35:01 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class InitScript extends Component
|
|
|
|
{
|
|
|
|
public array $script;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-08 12:35:01 +00:00
|
|
|
public int $index;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public ?string $filename;
|
|
|
|
|
|
|
|
public ?string $content;
|
2023-08-08 12:35:01 +00:00
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'filename' => 'required|string',
|
|
|
|
'content' => 'required|string',
|
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-08 12:35:01 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'filename' => 'Filename',
|
|
|
|
'content' => 'Content',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->index = data_get($this->script, 'index');
|
|
|
|
$this->filename = data_get($this->script, 'filename');
|
|
|
|
$this->content = data_get($this->script, 'content');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
try {
|
|
|
|
$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()
|
|
|
|
{
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('delete_init_script', $this->script);
|
2023-08-08 12:35:01 +00:00
|
|
|
}
|
|
|
|
}
|