Merge pull request #301 from cachethq/incident-component

Link incidents to components
This commit is contained in:
James Brooks
2015-01-14 17:28:16 +00:00
9 changed files with 91 additions and 10 deletions

View File

@@ -96,6 +96,19 @@ $(function() {
$(this).parents('div.alert').addClass('hide');
});
$('form[name=IncidentForm] select[name=incident\\[component_id\\]]').on('change', function() {
var $option = $(this).find('option:selected');
var $componentStatus = $('#component-status');
if ($option.val() !== '') {
if ($componentStatus.hasClass('hidden')) {
$componentStatus.removeClass('hidden');
} else {
$componentStatus.addClass('hidden');
}
}
});
// Sortable components.
var componentList = document.getElementById("component-list");
if (componentList) {

View File

@@ -98,5 +98,8 @@ return [
'delete' => 'Löschen',
'submit' => 'Speichern',
'cancel' => 'Abbrechen',
'remove' => 'Entfernen'
'remove' => 'Entfernen',
// Other
'optional' => '* Optional',
];

View File

@@ -27,6 +27,7 @@ return [
'incidents' => [
'name' => 'Name',
'status' => 'Status',
'component' => 'Component',
'message' => 'Message',
'message-help' => 'You may also use Markdown.',
@@ -98,5 +99,8 @@ return [
'delete' => 'Delete',
'submit' => 'Submit',
'cancel' => 'Cancel',
'remove' => 'Remove'
'remove' => 'Remove',
// Other
'optional' => '* Optional',
];

View File

@@ -98,5 +98,8 @@ return [
'delete' => 'Effacer',
'submit' => 'Envoyer',
'cancel' => 'Annuler',
'remove' => 'Supprimer'
'remove' => 'Supprimer',
// Other
'optional' => '* Optional',
];

View File

@@ -43,6 +43,30 @@
{{ trans('cachet.incidents.status')[4] }}
</label>
</div>
<div class="form-group">
<label>{{ trans('forms.incidents.component') }}</label>
<select name='incident[component_id]' class='form-control'>
<option value='0' selected></option>
@foreach($components as $component)
<option value='{{ $component->id }}'>{{ $component->name }}</option>
@endforeach
</select>
<span class='help-block'>{{ trans('forms.optional') }}</span>
</div>
<div class="form-group hidden" id='component-status'>
<div class="well">
<div class="radio-items">
@foreach(trans('cachet.components.status') as $statusID => $status)
<div class="radio-inline">
<label>
<input type="radio" name="incident[component_status]" value="{{ $statusID }}" />
{{ $status }}
</label>
</div>
@endforeach
</div>
</div>
</div>
<div class="form-group">
<label>{{ trans('forms.incidents.message') }}</label>
<textarea name="incident[message]" class="form-control" rows="5" required>{{ Input::old('incident.message') }}</textarea>

View File

@@ -43,6 +43,30 @@
{{ trans('cachet.incidents.status')[4] }}
</label>
</div>
<div class='form-group'>
<label>{{ trans('forms.incidents.component') }}</label>
<select name='incident[component_id]' class='form-control'>
<option value='0' {{ $incident->id === 0 ? "selected" : null }}></option>
@foreach($components as $component)
<option value='{{ $component->id }}' {{ $incident->component_id === $component->id ? "selected" : null }}>{{ $component->name }}</option>
@endforeach
</select>
<span class='help-block'>{{ trans('forms.optional') }}</span>
</div>
<div class="form-group {{ $incident->component_id === 0 ? 'hidden' : null }}" id='component-status'>
<div class="well">
<div class="radio-items">
@foreach(trans('cachet.components.status') as $statusID => $status)
<div class="radio-inline">
<label>
<input type="radio" name="incident[component_status]" value="{{ $statusID }}" {{ $incident->component->status === $statusID ? 'checked' : null }} />
{{ $status }}
</label>
</div>
@endforeach
</div>
</div>
</div>
<div class="form-group">
<label>{{ trans('forms.incidents.message') }}</label>
<textarea name="incident[message]" class="form-control" rows="5" required>{{ $incident->message }}</textarea>

View File

@@ -2,8 +2,6 @@
namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use DateTime;
use DateTimeZone;
use Illuminate\Support\Facades\View;

View File

@@ -2,6 +2,7 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use GrahamCampbell\Binput\Facades\Binput;
@@ -34,7 +35,8 @@ class DashIncidentController extends Controller
public function showAddIncident()
{
return View::make('dashboard.incidents.add')->with([
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
'components' => Component::all(),
]);
}
@@ -45,7 +47,9 @@ class DashIncidentController extends Controller
*/
public function createIncidentAction()
{
$incident = Incident::create(Binput::get('incident'));
$incidentData = Binput::get('incident');
$componentStatus = array_pull($incidentData, 'component_status');
$incident = Incident::create($incidentData);
if (! $incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
@@ -57,6 +61,13 @@ class DashIncidentController extends Controller
->with('errors', $incident->getErrors());
}
// Update the component.
if ((int) $incidentData['component_id'] > 0) {
Component::find($incidentData['component_id'])->update([
'status' => $componentStatus,
]);
}
$successMsg = sprintf(
'<strong>%s</strong> %s',
trans('dashboard.notifications.awesome'),
@@ -131,8 +142,9 @@ class DashIncidentController extends Controller
public function showEditIncidentAction(Incident $incident)
{
return View::make('dashboard.incidents.edit')->with([
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
'incident' => $incident,
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
'incident' => $incident,
'components' => Component::all(),
]);
}

View File

@@ -32,7 +32,7 @@ class SetupController extends Controller
*/
public function getIndex()
{
return View::make('setup')->with([
return View::make('setup')->with([
'pageTitle' => trans('setup.setup'),
]);
}