diff --git a/app/Bus/Commands/ComponentGroup/AddComponentGroupCommand.php b/app/Bus/Commands/ComponentGroup/AddComponentGroupCommand.php index 78a93b3e..d311217e 100644 --- a/app/Bus/Commands/ComponentGroup/AddComponentGroupCommand.php +++ b/app/Bus/Commands/ComponentGroup/AddComponentGroupCommand.php @@ -27,14 +27,22 @@ final class AddComponentGroupCommand */ public $order; + /** + * Is the component group collapsed? + * + * @var bool + */ + public $collapsed; + /** * The validation rules. * * @var string[] */ public $rules = [ - 'name' => 'required|string', - 'order' => 'int', + 'name' => 'required|string', + 'order' => 'int', + 'collapsed' => 'bool', ]; /** @@ -42,12 +50,14 @@ final class AddComponentGroupCommand * * @param string $name * @param int $order + * @param bool $collapsed * * @return void */ - public function __construct($name, $order) + public function __construct($name, $order, $collapsed) { $this->name = $name; $this->order = (int) $order; + $this->collapsed = $collapsed; } } diff --git a/app/Bus/Commands/ComponentGroup/UpdateComponentGroupCommand.php b/app/Bus/Commands/ComponentGroup/UpdateComponentGroupCommand.php index ae993364..dea3573e 100644 --- a/app/Bus/Commands/ComponentGroup/UpdateComponentGroupCommand.php +++ b/app/Bus/Commands/ComponentGroup/UpdateComponentGroupCommand.php @@ -36,14 +36,22 @@ final class UpdateComponentGroupCommand */ public $order; + /** + * Is the component group collapsed? + * + * @var bool + */ + public $collapsed; + /** * The validation rules. * * @var string[] */ public $rules = [ - 'name' => 'string', - 'order' => 'int', + 'name' => 'string', + 'order' => 'int', + 'collapsed' => 'bool', ]; /** @@ -52,13 +60,15 @@ final class UpdateComponentGroupCommand * @param \CachetHQ\Cachet\Models\ComponentGroup $group * @param string $name * @param int $order + * @param bool $collapsed * * @return void */ - public function __construct(ComponentGroup $group, $name, $order) + public function __construct(ComponentGroup $group, $name, $order, $collapsed) { $this->group = $group; $this->name = $name; $this->order = (int) $order; + $this->collapsed = $collapsed; } } diff --git a/app/Bus/Handlers/Commands/ComponentGroup/AddComponentGroupCommandHandler.php b/app/Bus/Handlers/Commands/ComponentGroup/AddComponentGroupCommandHandler.php index dca0ff3f..9066df51 100644 --- a/app/Bus/Handlers/Commands/ComponentGroup/AddComponentGroupCommandHandler.php +++ b/app/Bus/Handlers/Commands/ComponentGroup/AddComponentGroupCommandHandler.php @@ -27,8 +27,9 @@ class AddComponentGroupCommandHandler public function handle(AddComponentGroupCommand $command) { $group = ComponentGroup::create([ - 'name' => $command->name, - 'order' => $command->order, + 'name' => $command->name, + 'order' => $command->order, + 'collapsed' => $command->collapsed, ]); event(new ComponentGroupWasAddedEvent($group)); diff --git a/app/Bus/Handlers/Commands/ComponentGroup/UpdateComponentGroupCommandHandler.php b/app/Bus/Handlers/Commands/ComponentGroup/UpdateComponentGroupCommandHandler.php index cac526d5..4ea40186 100644 --- a/app/Bus/Handlers/Commands/ComponentGroup/UpdateComponentGroupCommandHandler.php +++ b/app/Bus/Handlers/Commands/ComponentGroup/UpdateComponentGroupCommandHandler.php @@ -26,13 +26,30 @@ class UpdateComponentGroupCommandHandler public function handle(UpdateComponentGroupCommand $command) { $group = $command->group; - $group->update([ - 'name' => $command->name, - 'order' => $command->order, - ]); + $group->update($this->filter($command)); event(new ComponentGroupWasUpdatedEvent($group)); return $group; } + + /** + * Filter the command data. + * + * @param \CachetHQ\Cachet\Bus\Commands\ComponentGroup\UpdateComponentGroupCommand $command + * + * @return array + */ + protected function filter(UpdateComponentGroupCommand $command) + { + $params = [ + 'name' => $command->name, + 'order' => $command->order, + 'collapsed' => $command->collapsed, + ]; + + return array_filter($params, function ($val) { + return $val !== null; + }); + } } diff --git a/app/Http/Controllers/Api/ComponentGroupController.php b/app/Http/Controllers/Api/ComponentGroupController.php index 9410f4d0..989bd131 100644 --- a/app/Http/Controllers/Api/ComponentGroupController.php +++ b/app/Http/Controllers/Api/ComponentGroupController.php @@ -56,7 +56,8 @@ class ComponentGroupController extends AbstractApiController try { $group = dispatch(new AddComponentGroupCommand( Binput::get('name'), - Binput::get('order', 0) + Binput::get('order', 0), + Binput::get('collapsed') )); } catch (QueryException $e) { throw new BadRequestHttpException(); @@ -78,7 +79,8 @@ class ComponentGroupController extends AbstractApiController $group = dispatch(new UpdateComponentGroupCommand( $group, Binput::get('name'), - Binput::get('order', 0) + Binput::get('order', 0), + Binput::get('collapsed') )); } catch (QueryException $e) { throw new BadRequestHttpException(); diff --git a/app/Http/Controllers/Dashboard/ComponentController.php b/app/Http/Controllers/Dashboard/ComponentController.php index a0cbe106..1875328b 100644 --- a/app/Http/Controllers/Dashboard/ComponentController.php +++ b/app/Http/Controllers/Dashboard/ComponentController.php @@ -276,7 +276,8 @@ class ComponentController extends Controller try { $group = dispatch(new AddComponentGroupCommand( Binput::get('name'), - Binput::get('order', 0) + Binput::get('order', 0), + Binput::get('collapsed') )); } catch (ValidationException $e) { return Redirect::route('dashboard.components.groups.add') @@ -302,7 +303,8 @@ class ComponentController extends Controller $group = dispatch(new UpdateComponentGroupCommand( $group, Binput::get('name'), - Binput::get('order', 0) + Binput::get('order', 0), + Binput::get('collapsed') )); } catch (ValidationException $e) { return Redirect::route('dashboard.components.groups.edit', ['id' => $group->id]) diff --git a/app/Models/ComponentGroup.php b/app/Models/ComponentGroup.php index 8335ca69..034b5641 100644 --- a/app/Models/ComponentGroup.php +++ b/app/Models/ComponentGroup.php @@ -26,8 +26,9 @@ class ComponentGroup extends Model implements HasPresenter * @var string[] */ protected $casts = [ - 'name' => 'string', - 'order' => 'int', + 'name' => 'string', + 'order' => 'int', + 'collapsed' => 'bool', ]; /** @@ -35,7 +36,7 @@ class ComponentGroup extends Model implements HasPresenter * * @var string[] */ - protected $fillable = ['name', 'order']; + protected $fillable = ['name', 'order', 'collapsed']; /** * The validation rules. @@ -43,8 +44,9 @@ class ComponentGroup extends Model implements HasPresenter * @var string[] */ public $rules = [ - 'name' => 'required|string', - 'order' => 'int', + 'name' => 'required|string', + 'order' => 'int', + 'collapsed' => 'bool', ]; /** diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 380e7555..312ecc81 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -32,8 +32,9 @@ $factory->define(Component::class, function ($faker) { $factory->define(ComponentGroup::class, function ($faker) { return [ - 'name' => $faker->words(2, true), - 'order' => 0, + 'name' => $faker->words(2, true), + 'order' => 0, + 'collapsed' => false, ]; }); diff --git a/database/migrations/2016_01_29_154937_AlterTableComponentGroupsAddCollapsedColumn.php b/database/migrations/2016_01_29_154937_AlterTableComponentGroupsAddCollapsedColumn.php new file mode 100644 index 00000000..8b8b9d84 --- /dev/null +++ b/database/migrations/2016_01_29_154937_AlterTableComponentGroupsAddCollapsedColumn.php @@ -0,0 +1,41 @@ +boolean('collapsed')->after('order')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('component_groups', function (Blueprint $table) { + $table->dropColumn('collapsed'); + }); + } +} diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index e0a411f6..c1945012 100755 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -68,7 +68,8 @@ return [ 'enabled' => 'Component enabled?', 'groups' => [ - 'name' => 'Name', + 'name' => 'Name', + 'collapsed' => 'Collapse the group by default?', ], ], diff --git a/resources/views/dashboard/components/groups/add.blade.php b/resources/views/dashboard/components/groups/add.blade.php index ece35042..e6079c42 100644 --- a/resources/views/dashboard/components/groups/add.blade.php +++ b/resources/views/dashboard/components/groups/add.blade.php @@ -18,9 +18,16 @@