diff --git a/app/Http/Controllers/Dashboard/IncidentController.php b/app/Http/Controllers/Dashboard/IncidentController.php index 9d3be7bc..94494386 100644 --- a/app/Http/Controllers/Dashboard/IncidentController.php +++ b/app/Http/Controllers/Dashboard/IncidentController.php @@ -16,10 +16,12 @@ use CachetHQ\Cachet\Bus\Commands\Incident\CreateIncidentCommand; use CachetHQ\Cachet\Bus\Commands\Incident\RemoveIncidentCommand; use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand; use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\CreateIncidentUpdateCommand; +use CachetHQ\Cachet\Bus\Commands\IncidentUpdate\UpdateIncidentUpdateCommand; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\IncidentTemplate; +use CachetHQ\Cachet\Models\IncidentUpdate; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Contracts\Auth\Guard; use Illuminate\Routing\Controller; @@ -293,9 +295,21 @@ class IncidentController extends Controller * * @return \Illuminate\View\View */ - public function showIncidentUpdateAction(Incident $incident) + public function showIncidentUpdates(Incident $incident) { - return View::make('dashboard.incidents.update')->withIncident($incident); + return View::make('dashboard.incidents.updates.index')->withIncident($incident); + } + + /** + * Shows the incident update form. + * + * @param \CachetHQ\Cachet\Models\Incident $incident + * + * @return \Illuminate\View\View + */ + public function showCreateIncidentUpdateAction(Incident $incident) + { + return View::make('dashboard.incidents.updates.add')->withIncident($incident); } /** @@ -308,20 +322,63 @@ class IncidentController extends Controller public function createIncidentUpdateAction(Incident $incident) { try { - $incident = dispatch(new CreateIncidentUpdateCommand( + $incidentUpdate = dispatch(new CreateIncidentUpdateCommand( $incident, Binput::get('status'), Binput::get('message'), $this->auth->user() )); } catch (ValidationException $e) { - return cachet_redirect('dashboard.incidents.updates', ['id' => $incident->id]) + return cachet_redirect('dashboard.incidents.updates.create', ['id' => $incident->id]) ->withInput(Binput::all()) - ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure'))) + ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.add.failure'))) ->withErrors($e->getMessageBag()); } return cachet_redirect('dashboard.incidents') - ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.update.success'))); + ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.success'))); + } + + /** + * Shows the edit incident view. + * + * @param \CachetHQ\Cachet\Models\Incident $incident + * @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate + * + * @return \Illuminate\View\View + */ + public function showEditIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate) + { + return View::make('dashboard.incidents.updates.edit') + ->withIncident($incident) + ->withUpdate($incidentUpdate); + } + + /** + * Edit an incident update. + * + * @param \CachetHQ\Cachet\Models\Incident $incident + * @param \CachetHQ\Cachet\Models\IncidentUpdate $incidentUpdate + * + * @return \Illuminate\Http\RedirectResponse + */ + public function editIncidentUpdateAction(Incident $incident, IncidentUpdate $incidentUpdate) + { + try { + $incidentUpdate = dispatch(new UpdateIncidentUpdateCommand( + $incidentUpdate, + Binput::get('status'), + Binput::get('message'), + $this->auth->user() + )); + } catch (ValidationException $e) { + return cachet_redirect('dashboard.incidents.updates.edit', ['incident' => $incident->id, 'incident_update' => $incidentUpdate->id]) + ->withInput(Binput::all()) + ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.updates.edit.failure'))) + ->withErrors($e->getMessageBag()); + } + + return cachet_redirect('dashboard.incidents.updates', ['incident' => $incident->id]) + ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.updates.edit.success'))); } } diff --git a/app/Http/Routes/Dashboard/IncidentRoutes.php b/app/Http/Routes/Dashboard/IncidentRoutes.php index c312bc08..3519cf49 100644 --- a/app/Http/Routes/Dashboard/IncidentRoutes.php +++ b/app/Http/Routes/Dashboard/IncidentRoutes.php @@ -71,12 +71,24 @@ class IncidentRoutes $router->get('{incident}/updates', [ 'as' => 'get:dashboard.incidents.updates', - 'uses' => 'IncidentController@showIncidentUpdateAction', + 'uses' => 'IncidentController@showIncidentUpdates', ]); - $router->post('{incident}/updates', [ - 'as' => 'post:dashboard.incidents.updates', + $router->get('{incident}/updates/create', [ + 'as' => 'get:dashboard.incidents.updates.create', + 'uses' => 'IncidentController@showCreateIncidentUpdateAction', + ]); + $router->post('{incident}/updates/create', [ + 'as' => 'post:dashboard.incidents.updates.create', 'uses' => 'IncidentController@createIncidentUpdateAction', ]); + $router->get('{incident}/updates/{incident_update}', [ + 'as' => 'get:dashboard.incidents.updates.edit', + 'uses' => 'IncidentController@showEditIncidentUpdateAction', + ]); + $router->post('{incident}/updates/{incident_update}', [ + 'as' => 'post:dashboard.incidents.updates.edit', + 'uses' => 'IncidentController@editIncidentUpdateAction', + ]); }); } } diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index 2d452d09..a4894d3c 100644 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -21,7 +21,20 @@ return [ 'logged' => '{0} There are no incidents, good work.|[1] You have logged one incident.|[2, Inf] You have reported :count incidents.', 'incident-create-template' => 'Create Template', 'incident-templates' => 'Incident Templates', - 'updates' => '{0} Zero Updates|[1] One Update|[2] Two Updates|[3,Inf] Several Updates', + 'updates' => [ + 'title' => 'Incident updates for :incident', + 'count' => '{0} Zero Updates|[1] One Update|[2] Two Updates|[3,*] Several Updates', + 'add' => [ + 'title' => 'Create new incident update', + 'success' => 'Your new incident update has been created.', + 'failure' => 'Something went wrong with the incident update.', + ], + 'edit' => [ + 'title' => 'Edit incident update', + 'success' => 'The incident update has been updated.', + 'failure' => 'Something went wrong updating the incident update', + ], + ], 'add' => [ 'title' => 'Report an incident', 'success' => 'Incident added.', @@ -36,11 +49,6 @@ return [ 'success' => 'The incident has been deleted and will not show on your status page.', 'failure' => 'The incident could not be deleted, please try again.', ], - 'update' => [ - 'title' => 'Create new incident update', - 'subtitle' => 'Add an update to :incident', - 'success' => 'Update added.', - ], // Incident templates 'templates' => [ diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index b057b053..aacc8e03 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -224,17 +224,18 @@ return [ ], // Buttons - 'add' => 'Add', - 'save' => 'Save', - 'update' => 'Update', - 'create' => 'Create', - 'edit' => 'Edit', - 'delete' => 'Delete', - 'submit' => 'Submit', - 'cancel' => 'Cancel', - 'remove' => 'Remove', - 'invite' => 'Invite', - 'signup' => 'Sign Up', + 'add' => 'Add', + 'save' => 'Save', + 'update' => 'Update', + 'create' => 'Create', + 'edit' => 'Edit', + 'delete' => 'Delete', + 'submit' => 'Submit', + 'cancel' => 'Cancel', + 'remove' => 'Remove', + 'invite' => 'Invite', + 'signup' => 'Sign Up', + 'manage_updates' => 'Manage Updates', // Other 'optional' => '* Optional', diff --git a/resources/views/dashboard/incidents/index.blade.php b/resources/views/dashboard/incidents/index.blade.php index dcfb2a72..78e62cf4 100644 --- a/resources/views/dashboard/incidents/index.blade.php +++ b/resources/views/dashboard/incidents/index.blade.php @@ -22,14 +22,14 @@ @foreach($incidents as $incident)
{{ Str::words($incident->message, 5) }}
@endif{!! trans('dashboard.incidents.update.subtitle', ['incident' => $incident->name]) !!}