diff --git a/app/models/Component.php b/app/models/Component.php index 34111947..a7a8e25b 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -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. * diff --git a/app/view-composers.php b/app/view-composers.php index 6b7f0742..16ef0446 100644 --- a/app/view-composers.php +++ b/app/view-composers.php @@ -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');