I introduced the tablesorting capabilities to the content listing in admin/content/node.

While this is also a step to making Drupal 6 UI as consistent as possible, it is mainly a major usability improvement. I don't want to decide whether this is considered featureish or not. However, I'd be happy to see this in D6.

I didn't add a default sorting order, as we need to discuss this. Would be no problem though.
The enclosed patch has been tested to some extent and should work as advertised. Some more testing would be helpful anyway.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tonyn’s picture

Table sorting is useful in almost all instances I can think of, I surprised we haven't seen this sooner!

birdmanx35’s picture

Version: 6.x-dev » 7.x-dev
Category: task » feature

This patch applies cleanly. I am changing it to a feature request and 7.x; if you feel otherwise, feel free to change it.

tonyn’s picture

Version: 7.x-dev » 6.x-dev
FileSize
5.05 KB

Why does this have to wait until 7.0?

This patch uses a sorting method (tablesort.inc) that has been around since the stone age.

The interface looks identical. Multiple selection options works (stick, publish, unpublish, fp, demote fp, delete, etc). Filters work.

When no nodes are present:
warning: Invalid argument supplied for foreach() in ....drupal6/includes/theme.inc on line 1292.

theme.inc beginning with line 1292.

         foreach ($cells as $cell) {
          $cell = tablesort_cell($cell, $header, $ts, $i++);
          $output .= _theme_table_cell($cell);
        } 

This was fixed by changing $rows to $rows[] in node.admin.inc, on line 571 (after patched).

Testers?

birdmanx35’s picture

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

I'm changing this to 7.x-dev because it is a feature change. Feature changes go to 7.x-dev.

Also, AFAIK, this patch update no longer applies cleanly. I get this message:

$ patch -p0 < sortable_node_admin_nodes_1.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- node.admin.inc_original 2008-01-26 20:24:44.000000000 -0600
|+++ node.admin.inc 2008-01-26 21:06:47.000000000 -0600
--------------------------
File to patch:

That may just be my newbieness, however, this IS a 7.x-dev issue because it is a feature request, and feature requests go to 7.x-dev.

yched’s picture

Definitely for 7.x. D6 is now frozen, only bugfixes get in.

tonyn’s picture

I did something wrong.

The command I used was for the relative dir. I think, because it works for me. (

Macintosh:node tony$ patch < sortable_node_admin_nodes_1.patch node.admin.inc_original2
patching file node.admin.inc_original2

created using diff -up..

Does this one apply?

Pancho’s picture

Didn't apply anymore after heavy changes to node.admin.inc.
Refactored (including skiquels' correction) and rerolled against HEAD (D7).
Please test!

Pancho’s picture

Marked #132714 a duplicate of this. Though the other one is older, this one is more up to date.

Pasqualle’s picture

I did not tested, but as I see from the patch, you removed the default sort. Sorting by node.changed column is very useful, it should be there. Maybe adding column "last modification" would be a possible option.

Please add table name to field items like changing 'field' => 'title' to 'field' => 'n.title'. It should be useful when someone tries to rewrite this sql (db_rewrite_sql) with a table containing same column names.

-  // Enable language column if locale is enabled or if we have any node with language
-  $count = db_result(db_query("SELECT COUNT(*) FROM {node} n WHERE language != ''"));
-  $multilanguage = (module_exists('locale') || $count);

why is this part rewritten? I can't see any improvement on it.
and I still think that the language should be checked by translation module not locale module, but maybe I am wrong.

-  $form = node_filter_form();
-
-  $form['#theme'] = 'node_filter_form';
-  $form['admin']  = node_admin_nodes();
-
-  return $form;
+  else {
+    $form = node_filter_form();
+    $form['#theme'] = 'node_filter_form';
+    $form['admin'] = node_admin_nodes();
+    return $form;
+  }

this is also unnecessary, and I do not agree with using unnecessary else statements. Try to write a whole application without using else statements (like I did some years ago), and you will feel the difference. (no, I am not kidding, I really did, and it was a really big application. And I was not so confident with the stability of my code since then.)

I really like the way how you solved the header. I learned something new, thank you.

Pancho’s picture

Thank you very much for your valuable review!

  • Sorting by node.changed column and tablesorting has been a bit tricky: tablesort_sql() was allowing only for additional sorting before tablesorting, so I had to completely refactor it to allow for additional sorting after tablesorting as well (see: http://drupal.org/node/219454).
  • I added the table name to field items to allow db_rewrite_sql() to do its job. Good point.
  • You are right, we need to check for translation module and not locale module. This is also wrong in D6 core. I will create a new issue for that.
  • The initialization of the $multilanguage flag has been rewritten, because we don't need to perform the "SELECT COUNT" query if the translation module is active. In my new patch, I made it less verbose, though.
  • Concerning the unnessecary else-clause: I actually like being a little more verbose on that, but as that's just a personal bias, I removed it.

Note, that this patch now depends on and doesn't work without http://drupal.org/node/219454. Would be great if you helped me getting that one in early.

Some more testing would be cool now!

Pancho’s picture

Just a minor reroll with some codestyle and comment nitpicks...

Pancho’s picture

Some more nitpicking... :)

Pasqualle’s picture

an idea:
you can add header "Last modification" (or something similar), and do not show the column (only the header). This way the user can sort by it, and it does not take space from the table with showing the dates (n.changed).

Something like "Species", "Height", "Weight" headers on this page, just make it sortable.
http://www.star-fleet.com/webb/node/922?sort=asc&order=User
(i know the columns are there and they are empty. it seems as a good "visual" example for this now.)

catch’s picture

Category: feature » task
Status: Needs review » Needs work

Nice idea, but no longer applies.

deviantintegral’s picture

Status: Needs work » Needs review
FileSize
5.11 KB

I've updated the patch so it applies. I realized that as-is, there was no way to reset the sort back to the original order, as no 'Updated' column was being rendered. This patch adds that, and properly shows the default sort. This actually was a serious issue for a client of mine, as they couldn't figure out the default sorting of the list on their own. Unfortunately, it does make the table a little tighter, but I don't see a way around it.

Enjoy!

--Andrew

swentel’s picture

Nice, applies cleanly. Generated about 200 nodes having 3 content types. Being able to sort is a real enchancement!

(When this might get in, why not write a patch to be able to hook into node_filters?)

kscheirer’s picture

works for me, patch applied cleanly. I like the addition of the "Updated" column.

lilou’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applied.

Work great.

SocialNicheGuru’s picture

is this only for drupal 7+?

Chris

lilou’s picture

Yes, no new feature in stable version.

deviantintegral’s picture

FileSize
465.48 KB
437.97 KB

I agree this is RTBC. Here's a few screenshots for anyone reviewing this patch.

--Andrew

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This looks like a great improvement, and something we ought to probably back-port to Drupal 6 since all of the other table-like things work this way.

However.... needs updating to DBTNG. :(

Damien Tournoud’s picture

Status: Needs work » Needs review

That query is a db_rewrite_sql() one, which will be converted anyway when we will have replaced all db_rewrite_sql by hook_query_alter() (see http://drupal.org/node/299176). There is no need to rush the conversion, the query could stay that way for now.

webchick’s picture

Status: Needs review » Fixed

Cool, thanks Damien.

This patch one of those obvious "duh" usability things that must've somehow been overlooked over the years. It also makes the node screen consistent with the comment and user admin screens.

I clicked through a bunch of stuff manually since we don't yet have tests for node.admin.inc, and things seem to work. Node tests we do have all passed. Code looks good, so committed. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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