From cb677bbf3bd7f417588f68d800c321c58feb804f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 29 Jun 2020 16:44:16 -0400 Subject: [PATCH] LPXXX Angular Volcopy data api Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 2a144b71a9..40527a5133 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -1919,6 +1919,131 @@ sub retrieve_tag_table { } } +__PACKAGE__->register_method( + method => "volcopy_data", + api_name => "open-ils.cat.volcopy.data", + stream => 1, + argc => 3, + signature => { + desc => q|Returns a batch of org-scoped data types needed by the + volume/copy editor|, + params => [ + {desc => 'Authtoken', type => 'string'} + ] + }, + return => {desc => 'Stream of various object type lists', type => 'array'} +); + +sub volcopy_data { + my ($self, $client, $auth) = @_; + my $e = new_editor(authtoken => $auth); + + $e->checkauth or return $e->event; + my $org_ids = $U->get_org_ancestors($e->requestor->ws_ou); + + $client->respond({ + acp_location => $e->search_asset_copy_location([ + {deleted => 'f', owning_lib => $org_ids}, + {order_by => {acpl => 'name'}} + ]) + }); + + $client->respond({ + acp_status => $e->search_config_copy_status([ + {id => {'!=' => undef}}, + {order_by => {ccs => 'name'}} + ]) + }); + + $client->respond({ + acp_age_protect => $e->search_config_rules_age_hold_protect([ + {id => {'!=' => undef}}, + {order_by => {crahp => 'name'}} + ]) + }); + + $client->respond({ + acp_floating_group => $e->search_config_floating_group([ + {id => {'!=' => undef}}, + {order_by => {cfg => 'name'}} + ]) + }); + + $client->respond({ + acp_circ_modifier => $e->search_config_circ_modifier([ + {code => {'!=' => undef}}, + {order_by => {ccm => 'name'}} + ]) + }); + + $client->respond({ + acp_item_type_map => $e->search_config_item_type_map([ + {code => {'!=' => undef}}, + {order_by => {ccm => 'value'}} + ]) + }); + + $client->respond({ + acn_class => $e->search_asset_call_number_class([ + {id => {'!=' => undef}}, + {order_by => {acnc => 'name'}} + ]) + }); + + $client->respond({ + acn_prefix => $e->search_asset_call_number_prefix([ + {owning_lib => $org_ids}, + {order_by => {acnp => 'label_sortkey'}} + ]) + }); + + $client->respond({ + acn_suffix => $e->search_asset_call_number_suffix([ + {owning_lib => $org_ids}, + {order_by => {acns => 'label_sortkey'}} + ]) + }); + + # Some object types require more complex sorting, etc. + + my $cats = $e->search_asset_stat_cat([ + {owner => $org_ids}, + { flesh => 2, + flesh_fields => {asc => ['owner', 'entries'], aou => ['ou_type']} + } + ]); + + # Sort stat cats by depth then by name within each depth group. + $cats = [ + sort { + my $d1 = $a->owner->ou_type->depth; + my $d2 = $b->owner->ou_type->depth; + + if ($d1 > $d2) { + return -1; + } elsif ($d1 < $d2) { + return 1; + } else { + return $a->name cmp $b->name; + } + } + @$cats + ]; + + for my $cat (@$cats) { + # de-flesh org data + $cat->owner($cat->owner->id); + + # sort entries + $cat->entries([sort {$a->value cmp $b->value} @{$cat->entries}]); + } + + $client->respond({acp_stat_cat => $cats}); + + return undef; +} + + 1; # vi:et:ts=4:sw=4 -- 2.11.0