Item11178: JQGridPlugin SearchConnector not working on Foswiki 1.1

pencil
Priority: Urgent
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: JQGridPlugin
Branches:
Reported By: PaulHarvey
Waiting For:
Last Change By: PaulHarvey
Very embarrassing, sorry frown, sad smile

  1. Was using an unreleased QUERY syntax. Changed to a CALC.
  2. Somehow, we end up not escaping " quotes so the XML is never valid (TML stops processing early).
  3. Sorting on topic name/modified/by was broken.

Here's the patch

diff --git a/lib/Foswiki/Plugins/JQGridPlugin/SearchConnector.pm lib/Foswiki/Plugins/JQGridPlugin/SearchConnector.pm
index 25c66c0..c874f3b 100644
--- a/lib/Foswiki/Plugins/JQGridPlugin/SearchConnector.pm
+++ lib/Foswiki/Plugins/JQGridPlugin/SearchConnector.pm
@@ -50,11 +50,18 @@ sub new {
     'By' => 'info.author',
     'Author' => 'info.author'
   };
+  # maps column names to accessors appropriate for sorting
+  $this->{sortPropertyMap} = {
+    'Topic' => 'topic',
+    'Modified' => 'modified',
+    'Changed' => 'modified',
+    'By' => 'editby',
+    'Author' => 'editby'
+  };
 
   return $this;
 }
 
-
 =begin TML
 
 ---++ ClassMethod restHandleSearch( $request, $response )
@@ -115,6 +122,12 @@ sub restHandleSearch {
   $this->{session}->writeCompletePage($result, 'view', 'text/xml');
 }
 
+sub column2SortProperty {
+  my ($this, $column) = @_;
+
+  return $this->{sortPropertyMap}{$column} || "formfield($column)";
+}
+
 =begin TML
 
 ---++ ClassMethod search( $web, %params ) -> $xml
@@ -129,10 +142,7 @@ sub search {
   my $context = Foswiki::Func::getContext();
 
   # TODO: get this sorted out
-  my $order = $this->column2Property($params{sort});
-  if ($order =~ /^[a-zA-Z-_]+$/) { # SMELL: poor-man's formfield check
-    $order = "formfield($order)";
-  }
+  my $order = $this->column2SortProperty($params{sort});
 
   my $tml = <<"HERE";
 <literal><noautolink>%SEARCH{
@@ -148,10 +158,10 @@ sub search {
   pagerformat=" "
       pagerformat2="<page>\$currentpage</page>
       <total>\$numberofpages</total>
-      <records>\$percntQUERY{\$numberofpages * \$pagesize}\$percnt</records>\$n"
+      <records>\$percntCALC{\$EVAL(\$numberofpages * \$pagesize)}\$percnt</records>\$n"
   footer="\$n</rows>"
   header="<?xml version='1.0' encoding='utf-8'?><rows>
-  <page>\$currentpage</page><total>\$numberofpages</total><records>\$percntQUERY{\$numberofpages * \$pagesize}\$percnt</records>\$n"
+  <page>\$currentpage</page><total>\$numberofpages</total><records>\$percntCALC{\$EVAL(\$numberofpages * \$pagesize)}\$percnt</records>\$n"
   format="<row id='\$web.\$topic'>
 HERE
 
@@ -166,7 +176,7 @@ HERE
     } else {
       $cell .= '$percntQUERY{\"\'$web.$topic\'/' . $propertyName . '\"}$percnt';
     }
-    $tml .= '<cell name="'.$columnName.'"><![CDATA[<nop>' . $cell . ']]></cell>' . "\n";    # SMELL extra space behind cell needed to work around bug in Render::getRenderedVerision
+    $tml .= '<cell name=\"'.$columnName.'\"><![CDATA[<nop>' . $cell . ']]></cell>' . "\n";    # SMELL extra space behind cell needed to work around bug in Render::getRenderedVerision
   }
   $tml .= '</row>"}%</noautolink></literal>';

-- PaulHarvey - 11 Oct 2011

Why not use Foswiki::Func::query() or Foswiki::Func::searchInWebContent() instead of wading thru an uggly bunch of TML encoded into perl.

-- MichaelDaum - 11 Oct 2011

I will try to find some time to improve the SEARCH connector by using Foswiki::Func::query in a future release.

I bling'd up the examples so that they show the TML code under a twisty, hope that's okay smile

-- PaulHarvey - 19 Oct 2011

This was released in v2.02. Closing.

-- PaulHarvey - 21 Nov 2011
 
Topic revision: r8 - 21 Nov 2011, PaulHarvey
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