Skip to content

Commit dcf2f6f

Browse files
committed
fix up urls to follow a cleaner pattern
1 parent d822811 commit dcf2f6f

File tree

5 files changed

+82
-44
lines changed

5 files changed

+82
-44
lines changed

app/Http/Controllers/Admin/ServiceController.php

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function deleteService(Request $request, $service)
125125
return redirect()->route('admin.services.service', $service);
126126
}
127127

128-
public function getOption(Request $request, $option)
128+
public function getOption(Request $request, $service, $option)
129129
{
130130
$opt = Models\ServiceOptions::findOrFail($option);
131131
return view('admin.services.options.view', [
@@ -139,7 +139,7 @@ public function getOption(Request $request, $option)
139139
]);
140140
}
141141

142-
public function postOption(Request $request, $option)
142+
public function postOption(Request $request, $service, $option)
143143
{
144144
try {
145145
$repo = new ServiceRepository\Option;
@@ -148,15 +148,15 @@ public function postOption(Request $request, $option)
148148
]));
149149
Alert::success('Option settings successfully updated.')->flash();
150150
} catch (DisplayValidationException $ex) {
151-
return redirect()->route('admin.services.option', $option)->withErrors(json_decode($ex->getMessage()))->withInput();
151+
return redirect()->route('admin.services.option', [$service, $option])->withErrors(json_decode($ex->getMessage()))->withInput();
152152
} catch (\Exception $ex) {
153153
Log::error($ex);
154154
Alert::danger('An error occured while attempting to modify this option.')->flash();
155155
}
156-
return redirect()->route('admin.services.option', $option)->withInput();
156+
return redirect()->route('admin.services.option', [$service, $option])->withInput();
157157
}
158158

159-
public function deleteOption(Request $request, $option)
159+
public function deleteOption(Request $request, $service, $option)
160160
{
161161
try {
162162
$service = Models\ServiceOptions::select('parent_service')->where('id', $option)->first();
@@ -171,39 +171,35 @@ public function deleteOption(Request $request, $option)
171171
Log::error($ex);
172172
Alert::danger('An error was encountered while attempting to delete this option.')->flash();
173173
}
174-
return redirect()->route('admin.services.option', $option);
174+
return redirect()->route('admin.services.option', [$service, $option]);
175175
}
176176

177-
public function postOptionVariable(Request $request, $option, $variable)
177+
public function postOptionVariable(Request $request, $service, $option, $variable)
178178
{
179-
if ($variable === 'new') {
180-
// adding new variable
181-
} else {
182-
try {
183-
$repo = new ServiceRepository\Variable;
184-
185-
// Because of the way old() works on the display side we prefix all of the variables with thier ID
186-
// We need to remove that prefix here since the repo doesn't want it.
187-
$data = [];
188-
foreach($request->except(['_token']) as $id => $val) {
189-
$data[str_replace($variable.'_', '', $id)] = $val;
190-
}
191-
$repo->update($variable, $data);
192-
Alert::success('Successfully updated variable.')->flash();
193-
} catch (DisplayValidationException $ex) {
194-
$data = [];
195-
foreach(json_decode($ex->getMessage(), true) as $id => $val) {
196-
$data[$variable.'_'.$id] = $val;
197-
}
198-
return redirect()->route('admin.services.option', $option)->withErrors((object) $data)->withInput();
199-
} catch (DisplayException $ex) {
200-
Alert::danger($ex->getMessage())->flash();
201-
} catch (\Exception $ex) {
202-
Log::error($ex);
203-
Alert::danger('An error occurred while attempting to update this service.')->flash();
179+
try {
180+
$repo = new ServiceRepository\Variable;
181+
182+
// Because of the way old() works on the display side we prefix all of the variables with thier ID
183+
// We need to remove that prefix here since the repo doesn't want it.
184+
$data = [];
185+
foreach($request->except(['_token']) as $id => $val) {
186+
$data[str_replace($variable.'_', '', $id)] = $val;
204187
}
205-
return redirect()->route('admin.services.option', $option)->withInput();
188+
$repo->update($variable, $data);
189+
Alert::success('Successfully updated variable.')->flash();
190+
} catch (DisplayValidationException $ex) {
191+
$data = [];
192+
foreach(json_decode($ex->getMessage(), true) as $id => $val) {
193+
$data[$variable.'_'.$id] = $val;
194+
}
195+
return redirect()->route('admin.services.option', [$service, $option])->withErrors((object) $data)->withInput();
196+
} catch (DisplayException $ex) {
197+
Alert::danger($ex->getMessage())->flash();
198+
} catch (\Exception $ex) {
199+
Log::error($ex);
200+
Alert::danger('An error occurred while attempting to update this service.')->flash();
206201
}
202+
return redirect()->route('admin.services.option', [$service, $option])->withInput();
207203
}
208204

209205
public function newOption(Request $request, $service)
@@ -221,7 +217,7 @@ public function postNewOption(Request $request, $service)
221217
'_token'
222218
]));
223219
Alert::success('Successfully created new service option.')->flash();
224-
return redirect()->route('admin.services.option', $id);
220+
return redirect()->route('admin.services.option', [$service, $id]);
225221
} catch (DisplayValidationException $ex) {
226222
return redirect()->route('admin.services.option.new', $service)->withErrors(json_decode($ex->getMessage()))->withInput();
227223
} catch (\Exception $ex) {

app/Http/Routes/AdminRoutes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,29 +370,29 @@ public function map(Router $router) {
370370
'uses' => 'Admin\ServiceController@deleteService'
371371
]);
372372

373-
$router->get('/option/new/{service}', [
373+
$router->get('/service/{service}/option/new', [
374374
'as' => 'admin.services.option.new',
375375
'uses' => 'Admin\ServiceController@newOption'
376376
]);
377377

378-
$router->post('/option/new/{service}', [
378+
$router->post('/service/{service}/option/new', [
379379
'uses' => 'Admin\ServiceController@postNewOption'
380380
]);
381381

382-
$router->get('/option/{id}', [
382+
$router->get('/service/{service}/option/{option}', [
383383
'as' => 'admin.services.option',
384384
'uses' => 'Admin\ServiceController@getOption'
385385
]);
386386

387-
$router->post('/option/{id}', [
387+
$router->post('/service/{service}/option/{option}', [
388388
'uses' => 'Admin\ServiceController@postOption'
389389
]);
390390

391-
$router->delete('/option/{id}', [
391+
$router->delete('/service/{service}/option/{id}', [
392392
'uses' => 'Admin\ServiceController@deleteOption'
393393
]);
394394

395-
$router->post('/option/{option}/{variable}', [
395+
$router->post('/service/{service}/option/{option}/variable/{variable}', [
396396
'as' => 'admin.services.option.variable',
397397
'uses' => 'Admin\ServiceController@postOptionVariable'
398398
]);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{-- Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com> --}}
2+
3+
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
4+
{{-- of this software and associated documentation files (the "Software"), to deal --}}
5+
{{-- in the Software without restriction, including without limitation the rights --}}
6+
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
7+
{{-- copies of the Software, and to permit persons to whom the Software is --}}
8+
{{-- furnished to do so, subject to the following conditions: --}}
9+
10+
{{-- The above copyright notice and this permission notice shall be included in all --}}
11+
{{-- copies or substantial portions of the Software. --}}
12+
13+
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
14+
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
15+
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
16+
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
17+
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
18+
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
19+
{{-- SOFTWARE. --}}
20+
@extends('layouts.admin')
21+
22+
@section('title')
23+
New Variable for {{ $option->name }}
24+
@endsection
25+
26+
@section('content')
27+
<div class="col-md-12">
28+
<ul class="breadcrumb">
29+
<li><a href="/admin">Admin Control</a></li>
30+
<li><a href="/admin/services">Services</a></li>
31+
<li><a href="{{ route('admin.services.service', $service->id) }}">{{ $service->name }}</a></li>
32+
<li><a href="{{ route('admin.services.option', $option->id) }}">{{ $option->name }}</a></li>
33+
<li class="active">New Variable</li>
34+
</ul>
35+
<h3>New Option Variable</h3><hr />
36+
</div>
37+
<script>
38+
$(document).ready(function () {
39+
$('#sidebar_links').find("a[href='/admin/services']").addClass('active');
40+
});
41+
</script>
42+
@endsection

resources/views/admin/services/options/view.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</ul>
3434
<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>
3535
<h3>Settings</h3><hr />
36-
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
36+
<form action="{{ route('admin.services.option', [$service->id, $option->id]) }}" method="POST">
3737
<div class="row">
3838
<div class="col-md-6 form-group">
3939
<label class="control-label">Name:</label>
@@ -90,7 +90,7 @@
9090
</form>
9191
<h3>Variables</h3><hr />
9292
@foreach($variables as $variable)
93-
<form action="{{ route('admin.services.option.variable', [ 'option' => $option->id, 'variable' => $variable->id ]) }}" method="POST">
93+
<form action="{{ route('admin.services.option.variable', [$service->id, $option->id, $variable->id]) }}" method="POST">
9494
<div class="well">
9595
<div class="row">
9696
<div class="col-md-6 form-group">
@@ -185,7 +185,7 @@
185185
@endforeach
186186
</tbody>
187187
</table>
188-
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
188+
<form action="{{ route('admin.services.option', [$service->id, $option->id]) }}" method="POST">
189189
<div class="row">
190190
<div class="col-md-12">
191191
<div class="alert alert-danger">

resources/views/admin/services/view.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<tbody>
4545
@foreach($options as $option)
4646
<tr>
47-
<td><a href="{{ route('admin.services.option', $option->id) }}">{{ $option->name }}</a></td>
47+
<td><a href="{{ route('admin.services.option', [ $service->id, $option->id]) }}">{{ $option->name }}</a></td>
4848
<td>{!! $option->description !!}</td>
4949
<td><code>{{ $option->docker_image }}</code></td>
5050
<td><code>{{ $option->tag }}</code></td>

0 commit comments

Comments
 (0)