add support for deleting service option
This commit is contained in:
parent
1e9bf1c220
commit
dcfdb89e3c
4 changed files with 56 additions and 0 deletions
|
@ -156,6 +156,24 @@ class ServiceController extends Controller
|
||||||
return redirect()->route('admin.services.option', $option)->withInput();
|
return redirect()->route('admin.services.option', $option)->withInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteOption(Request $request, $option)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$service = Models\ServiceOptions::select('parent_service')->where('id', $option)->first();
|
||||||
|
$repo = new ServiceRepository\Option;
|
||||||
|
$repo->delete($option);
|
||||||
|
|
||||||
|
Alert::success('Successfully deleted that option.')->flash();
|
||||||
|
return redirect()->route('admin.services.service', $service->parent_service);
|
||||||
|
} catch (DisplayException $ex) {
|
||||||
|
Alert::danger($ex->getMessage())->flash();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
Log::error($ex);
|
||||||
|
Alert::danger('An error was encountered while attempting to delete this option.')->flash();
|
||||||
|
}
|
||||||
|
return redirect()->route('admin.services.option', $option);
|
||||||
|
}
|
||||||
|
|
||||||
public function postOptionVariable(Request $request, $option, $variable)
|
public function postOptionVariable(Request $request, $option, $variable)
|
||||||
{
|
{
|
||||||
if ($variable === 'new') {
|
if ($variable === 'new') {
|
||||||
|
|
|
@ -388,6 +388,10 @@ class AdminRoutes {
|
||||||
'uses' => 'Admin\ServiceController@postOption'
|
'uses' => 'Admin\ServiceController@postOption'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$router->delete('/option/{id}', [
|
||||||
|
'uses' => 'Admin\ServiceController@deleteOption'
|
||||||
|
]);
|
||||||
|
|
||||||
$router->post('/option/{option}/{variable}', [
|
$router->post('/option/{option}/{variable}', [
|
||||||
'as' => 'admin.services.option.variable',
|
'as' => 'admin.services.option.variable',
|
||||||
'uses' => 'Admin\ServiceController@postOptionVariable'
|
'uses' => 'Admin\ServiceController@postOptionVariable'
|
||||||
|
|
|
@ -73,6 +73,28 @@ class Option
|
||||||
return $option->id;
|
return $option->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$option = Models\ServiceOptions::findOrFail($id);
|
||||||
|
$servers = Models\Server::where('option', $option->id)->get();
|
||||||
|
|
||||||
|
if (count($servers) !== 0) {
|
||||||
|
throw new DisplayException('You cannot delete an option that has servers attached to it currently.');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Models\ServiceVariables::where('option_id', $option->id)->delete();
|
||||||
|
$option->delete();
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
DB::rollBack();
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function update($id, array $data)
|
public function update($id, array $data)
|
||||||
{
|
{
|
||||||
$option = Models\ServiceOptions::findOrFail($id);
|
$option = Models\ServiceOptions::findOrFail($id);
|
||||||
|
|
|
@ -185,6 +185,18 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<form action="{{ route('admin.services.option', $option->id) }}" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
Deleting an option is an irreversible action. An option can <em>only</em> be deleted if no servers are associated with it.
|
||||||
|
</div>
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
{!! method_field('DELETE') !!}
|
||||||
|
<input type="submit" class="btn btn-sm btn-danger pull-right" value="Delete Option" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
Loading…
Reference in a new issue