mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 21:49:01 +01:00
Merge pull request #1604 from CachetHQ/auto-expand-component-groups
Auto expand component groups
This commit is contained in:
commit
9919853d07
@ -11,6 +11,11 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Commands\ComponentGroup;
|
||||
|
||||
/**
|
||||
* This is the add component group command.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class AddComponentGroupCommand
|
||||
{
|
||||
/**
|
||||
@ -30,7 +35,7 @@ final class AddComponentGroupCommand
|
||||
/**
|
||||
* Is the component group collapsed?
|
||||
*
|
||||
* @var bool
|
||||
* @var int
|
||||
*/
|
||||
public $collapsed;
|
||||
|
||||
@ -42,7 +47,7 @@ final class AddComponentGroupCommand
|
||||
public $rules = [
|
||||
'name' => 'required|string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'bool',
|
||||
'collapsed' => 'int|between:0,3',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -50,7 +55,7 @@ final class AddComponentGroupCommand
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $order
|
||||
* @param bool $collapsed
|
||||
* @param int $collapsed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -13,6 +13,11 @@ namespace CachetHQ\Cachet\Bus\Commands\ComponentGroup;
|
||||
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
|
||||
/**
|
||||
* This is the update component group command.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
final class UpdateComponentGroupCommand
|
||||
{
|
||||
/**
|
||||
@ -39,7 +44,7 @@ final class UpdateComponentGroupCommand
|
||||
/**
|
||||
* Is the component group collapsed?
|
||||
*
|
||||
* @var bool
|
||||
* @var int
|
||||
*/
|
||||
public $collapsed;
|
||||
|
||||
@ -51,7 +56,7 @@ final class UpdateComponentGroupCommand
|
||||
public $rules = [
|
||||
'name' => 'string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'bool',
|
||||
'collapsed' => 'int|between:0,3',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -60,7 +65,7 @@ final class UpdateComponentGroupCommand
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
* @param string $name
|
||||
* @param int $order
|
||||
* @param bool $collapsed
|
||||
* @param int $collapsed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
@ -82,11 +82,11 @@ class DemoSeederCommand extends Command
|
||||
[
|
||||
'name' => 'Websites',
|
||||
'order' => 1,
|
||||
'collapsed' => false,
|
||||
'collapsed' => 0,
|
||||
], [
|
||||
'name' => 'Alt Three',
|
||||
'order' => 2,
|
||||
'collapsed' => true,
|
||||
'collapsed' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -30,7 +30,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
protected $casts = [
|
||||
'name' => 'string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'bool',
|
||||
'collapsed' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
public $rules = [
|
||||
'name' => 'required|string',
|
||||
'order' => 'int',
|
||||
'collapsed' => 'bool',
|
||||
'collapsed' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -92,6 +92,16 @@ class ComponentGroup extends Model implements HasPresenter
|
||||
return $this->hasMany(Component::class, 'group_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the incidents relation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function incidents()
|
||||
{
|
||||
return $this->hasManyThrough(Incident::class, Component::class, 'id', 'component_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the enabled components.
|
||||
*
|
||||
|
@ -63,7 +63,25 @@ class ComponentGroupPresenter extends BasePresenter implements Arrayable
|
||||
*/
|
||||
public function collapse_class()
|
||||
{
|
||||
return $this->wrappedObject->collapsed ? 'ion-ios-plus-outline' : 'ion-ios-minus-outline';
|
||||
return $this->is_collapsed() ? 'ion-ios-plus-outline' : 'ion-ios-minus-outline';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the group should be collapsed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_collapsed()
|
||||
{
|
||||
if ($this->wrappedObject->collapsed === 0) {
|
||||
return false;
|
||||
} elseif ($this->wrappedObject->collapsed === 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->wrappedObject->components->filter(function ($component) {
|
||||
return $component->status > 1;
|
||||
})->count() === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ $factory->define(ComponentGroup::class, function ($faker) {
|
||||
return [
|
||||
'name' => $faker->words(2, true),
|
||||
'order' => 0,
|
||||
'collapsed' => $faker->boolean(),
|
||||
'collapsed' => random_int(0, 3),
|
||||
];
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterTableComponentGroupsMakeColumnInteger extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('component_groups', function (Blueprint $table) {
|
||||
$table->integer('collapsed')->unsigned()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('component_groups', function (Blueprint $table) {
|
||||
$table->boolean('collapsed')->change();
|
||||
});
|
||||
}
|
||||
}
|
@ -68,8 +68,11 @@ return [
|
||||
'enabled' => 'Component enabled?',
|
||||
|
||||
'groups' => [
|
||||
'name' => 'Name',
|
||||
'collapsed' => 'Collapse the group by default?',
|
||||
'name' => 'Name',
|
||||
'collapsing' => 'Choose visibility of the group',
|
||||
'visible' => 'Always expanded',
|
||||
'collapsed' => 'Collapse the group by default',
|
||||
'collapsed_incident' => 'Collapse the group, but expand if there are issues',
|
||||
],
|
||||
],
|
||||
|
||||
|
@ -22,11 +22,12 @@
|
||||
<input type="text" class="form-control" name="name" id="group-name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input type="hidden" value="0" name="collapsed">
|
||||
<input type="checkbox" value="1" name="collapsed">
|
||||
{{ trans('forms.components.groups.collapsed') }}
|
||||
</label>
|
||||
<label>{{ trans('forms.components.groups.collapsing') }}</label>
|
||||
<select name="collapsed" class="form-control" required>
|
||||
<option value="0">{{ trans('forms.components.groups.visible') }}</option>
|
||||
<option value="1">{{ trans('forms.components.groups.collapsed') }}</option>
|
||||
<option value="2">{{ trans('forms.components.groups.collapsed_incident') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
|
@ -22,11 +22,12 @@
|
||||
<input type="text" class="form-control" name="name" id="group-name" value="{{ $group->name }}" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
<input type="hidden" value="0" name="collapsed">
|
||||
<input type="checkbox" value="1" name="collapsed" {{ $group->collapsed ? "checked" : null }}>
|
||||
{{ trans('forms.components.groups.collapsed') }}
|
||||
</label>
|
||||
<label>{{ trans('forms.components.groups.collapsing') }}</label>
|
||||
<select name="collapsed" class="form-control" required>
|
||||
<option value="0" {{ $group->collapsed === 0 ? "selected" : null }}>{{ trans('forms.components.groups.visible') }}</option>
|
||||
<option value="1" {{ $group->collapsed === 1 ? "selected" : null }}>{{ trans('forms.components.groups.collapsed') }}</option>
|
||||
<option value="2" {{ $group->collapsed === 2 ? "selected" : null }}>{{ trans('forms.components.groups.collapsed_incident') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
|
@ -11,10 +11,10 @@
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<div class="group-items {{ $componentGroup->collapsed ? "hide" : null }}">
|
||||
@foreach($componentGroup->enabled_components()->orderBy('order')->get() as $component)
|
||||
@include('partials.component', compact($component))
|
||||
@endforeach
|
||||
<div class="group-items {{ $componentGroup->is_collapsed ? "hide" : null }}">
|
||||
@foreach($componentGroup->enabled_components()->orderBy('order')->get() as $component)
|
||||
@include('partials.component', compact($component))
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</ul>
|
||||
|
@ -58,9 +58,9 @@ class ComponentGroupTest extends AbstractApiTestCase
|
||||
$this->post('/api/v1/components/groups', [
|
||||
'name' => 'Foo',
|
||||
'order' => 1,
|
||||
'collapsed' => true,
|
||||
'collapsed' => 1,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo', 'order' => 1, 'collapsed' => true]);
|
||||
$this->seeJson(['name' => 'Foo', 'order' => 1, 'collapsed' => 1]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class AddComponentGroupCommandTest extends AbstractTestCase
|
||||
|
||||
protected function getObjectAndParams()
|
||||
{
|
||||
$params = ['name' => 'Test', 'order' => 0, 'collapsed' => true];
|
||||
$params = ['name' => 'Test', 'order' => 0, 'collapsed' => 1];
|
||||
|
||||
$object = new AddComponentGroupCommand($params['name'], $params['order'], $params['collapsed']);
|
||||
|
||||
|
@ -29,7 +29,7 @@ class UpdateComponentGroupCommandTest extends AbstractTestCase
|
||||
|
||||
protected function getObjectAndParams()
|
||||
{
|
||||
$params = ['group' => new ComponentGroup(), 'name' => 'Foo', 'order' => 1, 'collapsed' => true];
|
||||
$params = ['group' => new ComponentGroup(), 'name' => 'Foo', 'order' => 1, 'collapsed' => 2];
|
||||
$object = new UpdateComponentGroupCommand(
|
||||
$params['group'],
|
||||
$params['name'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user