2014-11-16 22:26:08 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
|
|
|
* (c) James Brooks <james@cachethq.io>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-01-02 00:18:19 +00:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers;
|
2014-12-01 16:46:56 +00:00
|
|
|
|
2015-01-14 17:19:41 -06:00
|
|
|
use CachetHQ\Cachet\Facades\Setting;
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Component;
|
2015-03-20 18:30:45 -06:00
|
|
|
use CachetHQ\Cachet\Models\ComponentGroup;
|
2015-01-02 00:18:19 +00:00
|
|
|
use CachetHQ\Cachet\Models\Incident;
|
2015-01-21 02:32:18 -06:00
|
|
|
use CachetHQ\Cachet\Models\Metric;
|
2015-01-27 13:05:54 -06:00
|
|
|
use Carbon\Carbon;
|
2015-01-04 12:33:38 +00:00
|
|
|
use Exception;
|
2015-01-03 00:36:27 -06:00
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-01-01 19:44:15 +00:00
|
|
|
use GrahamCampbell\Markdown\Facades\Markdown;
|
2015-01-01 16:18:24 +00:00
|
|
|
use Illuminate\Support\Facades\View;
|
2015-01-14 20:30:23 +00:00
|
|
|
use Jenssegers\Date\Date;
|
2014-12-01 16:46:56 +00:00
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
class HomeController extends AbstractController
|
2015-01-01 15:45:04 +00:00
|
|
|
{
|
2014-11-27 16:05:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the rendered Blade templates.
|
2014-12-29 23:07:46 +00:00
|
|
|
*
|
2014-12-01 08:38:26 +00:00
|
|
|
* @return \Illuminate\View\View
|
2014-11-27 16:05:00 +00:00
|
|
|
*/
|
2014-12-20 21:20:17 +00:00
|
|
|
public function showIndex()
|
|
|
|
{
|
2015-01-27 13:05:54 -06:00
|
|
|
$today = Carbon::now();
|
|
|
|
$startDate = Carbon::now();
|
2015-01-14 20:30:23 +00:00
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
segment_track('Status Page', [
|
|
|
|
'event' => 'Landed',
|
|
|
|
]);
|
2015-01-03 00:36:27 -06:00
|
|
|
|
|
|
|
// Check if we have another starting date
|
|
|
|
if (Binput::has('start_date')) {
|
|
|
|
try {
|
|
|
|
// If date provided is valid
|
2015-01-14 20:30:23 +00:00
|
|
|
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
2015-01-23 17:24:34 +00:00
|
|
|
|
|
|
|
segment_track('Status Page', [
|
|
|
|
'start_date' => $oldDate->format('Y-m-d'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (Setting::get('app_tracking')) {
|
|
|
|
Segment::track([
|
|
|
|
'userId' => Config::get('app.key'),
|
|
|
|
'event' => 'Home Page',
|
|
|
|
'properties' => [
|
|
|
|
'start_date' => $oldDate,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-01-03 00:36:27 -06:00
|
|
|
// If trying to get a future date fallback to today
|
|
|
|
if ($today->gt($oldDate)) {
|
|
|
|
$startDate = $oldDate;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Fallback to today
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 02:32:18 -06:00
|
|
|
$metrics = null;
|
|
|
|
|
|
|
|
if ($displayMetrics = Setting::get('display_graphs')) {
|
|
|
|
$metrics = Metric::where('display_chart', 1)->get();
|
|
|
|
}
|
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
$daysToShow = Setting::get('app_incident_days') ?: 7;
|
|
|
|
$incidentDays = range(0, $daysToShow);
|
|
|
|
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
|
2015-02-28 20:18:30 +00:00
|
|
|
|
2015-04-20 23:28:53 +01:00
|
|
|
$allIncidents = Incident::notScheduled()->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 ($dateFormat) {
|
|
|
|
return $incident->created_at->format($dateFormat);
|
|
|
|
});
|
2015-01-27 13:05:54 -06:00
|
|
|
|
2015-04-20 23:28:53 +01:00
|
|
|
// Add in days that have no incidents
|
|
|
|
foreach($incidentDays as $i) {
|
|
|
|
$date = $startDate->copy()->subDays($i);
|
2015-01-27 13:05:54 -06:00
|
|
|
|
2015-04-20 23:28:53 +01:00
|
|
|
if (!isset($allIncidents[$date->format($dateFormat)])) {
|
|
|
|
$allIncidents[$date->format($dateFormat)] = [];
|
|
|
|
}
|
2015-01-01 21:58:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
// Scheduled maintenance code.
|
|
|
|
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
|
|
|
|
|
|
|
|
// Component & Component Group lists.
|
|
|
|
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
|
|
|
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->get();
|
|
|
|
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
|
|
|
|
2014-12-30 22:25:38 +00:00
|
|
|
return View::make('index', [
|
2015-03-20 18:30:45 -06:00
|
|
|
'componentGroups' => $componentGroups,
|
|
|
|
'ungroupedComponents' => $ungroupedComponents,
|
2015-02-28 20:18:30 +00:00
|
|
|
'displayMetrics' => $displayMetrics,
|
|
|
|
'metrics' => $metrics,
|
|
|
|
'allIncidents' => $allIncidents,
|
|
|
|
'scheduledMaintenance' => $scheduledMaintenance,
|
|
|
|
'pageTitle' => Setting::get('app_name'),
|
2015-03-20 18:30:45 -06:00
|
|
|
'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')),
|
2015-02-28 20:18:30 +00:00
|
|
|
'canPageForward' => (bool) $today->gt($startDate),
|
|
|
|
'previousDate' => $startDate->copy()->subWeek()->subDay()->toDateString(),
|
|
|
|
'nextDate' => $startDate->copy()->addWeek()->addDay()->toDateString(),
|
2014-12-30 22:25:38 +00:00
|
|
|
]);
|
2014-11-27 16:05:00 +00:00
|
|
|
}
|
2014-11-27 22:08:28 +00:00
|
|
|
}
|