Fixes #934 - Scheduled items now drop into the right days

This commit is contained in:
James Brooks 2015-09-04 08:18:10 +01:00
parent 860457bfae
commit 0851427f2d
4 changed files with 37 additions and 4 deletions

View File

@ -65,7 +65,13 @@ class HomeController extends AbstractController
$allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisiblity)->whereBetween('created_at', [
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00',
$startDate->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateTimeZone) {
])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateTimeZone) {
// If it's scheduled, get the scheduled at date.
if ($incident->is_scheduled) {
return (new Date($incident->scheduled_at))
->setTimezone($dateTimeZone)->toDateString();
}
return (new Date($incident->created_at))
->setTimezone($dateTimeZone)->toDateString();
});

View File

@ -141,7 +141,7 @@ class Incident extends Model implements HasPresenter
*/
public function getIsScheduledAttribute()
{
return $this->getOriginal('scheduled_at');
return $this->getOriginal('scheduled_at') !== null;
}
/**

View File

@ -129,6 +129,34 @@ class IncidentPresenter extends AbstractPresenter
return $this->wrappedObject->scheduled_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
}
/**
* Returns a formatted timestamp for use within the timeline.
*
* @return string
*/
public function timestamp_formatted()
{
if ($this->wrappedObject->is_scheduled) {
return $this->scheduled_at_formatted;
} else {
return $this->created_at_formatted;
}
}
/**
* Return the iso timestamp for use within the timeline.
*
* @return string
*/
public function timestamp_iso()
{
if ($this->wrappedObject->is_scheduled) {
return $this->scheduled_at_iso;
} else {
return $this->created_at_iso;
}
}
/**
* Present the status with an icon.
*

View File

@ -21,8 +21,7 @@
<strong>{{ $incident->name }}</strong>{{ $incident->isScheduled ? trans("cachet.incidents.scheduled_at", ["timestamp" => $incident->scheduled_at_diff]) : null }}
<br>
<small class="date">
<abbr class="timeago" data-toggle="tooltip" data-placement="right" title="{{ $incident->created_at_formatted }}" data-timeago="{{ $incident->created_at_iso }}">
</abbr>
<abbr class="timeago" data-toggle="tooltip" data-placement="right" title="{{ $incident->timestamp_formatted }}" data-timeago="{{ $incident->timestamp_iso }}"></abbr>
</small>
</div>
<div class="panel-body">