Update code to match master
This commit is contained in:
@@ -4,6 +4,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
@@ -68,10 +69,14 @@ class IncidentController extends AbstractController
|
||||
*/
|
||||
public function showAddIncident()
|
||||
{
|
||||
$componentsInGroups = ComponentGroup::with('components')->get();
|
||||
$componentsOutGroups = Component::where('group_id', 0)->get();
|
||||
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'componentsInGroups' => $componentsInGroups,
|
||||
'componentsOutGroups' => $componentsOutGroups,
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -248,10 +253,14 @@ class IncidentController extends AbstractController
|
||||
*/
|
||||
public function showEditIncidentAction(Incident $incident)
|
||||
{
|
||||
$componentsInGroups = ComponentGroup::with('components')->get();
|
||||
$componentsOutGroups = Component::where('group_id', 0)->get();
|
||||
|
||||
return View::make('dashboard.incidents.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'incident' => $incident,
|
||||
'components' => Component::all(),
|
||||
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'incident' => $incident,
|
||||
'componentsInGroups' => $componentsInGroups,
|
||||
'componentsOutGroups' => $componentsOutGroups,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,11 @@ class AtomController extends AbstractController
|
||||
/**
|
||||
* Generates an Atom feed of all incidents.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup|null $group
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
public function feedAction(ComponentGroup $group = null)
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
@@ -23,23 +25,37 @@ class AtomController extends AbstractController
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
if ($group) {
|
||||
$group->components->map(function ($component) use ($feed) {
|
||||
$component->incidents->orderBy('created_at', 'desc')->map(function ($incident) use ($feed) {
|
||||
$this->feedAddItem($feed, $incident);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Incident::orderBy('created_at', 'desc')->get()->map(function ($incident) use ($feed) {
|
||||
$this->feedAddItem($feed, $incident);
|
||||
});
|
||||
}
|
||||
|
||||
return $feed->render('atom');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the feed.
|
||||
*
|
||||
* @param \Thujohn\Rss\Rss $feed
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function feedAddItem(& $feed, $incident)
|
||||
{
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at->toAtomString(),
|
||||
$incident->message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ use Roumen\Feed\Facades\Feed;
|
||||
class RssController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Generates an RSS feed of all incidents.
|
||||
* Generates an Atom feed of all incidents.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup|null $group
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
public function feedAction(ComponentGroup $group = null)
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
@@ -23,23 +25,37 @@ class RssController extends AbstractController
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
if ($group) {
|
||||
$group->components->map(function ($component) use ($feed) {
|
||||
$component->incidents->orderBy('created_at', 'desc')->map(function ($incident) use ($feed) {
|
||||
$this->feedAddItem($feed, $incident);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Incident::orderBy('created_at', 'desc')->get()->map(function ($incident) use ($feed) {
|
||||
$this->feedAddItem($feed, $incident);
|
||||
});
|
||||
}
|
||||
|
||||
return $feed->render('rss');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an item to the feed.
|
||||
*
|
||||
* @param \Thujohn\Rss\Rss $feed
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function feedAddItem(& $feed, $incident)
|
||||
{
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at->toAtomString(),
|
||||
$incident->message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ class StatusPageRoutes
|
||||
'as' => 'status-page',
|
||||
'uses' => 'HomeController@showIndex',
|
||||
]);
|
||||
$router->get('/atom', 'AtomController@feedAction');
|
||||
$router->get('/rss', 'RssController@feedAction');
|
||||
$router->get('/atom/{component_group?}', 'AtomController@feedAction');
|
||||
$router->get('/rss/{component_group?}', 'RssController@feedAction');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
@@ -15,7 +14,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
*/
|
||||
class ComponentGroup extends Model
|
||||
{
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
@@ -33,13 +32,6 @@ class ComponentGroup extends Model
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
/**
|
||||
* A group can have many components.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,8 @@ use Watson\Validating\ValidatingTrait;
|
||||
* @property string $name
|
||||
* @property string $suffix
|
||||
* @property string $description
|
||||
* @property float $default_value
|
||||
* @property int $calc_type
|
||||
* @property int $display_chart
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
@@ -90,6 +92,8 @@ class Metric extends Model
|
||||
$queryType = "sum(metric_points.value)";
|
||||
} elseif ($this->calc_type === self::CALC_AVG) {
|
||||
$queryType = "avg(metric_points.value)";
|
||||
} else {
|
||||
$queryType = "sum(metric_points.value)";
|
||||
}
|
||||
|
||||
$query = DB::select("select {$queryType} as aggregate FROM metrics JOIN metric_points ON metric_points.metric_id = metrics.id WHERE to_char(metric_points.created_at, 'YYYYMMDDHH') = :timestamp AND to_char(metric_points.created_at, 'H') = to_char(now() - interval '{$hour} hour', 'H') GROUP BY to_char(metric_points.created_at, 'H')", [
|
||||
|
||||
Reference in New Issue
Block a user