From 0846cfdbca5dac2c2e55c048511c47b05998638c Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 4 Jan 2015 20:56:10 +0000 Subject: [PATCH 1/2] Component Groups. Closes #146. --- ...2_31_230032_CreateComponentGroupsTable.php | 34 +++++++++ ...6_AlterTableComponentsAddGroupIdColumn.php | 32 +++++++++ app/lang/en/cachet.php | 2 + app/routes/dashboard.php | 3 + .../dashboard/components/add-group.blade.php | 37 ++++++++++ app/views/dashboard/components/add.blade.php | 9 +++ app/views/dashboard/components/edit.blade.php | 9 +++ .../dashboard/components/index.blade.php | 7 +- app/views/dashboard/groups.blade.php | 36 ++++++++++ .../Controllers/DashComponentController.php | 72 +++++++++++++++++++ src/Models/Component.php | 21 +++++- src/Models/ComponentGroup.php | 45 ++++++++++++ 12 files changed, 305 insertions(+), 2 deletions(-) create mode 100644 app/database/migrations/2014_12_31_230032_CreateComponentGroupsTable.php create mode 100644 app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php create mode 100644 app/views/dashboard/components/add-group.blade.php create mode 100644 app/views/dashboard/groups.blade.php create mode 100644 src/Models/ComponentGroup.php diff --git a/app/database/migrations/2014_12_31_230032_CreateComponentGroupsTable.php b/app/database/migrations/2014_12_31_230032_CreateComponentGroupsTable.php new file mode 100644 index 00000000..812fd1e3 --- /dev/null +++ b/app/database/migrations/2014_12_31_230032_CreateComponentGroupsTable.php @@ -0,0 +1,34 @@ +increments('id'); + $table->string('name'); + $table->timestamps(); + + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('component_groups'); + } +} diff --git a/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php b/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php new file mode 100644 index 00000000..2dabefa7 --- /dev/null +++ b/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php @@ -0,0 +1,32 @@ +integer('group_id')->nullable()->default(null)->after('order'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('components', function(Blueprint $table) { + $table->dropColumn('group_id'); + }); + } +} diff --git a/app/lang/en/cachet.php b/app/lang/en/cachet.php index 6e4e81ab..1f1fafb5 100644 --- a/app/lang/en/cachet.php +++ b/app/lang/en/cachet.php @@ -42,6 +42,8 @@ return [ 'dashboard' => 'Dashboard', 'components' => 'Components', 'component-add' => 'Add Component', + 'component-groups' => 'Component Groups', + 'component-groups-add' => 'Create Group', 'incidents' => 'Incidents', 'incident-add' => 'Add Incident', 'incident-create-template' => 'Create Template', diff --git a/app/routes/dashboard.php b/app/routes/dashboard.php index 71ac5f62..9a9a9e4f 100644 --- a/app/routes/dashboard.php +++ b/app/routes/dashboard.php @@ -8,6 +8,9 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache Route::get('components', ['as' => 'dashboard.components', 'uses' => 'DashComponentController@showComponents']); Route::get('components/add', ['as' => 'dashboard.components.add', 'uses' => 'DashComponentController@showAddComponent']); Route::post('components/add', 'DashComponentController@createComponentAction'); + Route::get('components/groups', ['as' => 'dashboard.components.groups', 'uses' => 'DashComponentController@showComponentGroups']); + Route::get('components/groups/add', ['as' => 'dashboard.components.groups.add', 'uses' => 'DashComponentController@showAddComponentGroup']); + Route::post('components/groups/add', 'DashComponentController@postAddComponentGroup'); Route::get('components/{component}/delete', 'DashComponentController@deleteComponentAction'); Route::get('components/{component}/edit', 'DashComponentController@showEditComponent'); Route::post('components/{component}/edit', 'DashComponentController@updateComponentAction'); diff --git a/app/views/dashboard/components/add-group.blade.php b/app/views/dashboard/components/add-group.blade.php new file mode 100644 index 00000000..ee609021 --- /dev/null +++ b/app/views/dashboard/components/add-group.blade.php @@ -0,0 +1,37 @@ +@extends('layout.dashboard') + +@section('content') +
+ + {{ trans('cachet.dashboard.components') }} + + > Create a component group +
+
+
+
+ @if($group = Session::get('group')) +
+ @if($group->isValid()) + Awesome. Component group created. + @else + Whoops. Something went wrong with the group. {{ $group->getErrors() }} + @endif +
+ @endif + +
+
+
+ + +
+
+ + + Cancel +
+
+
+
+@stop diff --git a/app/views/dashboard/components/add.blade.php b/app/views/dashboard/components/add.blade.php index c638e1cc..332776a2 100644 --- a/app/views/dashboard/components/add.blade.php +++ b/app/views/dashboard/components/add.blade.php @@ -38,6 +38,15 @@ +
+ + +

diff --git a/app/views/dashboard/components/edit.blade.php b/app/views/dashboard/components/edit.blade.php index c313e017..89fb9107 100644 --- a/app/views/dashboard/components/edit.blade.php +++ b/app/views/dashboard/components/edit.blade.php @@ -38,6 +38,15 @@
+
+ + +

diff --git a/app/views/dashboard/components/index.blade.php b/app/views/dashboard/components/index.blade.php index 8ed3cc92..8d8bad6a 100644 --- a/app/views/dashboard/components/index.blade.php +++ b/app/views/dashboard/components/index.blade.php @@ -1,7 +1,11 @@ @extends('layout.dashboard') @section('content') -
+@if(isset($subMenu)) +@include('partials.dashboard.sub-sidebar') +@endif +
+
{{ trans('cachet.dashboard.components') }} @@ -40,4 +44,5 @@
+
@stop diff --git a/app/views/dashboard/groups.blade.php b/app/views/dashboard/groups.blade.php new file mode 100644 index 00000000..2f7e6dd9 --- /dev/null +++ b/app/views/dashboard/groups.blade.php @@ -0,0 +1,36 @@ +@extends('layout.dashboard') + +@section('content') +@if(isset($subMenu)) +@include('partials.dashboard.sub-sidebar') +@endif +
+
+ + {{ trans('cachet.dashboard.component-groups') }} + + + {{ trans('cachet.dashboard.component-groups-add') }} + +
+
+
+
+
+ @forelse($groups as $group) +
+
+ {{ $group->name }} +
+
+ Edit + Delete +
+
+ @empty +
You should add a component.
+ @endforelse +
+
+
+@stop diff --git a/src/Http/Controllers/DashComponentController.php b/src/Http/Controllers/DashComponentController.php index 68ab7c19..059c55bf 100644 --- a/src/Http/Controllers/DashComponentController.php +++ b/src/Http/Controllers/DashComponentController.php @@ -3,13 +3,39 @@ namespace CachetHQ\Cachet\Http\Controllers; use CachetHQ\Cachet\Models\Component; +use CachetHQ\Cachet\Models\ComponentGroup; use GrahamCampbell\Binput\Facades\Binput; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\View; class DashComponentController extends Controller { + protected $subMenu = []; + protected $subTitle = 'Components'; + + public function __construct() + { + $this->subMenu = [ + 'components' => [ + 'title' => 'Components', + 'url' => URL::route('dashboard.components'), + 'icon' => 'ion-ios-keypad', + 'active' => false, + ], + 'groups' => [ + 'title' => 'Component Groups', + 'url' => URL::route('dashboard.components.groups'), + 'icon' => 'ion-folder', + 'active' => false, + ], + ]; + + View::share('subTitle', $this->subTitle); + View::share('subMenu', $this->subMenu); + } + /** * Shows the components view. * @@ -19,9 +45,28 @@ class DashComponentController extends Controller { $components = Component::orderBy('order')->orderBy('created_at')->get(); + $this->subMenu['components']['active'] = true; + return View::make('dashboard.components.index')->with([ 'pageTitle' => 'Components - Dashboard', 'components' => $components, + 'subMenu' => $this->subMenu, + ]); + } + + /** + * Shows the component groups view. + * + * @return \Illuminate\View\View + */ + public function showComponentGroups() + { + $this->subMenu['groups']['active'] = true; + + return View::make('dashboard.groups')->with([ + 'pageTitle' => 'Component Groups - Dashboard', + 'groups' => ComponentGroup::all(), + 'subMenu' => $this->subMenu, ]); } @@ -34,9 +79,12 @@ class DashComponentController extends Controller */ public function showEditComponent(Component $component) { + $groups = ComponentGroup::all(); + return View::make('dashboard.components.edit')->with([ 'pageTitle' => 'Editing "'.$component->name.'" Component - Dashboard', 'component' => $component, + 'groups' => $groups, ]); } @@ -62,8 +110,11 @@ class DashComponentController extends Controller */ public function showAddComponent() { + $groups = ComponentGroup::all(); + return View::make('dashboard.components.add')->with([ 'pageTitle' => 'Add Component - Dashboard', + 'groups' => $groups, ]); } @@ -93,4 +144,25 @@ class DashComponentController extends Controller return Redirect::back(); } + + /** + * Shows the add component group view. + * + * @return \Illuminate\View\View + */ + public function showAddComponentGroup() + { + return View::make('dashboard.components.add-group')->with([ + 'pageTitle' => 'Create Component Group', + ]); + } + + public function postAddComponentGroup() + { + $_group = Binput::get('group'); + + $group = ComponentGroup::create($_group); + + return Redirect::back()->withGroup($group); + } } diff --git a/src/Models/Component.php b/src/Models/Component.php index 1f9e8373..e992a676 100644 --- a/src/Models/Component.php +++ b/src/Models/Component.php @@ -43,7 +43,26 @@ class Component extends Model implements TransformableInterface * * @var string[] */ - protected $fillable = ['name', 'description', 'status', 'user_id', 'tags', 'link', 'order']; + protected $fillable = [ + 'name', + 'description', + 'status', + 'user_id', + 'tags', + 'link', + 'order', + 'group_id', + ]; + + /** + * Components can belong to a group. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function group() + { + return $this->belongsTo('CachetHQ\Cachet\Models\ComponentGroup', 'group_id', 'id'); + } /** * Lookup all of the incidents reported on the component. diff --git a/src/Models/ComponentGroup.php b/src/Models/ComponentGroup.php new file mode 100644 index 00000000..9fda4290 --- /dev/null +++ b/src/Models/ComponentGroup.php @@ -0,0 +1,45 @@ + 'required|unique:component_groups', + ]; + + /** + * The fillable properties. + * + * @var string[] + */ + protected $fillable = ['name']; + + /** + * A group can have many components. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function components() + { + return $this->hasMany('CachetHQ\Cachet\Models\Component', 'id', 'group_id'); + } +} From b671688ade8e72df704d9e50125217b6422e45be Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sun, 4 Jan 2015 20:57:18 +0000 Subject: [PATCH 2/2] Fixed StyleCI --- ...6_AlterTableComponentsAddGroupIdColumn.php | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php b/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php index 2dabefa7..48a3645a 100644 --- a/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php +++ b/app/database/migrations/2015_01_04_194246_AlterTableComponentsAddGroupIdColumn.php @@ -6,27 +6,27 @@ use Illuminate\Support\Facades\Schema; class AlterTableComponentsAddGroupIdColumn extends Migration { - /** - * Run the migrations. - * - * @return void - */ - public function up() - { - Schema::table('components', function(Blueprint $table) { - $table->integer('group_id')->nullable()->default(null)->after('order'); - }); - } + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('components', function (Blueprint $table) { + $table->integer('group_id')->nullable()->default(null)->after('order'); + }); + } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('components', function(Blueprint $table) { - $table->dropColumn('group_id'); - }); - } + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('components', function (Blueprint $table) { + $table->dropColumn('group_id'); + }); + } }