Allow displays to be re-ordered
webchick - November 24, 2008 - 19:14
| Project: | Views |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | views 3.x roadmap |
Description
See screenshot for wacky, wacky fun:

My initial thought was it'd be pretty straight-forward to just sort these in alphabetical order. Views that go together are often named in much the same way.
However, I asked Earl about this and he pointed out that auto-reordering becomes problematic because the order of these displays matters in the case where two displays have the same path.
So sounds like Views needs a mechanism to somehow manually control the order of displays. Earl says:
it probably wouldn't be that difficult to create a command that uses the drag & drop code to re-order displays. I wouldn't do it from the tabs themselves, that'd be gnarly.
Filing as a feature request.
| Attachment | Size |
|---|---|
| views-display-horror.png | 52.11 KB |

#1
The easiest solution would be on the 'default' view under view settings, have a "Displays: Reorder" link which brings up a tabledrag list of displays and resets all their positions.
It would have to be sure that the weight range starts at 1, since Views expects the positions to start at 1 and increment up.
#2
adding a tag and pumping to the new version
#3
subscribing
#4
I've done a little patch for this, here it is.
There is one last thing missing, i don't know how to make the browser refresh the page to display the new order after submission
I'm in the drupalcon, so if there is something wrong, that would be a pleasure to discuss about it :)
#5
Thats quite strange, the patch does not apply to views 3.x
Here is a fix, also uses drupalalike patch format.
#6
Oops sorry for this.
Could you please give me the process to make a patch in the "drupal way" ? :) I'm not too accustomed to cvs command :p
what i've done was :
#7
Sure
cvs diff -up > file.patchQuite easy.
#8
Some minor things.
+++ includes/admin.inc@@ -1820,6 +1821,209 @@ function views_ui_analyze_view_form_submit($form, &$form_state) {
+ */
+function _views_position_sort($a, $b) {
+ if ($a->position != $b->position) {
+ return $a->position < $b->position ? -1 : 1;
+ }
+
+ return 0;
+}
I don't like the naming of the variables. Why not use $display1 and $display2 or similiar.
What means return 0, why not FALSE.
This review is powered by Dreditor.
Why not change reorder with analyse, this seems to be more logically for me, because reorder belongs to the displays more then analyse.
#9
Here is with the display1 and display2 var name
and, i'm returning 0 because it's 0 in the http://fr.php.net/manual/en/function.uasort.php documentation :)
I don't understand your last point, oculd you please be more verbose ? :p
#10
Any update ?
#11
I don't understand your last point, oculd you please be more verbose ? :pBasically switching the analyse button with your reorder button.
#12
Here it is :)
#13
Here is an update to my last patch to refresh the page by ajax
I still have some html in the code (only one line) may i move it into a new theme function.
#14
+++ includes/admin.inc 4 Sep 2009 07:44:22 -0000@@ -1820,6 +1821,216 @@ function views_ui_analyze_view_form_subm
+ l('<span>' . t('Remove') . '</span>',
+ 'javascript:void()',
+ array(
+ 'attributes' => array(
+ 'id' => 'display-remove-link-' . $key,
+ 'class' => 'views-button-remove display-remove-link',
+ 'alt' => t('Remove this display'),
+ 'title' => t('Remove this display')),
+ 'html' => true));
MINOR. I don't like this i indent.
alt is not what links need.
+++ includes/admin.inc 4 Sep 2009 07:44:22 -0000@@ -1820,6 +1821,216 @@ function views_ui_analyze_view_form_subm
+ 'html' => true));
MINOR: TRUE instead of true
+++ includes/admin.inc 4 Sep 2009 07:44:22 -0000@@ -1820,6 +1821,216 @@ function views_ui_analyze_view_form_subm
+ $header = array('', t('Weight'), t('Remove'));
Why not having a header for the name. Perhaps this will also help the not so nice display of the header.
+++ js/base.js 4 Sep 2009 07:44:22 -0000@@ -25,6 +25,14 @@ Drupal.behaviors.viewsTabs = function (c
});
+ $('a.display-remove-link')
+ .addClass('display-processed')
+ .click(function() {
+ var id = $(this).attr('id').replace('display-remove-link-', '');
+ $('#display-row-' + id).hide();
+ $('#display-removed-' + id).attr('checked', true);
+ return false;
+ });
Can you explain why you are doing this. Perhaps a inline comment would be nice.
This review is powered by Dreditor.
#15
Deleted displays handling
#16
Corrections with #14 comment
For the indent issue, what do you propose ?
i've no idea which one could be better :(
#17
What about
<?php$row[] = drupal_render($form[$id]['removed']) .
l('<span>' . t('Remove') . '</span>',
'javascript:void()',
array(
'attributes' => array(
'id' => 'display-remove-link-' . $key,
'class' => 'views-button-remove display-remove-link',
'alt' => t('Remove this display'),
'title' => t('Remove this display')),
?>
#18
Deal
#19
+++ includes/admin.inc 4 Sep 2009 08:47:14 -0000@@ -1820,6 +1821,223 @@ function views_ui_analyze_view_form_subm
+ if (isset($display['removed'])) {
+ $row[] = drupal_render($form[$id]['removed']) .
+ l('<span>' . t('Remove') . '</span>',
+ 'javascript:void()',
+ array(
+ 'attributes' => array(
+ 'id' => 'display-remove-link-' . $key,
+ 'class' => 'views-button-remove display-remove-link',
+ 'alt' => t('Remove this display'),
+ 'title' => t('Remove this display')),
+ 'html' => TRUE));
Its still in.
I'm on crack. Are you, too?
#20
Humpf ... didn't generate the .patch ... that was the old one !
sorry for this
#21
+++ js/base.js 4 Sep 2009 09:49:29 -0000@@ -25,6 +25,16 @@ Drupal.behaviors.viewsTabs = function (c
+ * (checking in the hidden checkbox and hiding out the row) */
MINOR: make a line break for */
I would use perhaps just the second line as description
I'm on crack. Are you, too?
#22
Here we go
#23
Little css fix
#24
During testing, I had a view with 8 or 9 displays. I was playing around, removing, restoring, removing, restoring, reordering. When I was done, I hit save. All but 1 display got removed.
I tried to reproduce this and couldn't, so I'm not sure what triggered it.
#25
Sub
#26
ok, i would test it as soon as i would get my dev server back ! :)