From 3d9ebd1a78b22732f4cbe7a1c1f3e94bd501f53e Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 9 Feb 2024 12:15:31 +0000 Subject: [PATCH] Bug 36045: Use DataTables filter for suggestions search This patch removes the server-side suggestions search form and related code from the OPAC suggestions page. In its place is a DataTables filter form and a custom dropdown to replace the "suggested by me/anyone" option from the old search. To test you should have some suggestions in your system submitted by two or more users. - Apply the patch and rebuild the OPAC CSS. - Go to Administration -> System preferences and set the "OPACViewOthersSuggestions" preference to "Show." - Log in to the OPAC as one of the users who has submitted suggetions. - Go to the purchase suggestions page. - The initial view should be of "your" suggestions. - The dropdown filter at the top should have "Suggested by me" selected. - The "Clear filter" button should be disabled. - Test that the "Suggested by me" dropdown works to change what's shown in the table. - The "Clear filter" button should be enabled when you choose "Suggested by anyone." - The DataTables "Search" field should work correctly with either setting of the "Suggested by..." dropdown. - Go back to Administration in the staff interface and disable the "OPACViewOthersSuggestions" preference. - Return to the suggestions page in the OPAC. - You should see only your suggestions, and the "Suggested by..." dropdown should not be there. - Confirm that filtering still works correctly. Signed-off-by: David Nind --- .../opac-tmpl/bootstrap/css/src/_common.scss | 9 +- .../bootstrap/en/modules/opac-suggestions.tt | 106 ++++++++++-------- opac/opac-suggestions.pl | 10 +- 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss b/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss index 647012a0a0a..407b3b1ff7c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss +++ b/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss @@ -656,11 +656,13 @@ table { } } - input { + input, + select { @extend .form-control; @extend .form-control-sm; display: inline-block; + margin-left: 5px; width: auto; &:focus { @@ -670,6 +672,11 @@ table { } } +.dataTables_info { + font-size: 0.875rem; + margin: 5px; +} + .table_entries { color: #797979; font-size: 90%; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index 8febcbcc3a3..acd3c71c757 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -338,36 +338,6 @@ [% IF ( deleted ) %]
The selected suggestions have been deleted.
[% END %] - [% IF (Koha.Preference( 'OPACViewOthersSuggestions' ) || loggedinusername) && (suggestions.size > 0 OR title_filter) %] - [% SET can_delete_suggestion = 0 %] -
-
- -
-
- -
- [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) %] - [% IF loggedinusername %] -
- - -
- [% END %] - [% END %] -
- -
-
- [% END %] [% IF suggestions.size > 0 %] [% SET can_delete_suggestion = 0 %]
@@ -401,14 +371,17 @@ [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 || loggedinusername %] - - [% IF ( loggedinusername ) %][% END %] + [% IF ( loggedinusername ) %][% END %] - [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %][% END %] + [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %] + + + [% END %] [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %][% END %] @@ -425,7 +398,7 @@ [% END %] [% END %] - + [% END %] [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]
Your purchase suggestions + Your purchase suggestions
  Summary Suggested on NoteSuggested forSuggested forManaged byStatus +

+ [% IF logged_in_user.borrowernumber == suggestion.suggester.borrowernumber %] + 1 + [% ELSE %] + 0 + [% END %] + @@ -567,31 +547,65 @@ [% END %] $(function() { - $("#suggestt").dataTable($.extend(true, {}, dataTablesDefaults, { + dataTablesDefaults.buttons.splice(1,3); // Remove copy, print, csv from button set + var suggestions_table = $("#suggestt").DataTable($.extend(true, {}, dataTablesDefaults, { "order": [[ 1, "asc" ]], "autoWidth": false, + "dom": '<"top"<"table_entries"i><"table_controls"fB>>t', "columnDefs": [ - [% IF ( loggedinusername ) %]{ "targets": [ 0 ], "sortable": false, "searchable": false }[% END %], + { "targets": ["NoSort"], "sortable": false, "searchable": false }, + { "visible": false, "targets" : [ "hidden" ] }, { "className": 'dtr-control', "orderable": false, "targets": -1 }, + { "type": "anti-the", "targets" : [ "anti-the" ] }, { responsivePriority: 1, targets: 1 } ], - "columns": [ - [% IF ( loggedinusername ) %]null,[% END %] - { "type": "anti-the" }, - null, - null, - [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]null,[% END %] - [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]null,[% END %] - null, - null - ], + "language": { + "search": "_INPUT_", + "searchPlaceholder": _("Search") + }, "responsive": { details: { type: 'column', target: -1 } }, + initComplete: function (settings, json) { + var tableId = settings.nTable.id; + [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 && loggedinusername %] + // Add select filter + $('#suggestt_filter').append('').append(''); + // Filter results on select change + let suggested_by_user = $("#suggested_by_user"); + suggested_by_user.on('change', function () { + suggestions_table.columns(5).search($(this).val()).draw(); + }); + $("body").on( 'search.dt', "#" + tableId, function ( e, settings ) { + if( settings.oPreviousSearch.sSearch == "" && suggested_by_user.val() == "1" ){ + $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled"); + } else { + $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled"); + } + }); + [% ELSE %] + $("body").on( 'search.dt', "#" + tableId, function ( e, settings ) { + if( settings.oPreviousSearch.sSearch == "" ){ + $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled"); + } else { + $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled"); + } + }); + [% END %] + } })); + $("#usersuggestions").on("click", ".dt_button_clear_filter",function(){ + suggestions_table.search("").columns().search("").draw(); + $("#suggested_by_user").val(1).change(); + $(this).addClass("disabled"); + }); + [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 && loggedinusername %] + suggestions_table.columns(5).search( 1 ).draw(); + [% END %] + [% IF ( loggedinusername ) %]$("span.clearall").html(""+_("Clear all")+"<\/a>"); $("span.checkall").html(""+_("Select all")+"<\/a>"); $("#CheckAll").on("click",function(e){ diff --git a/opac/opac-suggestions.pl b/opac/opac-suggestions.pl index 528bd9ccd7f..bfe0fd20503 100755 --- a/opac/opac-suggestions.pl +++ b/opac/opac-suggestions.pl @@ -105,10 +105,7 @@ my $suggested_by; if ( $op eq 'else' ) { if ( C4::Context->preference("OPACViewOthersSuggestions") ) { if ( $borrowernumber ) { - # A logged in user is able to see suggestions from others - $suggested_by = $suggested_by_anyone - ? undef - : $borrowernumber; + $suggested_by = undef; } # else: Non logged in user is able to see all suggestions } @@ -136,7 +133,7 @@ $suggestion = { ( defined $p && $p ne '' ? ( $_ => $p ) : () ) } keys %$suggestion }; -$suggestion->{suggestedby} = $borrowernumber; +$suggestion->{suggestedby} = $suggested_by; if ( $op eq "cud-add_validate" && not $biblionumber ) { # If we are creating the suggestion from an existing record we do not want to search for duplicates $op = 'cud-add_confirm'; @@ -226,9 +223,6 @@ my $suggestions = [ Koha::Suggestions->search_limited( $suggestion->{suggestedby} ? ( suggestedby => $suggestion->{suggestedby} ) : (), - $title_filter - ? ( title => $title_filter ) - : (), } )->as_list ]; -- 2.39.2