Skip to content

Commit 21b785a

Browse files
authoredSep 6, 2016
Merge pull request #2065 from sapk/stick-incident
Stick incident
2 parents 268e0c1 + 1954cf2 commit 21b785a

22 files changed

+191
-14
lines changed
 

‎app/Bus/Commands/Incident/ReportIncidentCommand.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ final class ReportIncidentCommand
6262
*/
6363
public $notify;
6464

65+
/**
66+
* Whether to stick the incident on top.
67+
*
68+
* @var bool
69+
*/
70+
public $stickied;
71+
6572
/**
6673
* The date at which the incident occurred.
6774
*
@@ -96,6 +103,7 @@ final class ReportIncidentCommand
96103
'component_id' => 'int|required_with:component_status',
97104
'component_status' => 'int|min:1|max:4|required_with:component_id',
98105
'notify' => 'bool',
106+
'stickied' => 'bool',
99107
'incident_date' => 'string',
100108
'template' => 'string',
101109
];
@@ -110,13 +118,14 @@ final class ReportIncidentCommand
110118
* @param int $component_id
111119
* @param int $component_status
112120
* @param bool $notify
121+
* @param bool $stickied
113122
* @param string|null $incident_date
114123
* @param string|null $template
115124
* @param array|null $template_vars
116125
*
117126
* @return void
118127
*/
119-
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date, $template, array $template_vars = null)
128+
public function __construct($name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = null)
120129
{
121130
$this->name = $name;
122131
$this->status = $status;
@@ -125,6 +134,7 @@ public function __construct($name, $status, $message, $visible, $component_id, $
125134
$this->component_id = $component_id;
126135
$this->component_status = $component_status;
127136
$this->notify = $notify;
137+
$this->stickied = $stickied;
128138
$this->incident_date = $incident_date;
129139
$this->template = $template;
130140
$this->template_vars = $template_vars;

‎app/Bus/Commands/Incident/UpdateIncidentCommand.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ final class UpdateIncidentCommand
7171
*/
7272
public $notify;
7373

74+
/**
75+
* Whether to stick the incident on top.
76+
*
77+
* @var bool
78+
*/
79+
public $stickied;
80+
7481
/**
7582
* The date that the incident occurred on.
7683
*
@@ -105,6 +112,7 @@ final class UpdateIncidentCommand
105112
'component_id' => 'int',
106113
'component_status' => 'int|min:1|max:4|required_with:component_id',
107114
'notify' => 'bool',
115+
'stickied' => 'bool',
108116
'template' => 'string',
109117
];
110118

@@ -119,13 +127,14 @@ final class UpdateIncidentCommand
119127
* @param int $component_id
120128
* @param int $component_status
121129
* @param bool $notify
130+
* @param bool $stickied
122131
* @param string|null $incident_date
123132
* @param string|null $template
124133
* @param array|null $template_vars
125134
*
126135
* @return void
127136
*/
128-
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $incident_date, $template, array $template_vars = null)
137+
public function __construct(Incident $incident, $name, $status, $message, $visible, $component_id, $component_status, $notify, $stickied, $incident_date, $template, array $template_vars = null)
129138
{
130139
$this->incident = $incident;
131140
$this->name = $name;
@@ -135,6 +144,7 @@ public function __construct(Incident $incident, $name, $status, $message, $visib
135144
$this->component_id = $component_id;
136145
$this->component_status = $component_status;
137146
$this->notify = $notify;
147+
$this->stickied = $stickied;
138148
$this->incident_date = $incident_date;
139149
$this->template = $template;
140150
$this->template_vars = $template_vars;

‎app/Bus/Handlers/Commands/Incident/ReportIncidentCommandHandler.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public function __construct(DateFactory $dates, Bridge $twig)
6565
public function handle(ReportIncidentCommand $command)
6666
{
6767
$data = [
68-
'name' => $command->name,
69-
'status' => $command->status,
70-
'visible' => $command->visible,
68+
'name' => $command->name,
69+
'status' => $command->status,
70+
'visible' => $command->visible,
71+
'stickied' => $command->stickied,
7172
];
7273

7374
if ($command->template) {

‎app/Bus/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function handle(ReportMaintenanceCommand $command)
5454
'scheduled_at' => $scheduledAt,
5555
'status' => 0,
5656
'visible' => 1,
57+
'stickied' => false,
5758
]);
5859

5960
$maintenanceEvent->notify = (bool) $command->notify;

‎app/Bus/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ protected function filter(UpdateIncidentCommand $command)
107107
'status' => $command->status,
108108
'message' => $command->message,
109109
'visible' => $command->visible,
110+
'stickied' => $command->stickied,
110111
'component_id' => $command->component_id,
111112
'component_status' => $command->component_status,
112113
'notify' => $command->notify,
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace CachetHQ\Cachet\Composers\Modules;
13+
14+
use CachetHQ\Cachet\Dates\DateFactory;
15+
use CachetHQ\Cachet\Models\Incident;
16+
use Illuminate\Contracts\View\View;
17+
18+
/**
19+
* This is the status page composer.
20+
*
21+
* @author James Brooks <james@alt-three.com>
22+
* @author Connor S. Parks <connor@connorvg.tv>
23+
* @author Antoine Girard <antoine.girard@sapk.fr>
24+
*/
25+
class StickiedComposer
26+
{
27+
/**
28+
* Index page view composer.
29+
*
30+
* @param \Illuminate\Contracts\View\View $view
31+
*
32+
* @return void
33+
*/
34+
public function compose(View $view)
35+
{
36+
$stickiedIncidents = Incident::stickied()->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) {
37+
return app(DateFactory::class)->make($incident->is_scheduled ? $incident->scheduled_at : $incident->created_at)->toDateString();
38+
});
39+
$view->withStickiedIncidents($stickiedIncidents);
40+
}
41+
}

‎app/Console/Commands/DemoSeederCommand.php

+15
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ protected function seedIncidents()
205205
'component_id' => 0,
206206
'scheduled_at' => null,
207207
'visible' => 1,
208+
'stickied' => false,
208209
],
209210
[
210211
'name' => 'Awesome',
@@ -213,6 +214,7 @@ protected function seedIncidents()
213214
'component_id' => 0,
214215
'scheduled_at' => null,
215216
'visible' => 1,
217+
'stickied' => false,
216218
],
217219
[
218220
'name' => 'Monitoring the fix',
@@ -221,6 +223,7 @@ protected function seedIncidents()
221223
'component_id' => 0,
222224
'scheduled_at' => null,
223225
'visible' => 1,
226+
'stickied' => false,
224227
],
225228
[
226229
'name' => 'Update',
@@ -229,6 +232,7 @@ protected function seedIncidents()
229232
'component_id' => 0,
230233
'scheduled_at' => null,
231234
'visible' => 1,
235+
'stickied' => false,
232236
],
233237
[
234238
'name' => 'Test Incident',
@@ -237,6 +241,7 @@ protected function seedIncidents()
237241
'component_id' => 0,
238242
'scheduled_at' => null,
239243
'visible' => 1,
244+
'stickied' => false,
240245
],
241246
[
242247
'name' => 'Investigating the API',
@@ -245,6 +250,16 @@ protected function seedIncidents()
245250
'component_id' => 1,
246251
'scheduled_at' => null,
247252
'visible' => 1,
253+
'stickied' => false,
254+
],
255+
[
256+
'name' => 'Stickied to the top',
257+
'message' => 'Will be forever hanged here.',
258+
'status' => 1,
259+
'component_id' => 1,
260+
'scheduled_at' => null,
261+
'visible' => 1,
262+
'stickied' => true,
248263
],
249264
];
250265

‎app/Foundation/Providers/ComposerServiceProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CachetHQ\Cachet\Composers\Modules\MetricsComposer as MetricsModuleComposer;
2020
use CachetHQ\Cachet\Composers\Modules\ScheduledComposer as ScheduledModuleComposer;
2121
use CachetHQ\Cachet\Composers\Modules\StatusComposer as StatusModuleComposer;
22+
use CachetHQ\Cachet\Composers\Modules\StickiedComposer as StickiedModuleComposer;
2223
use CachetHQ\Cachet\Composers\Modules\TimelineComposer as TimelineModuleComposer;
2324
use CachetHQ\Cachet\Composers\ThemeComposer;
2425
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
@@ -43,6 +44,7 @@ public function boot(Factory $factory)
4344
$factory->composer('*', ModuleComposer::class);
4445
$factory->composer('partials.modules.components', ComponentsModuleComposer::class);
4546
$factory->composer('partials.modules.metrics', MetricsModuleComposer::class);
47+
$factory->composer('partials.modules.stickied', StickiedModuleComposer::class);
4648
$factory->composer('partials.modules.scheduled', ScheduledModuleComposer::class);
4749
$factory->composer('partials.modules.status', StatusModuleComposer::class);
4850
$factory->composer('partials.modules.timeline', TimelineModuleComposer::class);

‎app/Foundation/Providers/ModuleServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ModuleServiceProvider extends ServiceProvider
2828
['group' => 'status', 'partial' => 'partials.modules.status'],
2929
['group' => 'components', 'partial' => 'partials.modules.components'],
3030
['group' => 'metrics', 'partial' => 'partials.modules.metrics'],
31+
['group' => 'stickied', 'partial' => 'partials.modules.stickied'],
3132
['group' => 'scheduled', 'partial' => 'partials.modules.scheduled'],
3233
['group' => 'timeline', 'partial' => 'partials.modules.timeline'],
3334
],
@@ -45,7 +46,8 @@ class ModuleServiceProvider extends ServiceProvider
4546
'components' => 30000,
4647
'metrics' => 40000,
4748
'scheduled' => 50000,
48-
'timeline' => 60000,
49+
'stickied' => 60000,
50+
'timeline' => 70000,
4951
],
5052
];
5153

‎app/Http/Controllers/Api/IncidentController.php

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function postIncidents()
7575
Binput::get('component_id'),
7676
Binput::get('component_status'),
7777
Binput::get('notify', true),
78+
Binput::get('stickied', false),
7879
Binput::get('created_at'),
7980
Binput::get('template'),
8081
Binput::get('vars')
@@ -105,6 +106,7 @@ public function putIncident(Incident $incident)
105106
Binput::get('component_id'),
106107
Binput::get('component_status'),
107108
Binput::get('notify', true),
109+
Binput::get('stickied', false),
108110
Binput::get('created_at'),
109111
Binput::get('template'),
110112
Binput::get('vars')

‎app/Http/Controllers/Dashboard/IncidentController.php

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function createIncidentAction()
115115
Binput::get('component_id'),
116116
Binput::get('component_status'),
117117
Binput::get('notify', false),
118+
Binput::get('stickied', false),
118119
Binput::get('created_at'),
119120
null,
120121
null
@@ -240,6 +241,7 @@ public function editIncidentAction(Incident $incident)
240241
Binput::get('component_id'),
241242
Binput::get('component_status'),
242243
Binput::get('notify', true),
244+
Binput::get('stickied', false),
243245
Binput::get('created_at'),
244246
null,
245247
null

‎app/Models/Incident.php

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Incident extends Model implements HasPresenter
3232
*/
3333
protected $casts = [
3434
'visible' => 'int',
35+
'stickied' => 'int',
3536
'scheduled_at' => 'date',
3637
'deleted_at' => 'date',
3738
];
@@ -46,6 +47,7 @@ class Incident extends Model implements HasPresenter
4647
'name',
4748
'status',
4849
'visible',
50+
'stickied',
4951
'message',
5052
'scheduled_at',
5153
'created_at',
@@ -62,6 +64,7 @@ class Incident extends Model implements HasPresenter
6264
'name' => 'required',
6365
'status' => 'required|int',
6466
'visible' => 'required|bool',
67+
'stickied' => 'bool',
6568
'message' => 'required',
6669
];
6770

@@ -76,6 +79,7 @@ class Incident extends Model implements HasPresenter
7679
'name',
7780
'status',
7881
'visible',
82+
'stickied',
7983
];
8084

8185
/**
@@ -88,6 +92,7 @@ class Incident extends Model implements HasPresenter
8892
'name',
8993
'status',
9094
'visible',
95+
'stickied',
9196
'message',
9297
];
9398

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

121+
/**
122+
* Finds all stickied incidents.
123+
*
124+
* @param \Illuminate\Database\Eloquent\Builder $query
125+
*
126+
* @return \Illuminate\Database\Eloquent\Builder
127+
*/
128+
public function scopeStickied(Builder $query)
129+
{
130+
return $query->where('stickied', true);
131+
}
132+
116133
/**
117134
* Finds all scheduled incidents (maintenance).
118135
*

‎database/factories/ModelFactory.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040

4141
$factory->define(Incident::class, function ($faker) {
4242
return [
43-
'name' => $faker->sentence(),
44-
'message' => $faker->paragraph(),
45-
'status' => random_int(1, 4),
46-
'visible' => 1,
43+
'name' => $faker->sentence(),
44+
'message' => $faker->paragraph(),
45+
'status' => random_int(1, 4),
46+
'visible' => 1,
47+
'stickied' => false,
4748
];
4849
});
4950

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Cachet.
5+
*
6+
* (c) Alt Three Services Limited
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Illuminate\Database\Migrations\Migration;
13+
use Illuminate\Database\Schema\Blueprint;
14+
use Illuminate\Support\Facades\Schema;
15+
16+
class AlterTableIncidentsAddStickiedColumn extends Migration
17+
{
18+
/**
19+
* Run the migrations.
20+
*/
21+
public function up()
22+
{
23+
Schema::table('incidents', function (Blueprint $table) {
24+
$table->boolean('stickied')->after('visible')->default(false);
25+
26+
$table->index('stickied');
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*/
33+
public function down()
34+
{
35+
Schema::table('incidents', function (Blueprint $table) {
36+
$table->dropColumn('stickied');
37+
});
38+
}
39+
}

‎resources/lang/en/cachet.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'past' => 'Past Incidents',
3131
'previous_week' => 'Previous week',
3232
'next_week' => 'Next week',
33+
'stickied' => 'Stickied Incidents',
3334
'scheduled' => 'Scheduled Maintenance',
3435
'scheduled_at' => ', scheduled :timestamp',
3536
'status' => [

‎resources/lang/en/forms.php

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
'incident_time' => 'When did this incident occur?',
5454
'notify_subscribers' => 'Notify subscribers?',
5555
'visibility' => 'Incident Visibility',
56+
'stick_status' => 'Stick Incident',
57+
'stickied' => 'Stickied',
58+
'not_stickied' => 'Not Stickied',
5659
'public' => 'Viewable by public',
5760
'logged_in_only' => 'Only visible to logged in users',
5861
'templates' => [

‎resources/views/dashboard/incidents/add.blade.php

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
<option value='0'>{{ trans('forms.incidents.logged_in_only') }}</option>
6363
</select>
6464
</div>
65+
<div class="form-group">
66+
<label for="incident-name">{{ trans('forms.incidents.stick_status') }}</label>
67+
<select name='stickied' class="form-control">
68+
<option value='1'>{{ trans('forms.incidents.stickied') }}</option>
69+
<option value='0' selected>{{ trans('forms.incidents.not_stickied') }}</option>
70+
</select>
71+
</div>
6572
@if(!$components_in_groups->isEmpty() || !$components_out_groups->isEmpty())
6673
<div class="form-group">
6774
<label>{{ trans('forms.incidents.component') }}</label>

‎resources/views/dashboard/incidents/edit.blade.php

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
<option value='0' {{ $incident->visible === 0 ? 'selected' : null }}>{{ trans('forms.incidents.logged_in_only') }}</option>
5252
</select>
5353
</div>
54+
<div class="form-group">
55+
<label for="incident-stick">{{ trans('forms.incidents.stick_status') }}</label>
56+
<select name="stickied" id="incident-stick" class="form-control">
57+
<option value='1' {{ $incident->stickied === 1 ? 'selected' : null }}>{{ trans('forms.incidents.stickied') }}</option>
58+
<option value='0' {{ $incident->stickied === 0 ? 'selected' : null }}>{{ trans('forms.incidents.not_stickied') }}</option>
59+
</select>
60+
</div>
5461
@if($incident->component)
5562
<div class="form-group" id='component-status'>
5663
<div class="panel panel-default">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@if(!$stickied_incidents->isEmpty())
2+
<div class="section-stickied">
3+
<h1>{{ trans('cachet.incidents.stickied') }}</h1>
4+
@foreach($stickied_incidents as $date => $incidents)
5+
@include('partials.incidents', [compact($date), compact($incidents)])
6+
@endforeach
7+
</div>
8+
@endif

‎tests/Api/IncidentTest.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public function testPostIncident()
5555
$this->beUser();
5656

5757
$this->post('/api/v1/incidents', [
58-
'name' => 'Foo',
59-
'message' => 'Lorem ipsum dolor sit amet',
60-
'status' => 1,
61-
'visible' => 1,
58+
'name' => 'Foo',
59+
'message' => 'Lorem ipsum dolor sit amet',
60+
'status' => 1,
61+
'visible' => 1,
62+
'stickied' => false,
6263
]);
6364
$this->seeJson(['name' => 'Foo']);
6465
$this->assertResponseOk();
@@ -77,6 +78,7 @@ public function testPostIncidentWithComponentStatus()
7778
'component_id' => $component->id,
7879
'component_status' => 1,
7980
'visible' => 1,
81+
'stickied' => false,
8082
]);
8183
$this->seeJson(['name' => 'Foo']);
8284
$this->assertResponseOk();
@@ -91,6 +93,7 @@ public function testCreateIncidentWithTemplate()
9193
'name' => 'Foo',
9294
'status' => 1,
9395
'visible' => 1,
96+
'stickied' => false,
9497
'template' => $template->slug,
9598
'vars' => [
9699
'name' => 'Foo',

‎tests/Bus/Commands/Incident/ReportIncidentCommandTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected function getObjectAndParams()
3636
'component_id' => 1,
3737
'component_status' => 1,
3838
'notify' => false,
39+
'stickied' => false,
3940
'incident_date' => null,
4041
'template' => null,
4142
'template_vars' => null,
@@ -49,6 +50,7 @@ protected function getObjectAndParams()
4950
$params['component_id'],
5051
$params['component_status'],
5152
$params['notify'],
53+
$params['stickied'],
5254
$params['incident_date'],
5355
$params['template'],
5456
$params['template_vars']

‎tests/Bus/Commands/Incident/UpdateIncidentCommandTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function getObjectAndParams()
3838
'component_id' => 1,
3939
'component_status' => 1,
4040
'notify' => false,
41+
'stickied' => false,
4142
'incident_date' => null,
4243
'template' => null,
4344
'template_vars' => null,
@@ -52,6 +53,7 @@ protected function getObjectAndParams()
5253
$params['component_id'],
5354
$params['component_status'],
5455
$params['notify'],
56+
$params['stickied'],
5557
$params['incident_date'],
5658
$params['template'],
5759
$params['template_vars']

0 commit comments

Comments
 (0)
Please sign in to comment.