From: Bill Erickson Date: Fri, 31 Jan 2014 22:01:50 +0000 (-0500) Subject: LP#1053397 MR holds; more formats / lang display bits X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=194a83091c6b44cce40ceed32264b6a594d3f31b;p=working%2FEvergreen.git LP#1053397 MR holds; more formats / lang display bits Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index ca0859d4ff..6d63aa21ad 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -2477,7 +2477,7 @@ sub do_possibility_checks { } elsif( $hold_type eq OILS_HOLD_TYPE_METARECORD ) { - my $recs = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats); + my ($recs) = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats); my @status = (); for my $rec (@$recs) { @status = _check_title_hold_is_possible( @@ -4236,6 +4236,7 @@ sub mr_hold_filter_attrs { my ($self, $client, $mr_id, $hold_ids) = @_; my $e = new_editor(); + my $mr = $e->retrieve_metabib_metarecord($mr_id) or return $e->event; my $bre_ids = $e->json_query({ select => {mmrsm => ['source']}, @@ -4244,6 +4245,7 @@ sub mr_hold_filter_attrs { }); $bre_ids = [map {$_->{source}} @$bre_ids]; + my $item_lang_attr = 'item_lang'; # configurable? my $format_attr = $e->retrieve_config_global_flag( 'opac.metarecord.holds.format_attr')->value; @@ -4261,7 +4263,7 @@ sub mr_hold_filter_attrs { }); } - my $langs = get_batch_ccvms($e, 'item_lang', $bre_ids); + my $langs = get_batch_ccvms($e, $item_lang_attr, $bre_ids); my $formats = get_batch_ccvms($e, $format_attr, $bre_ids); $client->respond({ @@ -4273,7 +4275,8 @@ sub mr_hold_filter_attrs { }); return unless $hold_ids; - my $icon_attr = $e->retrieve_config_global_flag('opac.icon_attr')->value; + my $icon_attr = $e->retrieve_config_global_flag('opac.icon_attr'); + $icon_attr = $icon_attr ? $icon_attr->value : ''; for my $hold_id (@$hold_ids) { my $hold = $e->retrieve_action_hold_request($hold_id) @@ -4281,14 +4284,47 @@ sub mr_hold_filter_attrs { next unless $hold->hold_type eq 'M'; + my $resp = { + hold => { + id => $hold_id, + formats => [], + langs => [] + } + }; + + # collect the ccvm's for the selected formats / language ( + # (i.e. the holdable formats) on the MR. + # this assumes a two-key structure for format / language, + # though assumption is made about the keys themselves. + my $hformats = OpenSRF::Utils::JSON->JSON2perl($hold->holdable_formats); + my $lang_vals = []; + my $format_vals = []; + for my $val (values %$hformats) { + # val is either a single ccvm or an array of them + $val = [$val] unless ref $val eq 'ARRAY'; + for my $node (@$val) { + push (@$lang_vals, $node->{_val}) + if $node->{_attr} eq $item_lang_attr; + push (@$format_vals, $node->{_val}) + if $node->{_attr} eq $format_attr; + } + } + + # fetch the ccvm's for consistency with the {metarecord} blob + $resp->{hold}{formats} = $e->search_config_coded_value_map({ + ctype => $format_attr, code => $format_vals}); + $resp->{hold}{langs} = $e->search_config_coded_value_map({ + ctype => $item_lang_attr, code => $lang_vals}); + # find all of the bib records within this metarcord whose # format / language match the holdable formats on the hold - my @bre_ids = $self->method_lookup( + my ($bre_ids) = $self->method_lookup( 'open-ils.circ.holds.metarecord.filterd_records')->run( $hold->target, $hold->holdable_formats); - my $icons = get_batch_ccvms($e, $icon_attr, \@bre_ids); - $client->respond({hold => {id => $hold_id, icons => $icons}}); + # now find all of the 'icon' attributes for the records + $resp->{hold}{icons} = get_batch_ccvms($e, $icon_attr, $bre_ids); + $client->respond($resp); } return; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index 82f6013a99..5731e6bf4e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -575,9 +575,24 @@ sub fetch_user_holds { [$blob->{hold}->{bre_id}], undef, {flesh => '{mra}'} ); $blob->{marc_xml} = $data[0]->{marc_xml}; - my $hold = $blob->{hold}->{hold}; - $blob->{metarecord_ccvms} = $self->get_mr_ccvms($hold->target) - if $hold->hold_type eq 'M'; + + # in the holds edit UI, we need to know what formats and + # languages the user selected for this hold, plus what + # formats/langs are available on the MR as a whole. + if ($blob->{hold}{hold}->hold_type eq 'M') { + my $hold = $blob->{hold}->{hold}; + + my $filter_data = $U->simplereq( + 'open-ils.circ', + 'open-ils.circ.mmr.holds.filters.authoritative.atomic', + $hold->target, [$hold->id] + ); + + $blob->{metarecord_filters} = + $filter_data->[0]->{metarecord}; + $blob->{metarecord_hold_extras} = + $filter_data->[1]->{hold}->{$hold->id}; + } push(@holds, $blob); } } @@ -792,8 +807,17 @@ sub load_place_hold { for my $id (@targets) { my ($mr) = grep {$_->id eq $id} @$mrecs; - my $avail_attrs = $self->get_mr_ccvms($mr->id); - my $format_attr = $avail_attrs->{formats}{attr}; + my $filter_data = $U->simplereq( + 'open-ils.circ', + 'open-ils.circ.mmr.holds.filters.authoritative', $mr->id); + + # pull the format attr from the format info returned + # from the API call, instead of fetching it again from + # the DB. If there are no formats, then the format attr + # is irrelevant. + my $format_attr = + $filter_data->{metarecord}->{formats}->[0]->ctype + if $filter_data->{metarecord}->{formats}->[0]; # during hold placement submission, the user selects # which of the available formats/langs are acceptiable. @@ -815,8 +839,8 @@ sub load_place_hold { push(@hold_data, $data_filler->({ target => $mr, record => $mr->master_record, - metarecord_ccvms => $avail_attrs, - holdable_formats => $holdable_formats + holdable_formats => $holdable_formats, + metarecord_filters => $filter_data->{metarecord} })); } }, @@ -1108,52 +1132,6 @@ sub attempt_hold_placement { } } -# fetches the CCVMs IDs representing available languages and formats -# for the constituent records of the selected metarecord. -sub get_mr_ccvms { - my ($self, $mr_id) = @_; - my $e = $self->editor; - - # crad.name which defines the set of metarecord formats - my $format_attr = $self->ctx->{search_cgf}->( # leverage caching - name => 'opac.metarecord.holds.format_attr')->[0]->value; - - my $bre_ids = - $e->search_metabib_metarecord_source_map({metarecord => $mr_id}); - $bre_ids = [map {$_->source} @$bre_ids]; - - my $query = { - select => {ccvm => [{column => 'id', transform => 'distinct'}]}, - from => {mraf => { - ccvm => { - fkey => 'attr', - field => 'ctype', - filter => {code => {'=' => {'+mraf' => 'value'}}} - } - }}, - where => {'+mraf' => {id => $bre_ids, attr => ''}} - }; - - $query->{where}{'+mraf'}{attr} = 'item_lang'; - my $langs = $e->json_query($query); - - $query->{where}{'+mraf'}{attr} = $format_attr; - my $formats = $e->json_query($query); - - return { - formats => { - attr => $format_attr, - values => [map { $_->{id} } @$formats], - }, - langs => { - attr => 'item_lang', - values => [map { $_->{id} } @$langs] - } - }; -} - - - sub fetch_user_circs { my $self = shift; my $flesh = shift; # flesh bib data, etc. diff --git a/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 b/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 index 8e0a81d3e4..4664e3fc7f 100644 --- a/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 +++ b/Open-ILS/src/templates/opac/myopac/holds/edit.tt2 @@ -35,11 +35,10 @@ [% l('Format:') %] [% attrs.format_label | html %]

[% END %] - [% IF hold.metarecord_ccvms.formats.values.size OR # should this be size > 1 - hold.metarecord_ccvms.langs.values.size > 1; - PROCESS metarecord_hold_filters_selector hold_data=hold; - END %] - + + [% IF hold.metarecord_filters.formats.size OR # should this be size > 1 + hold.metarecord_filters.langs.size > 1; + PROCESS metarecord_hold_filters_selector hold_data=hold; END %]

[% l('Status') %]: [% hold.human_status %]

diff --git a/Open-ILS/src/templates/opac/parts/metarecord_hold_filters.tt2 b/Open-ILS/src/templates/opac/parts/metarecord_hold_filters.tt2 index bc36bf2924..3806eb1cf9 100644 --- a/Open-ILS/src/templates/opac/parts/metarecord_hold_filters.tt2 +++ b/Open-ILS/src/templates/opac/parts/metarecord_hold_filters.tt2 @@ -24,22 +24,7 @@ limiting the set of desired records for a given metarecord. } -[% BLOCK metarecord_hold_filters_selector; - format_ccvms = []; - lang_ccvms = []; - # some CCVMs have search_labels, some use the value as the label - # instead. Accommodate both, starting with search_label - FOR ccvm_id IN hold_data.metarecord_ccvms.formats.values; - ccvm = ctx.get_ccvm(ccvm_id); - CALL ccvm.search_label(ccvm.value) UNLESS ccvm.search_label; - format_ccvms.push(ccvm); - END; - FOR ccvm_id IN hold_data.metarecord_ccvms.langs.values; - ccvm = ctx.get_ccvm(ccvm_id); - CALL ccvm.search_label(ccvm.value) UNLESS ccvm.search_label; - lang_ccvms.push(ccvm); - END; -%] +[% BLOCK metarecord_hold_filters_selector %]
@@ -48,7 +33,8 @@ limiting the set of desired records for a given metarecord.
- [% FOR lang_ccvm IN lang_ccvms.sort('search_label') %] + [% FOR lang_ccvm IN hold_data.metarecord_filters.langs.sort('value') %] [% END %] diff --git a/Open-ILS/src/templates/opac/parts/place_hold.tt2 b/Open-ILS/src/templates/opac/parts/place_hold.tt2 index 83668436de..6a8fb79cc5 100644 --- a/Open-ILS/src/templates/opac/parts/place_hold.tt2 +++ b/Open-ILS/src/templates/opac/parts/place_hold.tt2 @@ -64,8 +64,8 @@ [% END %] [% END %] - [% IF hdata.metarecord_ccvms.formats.values.size OR # should this be size > 1 - hdata.metarecord_ccvms.langs.values.size > 1; + [% IF hdata.metarecord_filters.formats.size OR # should this be size > 1 + hdata.metarecord_filters.langs.size > 1; PROCESS metarecord_hold_filters_selector hold_data=hdata; END %]