diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index c928ada3..4df9d1a3 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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(); }); diff --git a/app/Models/Incident.php b/app/Models/Incident.php index 82aa4581..e7922bac 100644 --- a/app/Models/Incident.php +++ b/app/Models/Incident.php @@ -141,7 +141,7 @@ class Incident extends Model implements HasPresenter */ public function getIsScheduledAttribute() { - return $this->getOriginal('scheduled_at'); + return $this->getOriginal('scheduled_at') !== null; } /** diff --git a/app/Presenters/IncidentPresenter.php b/app/Presenters/IncidentPresenter.php index ad044303..6613f26e 100644 --- a/app/Presenters/IncidentPresenter.php +++ b/app/Presenters/IncidentPresenter.php @@ -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. * diff --git a/resources/views/partials/incidents.blade.php b/resources/views/partials/incidents.blade.php index b847b71b..63f65f21 100644 --- a/resources/views/partials/incidents.blade.php +++ b/resources/views/partials/incidents.blade.php @@ -21,8 +21,7 @@ {{ $incident->name }}{{ $incident->isScheduled ? trans("cachet.incidents.scheduled_at", ["timestamp" => $incident->scheduled_at_diff]) : null }}
- - +