Merge pull request #2825 from rarguelloF/only-display-incidents
Add the possibility of only displaying incidents in the timeline
This commit is contained in:
@@ -45,36 +45,86 @@ class StatusPageController extends AbstractApiController
|
|||||||
*/
|
*/
|
||||||
public function showIndex()
|
public function showIndex()
|
||||||
{
|
{
|
||||||
$today = Date::now();
|
$only_disrupted_days = Config::get('setting.only_disrupted_days');
|
||||||
|
$appIncidentDays = (int) Config::get('setting.app_incident_days', 1);
|
||||||
|
|
||||||
|
// Used for the database query
|
||||||
$startDate = Date::now();
|
$startDate = Date::now();
|
||||||
|
$endDate = Date::now();
|
||||||
|
|
||||||
// Check if we have another starting date
|
$canPageForward = false;
|
||||||
if (Binput::has('start_date')) {
|
$canPageBackward = false;
|
||||||
try {
|
$previousDate = null;
|
||||||
// If date provided is valid
|
$nextDate = null;
|
||||||
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
|
||||||
|
|
||||||
// If trying to get a future date fallback to today
|
if ($only_disrupted_days) {
|
||||||
if ($today->gt($oldDate)) {
|
// In this case, start_date GET parameter means the page
|
||||||
$startDate = $oldDate;
|
$page = Binput::get('start_date', 0);
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
if (!is_numeric($page)) {
|
||||||
// Fallback to today
|
$page = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$page = (int) $page;
|
||||||
|
|
||||||
|
$allIncidentDays = Incident::where('visible', '>=', (int) !Auth::check())
|
||||||
|
->select('occurred_at')->distinct()->orderBy('occurred_at', 'desc')->get()->map(function (Incident $incident) {
|
||||||
|
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
|
||||||
|
})->unique()->values();
|
||||||
|
|
||||||
|
$numIncidentDays = count($allIncidentDays);
|
||||||
|
$numPages = round($numIncidentDays / $appIncidentDays);
|
||||||
|
|
||||||
|
$selectedDays = $allIncidentDays->slice($page * $appIncidentDays, $appIncidentDays)->all();
|
||||||
|
|
||||||
|
if (count($selectedDays) > 0) {
|
||||||
|
$startDate = Date::createFromFormat('Y-m-d', array_values(array_slice($selectedDays, -1))[0]);
|
||||||
|
$endDate = Date::createFromFormat('Y-m-d', array_values($selectedDays)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$canPageForward = $page > 0;
|
||||||
|
$canPageBackward = ($page + 1) < $numPages;
|
||||||
|
$previousDate = $page + 1;
|
||||||
|
$nextDate = $page - 1;
|
||||||
|
} else {
|
||||||
|
$today = Date::now();
|
||||||
|
$date = Date::now();
|
||||||
|
|
||||||
|
// Check if we have another starting date
|
||||||
|
if (Binput::has('start_date')) {
|
||||||
|
try {
|
||||||
|
// If date provided is valid
|
||||||
|
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
||||||
|
|
||||||
|
// If trying to get a future date fallback to today
|
||||||
|
if ($today->gt($oldDate)) {
|
||||||
|
$date = $oldDate;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Fallback to today
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$startDate = $date->copy()->subDays($appIncidentDays);
|
||||||
|
$endDate = $date->copy();
|
||||||
|
|
||||||
|
$canPageForward = (bool) $today->gt($date);
|
||||||
|
$canPageBackward = Incident::where('occurred_at', '<', $date->format('Y-m-d'))->count() > 0;
|
||||||
|
$previousDate = $date->copy()->subDays($appIncidentDays)->toDateString();
|
||||||
|
$nextDate = $date->copy()->addDays($appIncidentDays)->toDateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
$appIncidentDays = (int) Config::get('setting.app_incident_days', 1);
|
|
||||||
$incidentDays = array_pad([], $appIncidentDays, null);
|
|
||||||
|
|
||||||
$allIncidents = Incident::where('visible', '>=', (int) !Auth::check())->whereBetween('occurred_at', [
|
$allIncidents = Incident::where('visible', '>=', (int) !Auth::check())->whereBetween('occurred_at', [
|
||||||
$startDate->copy()->subDays($appIncidentDays)->format('Y-m-d').' 00:00:00',
|
$startDate->format('Y-m-d').' 00:00:00',
|
||||||
$startDate->format('Y-m-d').' 23:59:59',
|
$endDate->format('Y-m-d').' 23:59:59',
|
||||||
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
|
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
|
||||||
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
|
return app(DateFactory::class)->make($incident->occurred_at)->toDateString();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add in days that have no incidents
|
if (!$only_disrupted_days) {
|
||||||
if (Config::get('setting.only_disrupted_days') === false) {
|
$incidentDays = array_pad([], $appIncidentDays, null);
|
||||||
|
|
||||||
|
// Add in days that have no incidents
|
||||||
foreach ($incidentDays as $i => $day) {
|
foreach ($incidentDays as $i => $day) {
|
||||||
$date = app(DateFactory::class)->make($startDate)->subDays($i);
|
$date = app(DateFactory::class)->make($startDate)->subDays($i);
|
||||||
|
|
||||||
@@ -92,10 +142,10 @@ class StatusPageController extends AbstractApiController
|
|||||||
return View::make('index')
|
return View::make('index')
|
||||||
->withDaysToShow($appIncidentDays)
|
->withDaysToShow($appIncidentDays)
|
||||||
->withAllIncidents($allIncidents)
|
->withAllIncidents($allIncidents)
|
||||||
->withCanPageForward((bool) $today->gt($startDate))
|
->withCanPageForward($canPageForward)
|
||||||
->withCanPageBackward(Incident::where('occurred_at', '<', $startDate->format('Y-m-d'))->count() > 0)
|
->withCanPageBackward($canPageBackward)
|
||||||
->withPreviousDate($startDate->copy()->subDays($appIncidentDays)->toDateString())
|
->withPreviousDate($previousDate)
|
||||||
->withNextDate($startDate->copy()->addDays($appIncidentDays)->toDateString());
|
->withNextDate($nextDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user