[open-ils-commits] r16768 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/dojo/openils/acq/nls web/js/ui/default/acq/search (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Jun 21 16:21:02 EDT 2010


Author: senator
Date: 2010-06-21 16:20:57 -0400 (Mon, 21 Jun 2010)
New Revision: 16768

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
   trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
   trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
Log:
Acq: add default sort order to canned searches, and provide middle layer
support for sort order for unified search generally.  The UI for that may
come later.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-06-19 03:01:48 UTC (rev 16767)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-06-21 20:20:57 UTC (rev 16768)
@@ -366,8 +366,35 @@
     my $retriever = $RETRIEVERS{$ret_type};
     my $hint = F("acq::$ret_type")->{"hint"};
 
+    my $select_clause = {
+        $hint => [{"column" => "id", "transform" => "distinct"}]
+    };
+
+    if ($options->{"order_by"}) {
+        # What's the point of this block?  When using ORDER BY in conjuction
+        # with SELECT DISTINCT, the fields present in ORDER BY have to also
+        # be in the SELECT clause.  This will take _one_ such field and add
+        # it to the SELECT clause as needed.
+        my ($order_by, $class, $field);
+        unless (
+            ($order_by = $options->{"order_by"}->[0]) &&
+            ($class = $order_by->{"class"}) =~ /^[\da-z_]+$/ &&
+            ($field = $order_by->{"field"}) =~ /^[\da-z_]+$/
+        ) {
+            $e->disconnect;
+            return new OpenILS::Event(
+                "BAD_PARAMS", "note" =>
+q/order_by clause must be of the long form, like:
+"order_by": [{"class": "foo", "field": "bar", "direction": "asc"}]/
+            );
+        } else {
+            $select_clause->{$class} ||= [];
+            push @{$select_clause->{$class}}, $field;
+        }
+    }
+
     my $query = {
-        "select" => {$hint => [{"column" => "id", "transform" => "distinct"}]},
+        "select" => $select_clause,
         "from" => {
             "jub" => {
                 "acqpo" => {
@@ -394,7 +421,7 @@
                 }
             }
         },
-        "order_by" => {$hint => {"id" => {}}},
+        "order_by" => ($options->{"order_by"} || {$hint => {"id" => {}}}),
         "offset" => ($options->{"offset"} || 0)
     };
 
@@ -430,11 +457,12 @@
     }
 
     my $results = $e->json_query($query) or return $e->die_event;
+    my @id_list = map { $_->{"id"} } (grep { $_->{"id"} } @$results);
+
     if ($options->{"id_list"}) {
-        $conn->respond($_->{"id"}) foreach (grep { $_->{"id"} } @$results);
+        $conn->respond($_) foreach @id_list;
     } else {
-        $conn->respond($retriever->($e, $_->{"id"}, $options))
-            foreach (grep { $_->{"id"} } @$results);
+        $conn->respond($retriever->($e, $_, $options)) foreach @id_list;
     }
 
     $e->disconnect;

Modified: trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-06-19 03:01:48 UTC (rev 16767)
+++ trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-06-21 20:20:57 UTC (rev 16768)
@@ -74,5 +74,6 @@
     "PRINT" : "Print",
     "INVOICES" : "Invoices",
     "NUM_CLAIMS_EXISTING" : "Claims (${0} existing)",
-    "LOAD_TERMS_FIRST" : "You can't retrieve records until you've loaded a CSV file\nwith bibliographic IDs in the first column."
+    "LOAD_TERMS_FIRST" : "You can't retrieve records until you've loaded a CSV file\nwith bibliographic IDs in the first column.",
+    "SELECT_SEARCH_FIELD": "Select Search Field"
 }

Modified: trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-06-19 03:01:48 UTC (rev 16767)
+++ trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-06-21 20:20:57 UTC (rev 16768)
@@ -72,7 +72,7 @@
             "disabled": "disabled",
             "selected": "selected",
             "value": "",
-            "innerHTML": "Select Search Field" // XXX i18n
+            "innerHTML": localeStrings.SELECT_SEARCH_FIELD
         })
     );
 
@@ -736,7 +736,7 @@
             "&c=" + dojo.byId("acq-unified-conjunction").getValue();
     };
 
-    this.search = function(search_object, termManager) {
+    this.search = function(uriManager, termManager) {
         var bib_search_string = null;
         this.count_results = 0;
         this.result_type = dojo.byId("acq-unified-result-type").getValue();
@@ -761,7 +761,9 @@
 
         this.params[
             dojo.byId("acq-unified-conjunction").getValue() == "and" ? 1 : 2
-        ] = search_object;
+        ] = uriManager.search_object;
+        if (uriManager.order_by)
+            this.params[4].order_by = uriManager.order_by;
 
         var interface = this.result_types[this.result_type].interface;
         interface.dataLoader = this._dataLoader;
@@ -800,7 +802,10 @@
                 ]
             },
             "result_type": "purchase_order",
-            "conjunction": "and"
+            "conjunction": "and",
+            "order_by": [
+                {"class": "acqpo", "field": "edit_time", "direction": "desc"}
+            ]
         },
         "pl": {
             "search_object": {
@@ -809,7 +814,10 @@
                 ]
             },
             "result_type": "picklist",
-            "conjunction": "and"
+            "conjunction": "and",
+            "order_by": [
+                {"class": "acqpl", "field": "edit_time", "direction": "desc"}
+            ]
         },
         "inv": {
             "search_object": {
@@ -819,7 +827,10 @@
                 ]
             },
             "result_type": "invoice",
-            "conjunction": "and"
+            "conjunction": "and",
+            "order_by": [
+                {"class": "acqinv", "field": "recv_date", "direction": "desc"}
+            ]
         }
     };
 
@@ -861,7 +872,7 @@
             hideForm();
             openils.Util.show("acq-unified-body");
             termManager.reflect(uriManager.search_object);
-            resultManager.search(uriManager.search_object, termManager);
+            resultManager.search(uriManager, termManager);
         } else {
             termManager.addRow();
             openils.Util.show("acq-unified-body");



More information about the open-ils-commits mailing list