Smarter handling of the service status

This commit is contained in:
James Brooks
2014-12-31 15:56:08 +00:00
parent 655042da3c
commit 7d8bf7fb3a
2 changed files with 39 additions and 5 deletions

View File

@@ -33,6 +33,32 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
return $this->hasMany('Incident', 'component_id', 'id');
}
/**
* Finds all components by status.
*
* @param Illuminate\Database\Eloquent\Builder $query
* @param int $status
*
* @return Illuminate\Database\Eloquent\Builder
*/
public function scopeStatus($query, $status)
{
return $query->where('status', $status);
}
/**
* Finds all components which don't have the given status.
*
* @param Illuminate\Database\Eloquent\Builder $query
* @param int $status
*
* @return Illuminate\Database\Eloquent\Builder
*/
public function scopeNotStatus($query, $status)
{
return $query->where('status', '<>', $status);
}
/**
* Looks up the human readable version of the status.
*

View File

@@ -3,12 +3,20 @@
View::composer('index', function ($view) {
$date = date('Y-m-d');
$incidents = Incident::orderBy('created_at', 'desc')->get();
$incidentCount = $incidents->count();
$components = Component::notStatus(1);
if ($incidentCount === 0 || ($incidentCount > 1 && (int) $incidents->first()->status === 4)) {
$status = 'success';
$message = Lang::get('cachet.service.good');
if (Component::all()->count() === 0 || $components->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::orderBy('created_at', 'desc')->get();
$incidentCount = $incidents->count();
if ($incidentCount === 0 || ($incidentCount >= 1 && (int) $incidents->first()->status === 4)) {
$status = 'success';
$message = Lang::get('cachet.service.good');
} else {
$status = 'danger';
$message = Lang::get('cachet.service.bad');
}
} else {
$status = 'danger';
$message = Lang::get('cachet.service.bad');