From b808c3860cc23513aaa061398a0b4f7b5895bbc5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 4 Oct 2011 15:25:00 -0400 Subject: [PATCH] TPac: jump to details page on single hit When enabled, any time an OPAC search yields 1 result, the user will be redirected to the record detail page for that result. This change adds 2 new org unit settings, one to control the behavior in the staff client, the other to control the public catalog. Signed-off-by: Bill Erickson Signed-off-by: Lebbeous Fogle-Weekley --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 59 +++++++++++++++++++++- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 17 +++++++ .../0635.data.opac.jump-to-details-setting.sql | 44 ++++++++++++++++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0635.data.opac.jump-to-details-setting.sql diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 37fa582254..903dea75d4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -263,6 +263,9 @@ sub load_rresults { } ); + my $stat = $self->check_1hit_redirect($rec_ids); + return $stat if $stat; + # shove recs into context in search results order for my $rec_id (@$rec_ids) { push( @@ -276,6 +279,55 @@ sub load_rresults { return Apache2::Const::OK; } +# If the calling search results in 1 record and the client +# is configured to do so, redirect the search results to +# the record details page. +sub check_1hit_redirect { + my ($self, $rec_ids) = @_; + my $ctx = $self->ctx; + + return undef unless $rec_ids and @$rec_ids == 1; + + my ($sname, $org); + + if ($ctx->{is_staff}) { + $sname = 'opac.staff.jump_to_details_on_single_hit'; + $org = $ctx->{user}->ws_ou; + + } else { + $sname = 'opac.patron.jump_to_details_on_single_hit'; + $org = ($ctx->{user}) ? + $ctx->{user}->home_ou : + $ctx->{orig_loc} || + $self->ctx->{aou_tree}->()->id; + } + + return undef unless + $self->ctx->{get_org_setting}->($org, $sname); + + my $base_url = sprintf( + '%s://%s%s/record/%s', + $ctx->{proto}, + $self->apache->hostname, + $self->ctx->{opac_root}, + $$rec_ids[0], + ); + + # If we get here from the same record detail page to which we + # now wish to redirect, do not perform the redirect. This + # approach seems to work well, with the rare exception of + # performing a new serach directly from the detail page that + # happens to result in the same single hit. In this case, the + # user will be left on the search results page. This could be + # overcome w/ additional CGI, etc., but I'm not sure it's necessary. + if (my $referer = $ctx->{referer}) { + $referer =~ s/([^?]*).*/$1/g; + return undef if $base_url eq $referer; + } + + return $self->generic_redirect($base_url . '?' . $self->cgi->query_string); +} + # Searching by barcode is a special search that does /not/ respect any other # of the usual search parameters, not even the ones for sorting and paging! sub item_barcode_shortcut { @@ -385,13 +437,18 @@ sub marc_expert_search { } $self->ctx->{ids} = [ grep { $_ } @{$results->{ids}} ]; + $self->ctx->{hit_count} = $results->{count}; + + return Apache2::Const::OK if @{$self->ctx->{ids}} == 0 or $args{internal}; + + my $stat = $self->check_1hit_redirect($self->ctx->{ids}); + return $stat if $stat; my ($facets, @data) = $self->get_records_and_facets( $self->ctx->{ids}, undef, {flesh => "{holdings_xml,mra}"} ); $self->ctx->{records} = [@data]; - $self->ctx->{hit_count} = $results->{count}; return Apache2::Const::OK; } diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 12c0843d94..e52f406b05 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0634', :eg_version); -- tsbere/phasefx +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0635', :eg_version); -- berick/senator CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 441b2b9828..09466eb983 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -4430,6 +4430,23 @@ INSERT into config.org_unit_setting_type 'coust', 'description'), 'integer', null) +,( 'opac.staff.jump_to_details_on_single_hit', 'opac', + oils_i18n_gettext('opac.staff.jump_to_details_on_single_hit', + 'Jump to details on 1 hit (staff client)', + 'coust', 'label'), + oils_i18n_gettext('opac.staff.jump_to_details_on_single_hit', + 'When a search yields only 1 result, jump directly to the record details page. This setting only affects the OPAC within the staff client', + 'coust', 'description'), + 'bool', null) +,( 'opac.patron.jump_to_details_on_single_hit', 'opac', + oils_i18n_gettext('opac.patron.jump_to_details_on_single_hit', + 'Jump to details on 1 hit (public)', + 'coust', 'label'), + oils_i18n_gettext('opac.patron.jump_to_details_on_single_hit', + 'When a search yields only 1 result, jump directly to the record details page. This setting only affects the public OPAC', + 'coust', 'description'), + 'bool', null) + ; UPDATE config.org_unit_setting_type diff --git a/Open-ILS/src/sql/Pg/upgrade/0635.data.opac.jump-to-details-setting.sql b/Open-ILS/src/sql/Pg/upgrade/0635.data.opac.jump-to-details-setting.sql new file mode 100644 index 0000000000..c92be5788a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0635.data.opac.jump-to-details-setting.sql @@ -0,0 +1,44 @@ +-- Evergreen DB patch 0635.data.opac.jump-to-details-setting.sql +-- +BEGIN; + + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0635', :eg_version); + +INSERT INTO config.org_unit_setting_type ( name, grp, label, description, datatype ) + VALUES ( + 'opac.staff.jump_to_details_on_single_hit', + 'opac', + oils_i18n_gettext( + 'opac.staff.jump_to_details_on_single_hit', + 'Jump to details on 1 hit (staff client)', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'opac.staff.jump_to_details_on_single_hit', + 'When a search yields only 1 result, jump directly to the record details page. This setting only affects the OPAC within the staff client', + 'coust', + 'description' + ), + 'bool' + ), ( + 'opac.patron.jump_to_details_on_single_hit', + 'opac', + oils_i18n_gettext( + 'opac.patron.jump_to_details_on_single_hit', + 'Jump to details on 1 hit (public)', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'opac.patron.jump_to_details_on_single_hit', + 'When a search yields only 1 result, jump directly to the record details page. This setting only affects the public OPAC', + 'coust', + 'description' + ), + 'bool' + ); + +COMMIT; -- 2.11.0