From a11de26b8b9ff99a4d6d76a8f5d7758970805e97 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 26 Aug 2011 10:56:55 -0400 Subject: [PATCH] Sort POs by title by default; lineitem search cleanup * Added lineitem attribute sorting to open-ils.acq.lineitem.search * Pillaged and removed open-ils.acq.lineitem.picklist.retrieve. Code now uses open-ils.acq.lineitem.search instead. * PO's now sort by title by default since that's the default sort for open-ils.acq.lineitem.search Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Acq/Lineitem.pm | 89 ++++++++++++++--- .../lib/OpenILS/Application/Acq/Picklist.pm | 109 --------------------- Open-ILS/web/js/ui/default/acq/picklist/view.js | 4 +- Open-ILS/web/js/ui/default/acq/po/view_po.js | 2 +- 4 files changed, 77 insertions(+), 127 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm index c36bf60b1d..f328abd4e9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm @@ -306,34 +306,93 @@ sub update_lineitem_impl { __PACKAGE__->register_method( method => 'lineitem_search', - api_name => 'open-ils.acq.lineitem.search', + api_name => 'open-ils.acq.lineitem.search', stream => 1, + authoritative => 1, signature => { desc => 'Searches lineitems', params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'Search definition', type => 'object'}, - {desc => 'Options hash. idlist=true', type => 'object'}, - {desc => 'List of lineitems', type => 'object/number'}, - ] + {desc => 'Authentication token', type => 'string'}, + {desc => q/ + Search hash. This will be the WHERE component {"+jub": {...}} of a json_query + E.g. { "purchase_order" : 123 } /, + type => 'hash'}, + {desc => q/Options, including + "sort_attr", which defines the attribute to sort on; + "sort_attr_type", which defines the attribute type sort on; + "sort_dir", which defines the sort order between "asc" and "desc"; + "limit", retrieval limit; + "offset", retrieval offset; + "idlist", return a list of IDs instead of objects + "flesh_attrs", additionaly return the list of flattened attributes + "clear_marc", discards the raw MARC data to reduce data size + "flesh_notes", flesh lineitem notes + "flesh_cancel_reason", flesh cancel_reason + /, + type => 'hash'} + ], + return => {desc => 'Array of lineitem objects or IDs, on success, Event on error'} } ); +my $LI_SEARCH_JSON_QUERY = { + select => {jub => ['id'], 'acqlia' => ['attr_value']}, + from => { + jub => { + acqlia => { + fkey => 'id', + field => 'lineitem', + type => 'left', + filter => { + attr_type => 'lineitem_marc_attr_definition', + attr_name => 'title' + } + } + } + }, + where => {'+jub' => {}}, + order_by => {acqlia => {attr_value => {direction => 'asc'}}}, + distinct => 1, + limit => 10, + offset => 0 +}; + sub lineitem_search { - my($self, $conn, $auth, $search, $options) = @_; + my($self, $conn, $auth, $where, $options) = @_; + my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; - return $e->event unless $e->allowed('CREATE_PICKLIST'); - # XXX needs permissions consideration - my $lis = $e->search_acq_lineitem($search, {idlist=>1}); - for my $li_id (@$lis) { - if($$options{idlist}) { - $conn->respond($li_id); + # Permissions are checked per-lineitem in retrieve_lineitem() + + return undef unless $where; + + my $sort_attr = $$options{sort_attr} || 'title'; + my $sort_attr_type = $$options{sort_attr_type} || 'lineitem_marc_attr_definition'; + my $sort_dir = $$options{sort_dir} || 'asc'; + my $offset = $$options{offset} || 0; + my $limit = $$options{limit} || 10; + + $LI_SEARCH_JSON_QUERY->{where}->{'+jub'} = $where; + $LI_SEARCH_JSON_QUERY->{from}->{jub}->{acqlia}->{filter}->{attr_name} = $sort_attr; + $LI_SEARCH_JSON_QUERY->{from}->{jub}->{acqlia}->{filter}->{attr_type} = $sort_attr_type; + $LI_SEARCH_JSON_QUERY->{order_by}->{acqlia}->{attr_value}->{direction} = $sort_dir; + $LI_SEARCH_JSON_QUERY->{limit} = $limit; + $LI_SEARCH_JSON_QUERY->{offset} = $offset; + + my $li_ids = $e->json_query($LI_SEARCH_JSON_QUERY); + + for my $li_id ( map {$_->{id}} @$li_ids ) { + my $res = retrieve_lineitem_impl($e, $li_id, $options); + + if( my $ecode = $U->event_code($res) ) { + next if $ecode == 5000; # PERM_FAILURE, return nothing } else { - my $res = retrieve_lineitem($self, $conn, $auth, $li_id, $options); - $conn->respond($res) unless $U->event_code($res); + $res = $li_id if $$options{idlist}; } + + $conn->respond($res); } + return undef; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Picklist.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Picklist.pm index eee578f9d9..4b96d1364b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Picklist.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Picklist.pm @@ -279,115 +279,6 @@ sub retrieve_all_user_picklist { } __PACKAGE__->register_method( - method => 'retrieve_pl_lineitem', - api_name => 'open-ils.acq.lineitem.picklist.retrieve', - stream => 1, - signature => { - desc => 'Retrieves lineitem objects according to picklist', - params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'Picklist ID whose entries to retrieve', type => 'number'}, - {desc => q/Options, including - "sort_attr", which defines the attribute to sort on; - "sort_attr_type", which defines the attribute type sort on; - "sort_dir", which defines the sort order between "asc" and "desc"; - "limit", retrieval limit; - "offset", retrieval offset; - "idlist", return a list of IDs instead of objects - "flesh_attrs", additionaly return the list of flattened attributes - "clear_marc", discards the raw MARC data to reduce data size - "flesh_notes", flesh lineitem notes - "flesh_cancel_reason", flesh cancel_reason - /, - type => 'hash'} - ], - return => {desc => 'Array of lineitem objects or IDs, on success, Event on error'} - } -); - - -my $PL_ENTRY_JSON_QUERY = { - select => {jub => ["id"], "acqlia" => ["attr_value"]}, - "from" => { - "jub" => { - "acqlia" => { - "fkey" => "id", - "field" => "lineitem", - "type" => "left", - "filter" => { - "attr_type" => "lineitem_marc_attr_definition", - "attr_name" => "author" - } - } - } - }, - "order_by" => {"acqlia" => {"attr_value" => {"direction"=>"asc"}}}, - "limit" => 10, - "where" => {"+jub" => {"picklist"=>2}}, - "offset" => 0 -}; - -sub retrieve_pl_lineitem { - my($self, $conn, $auth, $picklist_id, $options) = @_; - my $e = new_editor(authtoken=>$auth); - return $e->event unless $e->checkauth; - - # collect the retrieval options - my $sort_attr = $$options{sort_attr} || 'title'; - my $sort_attr_type = $$options{sort_attr_type} || 'lineitem_marc_attr_definition'; - my $sort_dir = $$options{sort_dir} || 'asc'; - my $limit = $$options{limit} || 10; - my $offset = $$options{offset} || 0; - - $PL_ENTRY_JSON_QUERY->{where}->{'+jub'}->{picklist} = $picklist_id; - $PL_ENTRY_JSON_QUERY->{from}->{jub}->{acqlia}->{filter}->{attr_name} = $sort_attr; - $PL_ENTRY_JSON_QUERY->{from}->{jub}->{acqlia}->{filter}->{attr_type} = $sort_attr_type; - $PL_ENTRY_JSON_QUERY->{order_by}->{acqlia}->{attr_value}->{direction} = $sort_dir; - $PL_ENTRY_JSON_QUERY->{limit} = $limit; - $PL_ENTRY_JSON_QUERY->{offset} = $offset; - - my $entries = $e->json_query($PL_ENTRY_JSON_QUERY); - - my @ids; - for my $entry (@$entries) { - push(@ids, $entry->{id}) unless grep { $_ eq $entry->{id} } @ids; - } - - for my $id (@ids) { - if($$options{idlist}) { - $conn->respond($id); - next; - } - - my $entry; - my $flesh = {}; - if($$options{flesh_attrs} or $$options{flesh_notes} or $$options{flesh_cancel_reason}) { - $flesh = {flesh => 2, flesh_fields => {jub => []}}; - if($$options{flesh_notes}) { - push(@{$flesh->{flesh_fields}->{jub}}, 'lineitem_notes'); - $flesh->{flesh_fields}->{acqlin} = ['alert_text']; - } - push(@{$flesh->{flesh_fields}->{jub}}, 'attributes') if $$options{flesh_attrs}; - push @{$flesh->{flesh_fields}->{jub}}, 'cancel_reason' if $$options{flesh_cancel_reason}; - } - - $entry = $e->retrieve_acq_lineitem([$id, $flesh]); - my $details = $e->search_acq_lineitem_detail({lineitem => $id}, {idlist=>1}); - $entry->item_count(scalar(@$details)); - $entry->clear_marc if $$options{clear_marc}; - $conn->respond($entry); - } - - return undef; -} - -=head comment -request open-ils.cstore open-ils.cstore.json_query.atomic {"select":{"jub":[{"transform":"count", "attregate":1, "column":"id","alias":"count"}]}, "from":"jub","where":{"picklist":1}} -=cut - - - -__PACKAGE__->register_method( method => "record_distribution_formula_application", api_name => "open-ils.acq.distribution_formula.record_application", signature => { diff --git a/Open-ILS/web/js/ui/default/acq/picklist/view.js b/Open-ILS/web/js/ui/default/acq/picklist/view.js index 7cbc0c5f25..b6688d7845 100644 --- a/Open-ILS/web/js/ui/default/acq/picklist/view.js +++ b/Open-ILS/web/js/ui/default/acq/picklist/view.js @@ -75,9 +75,9 @@ function loadLIs() { fieldmapper.standardRequest( - ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'], + ['open-ils.acq', 'open-ils.acq.lineitem.search'], { async: true, - params: [openils.User.authtoken, plId, + params: [openils.User.authtoken, {picklist : plId}, {flesh_notes:true, flesh_cancel_reason:true, flesh_attrs:true, clear_marc:true, offset:plOffset, limit:plLimit}], onresponse: function(r) { var li = openils.Util.readResponse(r); diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js index 8e510f956e..5738f524d1 100644 --- a/Open-ILS/web/js/ui/default/acq/po/view_po.js +++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js @@ -396,7 +396,7 @@ function init() { { async: true, params: [ openils.User.authtoken, - [{purchase_order:poId}, {"order_by": {"jub": "id ASC"}}], + {purchase_order : poId}, {flesh_attrs:true, flesh_notes:true, flesh_cancel_reason:true, clear_marc:true} ], onresponse: function(r) { -- 2.11.0