2014-12-20 18:53:52 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-08-31 18:59:17 +01:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
2015-01-01 15:45:04 +00:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
use AltThree\Validator\ValidationException;
|
2016-01-05 02:38:07 +00:00
|
|
|
use CachetHQ\Cachet\Bus\Commands\Incident\RemoveIncidentCommand;
|
|
|
|
use CachetHQ\Cachet\Bus\Commands\Incident\ReportIncidentCommand;
|
|
|
|
use CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand;
|
2015-01-06 11:43:32 +00:00
|
|
|
use CachetHQ\Cachet\Models\Component;
|
2015-03-26 15:07:16 -06:00
|
|
|
use CachetHQ\Cachet\Models\ComponentGroup;
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Incident;
|
|
|
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
2015-01-02 12:05:50 +00:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-08-05 17:18:51 -05:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-01-01 15:45:04 +00:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
2015-08-05 17:18:51 -05:00
|
|
|
class IncidentController extends Controller
|
2014-12-20 21:20:17 +00:00
|
|
|
{
|
2015-02-28 20:18:30 +00:00
|
|
|
/**
|
|
|
|
* Stores the sub-sidebar tree list.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $subMenu = [];
|
|
|
|
|
|
|
|
/**
|
2015-11-04 15:02:56 +00:00
|
|
|
* Creates a new incident controller instance.
|
2015-02-28 20:18:30 +00:00
|
|
|
*
|
2015-12-23 09:39:10 +00:00
|
|
|
* @return void
|
2015-02-28 20:18:30 +00:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->subMenu = [
|
|
|
|
'incidents' => [
|
|
|
|
'title' => trans('dashboard.incidents.incidents'),
|
2015-08-07 14:52:44 +01:00
|
|
|
'url' => route('dashboard.incidents.index'),
|
2015-02-28 20:18:30 +00:00
|
|
|
'icon' => 'ion-android-checkmark-circle',
|
|
|
|
'active' => true,
|
|
|
|
],
|
2015-06-16 09:07:49 +01:00
|
|
|
'schedule' => [
|
2015-02-28 20:18:30 +00:00
|
|
|
'title' => trans('dashboard.schedule.schedule'),
|
2015-08-07 14:52:44 +01:00
|
|
|
'url' => route('dashboard.schedule.index'),
|
2015-02-28 20:18:30 +00:00
|
|
|
'icon' => 'ion-android-calendar',
|
|
|
|
'active' => false,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2015-07-02 16:37:38 +01:00
|
|
|
View::share('sub_menu', $this->subMenu);
|
|
|
|
View::share('sub_title', trans('dashboard.incidents.title'));
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Shows the incidents view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showIncidents()
|
|
|
|
{
|
2015-02-28 20:18:30 +00:00
|
|
|
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
2014-12-20 21:20:17 +00:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.incidents.index')
|
|
|
|
->withPageTitle(trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withIncidents($incidents);
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the add incident view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddIncident()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.incidents.add')
|
|
|
|
->withPageTitle(trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withComponentsInGroups(ComponentGroup::with('components')->get())
|
|
|
|
->withComponentsOutGroups(Component::where('group_id', 0)->get())
|
|
|
|
->withIncidentTemplates(IncidentTemplate::all());
|
2015-01-08 08:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the incident templates.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showTemplates()
|
|
|
|
{
|
2015-08-16 15:15:54 +01:00
|
|
|
return View::make('dashboard.templates.index')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withPageTitle(trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withIncidentTemplates(IncidentTemplate::all());
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 20:21:29 -06:00
|
|
|
/**
|
|
|
|
* Creates a new incident.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function createIncidentAction()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2015-12-24 15:16:09 +00:00
|
|
|
$incident = dispatch(new ReportIncidentCommand(
|
2015-08-31 11:32:39 +01:00
|
|
|
Binput::get('name'),
|
|
|
|
Binput::get('status'),
|
|
|
|
Binput::get('message'),
|
|
|
|
Binput::get('visible', true),
|
|
|
|
Binput::get('component_id'),
|
|
|
|
Binput::get('component_status'),
|
2016-02-16 08:58:44 +00:00
|
|
|
Binput::get('notify', false),
|
2015-11-15 17:08:45 +00:00
|
|
|
Binput::get('created_at'),
|
|
|
|
null,
|
|
|
|
null
|
2015-08-31 11:32:39 +01:00
|
|
|
));
|
2015-08-03 22:32:36 +01:00
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.incidents.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::all())
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:21:29 -06:00
|
|
|
}
|
|
|
|
|
2015-11-20 17:02:11 +08:00
|
|
|
return Redirect::route('dashboard.incidents.index')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
|
2015-01-09 20:21:29 -06:00
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Shows the add incident template view.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddIncidentTemplate()
|
|
|
|
{
|
2015-08-16 15:15:54 +01:00
|
|
|
return View::make('dashboard.templates.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withPageTitle(trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'));
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 08:58:09 +00:00
|
|
|
/**
|
|
|
|
* Shows the edit incident template view.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showEditTemplateAction(IncidentTemplate $template)
|
|
|
|
{
|
2015-08-16 15:15:54 +01:00
|
|
|
return View::make('dashboard.templates.edit')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withPageTitle(trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withTemplate($template);
|
2015-01-08 08:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes an incident template.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteTemplateAction(IncidentTemplate $template)
|
|
|
|
{
|
|
|
|
$template->delete();
|
|
|
|
|
2015-11-20 17:02:11 +08:00
|
|
|
return Redirect::route('dashboard.templates.index')
|
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.delete.success')));
|
2015-01-08 08:58:09 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 21:20:17 +00:00
|
|
|
/**
|
|
|
|
* Creates a new incident template.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-20 21:20:17 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function createIncidentTemplateAction()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
|
|
|
IncidentTemplate::create(Binput::get('template'));
|
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.templates.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::all())
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.add.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:21:29 -06:00
|
|
|
}
|
2014-12-20 21:20:17 +00:00
|
|
|
|
2015-11-20 17:02:11 +08:00
|
|
|
return Redirect::route('dashboard.templates.index')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
|
2014-12-20 21:20:17 +00:00
|
|
|
}
|
2014-12-22 12:55:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a given incident.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2015-01-02 00:18:19 +00:00
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-22 12:55:26 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteIncidentAction(Incident $incident)
|
|
|
|
{
|
2015-12-24 15:16:09 +00:00
|
|
|
dispatch(new RemoveIncidentCommand($incident));
|
2014-12-22 12:55:26 +00:00
|
|
|
|
2015-11-20 17:02:11 +08:00
|
|
|
return Redirect::route('dashboard.incidents.index')
|
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.delete.success')));
|
2014-12-22 12:55:26 +00:00
|
|
|
}
|
2015-01-02 20:35:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the edit incident view.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showEditIncidentAction(Incident $incident)
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.incidents.edit')
|
|
|
|
->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withIncident($incident)
|
|
|
|
->withComponentsInGroups(ComponentGroup::with('components')->get())
|
|
|
|
->withComponentsOutGroups(Component::where('group_id', 0)->get());
|
2015-01-02 20:35:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an incident.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $incident
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function editIncidentAction(Incident $incident)
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2015-12-24 15:16:09 +00:00
|
|
|
$incident = dispatch(new UpdateIncidentCommand(
|
2015-09-22 19:48:08 +01:00
|
|
|
$incident,
|
|
|
|
Binput::get('name'),
|
|
|
|
Binput::get('status'),
|
|
|
|
Binput::get('message'),
|
|
|
|
Binput::get('visible', true),
|
|
|
|
Binput::get('component_id'),
|
|
|
|
Binput::get('component_status'),
|
2015-09-26 14:42:42 +01:00
|
|
|
Binput::get('notify', true),
|
2015-11-15 17:08:45 +00:00
|
|
|
Binput::get('created_at'),
|
|
|
|
null,
|
|
|
|
null
|
2015-09-22 19:48:08 +01:00
|
|
|
));
|
2015-08-03 22:32:36 +01:00
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::all())
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:21:29 -06:00
|
|
|
}
|
|
|
|
|
2015-06-15 16:27:42 +01:00
|
|
|
if ($incident->component) {
|
2015-11-21 10:10:52 +08:00
|
|
|
$incident->component->update(['status' => Binput::get('component_status')]);
|
2015-06-15 16:27:42 +01:00
|
|
|
}
|
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
|
2015-01-02 20:35:02 +01:00
|
|
|
}
|
2015-01-08 08:58:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an incident template.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function editTemplateAction(IncidentTemplate $template)
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
|
|
|
$template->update(Binput::get('template'));
|
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.templates.edit', ['id' => $template->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withUpdatedTemplate($template)
|
|
|
|
->withTemplateErrors($e->getMessageBag()->getErrors());
|
|
|
|
}
|
2015-01-08 08:58:09 +00:00
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.templates.edit', ['id' => $template->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withUpdatedTemplate($template);
|
2015-01-08 08:58:09 +00:00
|
|
|
}
|
2014-12-20 18:53:52 +00:00
|
|
|
}
|