refactor initscripts view

This commit is contained in:
Andras Bacsai
2024-11-04 12:21:31 +01:00
parent c11dfdee1f
commit 2cbac34877

View File

@@ -3,39 +3,39 @@
namespace App\Livewire\Project\Database; namespace App\Livewire\Project\Database;
use Exception; use Exception;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Rule;
use Livewire\Component; use Livewire\Component;
class InitScript extends Component class InitScript extends Component
{ {
#[Locked]
public array $script; public array $script;
#[Locked]
public int $index; public int $index;
public ?string $filename; #[Rule(['nullable', 'string'])]
public ?string $filename = null;
public ?string $content; #[Rule(['nullable', 'string'])]
public ?string $content = null;
protected $rules = [
'filename' => 'required|string',
'content' => 'required|string',
];
protected $validationAttributes = [
'filename' => 'Filename',
'content' => 'Content',
];
public function mount() public function mount()
{ {
try {
$this->index = data_get($this->script, 'index'); $this->index = data_get($this->script, 'index');
$this->filename = data_get($this->script, 'filename'); $this->filename = data_get($this->script, 'filename');
$this->content = data_get($this->script, 'content'); $this->content = data_get($this->script, 'content');
} catch (Exception $e) {
return handleError($e, $this);
}
} }
public function submit() public function submit()
{ {
$this->validate();
try { try {
$this->validate();
$this->script['index'] = $this->index; $this->script['index'] = $this->index;
$this->script['content'] = $this->content; $this->script['content'] = $this->content;
$this->script['filename'] = $this->filename; $this->script['filename'] = $this->filename;
@@ -47,6 +47,10 @@ class InitScript extends Component
public function delete() public function delete()
{ {
try {
$this->dispatch('delete_init_script', $this->script); $this->dispatch('delete_init_script', $this->script);
} catch (Exception $e) {
return handleError($e, $this);
}
} }
} }