From dcf2f6fa0a87de2760223c588fa3c71ff2af043c Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 21 Feb 2016 00:07:03 -0500 Subject: [PATCH] fix up urls to follow a cleaner pattern --- .../Controllers/Admin/ServiceController.php | 62 +++++++++---------- app/Http/Routes/AdminRoutes.php | 12 ++-- .../admin/services/options/variable.blade.php | 42 +++++++++++++ .../admin/services/options/view.blade.php | 6 +- resources/views/admin/services/view.blade.php | 2 +- 5 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 resources/views/admin/services/options/variable.blade.php diff --git a/app/Http/Controllers/Admin/ServiceController.php b/app/Http/Controllers/Admin/ServiceController.php index 5ab9e96df..325c1987d 100644 --- a/app/Http/Controllers/Admin/ServiceController.php +++ b/app/Http/Controllers/Admin/ServiceController.php @@ -125,7 +125,7 @@ class ServiceController extends Controller return redirect()->route('admin.services.service', $service); } - public function getOption(Request $request, $option) + public function getOption(Request $request, $service, $option) { $opt = Models\ServiceOptions::findOrFail($option); return view('admin.services.options.view', [ @@ -139,7 +139,7 @@ class ServiceController extends Controller ]); } - public function postOption(Request $request, $option) + public function postOption(Request $request, $service, $option) { try { $repo = new ServiceRepository\Option; @@ -148,15 +148,15 @@ class ServiceController extends Controller ])); Alert::success('Option settings successfully updated.')->flash(); } catch (DisplayValidationException $ex) { - return redirect()->route('admin.services.option', $option)->withErrors(json_decode($ex->getMessage()))->withInput(); + return redirect()->route('admin.services.option', [$service, $option])->withErrors(json_decode($ex->getMessage()))->withInput(); } catch (\Exception $ex) { Log::error($ex); Alert::danger('An error occured while attempting to modify this option.')->flash(); } - return redirect()->route('admin.services.option', $option)->withInput(); + return redirect()->route('admin.services.option', [$service, $option])->withInput(); } - public function deleteOption(Request $request, $option) + public function deleteOption(Request $request, $service, $option) { try { $service = Models\ServiceOptions::select('parent_service')->where('id', $option)->first(); @@ -171,39 +171,35 @@ class ServiceController extends Controller Log::error($ex); Alert::danger('An error was encountered while attempting to delete this option.')->flash(); } - return redirect()->route('admin.services.option', $option); + return redirect()->route('admin.services.option', [$service, $option]); } - public function postOptionVariable(Request $request, $option, $variable) + public function postOptionVariable(Request $request, $service, $option, $variable) { - if ($variable === 'new') { - // adding new variable - } else { - try { - $repo = new ServiceRepository\Variable; + try { + $repo = new ServiceRepository\Variable; - // Because of the way old() works on the display side we prefix all of the variables with thier ID - // We need to remove that prefix here since the repo doesn't want it. - $data = []; - foreach($request->except(['_token']) as $id => $val) { - $data[str_replace($variable.'_', '', $id)] = $val; - } - $repo->update($variable, $data); - Alert::success('Successfully updated variable.')->flash(); - } catch (DisplayValidationException $ex) { - $data = []; - foreach(json_decode($ex->getMessage(), true) as $id => $val) { - $data[$variable.'_'.$id] = $val; - } - return redirect()->route('admin.services.option', $option)->withErrors((object) $data)->withInput(); - } catch (DisplayException $ex) { - Alert::danger($ex->getMessage())->flash(); - } catch (\Exception $ex) { - Log::error($ex); - Alert::danger('An error occurred while attempting to update this service.')->flash(); + // Because of the way old() works on the display side we prefix all of the variables with thier ID + // We need to remove that prefix here since the repo doesn't want it. + $data = []; + foreach($request->except(['_token']) as $id => $val) { + $data[str_replace($variable.'_', '', $id)] = $val; } - return redirect()->route('admin.services.option', $option)->withInput(); + $repo->update($variable, $data); + Alert::success('Successfully updated variable.')->flash(); + } catch (DisplayValidationException $ex) { + $data = []; + foreach(json_decode($ex->getMessage(), true) as $id => $val) { + $data[$variable.'_'.$id] = $val; + } + return redirect()->route('admin.services.option', [$service, $option])->withErrors((object) $data)->withInput(); + } catch (DisplayException $ex) { + Alert::danger($ex->getMessage())->flash(); + } catch (\Exception $ex) { + Log::error($ex); + Alert::danger('An error occurred while attempting to update this service.')->flash(); } + return redirect()->route('admin.services.option', [$service, $option])->withInput(); } public function newOption(Request $request, $service) @@ -221,7 +217,7 @@ class ServiceController extends Controller '_token' ])); Alert::success('Successfully created new service option.')->flash(); - return redirect()->route('admin.services.option', $id); + return redirect()->route('admin.services.option', [$service, $id]); } catch (DisplayValidationException $ex) { return redirect()->route('admin.services.option.new', $service)->withErrors(json_decode($ex->getMessage()))->withInput(); } catch (\Exception $ex) { diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index d597d342b..7bea4118a 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -370,29 +370,29 @@ class AdminRoutes { 'uses' => 'Admin\ServiceController@deleteService' ]); - $router->get('/option/new/{service}', [ + $router->get('/service/{service}/option/new', [ 'as' => 'admin.services.option.new', 'uses' => 'Admin\ServiceController@newOption' ]); - $router->post('/option/new/{service}', [ + $router->post('/service/{service}/option/new', [ 'uses' => 'Admin\ServiceController@postNewOption' ]); - $router->get('/option/{id}', [ + $router->get('/service/{service}/option/{option}', [ 'as' => 'admin.services.option', 'uses' => 'Admin\ServiceController@getOption' ]); - $router->post('/option/{id}', [ + $router->post('/service/{service}/option/{option}', [ 'uses' => 'Admin\ServiceController@postOption' ]); - $router->delete('/option/{id}', [ + $router->delete('/service/{service}/option/{id}', [ 'uses' => 'Admin\ServiceController@deleteOption' ]); - $router->post('/option/{option}/{variable}', [ + $router->post('/service/{service}/option/{option}/variable/{variable}', [ 'as' => 'admin.services.option.variable', 'uses' => 'Admin\ServiceController@postOptionVariable' ]); diff --git a/resources/views/admin/services/options/variable.blade.php b/resources/views/admin/services/options/variable.blade.php new file mode 100644 index 000000000..c48a4f21e --- /dev/null +++ b/resources/views/admin/services/options/variable.blade.php @@ -0,0 +1,42 @@ +{{-- Copyright (c) 2015 - 2016 Dane Everitt --}} + +{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}} +{{-- of this software and associated documentation files (the "Software"), to deal --}} +{{-- in the Software without restriction, including without limitation the rights --}} +{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}} +{{-- copies of the Software, and to permit persons to whom the Software is --}} +{{-- furnished to do so, subject to the following conditions: --}} + +{{-- The above copyright notice and this permission notice shall be included in all --}} +{{-- copies or substantial portions of the Software. --}} + +{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}} +{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}} +{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}} +{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}} +{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}} +{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}} +{{-- SOFTWARE. --}} +@extends('layouts.admin') + +@section('title') + New Variable for {{ $option->name }} +@endsection + +@section('content') +
+ +

New Option Variable


+
+ +@endsection diff --git a/resources/views/admin/services/options/view.blade.php b/resources/views/admin/services/options/view.blade.php index cea388786..e4626356b 100644 --- a/resources/views/admin/services/options/view.blade.php +++ b/resources/views/admin/services/options/view.blade.php @@ -33,7 +33,7 @@
Warning! This page contains advanced settings that the panel and daemon use to control servers. Modifying information on this page is not recommended unless you are absolutely sure of what you are doing.

Settings


-
+
@@ -90,7 +90,7 @@

Variables


@foreach($variables as $variable) -
+
@@ -185,7 +185,7 @@ @endforeach - +
diff --git a/resources/views/admin/services/view.blade.php b/resources/views/admin/services/view.blade.php index 28e560fc5..463fadaa8 100644 --- a/resources/views/admin/services/view.blade.php +++ b/resources/views/admin/services/view.blade.php @@ -44,7 +44,7 @@ @foreach($options as $option) - {{ $option->name }} + {{ $option->name }} {!! $option->description !!} {{ $option->docker_image }} {{ $option->tag }}