fix(podcast-import): show cancel or retry action depending on task status
This commit is contained in:
parent
06c4f15477
commit
e42258de1f
|
@ -145,11 +145,17 @@ class PodcastImportController extends BaseController
|
||||||
$importTask = $importQueue[$taskId];
|
$importTask = $importQueue[$taskId];
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'cancel':
|
case 'cancel':
|
||||||
$importTask->cancel();
|
if ($importTask->status === TaskStatus::Running || $importTask->status === TaskStatus::Queued) {
|
||||||
|
$importTask->cancel();
|
||||||
|
|
||||||
|
return redirect()->back()
|
||||||
|
->with('message', lang('PodcastImport.messages.canceled'));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
->with('message', lang('PodcastImport.messages.canceled'));
|
->with('error', lang('PodcastImport.messages.notRunning'));
|
||||||
case 'retry':
|
case 'retry':
|
||||||
if ($importTask->status === TaskStatus::Running) {
|
if ($importTask->status === TaskStatus::Running || $importTask->status === TaskStatus::Queued) {
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
->with('error', lang('PodcastImport.messages.alreadyRunning'));
|
->with('error', lang('PodcastImport.messages.alreadyRunning'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ return [
|
||||||
],
|
],
|
||||||
'messages' => [
|
'messages' => [
|
||||||
'canceled' => 'Import task has been successfully canceled!',
|
'canceled' => 'Import task has been successfully canceled!',
|
||||||
|
'notRunning' => 'Cannot cancel Import Task as it is not running.',
|
||||||
'alreadyRunning' => 'Import Task is already running. You may cancel it before retrying.',
|
'alreadyRunning' => 'Import Task is already running. You may cancel it before retrying.',
|
||||||
'retried' => 'Import task has been queued, it will be retried shortly!',
|
'retried' => 'Import task has been queued, it will be retried shortly!',
|
||||||
'deleted' => 'Import task has been successfully deleted!',
|
'deleted' => 'Import task has been successfully deleted!',
|
||||||
|
|
|
@ -98,31 +98,37 @@ use Modules\PodcastImport\Entities\TaskStatus;
|
||||||
[
|
[
|
||||||
'header' => lang('Common.list.actions'),
|
'header' => lang('Common.list.actions'),
|
||||||
'cell' => function (PodcastImportTask $importTask) {
|
'cell' => function (PodcastImportTask $importTask) {
|
||||||
|
$menuItems = [
|
||||||
|
[
|
||||||
|
'type' => 'separator',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'type' => 'link',
|
||||||
|
'title' => lang('PodcastImport.queue.actions.delete'),
|
||||||
|
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'delete'),
|
||||||
|
'class' => 'font-semibold text-red-600',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($importTask->status === TaskStatus::Running || $importTask->status === TaskStatus::Queued) {
|
||||||
|
array_unshift($menuItems, [
|
||||||
|
'type' => 'link',
|
||||||
|
'title' => lang('PodcastImport.queue.actions.cancel'),
|
||||||
|
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'cancel'),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
array_unshift($menuItems, [
|
||||||
|
'type' => 'link',
|
||||||
|
'title' => lang('PodcastImport.queue.actions.retry'),
|
||||||
|
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'retry'),
|
||||||
|
], );
|
||||||
|
}
|
||||||
|
|
||||||
return '<div class="inline-flex items-center gap-x-2">' .
|
return '<div class="inline-flex items-center gap-x-2">' .
|
||||||
'<button id="more-dropdown-' . $importTask->id . '" type="button" class="inline-flex items-center p-1 rounded-full focus:ring-accent" data-dropdown="button" data-dropdown-target="more-dropdown-' . $importTask->id . '-menu" aria-haspopup="true" aria-expanded="false">' .
|
'<button id="more-dropdown-' . $importTask->id . '" type="button" class="inline-flex items-center p-1 rounded-full focus:ring-accent" data-dropdown="button" data-dropdown-target="more-dropdown-' . $importTask->id . '-menu" aria-haspopup="true" aria-expanded="false">' .
|
||||||
icon('more') .
|
icon('more') .
|
||||||
'</button>' .
|
'</button>' .
|
||||||
'<DropdownMenu id="more-dropdown-' . $importTask->id . '-menu" labelledby="more-dropdown-' . $importTask->id . '" offsetY="-24" items="' . esc(json_encode([
|
'<DropdownMenu id="more-dropdown-' . $importTask->id . '-menu" labelledby="more-dropdown-' . $importTask->id . '" offsetY="-24" items="' . esc(json_encode($menuItems)) . '" />' .
|
||||||
[
|
|
||||||
'type' => 'link',
|
|
||||||
'title' => lang('PodcastImport.queue.actions.cancel'),
|
|
||||||
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'cancel'),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'type' => 'link',
|
|
||||||
'title' => lang('PodcastImport.queue.actions.retry'),
|
|
||||||
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'retry'),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'type' => 'separator',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'type' => 'link',
|
|
||||||
'title' => lang('PodcastImport.queue.actions.delete'),
|
|
||||||
'uri' => route_to('podcast-imports-task-action', $importTask->id, 'delete'),
|
|
||||||
'class' => 'font-semibold text-red-600',
|
|
||||||
],
|
|
||||||
])) . '" />' .
|
|
||||||
'</div>';
|
'</div>';
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue