2015-02-28 20:18:30 +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-02-28 20:18:30 +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\ReportMaintenanceCommand;
|
2015-11-07 13:16:54 +00:00
|
|
|
use CachetHQ\Cachet\Dates\DateFactory;
|
2015-02-28 20:18:30 +00:00
|
|
|
use CachetHQ\Cachet\Models\Incident;
|
|
|
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-08-05 17:18:51 -05:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-02-28 20:18:30 +00:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
use Illuminate\Support\MessageBag;
|
2015-03-11 01:53:01 -06:00
|
|
|
use Jenssegers\Date\Date;
|
2015-02-28 20:18:30 +00:00
|
|
|
|
2015-08-05 17:18:51 -05:00
|
|
|
class ScheduleController extends Controller
|
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 schedule 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-13 22:28:30 +01:00
|
|
|
'url' => route('dashboard.incidents.index'),
|
2015-02-28 20:18:30 +00:00
|
|
|
'icon' => 'ion-android-checkmark-circle',
|
|
|
|
'active' => false,
|
|
|
|
],
|
2015-06-16 09:07:49 +01:00
|
|
|
'schedule' => [
|
2015-02-28 20:18:30 +00:00
|
|
|
'title' => trans('dashboard.schedule.schedule'),
|
2015-08-13 22:28:30 +01:00
|
|
|
'url' => route('dashboard.schedule.index'),
|
2015-02-28 20:18:30 +00:00
|
|
|
'icon' => 'ion-android-calendar',
|
|
|
|
'active' => true,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all scheduled maintenance.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showIndex()
|
|
|
|
{
|
|
|
|
$schedule = Incident::scheduled()->orderBy('created_at')->get();
|
2015-11-11 15:31:11 +08:00
|
|
|
|
2015-11-11 14:57:02 +08:00
|
|
|
return View::make('dashboard.schedule.index')
|
|
|
|
->withPageTitle(trans('dashboard.schedule.schedule').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withSchedule($schedule);
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the add schedule maintenance form.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddSchedule()
|
|
|
|
{
|
|
|
|
$incidentTemplates = IncidentTemplate::all();
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.schedule.add')
|
2015-11-11 14:57:02 +08:00
|
|
|
->withPageTitle(trans('dashboard.schedule.add.title').' - '.trans('dashboard.dashboard'))
|
2015-08-03 22:32:36 +01:00
|
|
|
->withIncidentTemplates($incidentTemplates);
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new scheduled maintenance "incident".
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function addScheduleAction()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2015-12-24 15:16:09 +00:00
|
|
|
$incident = dispatch(new ReportMaintenanceCommand(
|
2016-03-16 17:40:26 +00:00
|
|
|
Binput::get('name'),
|
|
|
|
Binput::get('message'),
|
|
|
|
Binput::get('notify'),
|
|
|
|
Binput::get('scheduled_at')
|
2015-08-31 20:16:15 +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.schedule.add')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::all())
|
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.add.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 17:02:11 +08:00
|
|
|
return Redirect::route('dashboard.schedule.index')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.add.success')));
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the edit schedule maintenance form.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showEditSchedule(Incident $schedule)
|
|
|
|
{
|
|
|
|
$incidentTemplates = IncidentTemplate::all();
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.schedule.edit')
|
2015-11-11 14:57:02 +08:00
|
|
|
->withPageTitle(trans('dashboard.schedule.edit.title').' - '.trans('dashboard.dashboard'))
|
2015-08-03 22:32:36 +01:00
|
|
|
->withIncidentTemplates($incidentTemplates)
|
|
|
|
->withSchedule($schedule);
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the given incident.
|
|
|
|
*
|
2015-12-23 14:51:18 +00:00
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
2015-02-28 20:18:30 +00:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2015-12-23 14:51:18 +00:00
|
|
|
public function editScheduleAction(Incident $schedule)
|
2015-02-28 20:18:30 +00:00
|
|
|
{
|
|
|
|
$scheduleData = Binput::get('incident');
|
2015-11-07 13:16:54 +00:00
|
|
|
|
2015-02-28 20:18:30 +00:00
|
|
|
// Parse the schedule date.
|
2016-03-31 13:29:36 +01:00
|
|
|
$scheduledAt = app(DateFactory::class)->create('d/m/Y H:i', $scheduleData['scheduled_at']);
|
2015-02-28 20:18:30 +00:00
|
|
|
|
|
|
|
if ($scheduledAt->isPast()) {
|
|
|
|
$messageBag = new MessageBag();
|
2015-08-03 22:32:36 +01:00
|
|
|
$messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
|
2015-02-28 20:18:30 +00:00
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag);
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scheduleData['scheduled_at'] = $scheduledAt;
|
|
|
|
// Bypass the incident.status field.
|
|
|
|
$scheduleData['status'] = 0;
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
|
|
|
$schedule->update($scheduleData);
|
|
|
|
} catch (ValidationException $e) {
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::all())
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')));
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a given schedule.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteScheduleAction(Incident $schedule)
|
|
|
|
{
|
2015-03-06 08:13:22 +00:00
|
|
|
$schedule->delete();
|
2015-02-28 20:18:30 +00:00
|
|
|
|
2015-08-13 22:28:30 +01:00
|
|
|
return Redirect::route('dashboard.schedule.index')
|
2015-11-20 17:02:11 +08:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.delete.success')));
|
2015-02-28 20:18:30 +00:00
|
|
|
}
|
|
|
|
}
|