From 2bb6fe60f14f96f2fa820546573733236e09b738 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 31 Jul 2012 13:43:15 -0400 Subject: [PATCH] acq invoice : sort by title Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/Application/Acq/Search.pm | 32 +++++++++++++++++++++- Open-ILS/src/templates/acq/invoice/view.tt2 | 3 ++ Open-ILS/web/js/ui/default/acq/invoice/view.js | 6 ++++ Open-ILS/web/js/ui/default/acq/search/unified.js | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm index d924e4c246..da594a2355 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm @@ -425,6 +425,7 @@ sub unified_search { $hint => [{"column" => "id", "transform" => "distinct"}] }; + my $attr_from_filter; 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 @@ -442,9 +443,30 @@ sub unified_search { q/order_by clause must be of the long form, like: "order_by": [{"class": "foo", "field": "bar", "direction": "asc"}]/ ); + } else { + + # we can't combine distinct(id) with another select column, + # since the non-distinct column may arbitrarily (via hash keys) + # sort to the front of the final SQL, which PG will complain about. + $select_clause = { $hint => ["id"] }; $select_clause->{$class} ||= []; - push @{$select_clause->{$class}}, $field; + push @{$select_clause->{$class}}, + {column => $field, transform => 'first', aggregate => 1}; + + # when sorting by LI attr values, we have to limit + # to a specific type of attr value to sort on. + if ($class eq 'acqlia') { + $attr_from_filter = { + "fkey" => "id", + "filter" => { + "attr_type" => "lineitem_marc_attr_definition", + "attr_name" => $options->{"order_by_attr"} || "title" + }, + "type" => "left", + "field" =>"lineitem" + }; + } } } @@ -479,6 +501,14 @@ q/order_by clause must be of the long form, like: return new OpenILS::Event("BAD_PARAMS", "desc" => "No usable terms"); } + + # if ordering by acqlia, insert the from clause + # filter to limit to one type of attr. + if ($attr_from_filter) { + $query->{from}->{jub} = {} unless $query->{from}->{jub}; + $query->{from}->{jub}->{acqlia} = $attr_from_filter; + } + my $results = $e->json_query($query) or return $e->die_event; my @id_list = map { $_->{"id"} } (grep { $_->{"id"} } @$results); diff --git a/Open-ILS/src/templates/acq/invoice/view.tt2 b/Open-ILS/src/templates/acq/invoice/view.tt2 index 59c5bb0542..add14fc615 100644 --- a/Open-ILS/src/templates/acq/invoice/view.tt2 +++ b/Open-ILS/src/templates/acq/invoice/view.tt2 @@ -247,6 +247,9 @@ + + [% l('Sort by title') %] + [% l('Limit to Invoiceable Items') %] diff --git a/Open-ILS/web/js/ui/default/acq/invoice/view.js b/Open-ILS/web/js/ui/default/acq/invoice/view.js index 3848b22c0d..28d82ff125 100644 --- a/Open-ILS/web/js/ui/default/acq/invoice/view.js +++ b/Open-ILS/web/js/ui/default/acq/invoice/view.js @@ -277,6 +277,11 @@ function performSearch() { } } + if (dojo.byId('acq-invoice-search-sort-title').checked) { + uriManager.order_by = + [ {"class": "acqlia", "field":"attr_value", "transform":"first"} ]; + } + resultManager.go(searchObject) console.log('Lineitem Search: ' + js2JSON(searchObject)); focusLastSearchInput(); @@ -291,6 +296,7 @@ function renderUnifiedSearch() { termManager = new TermManager(); resultManager = new ResultManager(); resultsLoader = new searchResultsLoader(); + uriManager = new URIManager(); // define custom lineitem result handler resultManager.result_types = { 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 bf73d6125d..2c1eff01bc 100644 --- a/Open-ILS/web/js/ui/default/acq/search/unified.js +++ b/Open-ILS/web/js/ui/default/acq/search/unified.js @@ -800,7 +800,7 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) { if (window.unifiedSearchExternalMode) { // assume for now that external mode implies inline results display - uriManager = new URIManager(); + uriManager = uriManager || new URIManager(); uriManager.search_object = search_object; uriManager.result_type = dojo.byId("acq-unified-result-type").getValue(); uriManager.conjunction = dojo.byId("acq-unified-conjunction").getValue(); -- 2.11.0