mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 09:54:44 +02:00
Rework Schedules (#843)
This commit is contained in:
parent
a8680c7aed
commit
1571e3cb24
@ -22,6 +22,50 @@ class TasksRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'tasks';
|
||||
|
||||
private function getActionOptions(bool $full = true): array
|
||||
{
|
||||
return [
|
||||
Task::ACTION_POWER => $full ? 'Send power action' : 'Power action',
|
||||
Task::ACTION_COMMAND => $full ? 'Send command' : 'Command',
|
||||
Task::ACTION_BACKUP => $full ? 'Create backup' : 'Files to ignore',
|
||||
Task::ACTION_DELETE_FILES => $full ? 'Delete files' : 'Files to delete',
|
||||
];
|
||||
}
|
||||
|
||||
private function getTaskForm(Schedule $schedule): array
|
||||
{
|
||||
return [
|
||||
Select::make('action')
|
||||
->required()
|
||||
->live()
|
||||
->disableOptionWhen(fn (string $value): bool => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0)
|
||||
->options($this->getActionOptions())
|
||||
->selectablePlaceholder(false),
|
||||
Textarea::make('payload')
|
||||
->hidden(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label(fn (Get $get) => $this->getActionOptions(false)[$get('action')] ?? 'Payload'),
|
||||
Select::make('payload')
|
||||
->visible(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label('Power Action')
|
||||
->required()
|
||||
->options([
|
||||
'start' => 'Start',
|
||||
'restart' => 'Restart',
|
||||
'stop' => 'Stop',
|
||||
'kill' => 'Kill',
|
||||
])
|
||||
->selectablePlaceholder(false),
|
||||
TextInput::make('time_offset')
|
||||
->hidden(fn (Get $get) => config('queue.default') === 'sync' || $get('sequence_id') === 1)
|
||||
->default(0)
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(900)
|
||||
->suffix('Seconds'),
|
||||
Toggle::make('continue_on_failure'),
|
||||
];
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var Schedule $schedule */
|
||||
@ -31,13 +75,17 @@ class TasksRelationManager extends RelationManager
|
||||
->reorderable('sequence_id', true)
|
||||
->columns([
|
||||
TextColumn::make('action')
|
||||
->state(fn (Task $task) => match ($task->action) {
|
||||
Task::ACTION_POWER => 'Send power action',
|
||||
Task::ACTION_COMMAND => 'Send command',
|
||||
Task::ACTION_BACKUP => 'Create backup',
|
||||
Task::ACTION_DELETE_FILES => 'Delete files',
|
||||
default => $task->action
|
||||
}),
|
||||
->state(fn (Task $task) => $this->getActionOptions()[$task->action] ?? $task->action),
|
||||
TextColumn::make('payload')
|
||||
->state(function (Task $task) {
|
||||
$payload = match ($task->payload) {
|
||||
'start', 'restart', 'stop', 'kill' => mb_ucfirst($task->payload),
|
||||
default => $task->payload
|
||||
};
|
||||
|
||||
return explode(PHP_EOL, $payload);
|
||||
})
|
||||
->badge(),
|
||||
TextColumn::make('time_offset')
|
||||
->hidden(fn () => config('queue.default') === 'sync')
|
||||
->suffix(' Seconds'),
|
||||
@ -46,45 +94,7 @@ class TasksRelationManager extends RelationManager
|
||||
])
|
||||
->actions([
|
||||
EditAction::make()
|
||||
->form([
|
||||
Select::make('action')
|
||||
->required()
|
||||
->live()
|
||||
->disableOptionWhen(fn (string $value): bool => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0)
|
||||
->options([
|
||||
Task::ACTION_POWER => 'Send power action',
|
||||
Task::ACTION_COMMAND => 'Send command',
|
||||
Task::ACTION_BACKUP => 'Create backup',
|
||||
Task::ACTION_DELETE_FILES => 'Delete files',
|
||||
]),
|
||||
Textarea::make('payload')
|
||||
->hidden(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label(fn (Get $get) => match ($get('action')) {
|
||||
Task::ACTION_POWER => 'Power action',
|
||||
Task::ACTION_COMMAND => 'Command',
|
||||
Task::ACTION_BACKUP => 'Files to ignore',
|
||||
Task::ACTION_DELETE_FILES => 'Files to delete',
|
||||
default => 'Payload'
|
||||
}),
|
||||
Select::make('payload')
|
||||
->visible(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label('Power Action')
|
||||
->required()
|
||||
->options([
|
||||
'start' => 'Start',
|
||||
'restart' => 'Restart',
|
||||
'stop' => 'Stop',
|
||||
'Kill' => 'Kill',
|
||||
]),
|
||||
TextInput::make('time_offset')
|
||||
->hidden(fn (Get $get) => config('queue.default') === 'sync' || $get('sequence_id') === 1)
|
||||
->default(0)
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(900)
|
||||
->suffix('Seconds'),
|
||||
Toggle::make('continue_on_failure'),
|
||||
]),
|
||||
->form($this->getTaskForm($schedule)),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->headerActions([
|
||||
@ -92,45 +102,7 @@ class TasksRelationManager extends RelationManager
|
||||
->createAnother(false)
|
||||
->label(fn () => $schedule->tasks()->count() >= config('panel.client_features.schedules.per_schedule_task_limit', 10) ? 'Task Limit Reached' : 'Create Task')
|
||||
->disabled(fn () => $schedule->tasks()->count() >= config('panel.client_features.schedules.per_schedule_task_limit', 10))
|
||||
->form([
|
||||
Select::make('action')
|
||||
->required()
|
||||
->live()
|
||||
->disableOptionWhen(fn (string $value): bool => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0)
|
||||
->options([
|
||||
Task::ACTION_POWER => 'Send power action',
|
||||
Task::ACTION_COMMAND => 'Send command',
|
||||
Task::ACTION_BACKUP => 'Create backup',
|
||||
Task::ACTION_DELETE_FILES => 'Delete files',
|
||||
]),
|
||||
Textarea::make('payload')
|
||||
->hidden(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label(fn (Get $get) => match ($get('action')) {
|
||||
Task::ACTION_POWER => 'Power action',
|
||||
Task::ACTION_COMMAND => 'Command',
|
||||
Task::ACTION_BACKUP => 'Files to ignore',
|
||||
Task::ACTION_DELETE_FILES => 'Files to delete',
|
||||
default => 'Payload'
|
||||
}),
|
||||
Select::make('payload')
|
||||
->visible(fn (Get $get) => $get('action') === Task::ACTION_POWER)
|
||||
->label('Power Action')
|
||||
->required()
|
||||
->options([
|
||||
'start' => 'Start',
|
||||
'restart' => 'Restart',
|
||||
'stop' => 'Stop',
|
||||
'Kill' => 'Kill',
|
||||
]),
|
||||
TextInput::make('time_offset')
|
||||
->hidden(fn (Get $get) => config('queue.default') === 'sync' || $get('sequence_id') === 1)
|
||||
->default(0)
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(900)
|
||||
->suffix('Seconds'),
|
||||
Toggle::make('continue_on_failure'),
|
||||
])
|
||||
->form($this->getTaskForm($schedule))
|
||||
->action(function ($data) use ($schedule) {
|
||||
$sequenceId = ($schedule->tasks()->orderByDesc('sequence_id')->first()->sequence_id ?? 0) + 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user