Incident Templates are now supported.
This commit is contained in:
@@ -156,6 +156,32 @@ $(function() {
|
||||
});
|
||||
});
|
||||
|
||||
// Incident management
|
||||
$('select[name=template]').on('change', function() {
|
||||
var $this = $(this).find('option:selected'),
|
||||
slug = $this.val();
|
||||
|
||||
// Only fetch the template if we've picked one.
|
||||
if (slug) {
|
||||
$.ajax({
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
slug: slug
|
||||
},
|
||||
url: '/dashboard/api/incidents/templates',
|
||||
success: function(tpl) {
|
||||
var $form = $('form[name=IncidentForm]');
|
||||
$form.find('input[name=incident\\[name\\]]').val(tpl.name);
|
||||
$form.find('textarea[name=incident\\[message\\]]').val(tpl.template);
|
||||
},
|
||||
error: function() {
|
||||
(new CachetHQ.Notifier()).notify('There was an error finding that template.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Banner removal JS
|
||||
$('#remove-banner').click(function(){
|
||||
$('#banner-view').remove();
|
||||
|
||||
@@ -9,6 +9,7 @@ return [
|
||||
'incidents' => 'Incidents',
|
||||
'logged' => '{0} There are no incidents, good work.|You have logged one incident.|You have reported <strong>:count</strong> incidents.',
|
||||
'incident-create-template' => 'Create Template',
|
||||
'incident-templates' => 'Incident Templates',
|
||||
'add' => [
|
||||
'title' => 'Add an incident',
|
||||
'success' => 'Incident added.',
|
||||
@@ -22,11 +23,17 @@ return [
|
||||
|
||||
// Incident templates
|
||||
'templates' => [
|
||||
'add' => [
|
||||
'title' => 'Incident Templates',
|
||||
'add' => [
|
||||
'title' => 'Create an incident template',
|
||||
'success' => 'Template created.',
|
||||
'failure' => 'Something went wrong with the incident template.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Edit template',
|
||||
'success' => 'Template has been updated!',
|
||||
'failure' => 'Something went wrong updating the incident template',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ return [
|
||||
'incidents' => 'Incidents',
|
||||
'logged' => '{0} Il n\'y a aucun incident, bien joué !|Vous avez reporté un incident.|Vous avez reporté <strong>:count</strong> incidents.',
|
||||
'incident-create-template' => 'Créer un modèle',
|
||||
'incident-templates' => 'Modèles d\'incident',
|
||||
'add' => [
|
||||
'title' => 'Ajouter un incident',
|
||||
'success' => 'Incident ajouté.',
|
||||
@@ -27,6 +28,11 @@ return [
|
||||
'success' => 'Modèle créé.',
|
||||
'failure' => 'Il s\'est passé quelque chose avec ce modèle d\'incident.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Modifier un modèle',
|
||||
'success' => 'Modèle mis à jour.',
|
||||
'failure' => 'Une erreur s\'est produite lors de la mise à jour du modèle.',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@@ -47,11 +47,24 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache
|
||||
Route::delete('{incident}/delete', 'DashIncidentController@deleteIncidentAction');
|
||||
Route::get('{incident}/edit', 'DashIncidentController@showEditIncidentAction');
|
||||
Route::post('{incident}/edit', 'DashIncidentController@editIncidentAction');
|
||||
Route::get('template', [
|
||||
'as' => 'dashboard.incidents.template',
|
||||
});
|
||||
|
||||
// Incident Templates
|
||||
Route::group(['prefix' => 'templates'], function () {
|
||||
Route::get('/', [
|
||||
'as' => 'dashboard.templates',
|
||||
'uses' => 'DashIncidentController@showTemplates',
|
||||
]);
|
||||
|
||||
Route::get('add', [
|
||||
'as' => 'dashboard.templates.add',
|
||||
'uses' => 'DashIncidentController@showAddIncidentTemplate',
|
||||
]);
|
||||
Route::post('template', 'DashIncidentController@createIncidentTemplateAction');
|
||||
Route::post('add', 'DashIncidentController@createIncidentTemplateAction');
|
||||
|
||||
Route::get('{incident_template}/edit', 'DashIncidentController@showEditTemplateAction');
|
||||
Route::post('{incident_template}/edit', 'DashIncidentController@editTemplateAction');
|
||||
Route::delete('{incident_template}/delete', 'DashIncidentController@deleteTemplateAction');
|
||||
});
|
||||
|
||||
// Metrics
|
||||
@@ -119,6 +132,7 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache
|
||||
// Internal API.
|
||||
// This should only be used for making requests within the dashboard.
|
||||
Route::group(['prefix' => 'api'], function () {
|
||||
Route::get('incidents/templates', 'DashAPIController@getIncidentTemplate');
|
||||
Route::post('components/order', 'DashAPIController@postUpdateComponentOrder');
|
||||
Route::post('components/{component}', 'DashAPIController@postUpdateComponent');
|
||||
});
|
||||
|
||||
@@ -16,6 +16,15 @@
|
||||
@include('partials.dashboard.errors')
|
||||
{{ Form::open(['name' => 'IncidentForm', 'class' => 'form-vertical', 'role' => 'form']) }}
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="incident-template">{{ trans('forms.incidents.templates.template') }}</label>
|
||||
<select class="form-control" name="template">
|
||||
<option selected></option>
|
||||
@foreach($incidentTemplates as $tpl)
|
||||
<option value="{{ $tpl->slug }}">{{ $tpl->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="incident-name">{{ trans('forms.incidents.name') }}</label>
|
||||
<input type="text" class="form-control" name="incident[name]" id="incident-name" required value="{{ Input::old('incident.name') }}" />
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-plus"></i> {{ trans('dashboard.incidents.incidents') }}
|
||||
<i class="icon ion-plus"></i> {{ trans('dashboard.incidents.templates.title') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.incidents.templates.add.title') }}</small>
|
||||
</div>
|
||||
|
||||
43
app/views/dashboard/incidents/templates/edit.blade.php
Normal file
43
app/views/dashboard/incidents/templates/edit.blade.php
Normal file
@@ -0,0 +1,43 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-document"></i> {{ trans('dashboard.incidents.templates.title') }}
|
||||
</span>
|
||||
> <small>{{ trans('dashboard.incidents.templates.edit.title') }}</small>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@if($updatedTemplate = Session::get('updatedTemplate'))
|
||||
<div class="alert alert-{{ $updatedTemplate->isValid() ? 'success' : 'danger' }}">
|
||||
@if($updatedTemplate->isValid())
|
||||
{{ sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.edit.success')) }}
|
||||
@else
|
||||
{{ sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure').' '.$updatedTemplate->getErrors()) }}
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{ Form::open(['name' => 'IncidentTemplateForm', 'class' => 'form-vertical', 'role' => 'form']) }}
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label for="template-name">{{ trans('forms.incidents.templates.name') }}</label>
|
||||
<input type="text" class="form-control" name="template[name]" id="template-name" required value="{{ $template->name }}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.incidents.templates.template') }}</label>
|
||||
<textarea name="template[template]" class="form-control" rows="5" required>{{ $template->template }}</textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<button type="submit" class="btn btn-success">{{ trans('forms.update') }}</button>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
35
app/views/dashboard/incidents/templates/index.blade.php
Normal file
35
app/views/dashboard/incidents/templates/index.blade.php
Normal file
@@ -0,0 +1,35 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-document-text"></i> {{ trans('dashboard.incidents.templates.title') }}
|
||||
</span>
|
||||
<a class="btn btn-sm btn-success pull-right" href="{{ route('dashboard.templates.add') }}">
|
||||
{{ trans('dashboard.incidents.templates.add.title') }}
|
||||
</a>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="striped-list">
|
||||
@foreach($incidentTemplates as $template)
|
||||
<div class="row striped-list-item">
|
||||
<div class="col-md-6">
|
||||
<strong>{{ $template->name }}</strong>
|
||||
<p><small>{{ $template->template }}</small></p>
|
||||
</div>
|
||||
<div class="col-md-6 text-right">
|
||||
<a href="/dashboard/templates/{{ $template->id }}/edit" class="btn btn-default">{{ trans('forms.edit') }}</a>
|
||||
<a href="/dashboard/templates/{{ $template->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
@@ -37,11 +37,11 @@
|
||||
<span>{{ trans('dashboard.incidents.incidents') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{{-- <li {{ set_active('dashboard/incidents/templates') }}>
|
||||
<a href="{{ route('dashboard.incidents.template') }}">
|
||||
<i class="fa fa-plus"></i> {{ trans('cachet.dashboard.incident-create-template') }}
|
||||
<li {{ set_active('dashboard/templates*') }}>
|
||||
<a href="{{ route('dashboard.templates') }}">
|
||||
<i class="icons ion-document-text"></i> {{ trans('dashboard.incidents.incident-templates') }}
|
||||
</a>
|
||||
</li> --}}
|
||||
</li>
|
||||
<li {{ set_active('dashboard/components*') }}>
|
||||
<a href="{{ route('dashboard.components') }}">
|
||||
<i class="icons ion-ios-keypad"></i>
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class DashAPIController extends Controller
|
||||
@@ -44,4 +46,17 @@ class DashAPIController extends Controller
|
||||
|
||||
return $componentData;
|
||||
}
|
||||
|
||||
public function getIncidentTemplate()
|
||||
{
|
||||
$templateSlug = Binput::get('slug');
|
||||
|
||||
$template = IncidentTemplate::where('slug', $templateSlug)->first();
|
||||
|
||||
if ($template) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,22 @@ class DashIncidentController extends Controller
|
||||
public function showAddIncident()
|
||||
{
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incident templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTemplates()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -89,6 +103,35 @@ class DashIncidentController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident template view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'template' => $template,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
$template->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident template.
|
||||
*
|
||||
@@ -178,4 +221,18 @@ class DashIncidentController extends Controller
|
||||
|
||||
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
$template->update(Binput::get('template'));
|
||||
|
||||
return Redirect::back()->with('updatedTemplate', $template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class IncidentTemplate extends Model
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => 'alpha|required',
|
||||
'name' => 'required',
|
||||
'template' => 'required',
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user