Use APC cache for Docker and fix bug with changing component sort order

By default, the file cache is used, but this breaks the throttling detection when authenticating.
The APC cache is tagged and will allow you to log in again after installation.
---
When changing the sort order, a form with hidden inputs for every component was serialized. The hidden inputs
had names in the form of `component[id]`. When you removed components, there would be holes in this ID sequence,
yielding a serialized array with empty values (since JS arrays always have every index until the highest one, even
if you don't specify a value).

This is fixed by just passing an array of component IDs in the desired sort order to the API endpoint. The API
will then update the components based on the implicit given sort order. Much simpler.
This commit is contained in:
EdeMeijer 2015-04-21 17:35:01 +02:00 committed by Ede Meijer
parent dda8917db0
commit c4c55a73cb
7 changed files with 55 additions and 54 deletions

View File

@ -46,11 +46,9 @@ class ApiController extends AbstractController
public function postUpdateComponentOrder()
{
$componentData = Binput::all();
unset($componentData['component'][0]); // Remove random 0 index.
foreach ($componentData['component'] as $componentId => $order) {
foreach ($componentData['ids'] as $order => $componentId) {
$component = Component::find($componentId);
$component->update(['order' => $order]);
$component->update(['order' => $order + 1]); // Ordering should be 1-based, data comes in 0-based
}
return $componentData;

View File

@ -18,6 +18,7 @@ env[DB_HOST] = $DB_HOST
env[DB_DATABASE] = $DB_DATABASE
env[DB_USERNAME] = $DB_USERNAME
env[DB_PASSWORD] = $DB_PASSWORD
env[CACHE_DRIVER] = apc
[global]

File diff suppressed because one or more lines are too long

21
public/build/dist/js/all-73562b00.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"dist/css/all.css": "dist/css/all-9e808a49.css",
"dist/js/all.js": "dist/js/all-1ee9c181.js"
"dist/js/all.js": "dist/js/all-73562b00.js"
}

View File

@ -133,19 +133,17 @@ $(function() {
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.
var orderedComponentIds = $.map(
$('#component-list .striped-list-item'),
function(elem) {
return $(elem).data('component-id');
}
);
$.ajax({
async: true,
url: '/dashboard/api/components/order',
type: 'POST',
data: $('form[name=componentList]').serializeObject(),
data: {ids: orderedComponentIds},
success: function() {
(new CachetHQ.Notifier()).notify('Components updated.', 'success');
}

View File

@ -16,35 +16,32 @@
<div class="clearfix"></div>
</div>
<div class="row">
<form name="componentList">
<div class="col-sm-12 striped-list" id="component-list">
@forelse($components as $component)
<div class="row striped-list-item">
<div class="col-xs-6">
<h4>
@if($components->count() > 1)
<span class="drag-handle"><i class="ion-drag"></i></span>
@endif
{{ $component->name }} <small>{{ $component->humanStatus }}</small>
</h4>
@if($component->group)
<p><small>{{ trans('dashboard.components.listed_group', ['name' => $component->group->name]) }}</small></p>
<div class="col-sm-12 striped-list" id="component-list">
@forelse($components as $component)
<div class="row striped-list-item" data-component-id="{{ $component->id }}">
<div class="col-xs-6">
<h4>
@if($components->count() > 1)
<span class="drag-handle"><i class="ion-drag"></i></span>
@endif
@if($component->description)
<p>{{ $component->description }}</p>
@endif
</div>
<div class="col-xs-6 text-right">
<a href="/dashboard/components/{{ $component->id }}/edit" class="btn btn-default">{{ trans('forms.edit') }}</a>
<a href="/dashboard/components/{{ $component->id }}/delete" class="btn btn-danger confirm-action" data-method="DELETE">{{ trans('forms.delete') }}</a>
</div>
<input type="hidden" rel="order" name="component[{{ $component->id }}]" value="{{ $component->order }}">
{{ $component->name }} <small>{{ $component->humanStatus }}</small>
</h4>
@if($component->group)
<p><small>{{ trans('dashboard.components.listed_group', ['name' => $component->group->name]) }}</small></p>
@endif
@if($component->description)
<p>{{ $component->description }}</p>
@endif
</div>
<div class="col-xs-6 text-right">
<a href="/dashboard/components/{{ $component->id }}/edit" class="btn btn-default">{{ trans('forms.edit') }}</a>
<a href="/dashboard/components/{{ $component->id }}/delete" class="btn btn-danger confirm-action" data-method="DELETE">{{ trans('forms.delete') }}</a>
</div>
@empty
<div class="list-group-item text-danger">{{ trans('dashboard.components.add.message') }}</div>
@endforelse
</div>
</form>
@empty
<div class="list-group-item text-danger">{{ trans('dashboard.components.add.message') }}</div>
@endforelse
</div>
</div>
</div>
</div>