Download & Extend

reverse in admin view breaks drag-n-drop ordering

Project:Nodequeue
Version:6.x-2.x-dev
Component:User interface
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

In #234004: Drag and drop node ordering the drag and drop user interface to reorder items in a queue was fixed. This indeed works ok for your average queue. If you switch on 'reverse in admin view' to have the nodes enter on top and leave from the bottom of the queue, the dag and drop sorting messes up the order of the queue.

I installed nodequeue-6.x-2.x-dev on a fresh 6.14 install.
Created a couple of nodes.
created a nodequeue and added 4 nodes to it.

mysql> select * from nodequeue_nodes where qid=1 order by position;
+-----+------+------+----------+------------+
| qid | sqid | nid  | position | timestamp  |
+-----+------+------+----------+------------+
|   1 |    1 |    1 |        1 | 1254856996 |
|   1 |    1 |    2 |        2 | 1254856996 |
|   1 |    1 |    3 |        3 | 1254856996 |
|   1 |    1 |    4 |        4 | 1254856996 |
+-----+------+------+----------+------------+
4 rows in set (0.00 sec)

Now switch on 'reverse in admin view'
Go to the nodequeue edit screen /admin/content/nodequeueq/1/view
Node 4 is show on top of the queue, followed by 3, 2 and node 1 at the bottom
Now drag node 4 to the bottom of the list and save.
I would expect the result to be node 3, 2, 1, 4
However, the result is node 4, 1, 2, 3
In the database:

mysql> select * from nodequeue_nodes where qid=1 order by position;
+-----+------+------+----------+------------+
| qid | sqid | nid  | position | timestamp  |
+-----+------+------+----------+------------+
|   1 |    1 |    3 |        1 | 1254857039 |
|   1 |    1 |    2 |        2 | 1254857039 |
|   1 |    1 |    1 |        3 | 1254857039 |
|   1 |    1 |    4 |        4 | 1254857039 |
+-----+------+------+----------+------------+
4 rows in set (0.00 sec)

Looks like the reversed view is being stored as the desired order.

Comments

#1

Thanks for taking the time to do this on a fresh install and for the clear error report. I marked http://drupal.org/node/576380 as a duplicate of this.

Indeed, we'll want to fix this, keeping in mind both the javascript and degradable functionality. We probably want to check whether the save button or the reverse button was clicked when the form is being submitted, and then perform an additional (server-side) reverse of the queue order before sending it to nodequeue_save_subqueue_order.

#2

I just ran into this a couple of minutes ago. I created a video to show what is hapening on my system after checking "Reverse in admin view"

http://screencast.com/t/yVh5FtbUS

Regards, Tom

#3

Glad to see this already being worked on. Discovered the same thing. Fairly simple to work around if you understand what is happening but users are easily confused.

#4

Actually, I think I was mistaken about how this can be fixed. It seems like we'll need to do two things:
1) For non-JS users, In theme_nodequeue_arrange_subqueue_form() the table should sort on subqueue position ascending, if the queue is reversed.
2) We'll want to update the displayed position value for JS users probably by modifying Drupal.behaviors.nodequeueReverse .

#5

I just discovered this bug as well. The only way to prevent my nodequeues from reversing their order constantly was to turn off "reserve in admin."

Seeing as though that feature is basically broken, shouldn't this be marked critical?

#6

I noticed this behaviour as well, any new ideas?

#7

Priority:normal» critical

#8

This might be a special case where there are just 2 nodes in a queue, but drag and drop ordering on my queue has no effect on the DB at all.
When I remove the 'reverse in admin' setting things work as expected.

#9

Thats probably because there are 2 nodes. I can reproduce the problem on my part

#10

Version:7.x-2.x-dev» 6.x-2.5
Status:active» needs review

I patched this module and it fixed the problem for me. However, I'm not sure it's the best way to fix it. Essentially what it does is check for the reverse in admin option and if that is ticked, it reverses the subqueue just prior to the delete and re-insertion in the nodequeue_save_subqueue_order hook. I'll attach the patch here. It needs review.

AttachmentSizeStatusTest resultOperations
597498-10.patch804 bytesIgnored: Check issue status.NoneNone

#11

Hi,

I tested the patch submited above, it works fine for me.

And I have a real need for this feature, so please approve !

Thanks all for the good work.

#12

Status:needs review» reviewed & tested by the community

The patch in #10 works for us, too.

#13

works, thx

#14

Hi.

This works for me except that if I hit the Save button without doing any rearranging, then the order is reversed. I realize that there is no reason to hit save if I haven't rearranged the queue but regular-every-day-users might think that when they add something to the queue they must hit Save. If they do, the queue gets reversed for no apparent reason. This is very confusing for regular non-developer people and is a serious usability issue.

Using this patch is better than not using it, don't get me wrong. I appreciate the patch but it still only solves half the problem.

#15

Status:reviewed & tested by the community» needs work

einkahumor.com, you are right: clicking save without doing anything else reverses the nodequeue.

#16

Anyone had any luck to get the bug fixed when you click save without doing any rearranging?

#17

Curious if the maintainer has any interest in fixing this feature? I feel like if it doesn't get fixed soon, I'll submit a patch to remove this functionality entirely. I've now had a client select this feature and the wonder why their site was not functioning properly.

#18

Subscribe

#19

I've made a small addition to axlroach patch, which seems to solve the problem of the queue being reversed when hitting save without doing any rearranging.
Approach is pretty simple. It just checks if the positions have been changed, then only reverses the nodes if positions have changed.

$current_nodes = _nodequeue_dragdrop_get_nodes($queue, $subqueue);
$old_positions = array();

foreach($current_nodes as $node) {
$old_positions[$node->position] = $node->nid;
}

if ($queue->reverse == 1 && $nodes != $old_positions) {
$reverse_nodes = array();
$p = array_keys($nodes);
$v = array_values($nodes);
$v = array_reverse($v);
foreach ($v as $key => $value) {
$reverse_nodes[$p[$key]] = $value;
}
$nodes = $reverse_nodes;
}

#20

@mortenq: Could you post your updated patch?

#21

@Einkahumor: I don't know how to make a patch file.

There still seems to be a few bugs. If there are only 2 nodes in a queue the rearranging is failing, 3 nodes are fine though.
And if you remove a node from the queue and hit save, it reversed the queue.
So code really still needs work.

#22

Subscribing...

#23

Version:6.x-2.5» 6.x-2.9

@mortenq: http://drupal.org/patch/create

We are also seeing this bug, using the latest stable release.

This is definitely a critical bug. If you want to reverse the normal behaviour of nodequeues, that is, if you want the added node to be added on position one, and push the last one out, you need to enable "Reverse in admin view". So currently there is no way of doing this without opening the door to this bug.

#24

Same problem. I'd like to second what Manuel Garcia said in #23.

#25

Status:needs work» needs review

Here is #19's addition to number #10's patch in one patch file.

Works in my test but as to the best method to use I cannot say.

AttachmentSizeStatusTest resultOperations
reversebreak.patch1012 bytesIgnored: Check issue status.NoneNone

#26

it seems to work for all cases but breaks when removing an iteam. When removing it reverses the queue just like what simple moving was doing.

#27

this patch works for me, but there's still issues with 2 items in a queue, not sure why, but doesn't seem to be because of this patch

AttachmentSizeStatusTest resultOperations
reversebreak.patch1.03 KBIgnored: Check issue status.NoneNone

#28

Currently, when using the "reverse" option, the order is reversed and the items are also renumbered in the display. This makes for confusing interplay with Views (choosing ASC or DESC). Would it make more sense to reverse the display order but keep the numbering the same as in the DB--would that also simplify some of the code involved?

#29

I am using node queue with content slider, may you guide me how I could resolve the above issue?

#30

Resolved the remaining issue from #27, i. e. 2 items in a nodequeue are not repositioned. We have to do an exact match, i. e. $nodes !== $old_positions, of the new and old array in the if clause. When having arrays like:

array(1 => "A", 2 => "B");
array(2 => "B", 1 => "A");

They are not recognized as being different when only using the "!=" operator.

AttachmentSizeStatusTest resultOperations
nodequeue_reversebreak_GN.patch1.33 KBIgnored: Check issue status.NoneNone

#31

Status:needs review» needs work

Thanks! #30 seems to work, though it has some formatting issues:

-- there should be no tabs or trailing spaces
-- the inline comment should explain the code, rather than linking to this issue
-- the patch should apply to the nodequeue directory, rather than sites/all/modules...

#32

Comment #30 doesn't solve the issue entirely. When using "Reverse" or "Shuffle" button the nodequeue is reversed again.

So I discovered the problem is on the JavaScript side rather than on the server side. Node positions are updated on action that hasn't been done for simple drag/drop actions yet. This patch updates node position for this action as well.

AttachmentSizeStatusTest resultOperations
nodequeue_drag.patch2.06 KBIgnored: Check issue status.NoneNone

#33

Status:needs work» needs review

Change status

#34

I just tested briefly the #32 patch and it works. Thanks a lot for your work.

#35

Version:6.x-2.9» 7.x-2.x-dev

After a quick review of #32 on the July 11 dev, everything appears to be working great. Awesome work!

We probably need a few more eyes on it, but it looks like we're finally at a solution.

#36

I tried #32 patch too and it works. Thanks.

#37

I am running 6.x-2.9 of nodequeue. I have applied the patches provided in #32 and #30, but the problem still persists.

#38

I'm pretty sure you need to get the 6.x-2.x-dev version and apply the patch in #32 to that.

#39

OK, I installed 6.x-2.x-dev, applied patches #30 and #32 to that, and it did not fix the behavior.

#40

I just tried it on a fresh 6.17 install. I downloaded the newest 6.x-2.x-dev, applied ONLY the patch in #32 and it works perfectly. Can you tell us a little more about your installation?

#41

I just tried applying both #30 and #32 and indeed that doesn't work. You should ONLY use the patch from #32. Please try that out and tell us if it works.

#42

Yes! Applying just patch #32 did indeed fix the problem. Thank you!!!!!

#43

RTBC?

#44

Status:needs review» reviewed & tested by the community

#45

This worked for me - great work. Thanks.

#46

This works great.

#47

Status:reviewed & tested by the community» fixed

I tested the patch in #32 with JavaScript enabled and disabled with a queue set to reverse in admin view and without that option enabled. This looks good and is now committed. Thanks, @gnindl! http://drupal.org/cvs?commit=420666

Thanks also to folks who took the time to review this patch. A bit of feedback on reviewing patches: It's helpful to the maintainer and might get your issue fixed quicker if you specify how you tested, in addition to saying that "it works." In this case, it would have been particularly helpful for folks to report whether they had their queues set to be reversed, and whether they tested with JS enabled :).

#48

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#49

Version:7.x-2.x-dev» 6.x-2.x-dev

#50

If this was fixed over four months ago, could we have a new release of the module please?

#51

Question #1: which version is this supposed to be for 7.x or 6.x (why was it changed to 6.x )
Question #2: the above still doesn't work in 7.x for me, any body else has this problem? The problem is that every time I move one nodequeue item in the nodequeue order, and click save, the nodequeue becomes reversed. It happens every time. It looks as though the reverse in admin view, is applied every time you hit save.

#52

This is a 6.x patch

#53

Status:closed (fixed)» active

This bug still exists in 6.x-2.11 and 6.x-2.x-dev. I tried the #32 patch on the latter. Three out of four hunks failed. Maybe the dev version has changed such that the patch no longer works?

#54

Status:active» closed (fixed)

Sorry, I'm changing this back to closed again because I'm no longer sure if I'm seeing a bug or if I just misunderstood the UI. If I check the box for "reverse in admin view" then the order is the same in the admin view as it is on the front end. I don't know if that's the intended behavior or not, but it's at least consistent.

I'm now using 6.x-2.x-dev without the patch, and checking the box for "reverse in admin view". That gives me the behavior I want, in any case.

Thx

nobody click here