Components can now be re-ordered, closes #165

This commit is contained in:
James Brooks
2015-01-01 13:37:47 +00:00
parent 925818320c
commit 6ab16f98ab
17 changed files with 35878 additions and 44 deletions
+26
View File
@@ -69,6 +69,32 @@ $(function() {
$(this).parents('div.alert').addClass('hide'); $(this).parents('div.alert').addClass('hide');
}); });
// Sortable components.
var componentList = document.getElementById("component-list");
new Sortable(componentList, {
group: "omega",
handle: ".drag-handle",
onUpdate: function() {
// Loop each component, setting the order input to the new order.
var $components = $('#component-list .striped-list-item');
$.each($components, function(id) {
// Order should start from 1 now.
$(this).find('input[rel=order]').val(id + 1);
});
// Now POST the form to the internal API.
$.ajax({
async: true,
url: '/dashboard/api/components/order',
type: 'POST',
data: $('form[name=componentList]').serializeObject(),
success: function() {
(new CachetHQ.Notifier).notify('Components 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');
+15
View File
@@ -19,4 +19,19 @@ class DashAPIController extends Controller
App::abort(500); App::abort(500);
} }
} }
public function postUpdateComponentOrder()
{
$componentData = Input::all();
unset($componentData['component'][0]); // Remove random 0 index.
foreach ($componentData['component'] as $componentId => $order) {
$component = Component::find($componentId);
$component->update([
'order' => $order
]);
}
return $componentData;
}
} }
+1 -1
View File
@@ -9,7 +9,7 @@ class DashComponentController extends Controller
*/ */
public function showComponents() public function showComponents()
{ {
$components = Component::all(); $components = Component::orderBy('order')->orderBy('created_at')->get();
return View::make('dashboard.components.index')->with([ return View::make('dashboard.components.index')->with([
'pageTitle' => 'Components - Dashboard', 'pageTitle' => 'Components - Dashboard',
+3 -1
View File
@@ -28,8 +28,10 @@ class HomeController extends Controller
*/ */
public function showIndex() public function showIndex()
{ {
$components = Component::orderBy('order')->orderBy('created_at')->get();
return View::make('index', [ return View::make('index', [
'components' => $this->component->all(), 'components' => $components,
'pageTitle' => Setting::get('app_name') 'pageTitle' => Setting::get('app_name')
]); ]);
} }
@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTableComponentsAddOrderColumn extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('components', function(Blueprint $table)
{
$table->tinyInteger('order')->default(0)->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('components', function(Blueprint $table)
{
$table->dropColumn('order');
});
}
}
+1
View File
@@ -21,6 +21,7 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable
'user_id', 'user_id',
'tags', 'tags',
'link', 'link',
'order'
]; ];
/** /**
+1
View File
@@ -40,6 +40,7 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function () {
// Internal API. // Internal API.
// This should only be used for making requests within the dashboard. // This should only be used for making requests within the dashboard.
Route::group(['prefix' => 'api'], function () { Route::group(['prefix' => 'api'], function () {
Route::post('components/order', 'DashAPIController@postUpdateComponentOrder');
Route::post('components/{component}', 'DashAPIController@postUpdateComponent'); Route::post('components/{component}', 'DashAPIController@postUpdateComponent');
}); });
}); });
+19 -16
View File
@@ -12,24 +12,27 @@
</div> </div>
<div class="content-wrapper"> <div class="content-wrapper">
<div class="row"> <div class="row">
<div class="col-sm-12 striped-list"> <form name='componentList'>
@forelse($components as $component) <div class="col-sm-12 striped-list" id='component-list'>
<div class='row striped-list-item'> @forelse($components as $component)
<div class='col-md-8'> <div class='row striped-list-item'>
<strong>{{ $component->name }}</strong> <small>{{ $component->humanStatus }}</small> <div class='col-md-8'>
@if($component->description) <h4><span class='drag-handle'><i class='ion-drag'></i></span> {{ $component->name }} <small>{{ $component->humanStatus }}</small></h4>
<p><small>{{ $component->description }}</small></p> @if($component->description)
@endif <p><small>{{ $component->description }}</small></p>
</div> @endif
<div class='col-md-4 text-right'> </div>
<a href='/dashboard/components/{{ $component->id }}/edit' class='btn btn-default'>Edit</a> <div class='col-md-4 text-right'>
<a href='/dashboard/components/{{ $component->id }}/delete' class='btn btn-danger'>Delete</a> <a href='/dashboard/components/{{ $component->id }}/edit' class='btn btn-default'>Edit</a>
<a href='/dashboard/components/{{ $component->id }}/delete' class='btn btn-danger'>Delete</a>
</div>
<input type='hidden' rel='order' name='component[{{ $component->id }}]' value='{{ $component->order }}' />
</div> </div>
@empty
<div class='list-group-item text-danger'>You should add a component.</div>
@endforelse
</div> </div>
@empty </form>
<div class='list-group-item text-danger'>You should add a component.</div>
@endforelse
</div>
</div> </div>
</div> </div>
@stop @stop
+1
View File
@@ -1,6 +1,7 @@
{ {
"name": "Cachet", "name": "Cachet",
"dependencies": { "dependencies": {
"Sortable": "1.0.0",
"bootstrap-sass-official": "3.3.*", "bootstrap-sass-official": "3.3.*",
"jquery": "~2.1.1", "jquery": "~2.1.1",
"chartjs": "0.2.*", "chartjs": "0.2.*",
+1
View File
@@ -39,6 +39,7 @@ elixir(function (mix) {
'bower_components/lodash/dist/lodash.js', 'bower_components/lodash/dist/lodash.js',
'bower_components/messenger/build/js/messenger.js', 'bower_components/messenger/build/js/messenger.js',
// 'bower_components/chartjs/Chart.min.js', // 'bower_components/chartjs/Chart.min.js',
'bower_components/Sortable/Sortable.js',
'bower_components/jquery-minicolors/jquery.minicolors.js', 'bower_components/jquery-minicolors/jquery.minicolors.js',
'bower_components/jquery-serialize-object/jquery.serialize-object.js', 'bower_components/jquery-serialize-object/jquery.serialize-object.js',
'js/app.js', 'js/app.js',
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5404 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+12478 -6
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,4 +1,4 @@
{ {
"css/all.css": "css/all-84f50550.css", "css/all.css": "css/all-c5b65085.css",
"js/all.js": "js/all-b4f68abf.js" "js/all.js": "js/all-337c2216.js"
} }