From 99a67127c9190c2ffa749176f09ca6ab46e59b94 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 4 Jan 2016 16:09:22 -0500 Subject: [PATCH] Add toggle install status support --- .../Controllers/Admin/ServersController.php | 17 +++++++++++++++++ app/Http/Routes/AdminRoutes.php | 4 ++++ app/Repositories/ServerRepository.php | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index 69509d334..8ee797522 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -312,4 +312,21 @@ class ServersController extends Controller ]); } + public function postToggleInstall(Request $request, $id) + { + try { + $server = new ServerRepository; + $server->toggleInstall($id); + Alert::success('Server status was successfully toggled.')->flash(); + } catch(\Exception $e) { + Log::error($e); + Alert::danger('An unhandled exception occured while attemping to toggle this servers status.')->flash(); + } finally { + return redirect()->route('admin.servers.view', [ + 'id' => $id, + 'tab' => 'tab_manage' + ]); + } + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index f073f9e56..e1ef156f7 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -42,6 +42,10 @@ class AdminRoutes { $router->post('/new/service-variables', [ 'uses' => 'Admin\ServersController@postNewServerServiceVariables' ]); }); + // Change Install Status + $router->post('/view/{id}/installed', [ + 'uses' => 'Admin\ServersController@postToggleInstall' + ]); }); } diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 70713fc22..e9885c0dd 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -575,4 +575,11 @@ class ServerRepository } } + public function toggleInstall($id) + { + $server = Models\Server::findOrFail($id); + $server->installed = ($server->installed === 1) ? 0 : 1; + return $server->save(); + } + }