63
app/Composers/MetricsComposer.php
Normal file
63
app/Composers/MetricsComposer.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Repositories\MetricRepository;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class MetricsComposer
|
||||
{
|
||||
/**
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricRepository
|
||||
*/
|
||||
protected $metricRepository;
|
||||
|
||||
/**
|
||||
* Construct a new home controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricRepository $metricRepository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricRepository $metricRepository)
|
||||
{
|
||||
$this->metricRepository = $metricRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metrics view composer.
|
||||
*
|
||||
* @param \Illuminate\Contracts\View\View $view
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$metrics = null;
|
||||
$metricData = [];
|
||||
if ($displayMetrics = Setting::get('display_graphs')) {
|
||||
$metrics = Metric::where('display_chart', 1)->get();
|
||||
|
||||
$metrics->map(function ($metric) use (&$metricData) {
|
||||
$metricData[$metric->id] = [
|
||||
'today' => $this->metricRepository->listPointsToday($metric),
|
||||
'week' => $this->metricRepository->listPointsForWeek($metric),
|
||||
'month' => $this->metricRepository->listPointsForMonth($metric),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$view->withDisplayMetrics($displayMetrics)
|
||||
->withMetrics($metrics)
|
||||
->withMetricData($metricData);
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class IndexComposer
|
||||
class StatusPageComposer
|
||||
{
|
||||
/**
|
||||
* Index page view composer.
|
||||
@@ -49,6 +51,18 @@ class IndexComposer
|
||||
}
|
||||
}
|
||||
|
||||
$view->with($withData);
|
||||
// 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)->orderBy('order')->get();
|
||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$view->with($withData)
|
||||
->withComponentGroups($componentGroups)
|
||||
->withUngroupedComponents($ungroupedComponents)
|
||||
->withScheduledMaintenance($scheduledMaintenance)
|
||||
->withPageTitle(Setting::get('app_name'));
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,7 @@
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Repositories\MetricRepository;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
@@ -25,25 +21,8 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class HomeController extends Controller
|
||||
class StatusPageController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricRepository
|
||||
*/
|
||||
protected $metricRepository;
|
||||
|
||||
/**
|
||||
* Construct a new home controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricRepository $metricRepository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricRepository $metricRepository)
|
||||
{
|
||||
$this->metricRepository = $metricRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the status page.
|
||||
*
|
||||
@@ -69,20 +48,6 @@ class HomeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$metrics = null;
|
||||
$metricData = [];
|
||||
if ($displayMetrics = Setting::get('display_graphs')) {
|
||||
$metrics = Metric::where('display_chart', 1)->get();
|
||||
|
||||
$metrics->map(function ($metric) use (&$metricData) {
|
||||
$metricData[$metric->id] = [
|
||||
'today' => $this->metricRepository->listPointsToday($metric),
|
||||
'week' => $this->metricRepository->listPointsForWeek($metric),
|
||||
'month' => $this->metricRepository->listPointsForMonth($metric),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$daysToShow = Setting::get('app_incident_days') ?: 7;
|
||||
$incidentDays = range(0, $daysToShow - 1);
|
||||
$dateTimeZone = Setting::get('app_timezone');
|
||||
@@ -111,27 +76,12 @@ class HomeController extends Controller
|
||||
return strtotime($key);
|
||||
}, SORT_REGULAR, true)->all();
|
||||
|
||||
// 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)->orderBy('order')->get();
|
||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
return View::make('index')
|
||||
->withComponentGroups($componentGroups)
|
||||
->withUngroupedComponents($ungroupedComponents)
|
||||
->withDisplayMetrics($displayMetrics)
|
||||
->withMetrics($metrics)
|
||||
->withMetricData($metricData)
|
||||
->withAllIncidents($allIncidents)
|
||||
->withScheduledMaintenance($scheduledMaintenance)
|
||||
->withAboutApp(Markdown::convertToHtml(Setting::get('app_about')))
|
||||
->withCanPageForward((bool) $today->gt($startDate))
|
||||
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)
|
||||
->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())
|
||||
->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString())
|
||||
->withPageTitle(Setting::get('app_name'));
|
||||
->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class StatusPageRoutes
|
||||
'middleware' => ['app.hasSetting', 'localize'],
|
||||
'setting' => 'app_name',
|
||||
'as' => 'status-page',
|
||||
'uses' => 'HomeController@showIndex',
|
||||
'uses' => 'StatusPageController@showIndex',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace CachetHQ\Cachet\Providers;
|
||||
use CachetHQ\Cachet\Composers\AppComposer;
|
||||
use CachetHQ\Cachet\Composers\CurrentUserComposer;
|
||||
use CachetHQ\Cachet\Composers\DashboardComposer;
|
||||
use CachetHQ\Cachet\Composers\IndexComposer;
|
||||
use CachetHQ\Cachet\Composers\MetricsComposer;
|
||||
use CachetHQ\Cachet\Composers\StatusPageComposer;
|
||||
use CachetHQ\Cachet\Composers\ThemeComposer;
|
||||
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
@@ -31,7 +32,8 @@ class ComposerServiceProvider extends ServiceProvider
|
||||
{
|
||||
$factory->composer('*', AppComposer::class);
|
||||
$factory->composer('*', CurrentUserComposer::class);
|
||||
$factory->composer(['index', 'subscribe'], IndexComposer::class);
|
||||
$factory->composer(['index'], MetricsComposer::class);
|
||||
$factory->composer(['index', 'subscribe'], StatusPageComposer::class);
|
||||
$factory->composer(['index', 'subscribe'], ThemeComposer::class);
|
||||
$factory->composer('dashboard.*', DashboardComposer::class);
|
||||
$factory->composer(['setup', 'dashboard.settings.app-setup'], TimezoneLocaleComposer::class);
|
||||
|
||||
@@ -20,24 +20,20 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if($about_app)
|
||||
<div class="about-app">
|
||||
<h1>{{ trans('cachet.about_this_site') }}</h1>
|
||||
<p>{!! $about_app !!}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include('dashboard.partials.errors')
|
||||
|
||||
<h1>{{ trans('cachet.subscriber.subscribe') }}</h1>
|
||||
<form action="{{ route('subscribe.subscribe', [], false) }}" method="post">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
<div class="form-group">
|
||||
<label for="email">{{ trans('cachet.subscriber.email.subscribe') }}</label>
|
||||
<input class="form-control" type="text" name="email">
|
||||
<div class="panel panel-meassage">
|
||||
<div class="panel-heading">
|
||||
<strong>{{ trans('cachet.subscriber.subscribe') }}</strong>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="btn btn-success btn-outline" type="submit" value="{{ trans('cachet.subscriber.button') }}">
|
||||
<div class="panel-body">
|
||||
<form action="{{ route('subscribe.subscribe', [], false) }}" method="post" class="form">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="email" name="email">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">{{ trans('cachet.subscriber.button') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user