diff --git a/app/Http/Controllers/Dashboard/IncidentController.php b/app/Http/Controllers/Dashboard/IncidentController.php index 9d3be7bc..61e6c499 100644 --- a/app/Http/Controllers/Dashboard/IncidentController.php +++ b/app/Http/Controllers/Dashboard/IncidentController.php @@ -20,6 +20,7 @@ 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,7 +294,20 @@ class IncidentController extends Controller * * @return \Illuminate\View\View */ - public function showIncidentUpdateAction(Incident $incident) + public function showIncidentUpdates(Incident $incident) + { + $updates = IncidentUpdate::byIncident($incident)->orderBy('created_at', 'desc')->get(); + return View::make('dashboard.incidents.updates.index')->withIncident($incident)->withUpdates($updates); + } + + /** + * 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.update')->withIncident($incident); } @@ -315,7 +329,7 @@ class IncidentController extends Controller $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'))) ->withErrors($e->getMessageBag()); diff --git a/app/Http/Routes/Dashboard/IncidentRoutes.php b/app/Http/Routes/Dashboard/IncidentRoutes.php index c312bc08..ed9294eb 100644 --- a/app/Http/Routes/Dashboard/IncidentRoutes.php +++ b/app/Http/Routes/Dashboard/IncidentRoutes.php @@ -71,10 +71,14 @@ 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', ]); }); diff --git a/app/Models/IncidentUpdate.php b/app/Models/IncidentUpdate.php index 207e129e..846b48a0 100644 --- a/app/Models/IncidentUpdate.php +++ b/app/Models/IncidentUpdate.php @@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Models; use AltThree\Validator\ValidatingTrait; use CachetHQ\Cachet\Models\Traits\SortableTrait; use CachetHQ\Cachet\Presenters\IncidentUpdatePresenter; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use McCool\LaravelAutoPresenter\HasPresenter; @@ -73,6 +74,19 @@ class IncidentUpdate extends Model implements HasPresenter 'user_id', ]; + /** + * Scope all by incident. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param \CachetHQ\Cachet\Models\Incident $incident + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeByIncident(Builder $query, Incident $incident) + { + return $query->where('incident_id', '=', $incident->id); + } + /** * Get the incident relation. * diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index 2d452d09..ec84ef4a 100644 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -21,7 +21,10 @@ 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', + 'count' => '{0} Zero Updates|[1] One Update|[2] Two Updates|[3,Inf] Several Updates', + ], 'add' => [ 'title' => 'Report an incident', 'success' => 'Incident added.', diff --git a/resources/views/dashboard/incidents/index.blade.php b/resources/views/dashboard/incidents/index.blade.php index dcfb2a72..70a7bb81 100644 --- a/resources/views/dashboard/incidents/index.blade.php +++ b/resources/views/dashboard/incidents/index.blade.php @@ -22,7 +22,7 @@ @foreach($incidents as $incident)
- {{ $incident->name }} {{ trans_choice('dashboard.incidents.updates', $incident->updates()->count()) }} + {{ $incident->name }} {{ trans_choice('dashboard.incidents.updates.count', $incident->updates()->count()) }} @if($incident->message)

{{ Str::words($incident->message, 5) }}

@endif diff --git a/resources/views/dashboard/incidents/updates/index.blade.php b/resources/views/dashboard/incidents/updates/index.blade.php new file mode 100644 index 00000000..392dd759 --- /dev/null +++ b/resources/views/dashboard/incidents/updates/index.blade.php @@ -0,0 +1,37 @@ +@extends('layout.dashboard') + +@section('content') +
+ @includeWhen(isset($sub_menu), 'dashboard.partials.sub-sidebar') +
+
+ + {{ trans('dashboard.incidents.updates.title') }} + + + {{ trans('dashboard.incidents.update.title') }} + +
+
+
+
+ @include('dashboard.partials.errors') + +
+ @foreach($updates as $update) +
+
+ {{ Str::words($update->message, 8) }} +

{{ trans('cachet.incidents.posted', ['timestamp' => $update->created_at_diff]) }}

+
+ +
+ @endforeach +
+
+
+
+
+@stop