mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-04-08 01:23:25 +02:00
Merge pull request #1099 from cachethq/disable-components
Enabling/Disabling of components
This commit is contained in:
commit
ccc23fa70d
@ -55,6 +55,13 @@ final class AddComponentCommand
|
||||
*/
|
||||
public $group_id;
|
||||
|
||||
/**
|
||||
* Is the component enabled?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@ -67,6 +74,7 @@ final class AddComponentCommand
|
||||
'link' => 'url',
|
||||
'order' => 'int',
|
||||
'group_id' => 'int',
|
||||
'enabled' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -78,10 +86,11 @@ final class AddComponentCommand
|
||||
* @param string $link
|
||||
* @param int $order
|
||||
* @param int $group_id
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($name, $description, $status, $link, $order, $group_id)
|
||||
public function __construct($name, $description, $status, $link, $order, $group_id, $enabled)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
@ -89,5 +98,6 @@ final class AddComponentCommand
|
||||
$this->link = $link;
|
||||
$this->order = $order;
|
||||
$this->group_id = $group_id;
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,13 @@ final class UpdateComponentCommand
|
||||
*/
|
||||
public $group_id;
|
||||
|
||||
/**
|
||||
* Is the component enabled?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $enabled;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
@ -76,6 +83,7 @@ final class UpdateComponentCommand
|
||||
'link' => 'url',
|
||||
'order' => 'int',
|
||||
'group_id' => 'int',
|
||||
'enabled' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -88,10 +96,11 @@ final class UpdateComponentCommand
|
||||
* @param string $link
|
||||
* @param int $order
|
||||
* @param int $group_id
|
||||
* @param bool $enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Component $component, $name, $description, $status, $link, $order, $group_id)
|
||||
public function __construct(Component $component, $name, $description, $status, $link, $order, $group_id, $enabled)
|
||||
{
|
||||
$this->component = $component;
|
||||
$this->name = $name;
|
||||
@ -100,5 +109,6 @@ final class UpdateComponentCommand
|
||||
$this->link = $link;
|
||||
$this->order = $order;
|
||||
$this->group_id = $group_id;
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class StatusPageComposer
|
||||
'favicon' => 'favicon-high-alert',
|
||||
];
|
||||
|
||||
if (Component::notStatus(1)->count() === 0) {
|
||||
if (Component::where('enabled', true)->notStatus(1)->count() === 0) {
|
||||
// If all our components are ok, do we have any non-fixed incidents?
|
||||
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
||||
$incidentCount = $incidents->count();
|
||||
@ -48,7 +48,7 @@ class StatusPageComposer
|
||||
];
|
||||
}
|
||||
} else {
|
||||
if (Component::whereIn('status', [2, 3])->count() > 0) {
|
||||
if (Component::where('enabled', true)->whereIn('status', [2, 3])->count() > 0) {
|
||||
$withData['favicon'] = 'favicon-medium-alert';
|
||||
}
|
||||
}
|
||||
@ -57,9 +57,9 @@ class StatusPageComposer
|
||||
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
|
||||
|
||||
// Component & Component Group lists.
|
||||
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
||||
$usedComponentGroups = Component::where('enabled', true)->where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
||||
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
|
||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
$ungroupedComponents = Component::where('enabled', true)->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$view->with($withData)
|
||||
->withComponentGroups($componentGroups)
|
||||
|
@ -26,14 +26,18 @@ class AddComponentCommandHandler
|
||||
*/
|
||||
public function handle(AddComponentCommand $command)
|
||||
{
|
||||
$component = Component::create(array_filter([
|
||||
$componentData = array_filter([
|
||||
'name' => $command->name,
|
||||
'description' => $command->description,
|
||||
'link' => $command->link,
|
||||
'status' => $command->status,
|
||||
'order' => $command->order,
|
||||
'group_id' => $command->group_id,
|
||||
]));
|
||||
]);
|
||||
|
||||
$componentData['enabled'] = $command->enabled;
|
||||
|
||||
$component = Component::create($componentData);
|
||||
|
||||
event(new ComponentWasAddedEvent($component));
|
||||
|
||||
|
@ -27,14 +27,18 @@ class UpdateComponentCommandHandler
|
||||
public function handle(UpdateComponentCommand $command)
|
||||
{
|
||||
$component = $command->component;
|
||||
$component->update(array_filter([
|
||||
$componentData = array_filter([
|
||||
'name' => $command->name,
|
||||
'description' => $command->description,
|
||||
'link' => $command->link,
|
||||
'status' => $command->status,
|
||||
'order' => $command->order,
|
||||
'group_id' => $command->group_id,
|
||||
]));
|
||||
]);
|
||||
|
||||
$componentData['enabled'] = $command->enabled;
|
||||
|
||||
$component->update($componentData);
|
||||
|
||||
event(new ComponentWasUpdatedEvent($component));
|
||||
|
||||
|
@ -69,7 +69,8 @@ class ComponentController extends AbstractApiController
|
||||
Binput::get('status'),
|
||||
Binput::get('link'),
|
||||
Binput::get('order'),
|
||||
Binput::get('group_id')
|
||||
Binput::get('group_id'),
|
||||
(bool) Binput::get('enabled', true)
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
@ -109,7 +110,8 @@ class ComponentController extends AbstractApiController
|
||||
Binput::get('status'),
|
||||
Binput::get('link'),
|
||||
Binput::get('order'),
|
||||
Binput::get('group_id')
|
||||
Binput::get('group_id'),
|
||||
(bool) Binput::get('enabled')
|
||||
));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
|
@ -32,6 +32,7 @@ class Component extends Model implements HasPresenter
|
||||
'group_id' => 0,
|
||||
'description' => '',
|
||||
'link' => '',
|
||||
'enabled' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -46,6 +47,7 @@ class Component extends Model implements HasPresenter
|
||||
'description' => 'string',
|
||||
'link' => 'string',
|
||||
'deleted_at' => 'date',
|
||||
'enabled' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -61,6 +63,7 @@ class Component extends Model implements HasPresenter
|
||||
'link',
|
||||
'order',
|
||||
'group_id',
|
||||
'enabled',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -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 AlterTableComponentsAddEnabledColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('components', function (Blueprint $table) {
|
||||
$table->boolean('enabled')->after('group_id')->default(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('components', function (Blueprint $table) {
|
||||
$table->dropColumn('enabled');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
<ul class="list-group components">
|
||||
@if($component_groups->count() > 0)
|
||||
@foreach($component_groups as $componentGroup)
|
||||
@if($componentGroup->components->count() > 0)
|
||||
@if($componentGroup->components->where('enabled', true)->count() > 0)
|
||||
<li class="list-group-item group-name">
|
||||
<i class="ion-ios-minus-outline group-toggle"></i>
|
||||
<strong>{{ $componentGroup->name }}</strong>
|
||||
</li>
|
||||
|
||||
<div class="group-items">
|
||||
@foreach($componentGroup->components->sortBy('order') as $component)
|
||||
@foreach($componentGroup->components->where('enabled', true)->sortBy('order') as $component)
|
||||
@include('partials.component', compact($component))
|
||||
@endforeach
|
||||
</div>
|
||||
|
@ -61,11 +61,45 @@ class ComponentTest extends AbstractTestCase
|
||||
'link' => 'http://example.com',
|
||||
'order' => 1,
|
||||
'group_id' => 1,
|
||||
'enabled' => true,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo']);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostComponentWithoutEnabledField()
|
||||
{
|
||||
$this->beUser();
|
||||
|
||||
$this->post('/api/v1/components', [
|
||||
'name' => 'Foo',
|
||||
'description' => 'Bar',
|
||||
'status' => 1,
|
||||
'link' => 'http://example.com',
|
||||
'order' => 1,
|
||||
'group_id' => 1,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo', 'enabled' => true]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testPostDisabledComponent()
|
||||
{
|
||||
$this->beUser();
|
||||
|
||||
$this->post('/api/v1/components', [
|
||||
'name' => 'Foo',
|
||||
'description' => 'Bar',
|
||||
'status' => 1,
|
||||
'link' => 'http://example.com',
|
||||
'order' => 1,
|
||||
'group_id' => 1,
|
||||
'enabled' => 0,
|
||||
]);
|
||||
$this->seeJson(['name' => 'Foo', 'enabled' => false]);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testGetNewComponent()
|
||||
{
|
||||
$component = factory('CachetHQ\Cachet\Models\Component')->create();
|
||||
|
@ -31,6 +31,7 @@ class AddComponentCommandTest extends AbstractCommandTestCase
|
||||
'link' => 'https://cachethq.io',
|
||||
'order' => 0,
|
||||
'group_id' => 0,
|
||||
'enabled' => true,
|
||||
];
|
||||
$object = new AddComponentCommand(
|
||||
$params['name'],
|
||||
@ -38,7 +39,8 @@ class AddComponentCommandTest extends AbstractCommandTestCase
|
||||
$params['status'],
|
||||
$params['link'],
|
||||
$params['order'],
|
||||
$params['group_id']
|
||||
$params['group_id'],
|
||||
$params['enabled']
|
||||
);
|
||||
|
||||
return compact('params', 'object');
|
||||
|
@ -33,6 +33,7 @@ class UpdateComponentCommandTest extends AbstractCommandTestCase
|
||||
'link' => 'https://cachethq.io',
|
||||
'order' => 0,
|
||||
'group_id' => 0,
|
||||
'enabled' => true,
|
||||
];
|
||||
$object = new UpdateComponentCommand(
|
||||
$params['component'],
|
||||
@ -41,7 +42,8 @@ class UpdateComponentCommandTest extends AbstractCommandTestCase
|
||||
$params['status'],
|
||||
$params['link'],
|
||||
$params['order'],
|
||||
$params['group_id']
|
||||
$params['group_id'],
|
||||
$params['enabled']
|
||||
);
|
||||
|
||||
return compact('params', 'object');
|
||||
|
Loading…
x
Reference in New Issue
Block a user