Display a status circle next to component groups. Closes #1317

This commit is contained in:
James Brooks
2016-01-03 11:48:53 +00:00
parent 1ec12b7702
commit cf4cbfa605
3 changed files with 97 additions and 1 deletions

View File

@@ -12,9 +12,11 @@
namespace CachetHQ\Cachet\Models;
use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Presenters\ComponentGroupPresenter;
use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter;
class ComponentGroup extends Model
class ComponentGroup extends Model implements HasPresenter
{
use ValidatingTrait;
@@ -46,6 +48,13 @@ class ComponentGroup extends Model
'order' => 'int',
];
/**
* The relations to eager load on every query.
*
* @var string[]
*/
protected $with = ['enabled_components'];
/**
* A group can have many components.
*
@@ -55,4 +64,24 @@ class ComponentGroup extends Model
{
return $this->hasMany(Component::class, 'group_id', 'id');
}
/**
* Return all of the enabled components.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function enabled_components()
{
return $this->components()->enabled();
}
/**
* Get the presenter class.
*
* @return string
*/
public function getPresenterClass()
{
return ComponentGroupPresenter::class;
}
}

View 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\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
class ComponentGroupPresenter extends AbstractPresenter
{
use TimestampsTrait;
/**
* Returns the lowest component status.
*
* @return string
*/
public function lowest_status()
{
return $this->wrappedObject->enabled_components->first()->human_status;
}
/**
* Returns the lowest component status, readable by humans.
*
* @return string
*/
public function lowest_human_status()
{
return $this->wrappedObject->enabled_components->first()->human_status;
}
/**
* Returns the lowest component status color.
*
* @return string
*/
public function lowest_status_color()
{
return $this->wrappedObject->enabled_components->first()->status_color;
}
/**
* Convert the presenter instance to an array.
*
* @return string[]
*/
public function toArray()
{
return array_merge($this->wrappedObject->toArray(), [
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
'lowest_human_status' => $this->lowest_human_status(),
]);
}
}

View File

@@ -5,6 +5,10 @@
<li class="list-group-item group-name">
<i class="ion-ios-minus-outline group-toggle"></i>
<strong>{{ $componentGroup->name }}</strong>
<div class="pull-right">
<i class="ion-ios-circle-filled text-component-{{ $componentGroup->lowest_status }} {{ $componentGroup->lowest_status_color }}" data-toggle="tooltip" title="{{ $componentGroup->lowest_human_status }}"></i>
</div>
</li>
<div class="group-items">