From 232c05c31dcaf85b45dde3cd25f9a7cd74123830 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 10 Jan 2016 16:59:19 -0500 Subject: [PATCH] Add support for deleting nodes Finishes node management --- .../Controllers/Admin/NodesController.php | 18 ++++++++ app/Http/Routes/AdminRoutes.php | 5 +++ resources/views/admin/nodes/view.blade.php | 42 +++++++++++++++---- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index e0a7f0f46..0aa6aed19 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -186,4 +186,22 @@ class NodesController extends Controller } } + public function deleteNode(Request $request, $id) + { + $node = Models\Node::findOrFail($id); + $servers = Models\Server::where('node', $id)->count(); + if ($servers > 0) { + Alert::danger('You cannot delete a node with servers currently attached to it.')->flash(); + return redirect()->route('admin.nodes.view', [ + 'id' => $id, + 'tab' => 'tab_delete' + ]); + } + + $node->delete(); + Alert::success('Node successfully deleted.')->flash(); + return redirect()->route('admin.nodes'); + + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index f84fdd826..e2ebef0cb 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -186,6 +186,11 @@ class AdminRoutes { 'uses' => 'Admin\NodesController@postAllocations' ]); + $router->delete('/view/{id}', [ + 'as' => 'admin.nodes.delete', + 'uses' => 'Admin\NodesController@deleteNode' + ]); + }); } diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index a6729b8de..13d5ff3fa 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -42,7 +42,7 @@
  • Configuration
  • Allocation
  • Servers
  • -
  • Delete
  • + @if(count($servers) === 0)
  • Delete
  • @endif
    @@ -410,14 +410,27 @@
    -
    -
    -
    -
    - Delete + @if(count($servers) === 0) +
    +
    +
    +
    +
    +
    +
    + {!! method_field('DELETE') !!} + {!! csrf_field() !!} + +
    +
    +
    +
    Deleting this node is a permanent action, it cannot be undone.
    +
    +
    +
    -
    + @endif
    @@ -431,6 +444,21 @@ $(document).ready(function () { placement: 'auto' }); + $('#deleteNodeForm').submit(function (event) { + event.preventDefault(); + swal({ + type: 'warning', + title: 'Are You Sure?', + text: 'This will immediately delete this node, there is no undo.', + showCancelButton: true, + allowOutsideClick: true, + confirmButtonText: 'Delete', + confirmButtonColor: '#d9534f', + }, function () { + event.target.submit(); + }); + }); + $('.cloneElement').on('click', function (event) { event.preventDefault(); var cloned = $('#duplicate').clone();