From 701d069268f75620e145ea73a2e21aec7ec5db42 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 4 Feb 2016 17:19:03 -0500 Subject: [PATCH] LP#1549505: Add ability to set default sorter via global flag In addition, support for sorting by ascending popularity remains in the back end, however, since if one's configured badges such that almost every record has a badge score, that sort order could be useful for examining the long tail of the collection. Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 5 +++++ Open-ILS/src/sql/Pg/950.data.seed-values.sql | 14 ++++++++++++++ .../src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql | 7 +++++++ Open-ILS/src/templates/opac/parts/advanced/search.tt2 | 6 +++++- Open-ILS/src/templates/opac/parts/filtersort.tt2 | 12 ++++++++++++ Open-ILS/src/templates/opac/parts/searchbar.tt2 | 7 ++++++- 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index b1527fb87d..bd9c3df0dd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -256,6 +256,11 @@ sub load_common { return $self->redirect_ssl unless $self->cgi->https; } + # XXX Cache this? Makes testing difficult as apache needs a restart. + my $default_sort = $e->retrieve_config_global_flag('opac.default_sort'); + $ctx->{default_sort} = + ($default_sort && $U->is_true($default_sort->enabled)) ? $default_sort->value : ''; + $ctx->{referer} = $self->cgi->referer; $ctx->{path_info} = $self->cgi->path_info; $ctx->{full_path} = $ctx->{base_path} . $self->cgi->path_info; 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 9c59fa321b..31974ca386 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -11712,6 +11712,20 @@ INSERT INTO config.global_flag (name, label, value, enabled) VALUES ( TRUE ); +/* To be added when upgrade scripts are pulled into the baseline +INSERT INTO config.global_flag (name, label, value, enabled) VALUES ( + 'opac.default_sort', + oils_i18n_gettext( + 'opac.default_sort', + 'OPAC Default Sort (titlesort, authorsort, pubdate, popularity, poprel, or empty)', + 'cgf', + 'label' + ), + '', + TRUE +); +*/ + INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype) VALUES ( 'history.circ.retention_age', diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql index 1c9324dcfc..1bcbe63404 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.statisitcal-ratings.sql @@ -128,6 +128,13 @@ CREATE TRIGGER reporter_hold_request_record_trigger AFTER INSERT OR UPDATE ON ac CREATE SCHEMA rating; +INSERT INTO config.global_flag (name, label, value, enabled) VALUES ( + 'opac.default_sort', + 'OPAC Default Sort (titlesort, authorsort, pubdate, popularity, poprel, or empty for relevance)', + '', + TRUE +); + CREATE TABLE rating.popularity_parameter ( id INT PRIMARY KEY, name TEXT NOT NULL UNIQUE, -- i18n diff --git a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 index 8cfad7faa4..dc650a1c7b 100644 --- a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 +++ b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 @@ -118,9 +118,13 @@ [% END %] [% CASE "sort_selector"; + default_sort=ctx.default_sort; + IF CGI.param('sort'); + default_sort=CGI.param('sort'); + END; INCLUDE "opac/parts/filtersort.tt2" id=adv_chunk.id - value=CGI.param('sort') class='results_header_sel'; + value=default_sort class='results_header_sel'; %] [% IF NOT metarecords.disabled %] diff --git a/Open-ILS/src/templates/opac/parts/filtersort.tt2 b/Open-ILS/src/templates/opac/parts/filtersort.tt2 index 1907058175..29903524f8 100644 --- a/Open-ILS/src/templates/opac/parts/filtersort.tt2 +++ b/Open-ILS/src/templates/opac/parts/filtersort.tt2 @@ -14,4 +14,16 @@ + + + + + + diff --git a/Open-ILS/src/templates/opac/parts/searchbar.tt2 b/Open-ILS/src/templates/opac/parts/searchbar.tt2 index 20088fa93b..a48c4a0e6f 100644 --- a/Open-ILS/src/templates/opac/parts/searchbar.tt2 +++ b/Open-ILS/src/templates/opac/parts/searchbar.tt2 @@ -98,7 +98,12 @@ [% END %] [%- END %] - [% UNLESS took_care_of_form %][% END %] + [% UNLESS took_care_of_form %] + [% IF ctx.default_sort %] + + [% END %] + + [% END %] [% IF (is_advanced AND NOT is_special) AND CGI.param('qtype') %]