diff --git a/app/Http/Controllers/Server/TaskController.php b/app/Http/Controllers/Server/TaskController.php index f92a29deb..aa890e095 100644 --- a/app/Http/Controllers/Server/TaskController.php +++ b/app/Http/Controllers/Server/TaskController.php @@ -71,7 +71,24 @@ class TaskController extends Controller public function postNew(Request $request, $uuid) { - dd($request->input()); + $server = Models\Server::getByUUID($uuid); + $this->authorize('create-task', $server); + + try { + $repo = new Repositories\TaskRepository; + $repo->create($server->id, $request->except([ + '_token' + ])); + } catch (DisplayValidationException $ex) { + return redirect()->route('server.tasks', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput(); + } catch (DisplayException $ex) { + Alert::danger($ex->getMessage())->flash(); + } catch (\Exception $ex) { + Log::error($ex); + Alert::danger('An unknown error occured while attempting to create this task.')->flash(); + } + return redirect()->route('server.tasks', $uuid); + } public function getView(Request $request, $uuid, $id) diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index dead06381..5722ab929 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -106,12 +106,12 @@ class TaskRepository $validator = Validator::make($data, [ 'action' => 'string|required', 'data' => 'string|required', - 'year' => 'string|sometimes|required', - 'day_of_week' => 'string|sometimes|required', - 'month' => 'string|sometimes|required', - 'day_of_month' => 'string|sometimes|required', - 'hour' => 'string|sometimes|required', - 'minute' => 'string|sometimes|required' + 'year' => 'string|sometimes', + 'day_of_week' => 'string|sometimes', + 'month' => 'string|sometimes', + 'day_of_month' => 'string|sometimes', + 'hour' => 'string|sometimes', + 'minute' => 'string|sometimes' ]); if ($validator->fails()) { @@ -124,7 +124,7 @@ class TaskRepository $cron = $this->defaults; foreach ($this->defaults as $setting => $value) { - if (array_key_exists($setting, $data)) { + if (array_key_exists($setting, $data) && !is_null($data[$setting]) && $data[$setting] !== '') { $cron[$setting] = $data[$setting]; } } @@ -140,7 +140,7 @@ class TaskRepository $cron['year'] )); } catch (\Exception $ex) { - throw new DisplayException($ex); + throw $ex; } $task = new Models\Task; diff --git a/resources/views/server/tasks/index.blade.php b/resources/views/server/tasks/index.blade.php index 3598a76f8..7b166414f 100644 --- a/resources/views/server/tasks/index.blade.php +++ b/resources/views/server/tasks/index.blade.php @@ -40,7 +40,8 @@ @foreach($tasks as $task) active === 0)class="text-disabled"@endif> - {{ $actions[$task->action] }} + {{-- {{ $actions[$task->action] }} --}} + {{ $actions[$task->action] }} {{ $task->data }} {{ Carbon::parse($task->last_run)->toDayDateTimeString() }}

({{ Carbon::parse($task->last_run)->diffForHumans() }})

@@ -70,82 +71,85 @@ $(document).ready(function () { $('.server-tasks').addClass('active'); $('[data-toggle="tooltip"]').tooltip(); - $('[data-action="delete-task"]').click(function (event) { - var self = $(this); - swal({ - type: 'error', - title: 'Delete Task?', - text: 'Are you sure you want to delete this task? There is no undo.', - showCancelButton: true, - allowOutsideClick: true, - closeOnConfirm: false, - confirmButtonText: 'Delete Task', - confirmButtonColor: '#d9534f', - showLoaderOnConfirm: true - }, function () { - $.ajax({ - method: 'DELETE', - url: '{{ route('server.tasks', $server->uuidShort) }}/delete/' + self.data('id'), - headers: { - 'X-CSRF-TOKEN': '{{ csrf_token() }}' - } - }).done(function (data) { - swal({ - type: 'success', - title: '', - text: 'Task has been deleted.' - }); - self.parent().parent().slideUp(); - }).fail(function (jqXHR) { - console.error(jqXHR); - swal({ - type: 'error', - title: 'Whoops!', - text: 'An error occured while attempting to delete this task.' + @can('delete-task', $server) + $('[data-action="delete-task"]').click(function (event) { + var self = $(this); + swal({ + type: 'error', + title: 'Delete Task?', + text: 'Are you sure you want to delete this task? There is no undo.', + showCancelButton: true, + allowOutsideClick: true, + closeOnConfirm: false, + confirmButtonText: 'Delete Task', + confirmButtonColor: '#d9534f', + showLoaderOnConfirm: true + }, function () { + $.ajax({ + method: 'DELETE', + url: '{{ route('server.tasks', $server->uuidShort) }}/delete/' + self.data('id'), + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}' + } + }).done(function (data) { + swal({ + type: 'success', + title: '', + text: 'Task has been deleted.' + }); + self.parent().parent().slideUp(); + }).fail(function (jqXHR) { + console.error(jqXHR); + swal({ + type: 'error', + title: 'Whoops!', + text: 'An error occured while attempting to delete this task.' + }); }); }); }); - }); - - $('[data-action="toggle-task"]').click(function (event) { - var self = $(this); - swal({ - type: 'info', - title: 'Toggle Task', - text: 'This will toggle the selected task.', - showCancelButton: true, - allowOutsideClick: true, - closeOnConfirm: false, - confirmButtonText: 'Continue', - showLoaderOnConfirm: true - }, function () { - $.ajax({ - method: 'POST', - url: '{{ route('server.tasks', $server->uuidShort) }}/toggle/' + self.data('id'), - headers: { - 'X-CSRF-TOKEN': '{{ csrf_token() }}' - } - }).done(function (data) { - swal({ - type: 'success', - title: '', - text: 'Task has been toggled.' - }); - if (data.status !== 1) { - self.parent().parent().addClass('text-disabled'); - } else { - self.parent().parent().removeClass('text-disabled'); - } - }).fail(function (jqXHR) { - console.error(jqXHR); - swal({ - type: 'error', - title: 'Whoops!', - text: 'An error occured while attempting to toggle this task.' + @endcan + @can('toggle-task', $server) + $('[data-action="toggle-task"]').click(function (event) { + var self = $(this); + swal({ + type: 'info', + title: 'Toggle Task', + text: 'This will toggle the selected task.', + showCancelButton: true, + allowOutsideClick: true, + closeOnConfirm: false, + confirmButtonText: 'Continue', + showLoaderOnConfirm: true + }, function () { + $.ajax({ + method: 'POST', + url: '{{ route('server.tasks', $server->uuidShort) }}/toggle/' + self.data('id'), + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}' + } + }).done(function (data) { + swal({ + type: 'success', + title: '', + text: 'Task has been toggled.' + }); + if (data.status !== 1) { + self.parent().parent().addClass('text-disabled'); + } else { + self.parent().parent().removeClass('text-disabled'); + } + }).fail(function (jqXHR) { + console.error(jqXHR); + swal({ + type: 'error', + title: 'Whoops!', + text: 'An error occured while attempting to toggle this task.' + }); }); }); }); - }); + @endcan }); diff --git a/resources/views/server/users/new.blade.php b/resources/views/server/users/new.blade.php index c809f7bed..44f35671f 100644 --- a/resources/views/server/users/new.blade.php +++ b/resources/views/server/users/new.blade.php @@ -214,6 +214,49 @@ +
+
+

Task Management


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@can('edit-subuser', $server)
diff --git a/resources/views/server/users/view.blade.php b/resources/views/server/users/view.blade.php index 50e49f6f3..f9851934f 100644 --- a/resources/views/server/users/view.blade.php +++ b/resources/views/server/users/view.blade.php @@ -203,6 +203,49 @@
+
+
+

Task Management


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@can('edit-subuser', $server)