Add support for deleting service packs.

This commit is contained in:
Dane Everitt 2016-11-18 17:31:57 -05:00
parent d4729427aa
commit 5600f3201c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 39 additions and 14 deletions

View file

@ -138,19 +138,34 @@ class PackController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
try { if (!is_null($request->input('action_delete'))) {
$repo = new Pack; try {
$repo->update($id, $request->except([ $repo = new Pack;
'_token' $repo->delete($id);
])); Alert::success('The requested service pack has been deleted from the system.')->flash();
Alert::success('Service pack has been successfully updated.')->flash(); return redirect()->route('admin.services.packs');
} catch (DisplayValidationException $ex) { } catch (DisplayException $ex) {
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput(); Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) { } catch (\Exception $ex) {
Log::error($ex); Log::error($ex);
Alert::danger('An error occured while attempting to add edit this pack.')->flash(); Alert::danger('An error occured while attempting to delete this pack.')->flash();
}
return redirect()->route('admin.services.packs.edit', $id);
} else {
try {
$repo = new Pack;
$repo->update($id, $request->except([
'_token'
]));
Alert::success('Service pack has been successfully updated.')->flash();
} catch (DisplayValidationException $ex) {
return redirect()->route('admin.services.packs.edit', $id)->withErrors(json_decode($ex->getMessage()))->withInput();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An error occured while attempting to add edit this pack.')->flash();
}
return redirect()->route('admin.services.packs.edit', $id);
} }
return redirect()->route('admin.services.packs.edit', $id);
} }
public function export(Request $request, $id, $files = false) public function export(Request $request, $id, $files = false)

View file

@ -225,4 +225,13 @@ class Pack
}); });
} }
public function delete($id) {
$pack = Models\ServicePack::findOrFail($id);
// @TODO Check for linked servers; foreign key should block this.
DB::transaction(function () use ($pack) {
$pack->delete();
Storage::deleteDirectory('packs/' . $pack->uuid);
});
}
} }

View file

@ -186,8 +186,9 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
{!! csrf_field() !!} {!! csrf_field() !!}
<input type="submit" class="btn btn-sm btn-primary" value="Edit Service Pack" /> <input type="submit" name="action_submit" class="btn btn-sm btn-primary" value="Edit Service Pack" />
<a href="{{ route('admin.services.packs.export', $pack->id) }}"><button type="button" class="pull-right btn btn-sm btn-default"><i class="fa fa-file"></i> Export</button></a> <button type="submit" name="action_delete" class="pull-right btn btn-sm btn-danger"><i class="fa fa-times"></i> Delete</button>
<a href="{{ route('admin.services.packs.export', $pack->id) }}"><button type="button" class="pull-right btn btn-sm btn-default" style="margin-right:10px;"><i class="fa fa-file"></i> Export</button></a>
<a href="{{ route('admin.services.packs.export', [ $pack->id, 'true' ]) }}"><button type="button" class="pull-right btn btn-sm btn-default" style="margin-right:10px;"><i class="fa fa-download"></i> Export with Files</button></a> <a href="{{ route('admin.services.packs.export', [ $pack->id, 'true' ]) }}"><button type="button" class="pull-right btn btn-sm btn-default" style="margin-right:10px;"><i class="fa fa-download"></i> Export with Files</button></a>
</div> </div>
</div> </div>