Merge pull request #197 from cachethq/component-groups
[WIP] Component Groups
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateComponentGroupsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('component_groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('component_groups');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
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');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('components', function (Blueprint $table) {
|
||||
$table->dropColumn('group_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
|
||||
@@ -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');
|
||||
|
||||
37
app/views/dashboard/components/add-group.blade.php
Normal file
37
app/views/dashboard/components/add-group.blade.php
Normal file
@@ -0,0 +1,37 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<span class="uppercase">
|
||||
<i class="icons ion-ios-keypad"></i> {{ trans('cachet.dashboard.components') }}
|
||||
</span>
|
||||
> <small>Create a component group</small>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
@if($group = Session::get('group'))
|
||||
<div class='alert alert-{{ $group->isValid() ? "success" : "danger" }}'>
|
||||
@if($group->isValid())
|
||||
<strong>Awesome.</strong> Component group created.
|
||||
@else
|
||||
<strong>Whoops.</strong> Something went wrong with the group. {{ $group->getErrors() }}
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form name='CreateComponentGroupForm' class='form-vertical' role='form' action='/dashboard/components/groups/add' method='POST'>
|
||||
<fieldset>
|
||||
<div class='form-group'>
|
||||
<label for='incident-name'>Name</label>
|
||||
<input type='text' class='form-control' name='group[name]' id='group-name' required />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
<a class="btn btn-default" href="{{ route('dashboard.components.groups') }}">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
@@ -38,6 +38,15 @@
|
||||
<label>Description</label>
|
||||
<textarea name='component[description]' class='form-control' rows='5'></textarea>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label>Group</label>
|
||||
<select name='component[group_id]' class='form-control'>
|
||||
<option selected></option>
|
||||
@foreach($groups as $group)
|
||||
<option value='{{ $group->id }}'>{{ $group->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<hr />
|
||||
<div class='form-group'>
|
||||
<label>Link</label>
|
||||
|
||||
@@ -38,6 +38,15 @@
|
||||
<label>Description</label>
|
||||
<textarea name='component[description]' class='form-control' rows='5'>{{ $component->description }}</textarea>
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label>Group</label>
|
||||
<select name='component[group_id]' class='form-control'>
|
||||
<option {{ $component->group_id === null ? "selected" : null }}></option>
|
||||
@foreach($groups as $group)
|
||||
<option value='{{ $group->id }}' {{ $component->group_id === $group->id ? "selected" : null }}>{{ $group->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<hr />
|
||||
<div class='form-group'>
|
||||
<label>Link</label>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header fixed">
|
||||
@if(isset($subMenu))
|
||||
@include('partials.dashboard.sub-sidebar')
|
||||
@endif
|
||||
<div class='content-panel'>
|
||||
<div class="header">
|
||||
<span class="uppercase">
|
||||
<i class="icons ion-ios-keypad"></i> {{ trans('cachet.dashboard.components') }}
|
||||
</span>
|
||||
@@ -40,4 +44,5 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
|
||||
36
app/views/dashboard/groups.blade.php
Normal file
36
app/views/dashboard/groups.blade.php
Normal file
@@ -0,0 +1,36 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
@if(isset($subMenu))
|
||||
@include('partials.dashboard.sub-sidebar')
|
||||
@endif
|
||||
<div class='content-panel'>
|
||||
<div class="header">
|
||||
<span class="uppercase">
|
||||
<i class="icons ion-ios-keypad"></i> {{ trans('cachet.dashboard.component-groups') }}
|
||||
</span>
|
||||
<a class="btn btn-sm btn-success pull-right" href="{{ route('dashboard.components.groups.add') }}">
|
||||
{{ trans('cachet.dashboard.component-groups-add') }}
|
||||
</a>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 striped-list">
|
||||
@forelse($groups as $group)
|
||||
<div class='row striped-list-item'>
|
||||
<div class='col-md-8'>
|
||||
<strong>{{ $group->name }}</strong>
|
||||
</div>
|
||||
<div class='col-md-4 text-right'>
|
||||
<a href='#' class='btn btn-default'>Edit</a>
|
||||
<a href='#' class='btn btn-danger'>Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class='list-group-item text-danger'>You should add a component.</div>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
45
src/Models/ComponentGroup.php
Normal file
45
src/Models/ComponentGroup.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingTrait;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $component_id
|
||||
* @property int $group_id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
*/
|
||||
class ComponentGroup extends Model
|
||||
{
|
||||
use SoftDeletingTrait, ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The validation rules.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rules = [
|
||||
'name' => '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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user