Create an incident updates overview page

This commit is contained in:
Nico Stapelbroek
2018-01-13 15:34:26 +01:00
parent 42fd84ea79
commit 532d8a20c5
6 changed files with 79 additions and 7 deletions

View File

@@ -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());

View File

@@ -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',
]);
});

View File

@@ -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.
*

View File

@@ -21,7 +21,10 @@ return [
'logged' => '{0} There are no incidents, good work.|[1] You have logged one incident.|[2, Inf] You have reported <strong>:count</strong> 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.',

View File

@@ -22,7 +22,7 @@
@foreach($incidents as $incident)
<div class="row striped-list-item">
<div class="col-xs-6">
<i class="{{ $incident->icon }}"></i> <a href="{{ cachet_route('dashboard.incidents.edit', [$incident->id]) }}"><strong>{{ $incident->name }}</strong></a> <span class="badge badge-info">{{ trans_choice('dashboard.incidents.updates', $incident->updates()->count()) }}</span>
<i class="{{ $incident->icon }}"></i> <a href="{{ cachet_route('dashboard.incidents.edit', [$incident->id]) }}"><strong>{{ $incident->name }}</strong></a> <span class="badge badge-info">{{ trans_choice('dashboard.incidents.updates.count', $incident->updates()->count()) }}</span>
@if($incident->message)
<p><small>{{ Str::words($incident->message, 5) }}</small></p>
@endif

View File

@@ -0,0 +1,37 @@
@extends('layout.dashboard')
@section('content')
<div class="content-panel">
@includeWhen(isset($sub_menu), 'dashboard.partials.sub-sidebar')
<div class="content-wrapper">
<div class="header sub-header">
<span class="uppercase">
<i class="ion ion-ios-information-outline"></i> {{ trans('dashboard.incidents.updates.title') }}
</span>
<a class="btn btn-md btn-success pull-right" href="{{ cachet_route('dashboard.incidents.updates.create', [$incident]) }}">
{{ trans('dashboard.incidents.update.title') }}
</a>
<div class="clearfix"></div>
</div>
<div class="row">
<div class="col-sm-12">
@include('dashboard.partials.errors')
<div class="striped-list">
@foreach($updates as $update)
<div class="row striped-list-item">
<div class="col-xs-6">
<a href="{{ cachet_route('dashboard.incidents.edit', [$update->id]) }}"><strong>{{ Str::words($update->message, 8) }}</strong></a>
<p><small>{{ trans('cachet.incidents.posted', ['timestamp' => $update->created_at_diff]) }}</small></p>
</div>
<div class="col-xs-6 text-right">
<a href="{{ cachet_route('dashboard.incidents.edit', [$update->id]) }}" class="btn btn-default">{{ trans('forms.edit') }}</a>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
@stop