Bugzilla – Attachment 72908 Details for
Bug 15235
Add column filters to checkouts table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15235: Add column filters to checkouts table
Bug-15235-Add-column-filters-to-checkouts-table.patch (text/plain), 12.92 KB, created by
Julian Maurice
on 2018-03-15 08:45:51 UTC
(
hide
)
Description:
Bug 15235: Add column filters to checkouts table
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-03-15 08:45:51 UTC
Size:
12.92 KB
patch
obsolete
>From d4392e1441b77d32027b9625d614c528bb6b5a89 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 9 Feb 2017 16:19:42 +0100 >Subject: [PATCH] Bug 15235: Add column filters to checkouts table > >This adds a switch that allow to enable/disable column filters on >checkouts table (disabled by default) > >Depends on bug 15219 >--- > C4/Utils/DataTables.pm | 44 +++++++++------ > .../plugins/jquery.dataTables.columnFilter.js | 2 +- > koha-tmpl/intranet-tmpl/prog/css/datatables.css | 10 ++++ > .../prog/en/includes/checkouts-table.inc | 18 +++++++ > .../intranet-tmpl/prog/en/includes/strings.inc | 1 + > .../prog/en/modules/circ/circulation.tt | 1 + > .../prog/en/modules/members/moremember.tt | 1 + > koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 62 ++++++++++++++++++++++ > svc/checkouts | 6 +++ > 9 files changed, 129 insertions(+), 16 deletions(-) > >diff --git a/C4/Utils/DataTables.pm b/C4/Utils/DataTables.pm >index e6fc1ccbcf..62629c32f2 100644 >--- a/C4/Utils/DataTables.pm >+++ b/C4/Utils/DataTables.pm >@@ -20,6 +20,8 @@ package C4::Utils::DataTables; > use Modern::Perl; > require Exporter; > >+use Koha::DateUtils; >+ > use vars qw(@ISA @EXPORT); > > BEGIN { >@@ -138,14 +140,10 @@ sub dt_build_having { > my $mDataProp = $param->{'mDataProp_'.$i}; > my @filter_fields = $param->{$mDataProp.'_filteron'} > ? split(' ', $param->{$mDataProp.'_filteron'}) >- : (); >- if(@filter_fields > 0) { >- foreach my $field (@filter_fields) { >- push @gFilters, " $field LIKE ? "; >- push @gParams, "%$sSearch%"; >- } >- } else { >- push @gFilters, " $mDataProp LIKE ? "; >+ : ($mDataProp); >+ >+ foreach my $field (@filter_fields) { >+ push @gFilters, " $field LIKE ? "; > push @gParams, "%$sSearch%"; > } > } >@@ -163,17 +161,33 @@ sub dt_build_having { > my $mDataProp = $param->{'mDataProp_'.$i}; > my @filter_fields = $param->{$mDataProp.'_filteron'} > ? split(' ', $param->{$mDataProp.'_filteron'}) >- : (); >- if(@filter_fields > 0) { >- my @localfilters; >- foreach my $field (@filter_fields) { >+ : ($mDataProp); >+ >+ my @localfilters; >+ foreach my $field (@filter_fields) { >+ if ($sSearch =~ /^(.*)\~(.*)$/) { >+ my ($from, $to) = ($1, $2); >+ my @datefilters; >+ if ($from) { >+ my $date = dt_from_string($from); >+ push @datefilters, " $field >= ? "; >+ push @params, $date->ymd; >+ } >+ if ($to) { >+ my $date = dt_from_string($to); >+ push @datefilters, " $field <= ? "; >+ push @params, $date->ymd; >+ } >+ if (@datefilters) { >+ push @localfilters, ' (' . join(' AND ', @datefilters) . ') '; >+ } >+ } else { > push @localfilters, " $field LIKE ? "; > push @params, "%$sSearch%"; > } >+ } >+ if (@localfilters) { > push @filters, " ( ". join(" OR ", @localfilters) ." ) "; >- } else { >- push @filters, " $mDataProp LIKE ? "; >- push @params, "%$sSearch%"; > } > } > $i++; >diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js >index 89343f576f..342ecd0235 100644 >--- a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js >+++ b/koha-tmpl/intranet-tmpl/lib/jquery/plugins/jquery.dataTables.columnFilter.js >@@ -250,7 +250,6 @@ > //th.html(_fnRangeLabelPart(0)); > var sFromId = oTable.attr("id") + '_range_from_' + i; > var from = $('<input type="text" class="date_range_filter" id="' + sFromId + '" rel="' + i + '"/>'); >- from.datepicker(); > //th.append(from); > //th.append(_fnRangeLabelPart(1)); > var sToId = oTable.attr("id") + '_range_to_' + i; >@@ -275,6 +274,7 @@ > > > th.wrapInner('<span class="filter_column filter_date_range" />'); >+ from.datepicker(); > to.datepicker(); > var index = i; > aiCustomSearch_Indexes.push(i); >diff --git a/koha-tmpl/intranet-tmpl/prog/css/datatables.css b/koha-tmpl/intranet-tmpl/prog/css/datatables.css >index 71fdb6b2ec..05f28e31d9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/datatables.css >+++ b/koha-tmpl/intranet-tmpl/prog/css/datatables.css >@@ -257,6 +257,16 @@ span.filter_column > input[type="text"] { > box-sizing: border-box; > } > >+span.filter_column.filter_date_range { >+ white-space: nowrap; >+} >+ >+span.filter_column > input.date_range_filter { >+ font-size: 80%; >+ width: 6em; >+ padding: 0; >+} >+ > /* Row grouping */ > td.group, > table.group td.group { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc >index b723d62a66..621e8dfda0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc >@@ -9,6 +9,24 @@ > <form name="issues" action="/cgi-bin/koha/tools/export.pl" method="post" class="checkboxed"> > <table id="issues-table" style="width: 100% !Important;"> > <thead> >+ <tr class="filters_row" style="display: none"> >+ <th> </th> >+ <th> </th> >+ <th>Due date</th> >+ <th>Title</th> >+ <th>Item type</th> >+ <th>Location</th> >+ <th>Home library</th> >+ <th>Checked out on</th> >+ <th>Checked out from</th> >+ <th>Call no</th> >+ <th> </th> >+ <th> </th> >+ <th> </th> >+ <th> </th> >+ <th> </th> >+ <th> </th> >+ </tr> > <tr> > <th scope="col"> </th> > <th scope="col"> </th> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc >index ff87e4b0ad..4c43819201 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/strings.inc >@@ -44,5 +44,6 @@ > var RESUME_HOLD_ERROR_NOT_FOUND = _("Unable to resume, hold not found"); > var CURRENT = _(" (current) "); > var GROUP_TODAYS_CHECKOUTS = _("Group today's checkouts"); >+ var SHOW_COLUMN_FILTERS = _("Show column filters"); > //]]> > </script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >index ba48183ab1..0ec63cffa3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >@@ -979,6 +979,7 @@ No patron matched <span class="ex">[% message | html %]</span> > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery-ui-timepicker-addon.min_[% KOHA_VERSION %].js"></script> > [% INCLUDE 'timepicker.inc' %] > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.rowGrouping_[% KOHA_VERSION %].js"></script> >+ <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter_[% KOHA_VERSION %].js"></script> > <script type="text/javascript" src="[% interface %]/[% theme %]/js/pages/circulation_[% KOHA_VERSION %].js"></script> > [% INCLUDE 'checkouts.js.inc' %] > <script type="text/javascript" src="[% interface %]/[% theme %]/js/holds_[% KOHA_VERSION %].js"></script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >index eddf396e16..1c3d5ea08a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >@@ -549,6 +549,7 @@ > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery-ui-timepicker-addon.min_[% KOHA_VERSION %].js"></script> > [% INCLUDE 'timepicker.inc' %] > <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.rowGrouping_[% KOHA_VERSION %].js"></script> >+ <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.dataTables.columnFilter_[% KOHA_VERSION %].js"></script> > <script type="text/javascript" src="[% interface %]/[% theme %]/js/pages/circulation_[% KOHA_VERSION %].js"></script> > [% INCLUDE 'checkouts.js.inc' %] > <script type="text/javascript" src="[% interface %]/[% theme %]/js/holds_[% KOHA_VERSION %].js"></script> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js >index e5f0bcfa62..eab4fa8772 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js >@@ -22,6 +22,49 @@ function disableGrouping(datatable) { > } > } > >+function enableFiltering(datatable) { >+ var oSettings = datatable.fnSettings(); >+ var filters_row = $(oSettings.nTable).find('thead tr.filters_row'); >+ if (!filters_row.hasClass('columnFilter')) { >+ datatable.columnFilter({ >+ sPlaceHolder: "head:after", >+ bUseColVis: true, >+ sRangeFormat: "From {from}<br>to {to}", >+ aoColumns: [ >+ null, >+ null, >+ { type: "date-range" }, >+ { type: "text" }, >+ { type: "text" }, >+ { type: "text" }, >+ { type: "text" }, >+ { type: "date-range" }, >+ { type: "text" }, >+ { type: "text" }, >+ null, >+ null, >+ null, >+ null, >+ null, >+ null, >+ null >+ ] >+ }); >+ filters_row.addClass('columnFilter'); >+ } >+ filters_row.show(); >+} >+ >+function disableFiltering(datatable) { >+ var oSettings = datatable.fnSettings(); >+ var filters_row = $(oSettings.nTable).find('thead tr.filters_row'); >+ filters_row.find('input[type="text"]') >+ .val('') // Empty filter text boxes >+ .trigger('keyup') // Filter (display all rows) >+ .trigger('blur'); // Reset value to the column name >+ filters_row.hide(); >+} >+ > var renderers = { > groupOrder: function (data, type, row) { > if ( row.issued_today ) { >@@ -589,6 +632,25 @@ $(document).ready(function() { > .append('<label for="issues-table-row-grouping-switch">' + GROUP_TODAYS_CHECKOUTS + '</label>') > .appendTo('#issues-table_wrapper .top.pager'); > >+ var filteringSwitch = $('<input type="checkbox">') >+ .attr('id', 'issues-table-filtering-switch') >+ .css('vertical-align', 'middle') >+ .change(function() { >+ if ($(this).is(':checked')) { >+ enableFiltering(issuesTable); >+ } else { >+ disableFiltering(issuesTable); >+ } >+ }); >+ $('<div></div>') >+ .css('float', 'left') >+ .css('padding', '0.3em 0.5em') >+ .css('line-height', '1.9em') >+ .append(filteringSwitch) >+ .append(' ') >+ .append('<label for="issues-table-filtering-switch">' + SHOW_COLUMN_FILTERS + '</label>') >+ .appendTo('#issues-table_wrapper .top.pager'); >+ > if ( $("#issues-table").length ) { > $("#issues-table_processing").position({ > of: $( "#issues-table" ), >diff --git a/svc/checkouts b/svc/checkouts >index 34a8562e6c..864eb06e84 100755 >--- a/svc/checkouts >+++ b/svc/checkouts >@@ -52,6 +52,7 @@ my $count = $input->param('iDisplayLength'); > > my %params = dt_get_params($input); > my $orderby = dt_build_orderby(\%params); >+my ($having, $having_params) = dt_build_having(\%params); > > my $todaysIssuesDefaultSortOrder = > C4::Context->preference('todaysIssuesDefaultSortOrder'); >@@ -128,6 +129,11 @@ if ( @borrowernumber == 1 ) { > $sql .= $borrowernumber_sql; > push( @parameters, @borrowernumber ); > >+if (@$having) { >+ $sql .= ' HAVING ' . join (' AND ', @$having); >+ push @parameters, @$having_params; >+} >+ > $sql .= " $orderby"; > > if ($count && $count > 0) { >-- >2.14.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 15235
:
45096
|
60079
|
61160
|
72908
|
79205
|
79206