2024-01-01 18:33:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Shared\ScheduledTask;
|
|
|
|
|
|
|
|
use App\Models\ScheduledTask as ModelsScheduledTask;
|
|
|
|
use Livewire\Component;
|
2024-01-02 02:23:29 +00:00
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\Service;
|
2024-01-01 18:33:16 +00:00
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
|
|
|
|
class Show extends Component
|
|
|
|
{
|
|
|
|
public $parameters;
|
2024-01-02 02:23:29 +00:00
|
|
|
public Application|Service $resource;
|
2024-01-01 18:33:16 +00:00
|
|
|
public ModelsScheduledTask $task;
|
|
|
|
public ?string $modalId = null;
|
|
|
|
public string $type;
|
|
|
|
|
|
|
|
protected $rules = [
|
|
|
|
'task.name' => 'required|string',
|
|
|
|
'task.command' => 'required|string',
|
2024-01-02 02:23:29 +00:00
|
|
|
'task.frequency' => 'required|string',
|
|
|
|
'task.container' => 'nullable|string',
|
2024-01-01 18:33:16 +00:00
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
2024-01-02 02:23:29 +00:00
|
|
|
'name' => 'name',
|
|
|
|
'command' => 'command',
|
|
|
|
'frequency' => 'frequency',
|
|
|
|
'container' => 'container',
|
2024-01-01 18:33:16 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
|
2024-01-02 02:23:29 +00:00
|
|
|
if (data_get($this->parameters, 'application_uuid')) {
|
|
|
|
$this->type = 'application';
|
|
|
|
$this->resource = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail();
|
|
|
|
} else if (data_get($this->parameters, 'service_uuid')) {
|
|
|
|
$this->type = 'service';
|
|
|
|
$this->resource = Service::where('uuid', $this->parameters['service_uuid'])->firstOrFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->modalId = new Cuid2(7);
|
|
|
|
$this->task = ModelsScheduledTask::where('uuid', request()->route('task_uuid'))->first();
|
2024-01-01 18:33:16 +00:00
|
|
|
}
|
2024-01-02 02:23:29 +00:00
|
|
|
|
2024-01-01 18:33:16 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
$this->task->save();
|
2024-01-02 02:23:29 +00:00
|
|
|
$this->dispatch('success', 'Scheduled task updated successfully.');
|
2024-01-01 18:33:16 +00:00
|
|
|
$this->dispatch('refreshTasks');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->task->delete();
|
2024-01-02 02:23:29 +00:00
|
|
|
|
|
|
|
if ($this->type == 'application') {
|
|
|
|
return redirect()->route('project.application.configuration', $this->parameters);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return redirect()->route('project.service.configuration', $this->parameters);
|
|
|
|
}
|
|
|
|
|
2024-01-01 18:33:16 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return handleError($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|