You are here: Foswiki>Tasks Web>Item13910 (25 Sep 2016, GeorgeClark)Edit Attach

Item13910: TreePlugin wrong sorting

pencil
Priority: Normal
Current State: Confirmed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: TreePlugin
Branches:
Reported By: JozefMojzis
Waiting For:
Last Change By: GeorgeClark

Repo

  • Install TreePlugin
  • Create few unicode named topics
  • the WebTopicList shows correct sorting
  • the TREEVIEW macro wrong
  • screenshots attached
  • look at 4 character topic names..
screenshot - WebIndex - ok sort:
screenshot 11.png
TREEVIEW screenshot - wrong sort:
screenshot 12.png

-- JozefMojzis - 03 Jan 2016

Needs the same fix used for other sort code (not tested).
diff --git a/lib/Foswiki/Plugins/TreePlugin.pm b/lib/Foswiki/Plugins/TreePlugin.pm
index 43d52de..53e157d 100644
--- a/lib/Foswiki/Plugins/TreePlugin.pm
+++ b/lib/Foswiki/Plugins/TreePlugin.pm
@@ -284,7 +284,7 @@ sub HandleTreeTag {
 
     #Second loop:
     #   * Create nodes relationship
-    foreach my $nodeId ( sort keys %nodes ) {
+    foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %nodes ) {
         my $node = $nodes{$nodeId};
 
 #Make sure we don't set a parent to the web root otherwise we just go in an infinite loop while rendering
@@ -389,8 +389,8 @@ sub createCache {
         return;
     }
 
-    foreach my $nodeId ( sort keys %$nodesRef ) {
-        my $node = $nodesRef->{$nodeId};
+    foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %$nodesRef ) {
+           my $node = $nodesRef->{$nodeId};
 
 #Foswiki::Func::writeDebug( "- ${pluginName} Building cache for: " . $node->data('topic') ) if $debug;
         if ( !defined $webRoot

-- GeorgeClark - 03 Jan 2016

This works nicely. Just need add the use Unicode::Normalize; to the top.

-- JozefMojzis - 03 Jan 2016

Maybe would be worth adding to Foswiki:: namespace something as namesort and everywhere where need to change the sorting to NFKD use the new function, e.g. instead of the
foreach my $nodeId ( sort { NFKD($a) cmp NFKD($b) } keys %nodes ) {
use
for my $nodeId ( sort Foswiki::namesort keys %nodes ) {
and the the Foswiki package could contain
use Unicode::Normalize;
sub namesort { NFKD($a) cmp NFKD($b) }};
This allows easily change the name sorting in the future, to something more advanced, e.g. locale based sorting and so on, without the need everywhere again edit the sorting rule...

-- JozefMojzis - 04 Jan 2016

Nice idea, but we'd need to get this added to the API formally, and extensions would not be backwards compatible.

-- GeorgeClark - 05 Jan 2016

Confirming this. Note also that there are performance issues to the recommended sort above, Alternative suggested by MichaelDaum.

-- GeorgeClark - 25 Sep 2016
 
I Attachment Action Size Date Who Comment
screenshot_11.pngpng screenshot_11.png manage 157 K 03 Jan 2016 - 09:55 JozefMojzis screenshot - WebIndex - ok sort
screenshot_12.pngpng screenshot_12.png manage 44 K 03 Jan 2016 - 09:56 JozefMojzis TREEVIEW screenshot - wrong sort
Topic revision: r6 - 25 Sep 2016, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy