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:

Views display horror

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.

AttachmentSize
views-display-horror.png52.11 KB

#1

merlinofchaos - November 24, 2008 - 19:30

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

dereine - July 4, 2009 - 19:48
Version:6.x-2.x-dev» 6.x-3.x-dev

adding a tag and pumping to the new version

#3

superbaloo - September 2, 2009 - 17:30

subscribing

#4

superbaloo - September 3, 2009 - 09:04
Status:active» needs review

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 :)

AttachmentSize
views_reorder.patch 7.84 KB

#5

dereine - September 3, 2009 - 09:20

Thats quite strange, the patch does not apply to views 3.x

Here is a fix, also uses drupalalike patch format.

AttachmentSize
views_reorder.patch 8.17 KB

#6

superbaloo - September 3, 2009 - 09:27

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 :

  • cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-6--3 contributions/modules/views
  • code
  • cvs diff > file.patch

#7

dereine - September 3, 2009 - 10:00

Sure

cvs diff -up > file.patch

Quite easy.

#8

dereine - September 3, 2009 - 10:04

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

superbaloo - September 3, 2009 - 10:19

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

AttachmentSize
views_reorder.patch 8.99 KB

#10

superbaloo - September 3, 2009 - 17:42

Any update ?

#11

dereine - September 3, 2009 - 20:24

I don't understand your last point, oculd you please be more verbose ? :p

Basically switching the analyse button with your reorder button.

#12

superbaloo - September 3, 2009 - 20:48

Here it is :)

AttachmentSize
display-reorder.patch 9.02 KB

#13

superbaloo - September 4, 2009 - 07:46

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.

AttachmentSize
reorder-displays.patch 9.44 KB

#14

dereine - September 4, 2009 - 08:19

+++ 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

superbaloo - September 4, 2009 - 08:42

Deleted displays handling

AttachmentSize
reorder-displays.patch 9.81 KB

#16

superbaloo - September 4, 2009 - 08:51

Corrections with #14 comment

For the indent issue, what do you propose ?

i've no idea which one could be better :(

AttachmentSize
reorder-displays.patch 9.92 KB

#17

dereine - September 4, 2009 - 09:14

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

superbaloo - September 4, 2009 - 09:19

Deal

AttachmentSize
reorder-displays.patch 9.92 KB

#19

dereine - September 4, 2009 - 09:21

+++ 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

superbaloo - September 4, 2009 - 09:50

Humpf ... didn't generate the .patch ... that was the old one !

sorry for this

AttachmentSize
reorder-displays.patch 9.86 KB

#21

dereine - September 4, 2009 - 10:04

+++ 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

superbaloo - September 4, 2009 - 10:46

Here we go

AttachmentSize
reorder-displays.patch 9.84 KB

#23

superbaloo - September 4, 2009 - 13:12

Little css fix

AttachmentSize
reorder-displays.patch 10.52 KB

#24

merlinofchaos - September 21, 2009 - 22:17
Status:needs review» needs work

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

SeanBannister - September 22, 2009 - 12:00

Sub

#26

superbaloo - September 22, 2009 - 18:08

ok, i would test it as soon as i would get my dev server back ! :)

 
 

Drupal is a registered trademark of Dries Buytaert.