Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stick incident #2065

Merged
merged 1 commit into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/Bus/Commands/Incident/ReportIncidentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ final class ReportIncidentCommand
*/
public $notify;

/**
* Whether to stick the incident on top.
*
* @var bool
*/
public $stickied;

/**
* The date at which the incident occurred.
*
Expand Down Expand Up @@ -96,6 +103,7 @@ final class ReportIncidentCommand
'component_id' => 'int|required_with:component_status',
'component_status' => 'int|min:1|max:4|required_with:component_id',
'notify' => 'bool',
'stickied' => 'bool',
'incident_date' => 'string',
'template' => 'string',
];
Expand All @@ -110,13 +118,14 @@ final class ReportIncidentCommand
* @param int $component_id
* @param int $component_status
* @param bool $notify
* @param bool $stickied
* @param string|null $incident_date
* @param string|null $template
* @param array|null $template_vars
*
* @return void
*/
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date, $template, array $template_vars = null)
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = null)
{
$this->name = $name;
$this->status = $status;
Expand All @@ -125,6 +134,7 @@ public function __construct($name, $status, $message, $visible, $component_id, $
$this->component_id = $component_id;
$this->component_status = $component_status;
$this->notify = $notify;
$this->stickied = $stickied;
$this->incident_date = $incident_date;
$this->template = $template;
$this->template_vars = $template_vars;
Expand Down
12 changes: 11 additions & 1 deletion app/Bus/Commands/Incident/UpdateIncidentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ final class UpdateIncidentCommand
*/
public $notify;

/**
* Whether to stick the incident on top.
*
* @var bool
*/
public $stickied;

/**
* The date that the incident occurred on.
*
Expand Down Expand Up @@ -105,6 +112,7 @@ final class UpdateIncidentCommand
'component_id' => 'int',
'component_status' => 'int|min:1|max:4|required_with:component_id',
'notify' => 'bool',
'stickied' => 'bool',
'template' => 'string',
];

Expand All @@ -119,13 +127,14 @@ final class UpdateIncidentCommand
* @param int $component_id
* @param int $component_status
* @param bool $notify
* @param bool $stickied
* @param string|null $incident_date
* @param string|null $template
* @param array|null $template_vars
*
* @return void
*/
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date, $template, array $template_vars = null)
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = null)
{
$this->incident = $incident;
$this->name = $name;
Expand All @@ -135,6 +144,7 @@ public function __construct(Incident $incident, $name, $status, $message, $visib
$this->component_id = $component_id;
$this->component_status = $component_status;
$this->notify = $notify;
$this->stickied = $stickied;
$this->incident_date = $incident_date;
$this->template = $template;
$this->template_vars = $template_vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public function __construct(DateFactory $dates, Bridge $twig)
public function handle(ReportIncidentCommand $command)
{
$data = [
'name' => $command->name,
'status' => $command->status,
'visible' => $command->visible,
'name' => $command->name,
'status' => $command->status,
'visible' => $command->visible,
'stickied' => $command->stickied,
];

if ($command->template) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function handle(ReportMaintenanceCommand $command)
'scheduled_at' => $scheduledAt,
'status' => 0,
'visible' => 1,
'stickied' => false,
]);

$maintenanceEvent->notify = (bool) $command->notify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected function filter(UpdateIncidentCommand $command)
'status' => $command->status,
'message' => $command->message,
'visible' => $command->visible,
'stickied' => $command->stickied,
'component_id' => $command->component_id,
'component_status' => $command->component_status,
'notify' => $command->notify,
Expand Down
41 changes: 41 additions & 0 deletions app/Composers/Modules/StickiedComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers\Modules;

use CachetHQ\Cachet\Dates\DateFactory;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Contracts\View\View;

/**
* This is the status page composer.
*
* @author James Brooks <[email protected]>
* @author Connor S. Parks <[email protected]>
* @author Antoine Girard <[email protected]>
*/
class StickiedComposer
{
/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$stickiedIncidents = Incident::stickied()->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) {
return app(DateFactory::class)->make($incident->is_scheduled ? $incident->scheduled_at : $incident->created_at)->toDateString();
});
$view->withStickiedIncidents($stickiedIncidents);
}
}
15 changes: 15 additions & 0 deletions app/Console/Commands/DemoSeederCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ protected function seedIncidents()
'component_id' => 0,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Awesome',
Expand All @@ -213,6 +214,7 @@ protected function seedIncidents()
'component_id' => 0,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Monitoring the fix',
Expand All @@ -221,6 +223,7 @@ protected function seedIncidents()
'component_id' => 0,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Update',
Expand All @@ -229,6 +232,7 @@ protected function seedIncidents()
'component_id' => 0,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Test Incident',
Expand All @@ -237,6 +241,7 @@ protected function seedIncidents()
'component_id' => 0,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Investigating the API',
Expand All @@ -245,6 +250,16 @@ protected function seedIncidents()
'component_id' => 1,
'scheduled_at' => null,
'visible' => 1,
'stickied' => false,
],
[
'name' => 'Stickied to the top',
'message' => 'Will be forever hanged here.',
'status' => 1,
'component_id' => 1,
'scheduled_at' => null,
'visible' => 1,
'stickied' => true,
],
];

Expand Down
2 changes: 2 additions & 0 deletions app/Foundation/Providers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use CachetHQ\Cachet\Composers\Modules\MetricsComposer as MetricsModuleComposer;
use CachetHQ\Cachet\Composers\Modules\ScheduledComposer as ScheduledModuleComposer;
use CachetHQ\Cachet\Composers\Modules\StatusComposer as StatusModuleComposer;
use CachetHQ\Cachet\Composers\Modules\StickiedComposer as StickiedModuleComposer;
use CachetHQ\Cachet\Composers\Modules\TimelineComposer as TimelineModuleComposer;
use CachetHQ\Cachet\Composers\ThemeComposer;
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
Expand All @@ -43,6 +44,7 @@ public function boot(Factory $factory)
$factory->composer('*', ModuleComposer::class);
$factory->composer('partials.modules.components', ComponentsModuleComposer::class);
$factory->composer('partials.modules.metrics', MetricsModuleComposer::class);
$factory->composer('partials.modules.stickied', StickiedModuleComposer::class);
$factory->composer('partials.modules.scheduled', ScheduledModuleComposer::class);
$factory->composer('partials.modules.status', StatusModuleComposer::class);
$factory->composer('partials.modules.timeline', TimelineModuleComposer::class);
Expand Down
4 changes: 3 additions & 1 deletion app/Foundation/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ModuleServiceProvider extends ServiceProvider
['group' => 'status', 'partial' => 'partials.modules.status'],
['group' => 'components', 'partial' => 'partials.modules.components'],
['group' => 'metrics', 'partial' => 'partials.modules.metrics'],
['group' => 'stickied', 'partial' => 'partials.modules.stickied'],
['group' => 'scheduled', 'partial' => 'partials.modules.scheduled'],
['group' => 'timeline', 'partial' => 'partials.modules.timeline'],
],
Expand All @@ -45,7 +46,8 @@ class ModuleServiceProvider extends ServiceProvider
'components' => 30000,
'metrics' => 40000,
'scheduled' => 50000,
'timeline' => 60000,
'stickied' => 60000,
'timeline' => 70000,
],
];

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Api/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function postIncidents()
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true),
Binput::get('stickied', false),
Binput::get('created_at'),
Binput::get('template'),
Binput::get('vars')
Expand Down Expand Up @@ -105,6 +106,7 @@ public function putIncident(Incident $incident)
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true),
Binput::get('stickied', false),
Binput::get('created_at'),
Binput::get('template'),
Binput::get('vars')
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Dashboard/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function createIncidentAction()
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', false),
Binput::get('stickied', false),
Binput::get('created_at'),
null,
null
Expand Down Expand Up @@ -240,6 +241,7 @@ public function editIncidentAction(Incident $incident)
Binput::get('component_id'),
Binput::get('component_status'),
Binput::get('notify', true),
Binput::get('stickied', false),
Binput::get('created_at'),
null,
null
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Incident.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Incident extends Model implements HasPresenter
*/
protected $casts = [
'visible' => 'int',
'stickied' => 'int',
'scheduled_at' => 'date',
'deleted_at' => 'date',
];
Expand All @@ -46,6 +47,7 @@ class Incident extends Model implements HasPresenter
'name',
'status',
'visible',
'stickied',
'message',
'scheduled_at',
'created_at',
Expand All @@ -62,6 +64,7 @@ class Incident extends Model implements HasPresenter
'name' => 'required',
'status' => 'required|int',
'visible' => 'required|bool',
'stickied' => 'bool',
'message' => 'required',
];

Expand All @@ -76,6 +79,7 @@ class Incident extends Model implements HasPresenter
'name',
'status',
'visible',
'stickied',
];

/**
Expand All @@ -88,6 +92,7 @@ class Incident extends Model implements HasPresenter
'name',
'status',
'visible',
'stickied',
'message',
];

Expand All @@ -113,6 +118,18 @@ public function scopeVisible(Builder $query)
return $query->where('visible', 1);
}

/**
* Finds all stickied incidents.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStickied(Builder $query)
{
return $query->where('stickied', true);
}

/**
* Finds all scheduled incidents (maintenance).
*
Expand Down
9 changes: 5 additions & 4 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

$factory->define(Incident::class, function ($faker) {
return [
'name' => $faker->sentence(),
'message' => $faker->paragraph(),
'status' => random_int(1, 4),
'visible' => 1,
'name' => $faker->sentence(),
'message' => $faker->paragraph(),
'status' => random_int(1, 4),
'visible' => 1,
'stickied' => false,
];
});

Expand Down
Loading