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

Add incident column for when an incident occurred at #2212

Merged
merged 6 commits into from
Oct 29, 2016
Merged

Conversation

jbrooksuk
Copy link
Member

@jbrooksuk jbrooksuk commented Oct 27, 2016

Closes #2208


This does change the API requests, as we're now looking for a field called occurred_at instead of incident_date, or whatever.

@jbrooksuk jbrooksuk added this to the V2.4.0 milestone Oct 27, 2016
@jbrooksuk jbrooksuk self-assigned this Oct 27, 2016
@@ -110,7 +110,7 @@
'component_status' => 'nullable|required_with:component_id|int|min:0|max:4',
'notify' => 'nullable|bool',
'stickied' => 'required|bool',
'incident_date' => 'nullable|string',
'occurredAt' => 'nullable|string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon we should move to camelCase but I also reckon it should be done in it's own PR rather than just leaving random bits here and there.

if ($occurredAt = $command->occurredAt) {
if ($date = $this->dates->create('Y-m-d H:i', $occurredAt)) {
$incident->fill(['occurred_at' => $date]);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard > else - looks messy imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the exception doesn't do anything here, because create will throw, so we need to catch.

])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) {
return (new Date($incident->created_at))
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
return (new Date($incident->occurred_at))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not use the presenter here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this when I was looking at it this morning.

@@ -80,12 +85,12 @@ private function feedAction(ComponentGroup &$group, $isRss)
{
if ($group->exists) {
$group->components->map(function ($component) use ($isRss) {
$component->incidents()->visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use ($isRss) {
$component->incidents()->visible()->orderBy('occurred_at', 'desc')->get()->map(function ($incident) use ($isRss) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line is long 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add a better scope for this.

@@ -109,7 +109,7 @@ public function showIndex()
->withDaysToShow($daysToShow)
->withAllIncidents($allIncidents)
->withCanPageForward((bool) $today->gt($startDate))
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)
->withCanPageBackward(Incident::notScheduled()->where('occurred_at', '<', $startDate->format('Y-m-d'))->count() > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to format $startDate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because occurred_at might contain a time, but we're only interested in whole days.

*/
public function occurred_at()
{
return app(DateFactory::class)->make($this->wrappedObject->occurred_at)->toDateTimeString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off topic but is there any reason we don't just inject the DateFactory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Laziness.

{
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->created_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->occurred_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems overly complex / long. QoL goes down.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*/
public function created_at_formatted()
{
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->created_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous.

*/
function datetime_to_moment($format)
{
$replacements = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just bizarre. I see it's point tho 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't end up using this, but I like it, so I'm keeping it because I probably will use this at some point.

@@ -7,7 +7,7 @@
@stop

@section('content')
<h1>{{ $incident->name }} <small>{{ formatted_date($incident->created_at) }}</small></h1>
<h1>{{ $incident->name }} <small>{{ formatted_date($incident->occurred_at) }}</small></h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not using the presenter here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this too, dunno why.

@jbrooksuk
Copy link
Member Author

Let's merge and see what happens 👍 there might be an edge-case I've missed.

@jbrooksuk jbrooksuk merged commit a0f2d66 into 2.4 Oct 29, 2016
@jbrooksuk jbrooksuk deleted the reported-at-dat branch October 29, 2016 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants