Bugzilla – Attachment 170996 Details for
Bug 36045
Use DataTables filter for suggestions search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36045: Use DataTables filter for suggestions search
Bug-36045-Use-DataTables-filter-for-suggestions-se.patch (text/plain), 14.71 KB, created by
Owen Leonard
on 2024-09-03 17:33:39 UTC
(
hide
)
Description:
Bug 36045: Use DataTables filter for suggestions search
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2024-09-03 17:33:39 UTC
Size:
14.71 KB
patch
obsolete
>From 3d9ebd1a78b22732f4cbe7a1c1f3e94bd501f53e Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >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 <david@davidnind.com> >--- > .../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 ) %]<div class="alert alert-info">The selected suggestions have been deleted.</div>[% END %] > >- [% IF (Koha.Preference( 'OPACViewOthersSuggestions' ) || loggedinusername) && (suggestions.size > 0 OR title_filter) %] >- [% SET can_delete_suggestion = 0 %] >- <form action="/cgi-bin/koha/opac-suggestions.pl" class="row" id="search_suggestions_form" method="get"> >- <div class="col-auto gx-2 ms-2 my-1"> >- <label for="title_filter">Search for:</label> >- </div> >- <div class="col-auto gx-2 my-1"> >- <input type="text" name="title_filter" id="title_filter" value="[% title_filter | html %]" size="30" class="form-control form-control-sm" /> >- </div> >- [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) %] >- [% IF loggedinusername %] >- <div class="col-auto gx-2 my-1"> >- <label class="sr-only" for="suggested_by_anyone">Suggested by:</label> >- <select class="form-select form-select-sm" name="suggested_by_anyone" id="suggested_by_anyone"> >- [% IF suggested_by_anyone %] >- <option value="0">Suggested by me</option> >- <option value="1" selected="selected">Suggested by anyone</option> >- [% ELSE %] >- <option value="0" selected="selected">Suggested by me</option> >- <option value="1">Suggested by anyone</option> >- [% END %] >- </select> >- </div> >- [% END %] >- [% END %] >- <div class="col-auto gx-2 my-1"> >- <button type="submit" class="btn btn-sm btn-primary">Go</button> >- </div> >- </form> >- [% END %] > [% IF suggestions.size > 0 %] > [% SET can_delete_suggestion = 0 %] > <form action="/cgi-bin/koha/opac-suggestions.pl" method="post" id="delete_suggestions"> >@@ -401,14 +371,17 @@ > > [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 || loggedinusername %] > <table id="suggestt" class="table table-bordered tabled"> >- <caption class="sr-only">Your purchase suggestions<caption> >+ <caption class="sr-only">Your purchase suggestions</caption> > <thead> > <tr> >- [% IF ( loggedinusername ) %]<th> </th>[% END %] >+ [% IF ( loggedinusername ) %]<th class="NoSort"> </th>[% END %] > <th class="all">Summary</th> > <th>Suggested on</th> > <th>Note</th> >- [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %]<th>Suggested for</th>[% END %] >+ [% IF Koha.Preference( 'OPACViewOthersSuggestions' ) == 1 %] >+ <th>Suggested for</th> >+ <th class="hidden"></th> >+ [% END %] > [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %]<th>Managed by</th>[% END %] > <th>Status</th> > <th></th> >@@ -425,7 +398,7 @@ > [% END %] > </td> > [% END %] >- <td> >+ <td class="anti-the"> > <p> > <label for="id[% suggestions_loo.suggestionid | html %]"> > [% IF suggestion.biblionumber %] >@@ -459,6 +432,13 @@ > [% Branches.GetName(suggestion.branchcode) | html %] > [% END %] > </td> >+ <td> >+ [% IF logged_in_user.borrowernumber == suggestion.suggester.borrowernumber %] >+ 1 >+ [% ELSE %] >+ 0 >+ [% END %] >+ </td> > [% END %] > [% IF Koha.Preference( 'OpacSuggestionManagedBy' ) %] > <td> >@@ -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('<label for="suggested_by_user" class="sr-only">Filter:</label>').append('<select class="form-control form-control-sm" name="suggested_by_user" id="suggested_by_user"><option value="1" selected="selected">Suggested by me</option><option value="0">Suggested by anyone</option></select>'); >+ // 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("<a id=\"CheckNone\" class=\"btn btn-link btn-sm\" href=\"#\">"+_("Clear all")+"<\/a>"); > $("span.checkall").html("<a id=\"CheckAll\" class=\"btn btn-link btn-sm\" href=\"#\">"+_("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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36045
:
162061
|
165714
|
167792
| 170996