From ed8a7c22a62e95449dcbb8386442d5765d4eda11 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 11 Jun 2013 11:31:49 +0200 Subject: [PATCH] [PASSED QA] Bug 10857: Add facets cancellation When searching (at the OPAC or pro), facets can be enabled but never disabled. So a user is obliged to relaunch the search. This patch adds a new link "[x]" at the right of each selected facet. This link relaunch the search without this facet. Test plan: - Launch a search (OPAC and pro) - Enable some facets - Disable some facets Signed-off-by: sonia bouis Signed-off-by: Katrin Fischer Patches pass all tests and QA script. Nice feature! Tested in Boostrap and Prog, adding end removing multiple facets in different sequences, adding and removing the availability limit. --- catalogue/search.pl | 12 +++++++++ .../intranet-tmpl/prog/en/includes/facets.inc | 27 ++++++++++++++++--- .../opac-tmpl/prog/en/includes/opac-facets.inc | 31 +++++++++++++++++++--- opac/opac-search.pl | 13 +++++++++ 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/catalogue/search.pl b/catalogue/search.pl index 892ff15..2bb7600 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -411,6 +411,9 @@ my @operands = map uri_unescape($_), $cgi->param('q'); # limits are use to limit to results to a pre-defined category such as branch or language my @limits = map uri_unescape($_), $cgi->param('limit'); +my @nolimits = map uri_unescape($_), $cgi->param('nolimit'); +my %is_nolimit = map { $_ => 1 } @nolimits; +@limits = grep { not $is_nolimit{$_} } @limits; if($params->{'multibranchlimit'}) { my $multibranch = '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')'; @@ -686,6 +689,15 @@ my $gotopage = $cgi->param('gotoPage'); $template->{'VARS'}->{'gotoPage'} = $gotopage if $gotopage =~ m/^(ISBD|labeledMARC|MARC|more)?detail.pl$/; +my @input_values = map { $_->{input_value} } @limit_inputs; +for my $facet ( @$facets ) { + for my $entry ( @{ $facet->{facets} } ) { + my $index = $entry->{type_link_value}; + my $value = $entry->{facet_link_value}; + $entry->{active} = grep { $_ eq qq{$index:$value} } @input_values; + } +} + $template->param( #classlist => $classlist, total => $total, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index 765bf01..7cfa267 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -20,9 +20,30 @@ [% IF ( facets_loo.type_label_Libraries ) %]Libraries[% END %] [% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
    - [% FOREACH facet IN facets_loo.facets %]
  • [% facet.facet_label_value %] [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]
  • [% END %][% IF ( facets_loo.expandable ) %] -
  • Show more
  • -[% END %] + [% FOREACH facet IN facets_loo.facets %] +
  • + [% SET query_cgi_f = query_cgi | html %] + [% SET limit_cgi_f = limit_cgi | html %] + [% SET url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi_f _ limit_cgi_f %] + [% IF ( sort_by ) %] + [% SET url = url _ "&sort_by=" _ sort_by %] + [% END %] + [% IF facet.active %] + [% SET url = url _ "&nolimit=" _ facet.type_link_value _ ":" _ facet.facet_link_value %] + [% facet.facet_label_value %] + [x] + [% ELSE %] + [% SET url = url _ "&limit=" _ facet.type_link_value _ ":" _ facet.facet_link_value %] + [% facet.facet_label_value %] + [% IF ( displayFacetCount ) %] + ([% facet.facet_count %]) + [% END %] + [% END %] +
  • + [% END %] + [% IF ( facets_loo.expandable ) %] +
  • Show more
  • + [% END %]
[% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc b/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc index aae5d71..84183c5 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/opac-facets.inc @@ -21,10 +21,33 @@ [% END %] [% IF ( facets_loo.type_label_Location ) %]Locations[% END %]
    - [% FOREACH facet IN facets_loo.facets %]
  • [% facet.facet_label_value %] [% IF ( displayFacetCount ) %]([% facet.facet_count %])[% END %]
  • [% END %][% IF ( facets_loo.expandable ) %] -
  • Show more
  • -[% END %] -
+ [% FOREACH facet IN facets_loo.facets %] +
  • + [% SET query_cgi_f = query_cgi | html %] + [% SET limit_cgi_f = limit_cgi | html %] + [% SET url = "/cgi-bin/koha/opac-search.pl?" _ query_cgi_f _ limit_cgi_f %] + [% IF ( sort_by ) %] + [% SET url = url _ "&sort_by=" _ sort_by |html %] + [% END %] + [% IF facet.active %] + [% SET url = url _ "&nolimit=" _ facet.type_link_value _ ":" _ facet.facet_link_value %] + [% facet.facet_label_value %] + [x] + [% ELSE %] + [% SET url = url _ "&limit=" _ facet.type_link_value _ ":" _ facet.facet_link_value %] + [% facet.facet_label_value %] + [% IF ( displayFacetCount ) %] + ([% facet.facet_count %]) + [% END %] + [% END %] +
  • + [% END %] + [% IF ( facets_loo.expandable ) %] +
  • Show more +
  • + [% END %] + + [% END %] [% END %] diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 617d67e..b2c2403 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -400,6 +400,9 @@ if ($operands[0] && !$operands[1]) { # limits are use to limit to results to a pre-defined category such as branch or language my @limits = $cgi->param('limit'); +my @nolimits = $cgi->param('nolimit'); +my %is_nolimit = map { $_ => 1 } @nolimits; +@limits = grep { not $is_nolimit{$_} } @limits; @limits = map { uri_unescape($_) } @limits; if($params->{'multibranchlimit'}) { @@ -840,6 +843,16 @@ for (my $i=0;$i<@servers;$i++) { } #/end of the for loop #$template->param(FEDERATED_RESULTS => \@results_array); +my @input_values = map { $_->{input_value} } @limit_inputs; +for my $facet ( @$facets ) { + for my $entry ( @{ $facet->{facets} } ) { + my $index = $entry->{type_link_value}; + my $value = $entry->{facet_link_value}; + $entry->{active} = grep { $_ eq qq{$index:$value} } @input_values; + } +} + + $template->param( #classlist => $classlist, total => $total, -- 1.8.3.2