fix up urls to follow a cleaner pattern

This commit is contained in:
Dane Everitt 2016-02-21 00:07:03 -05:00
parent d822811a5d
commit dcf2f6fa0a
5 changed files with 81 additions and 43 deletions

View File

@ -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) {

View File

@ -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'
]);

View File

@ -0,0 +1,42 @@
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
{{-- 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')
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="/admin">Admin Control</a></li>
<li><a href="/admin/services">Services</a></li>
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
<li><a href="{{ route('admin.services.option', $option->id) }}">{{ $option->name }}</a></li>
<li class="active">New Variable</li>
</ul>
<h3>New Option Variable</h3><hr />
</div>
<script>
$(document).ready(function () {
$('#sidebar_links').find("a[href='/admin/services']").addClass('active');
});
</script>
@endsection

View File

@ -33,7 +33,7 @@
</ul>
<div class="alert alert-warning"><strong>Warning!</strong> 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.</div>
<h3>Settings</h3><hr />
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
<form action="{{ route('admin.services.option', [$service->id, $option->id]) }}" method="POST">
<div class="row">
<div class="col-md-6 form-group">
<label class="control-label">Name:</label>
@ -90,7 +90,7 @@
</form>
<h3>Variables</h3><hr />
@foreach($variables as $variable)
<form action="{{ route('admin.services.option.variable', [ 'option' => $option->id, 'variable' => $variable->id ]) }}" method="POST">
<form action="{{ route('admin.services.option.variable', [$service->id, $option->id, $variable->id]) }}" method="POST">
<div class="well">
<div class="row">
<div class="col-md-6 form-group">
@ -185,7 +185,7 @@
@endforeach
</tbody>
</table>
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
<form action="{{ route('admin.services.option', [$service->id, $option->id]) }}" method="POST">
<div class="row">
<div class="col-md-12">
<div class="alert alert-danger">

View File

@ -44,7 +44,7 @@
<tbody>
@foreach($options as $option)
<tr>
<td><a href="{{ route('admin.services.option', $option->id) }}">{{ $option->name }}</a></td>
<td><a href="{{ route('admin.services.option', [ $service->id, $option->id]) }}">{{ $option->name }}</a></td>
<td>{!! $option->description !!}</td>
<td><code>{{ $option->docker_image }}</code></td>
<td><code>{{ $option->tag }}</code></td>