Fix schedules (#949)

* Fix schedules

* Only explode when payload isn't a power action

* Run only on first day of the month

Co-authored-by: Boy132 <Boy132@users.noreply.github.com>

---------

Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
This commit is contained in:
MartinOscar 2025-01-27 17:57:17 +01:00 committed by GitHub
parent 3202a59b07
commit 7cde90a39a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View File

@ -264,7 +264,7 @@ class ScheduleResource extends Resource
->action(function (Set $set, $data) {
$set('cron_minute', '0');
$set('cron_hour', '0');
$set('cron_day_of_month', '0');
$set('cron_day_of_month', '1');
$set('cron_month', '*/' . $data['x']);
$set('cron_day_of_week', '*');
}),
@ -275,13 +275,13 @@ class ScheduleResource extends Resource
->label('')
->prefix('Every')
->options([
'0' => 'Sunday',
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday',
'0' => 'Sunday',
]),
])
->action(function (Set $set, $data) {

View File

@ -40,7 +40,8 @@ class TasksRelationManager extends RelationManager
->live()
->disableOptionWhen(fn (string $value): bool => $value === Task::ACTION_BACKUP && $schedule->server->backup_limit === 0)
->options($this->getActionOptions())
->selectablePlaceholder(false),
->selectablePlaceholder(false)
->default(Task::ACTION_POWER),
Textarea::make('payload')
->hidden(fn (Get $get) => $get('action') === Task::ACTION_POWER)
->label(fn (Get $get) => $this->getActionOptions(false)[$get('action')] ?? 'Payload'),
@ -77,13 +78,9 @@ class TasksRelationManager extends RelationManager
TextColumn::make('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);
->state(fn (Task $task) => match ($task->payload) {
'start', 'restart', 'stop', 'kill' => mb_ucfirst($task->payload),
default => explode(PHP_EOL, $task->payload)
})
->badge(),
TextColumn::make('time_offset')
@ -94,7 +91,12 @@ class TasksRelationManager extends RelationManager
])
->actions([
EditAction::make()
->form($this->getTaskForm($schedule)),
->form($this->getTaskForm($schedule))
->mutateFormDataUsing(function ($data) {
$data['payload'] ??= '';
return $data;
}),
DeleteAction::make(),
])
->headerActions([