From: senator Date: Mon, 21 Jun 2010 20:20:57 +0000 (+0000) Subject: Acq: add default sort order to canned searches, and provide middle layer X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d5bea835dabfe98ba9ff9005762a4a196860e0ea;p=evergreen%2Fbjwebb.git 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@16768 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm index e81977be2..753e03291 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm @@ -366,8 +366,35 @@ sub unified_search { 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 @@ sub unified_search { } } }, - "order_by" => {$hint => {"id" => {}}}, + "order_by" => ($options->{"order_by"} || {$hint => {"id" => {}}}), "offset" => ($options->{"offset"} || 0) }; @@ -430,11 +457,12 @@ sub unified_search { } 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; diff --git a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js index a308ab15b..f8f37815f 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -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" } diff --git a/Open-ILS/web/js/ui/default/acq/search/unified.js b/Open-ILS/web/js/ui/default/acq/search/unified.js index 9b279b2a9..91f8190c1 100644 --- a/Open-ILS/web/js/ui/default/acq/search/unified.js +++ b/Open-ILS/web/js/ui/default/acq/search/unified.js @@ -72,7 +72,7 @@ function TermSelectorFactory(terms) { "disabled": "disabled", "selected": "selected", "value": "", - "innerHTML": "Select Search Field" // XXX i18n + "innerHTML": localeStrings.SELECT_SEARCH_FIELD }) ); @@ -736,7 +736,7 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) { "&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 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) { 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 @@ function URIManager() { ] }, "result_type": "purchase_order", - "conjunction": "and" + "conjunction": "and", + "order_by": [ + {"class": "acqpo", "field": "edit_time", "direction": "desc"} + ] }, "pl": { "search_object": { @@ -809,7 +814,10 @@ function URIManager() { ] }, "result_type": "picklist", - "conjunction": "and" + "conjunction": "and", + "order_by": [ + {"class": "acqpl", "field": "edit_time", "direction": "desc"} + ] }, "inv": { "search_object": { @@ -819,7 +827,10 @@ function URIManager() { ] }, "result_type": "invoice", - "conjunction": "and" + "conjunction": "and", + "order_by": [ + {"class": "acqinv", "field": "recv_date", "direction": "desc"} + ] } }; @@ -861,7 +872,7 @@ openils.Util.addOnLoad( 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");