mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-18 05:58:18 +01:00
Merge pull request #650 from cachethq/order-component-groups
Allows ordering of component groups
This commit is contained in:
commit
8e06f6241b
@ -15,6 +15,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||||
use Exception;
|
use Exception;
|
||||||
use GrahamCampbell\Binput\Facades\Binput;
|
use GrahamCampbell\Binput\Facades\Binput;
|
||||||
@ -56,6 +57,23 @@ class ApiController extends AbstractController
|
|||||||
return $componentData;
|
return $componentData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the order of component groups.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function postUpdateComponentGroupOrder()
|
||||||
|
{
|
||||||
|
$groupData = Binput::all();
|
||||||
|
foreach ($groupData['ids'] as $order => $groupId) {
|
||||||
|
ComponentGroup::find($groupId)->update([
|
||||||
|
'order' => $order + 1,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groupData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a template by slug.
|
* Returns a template by slug.
|
||||||
*
|
*
|
||||||
|
@ -78,7 +78,7 @@ class ComponentController extends AbstractController
|
|||||||
|
|
||||||
return View::make('dashboard.components.groups.index')->with([
|
return View::make('dashboard.components.groups.index')->with([
|
||||||
'pageTitle' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
|
'pageTitle' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
|
||||||
'groups' => ComponentGroup::all(),
|
'groups' => ComponentGroup::orderBy('order')->get(),
|
||||||
'subMenu' => $this->subMenu,
|
'subMenu' => $this->subMenu,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ class HomeController extends AbstractController
|
|||||||
|
|
||||||
// Component & Component Group lists.
|
// Component & Component Group lists.
|
||||||
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
||||||
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->get();
|
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
|
||||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||||
|
|
||||||
$canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
|
$canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
|
||||||
|
@ -201,6 +201,7 @@ class AdminRoutes
|
|||||||
// This should only be used for making requests within the dashboard.
|
// This should only be used for making requests within the dashboard.
|
||||||
$router->group(['prefix' => 'api'], function ($router) {
|
$router->group(['prefix' => 'api'], function ($router) {
|
||||||
$router->get('incidents/templates', 'ApiController@getIncidentTemplate');
|
$router->get('incidents/templates', 'ApiController@getIncidentTemplate');
|
||||||
|
$router->post('components/groups/order', 'ApiController@postUpdateComponentGroupOrder');
|
||||||
$router->post('components/order', 'ApiController@postUpdateComponentOrder');
|
$router->post('components/order', 'ApiController@postUpdateComponentOrder');
|
||||||
$router->post('components/{component}', 'ApiController@postUpdateComponent');
|
$router->post('components/{component}', 'ApiController@postUpdateComponent');
|
||||||
});
|
});
|
||||||
|
@ -19,6 +19,7 @@ use Watson\Validating\ValidatingTrait;
|
|||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
|
* @property int $order
|
||||||
* @property \Carbon\Carbon $created_at
|
* @property \Carbon\Carbon $created_at
|
||||||
* @property \Carbon\Carbon $updated_at
|
* @property \Carbon\Carbon $updated_at
|
||||||
* @property \Carbon\Carbon $deleted_at
|
* @property \Carbon\Carbon $deleted_at
|
||||||
@ -41,7 +42,7 @@ class ComponentGroup extends Model
|
|||||||
*
|
*
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['name'];
|
protected $fillable = ['name', 'order'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A group can have many components.
|
* A group can have many components.
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) James Brooks <james@cachethq.io>
|
||||||
|
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
|
||||||
|
* (c) Graham Campbell <graham@mineuk.com>
|
||||||
|
*
|
||||||
|
* 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 AlterTableComponentGroupsAddOrder extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('component_groups', function (Blueprint $table) {
|
||||||
|
$table->integer('order')->after('name');
|
||||||
|
$table->index('order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('component_groups', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('order');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
17
public/build/dist/js/all-030dc0bd.js
vendored
17
public/build/dist/js/all-030dc0bd.js
vendored
File diff suppressed because one or more lines are too long
14
public/build/dist/js/all-495fb41f.js
vendored
Normal file
14
public/build/dist/js/all-495fb41f.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"dist/css/all.css": "dist/css/all-85d5201e.css",
|
"dist/css/all.css": "dist/css/all-11e30ad0.css",
|
||||||
"dist/js/all.js": "dist/js/all-030dc0bd.js"
|
"dist/js/all.js": "dist/js/all-495fb41f.js"
|
||||||
}
|
}
|
@ -167,6 +167,32 @@ $(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sortable Component Groups
|
||||||
|
var componentGroupList = document.getElementById("component-group-list");
|
||||||
|
if (componentGroupList) {
|
||||||
|
new Sortable(componentGroupList, {
|
||||||
|
group: "omega",
|
||||||
|
handle: ".drag-handle",
|
||||||
|
onUpdate: function() {
|
||||||
|
var orderedComponentGroupsIds = $.map(
|
||||||
|
$('#component-group-list .striped-list-item'),
|
||||||
|
function(elem) {
|
||||||
|
return $(elem).data('group-id');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$.ajax({
|
||||||
|
async: true,
|
||||||
|
url: '/dashboard/api/components/groups/order',
|
||||||
|
type: 'POST',
|
||||||
|
data: {ids: orderedComponentGroupsIds},
|
||||||
|
success: function() {
|
||||||
|
(new CachetHQ.Notifier()).notify('Component groups order has been updated.', 'success');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle inline component statuses.
|
// Toggle inline component statuses.
|
||||||
$('form.component-inline').on('click', 'input[type=radio]', function() {
|
$('form.component-inline').on('click', 'input[type=radio]', function() {
|
||||||
var $form = $(this).parents('form');
|
var $form = $(this).parents('form');
|
||||||
|
@ -16,11 +16,17 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 striped-list">
|
<div class="col-sm-12 striped-list" id="component-group-list">
|
||||||
@forelse($groups as $group)
|
@forelse($groups as $group)
|
||||||
<div class="row striped-list-item">
|
<div class="row striped-list-item" data-group-id="{{ $group->id }}">
|
||||||
<div class="col-xs-6">
|
<div class="col-xs-6">
|
||||||
<strong>{{ $group->name }}</strong> <span class="label label-info">{{ $group->components->count() }}</span>
|
<h4>
|
||||||
|
@if($groups->count() > 1)
|
||||||
|
<span class="drag-handle"><i class="ion-drag"></i></span>
|
||||||
|
@endif
|
||||||
|
{{ $group->name }}
|
||||||
|
<span class="label label-info">{{ $group->components->count() }}</span>
|
||||||
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-6 text-right">
|
<div class="col-xs-6 text-right">
|
||||||
<a href="{{ route('dashboard.components.groups.edit', [$group->id]) }}" class="btn btn-default">{{ trans('forms.edit') }}</a>
|
<a href="{{ route('dashboard.components.groups.edit', [$group->id]) }}" class="btn btn-default">{{ trans('forms.edit') }}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user