Bugzilla – Attachment 63088 Details for
Bug 7317
Add an Interlibrary Loan Module to Circulation and OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7317: Allow display/hiding of arbitrary request columns
Bug-7317-Allow-displayhiding-of-arbitrary-request-.patch (text/plain), 21.17 KB, created by
Alex Sassmannshausen
on 2017-05-04 10:33:35 UTC
(
hide
)
Description:
Bug 7317: Allow display/hiding of arbitrary request columns
Filename:
MIME Type:
Creator:
Alex Sassmannshausen
Created:
2017-05-04 10:33:35 UTC
Size:
21.17 KB
patch
obsolete
>From 9abdd4f5e5447f63c9a8d30b5c3036e19d57e2b6 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Fri, 3 Mar 2017 17:14:41 +0000 >Subject: [PATCH] Bug 7317: Allow display/hiding of arbitrary request columns > >Initially display a small selection of core fields, allow the user to >progressively display additional metadata fields if required >--- > koha-tmpl/intranet-tmpl/prog/css/staff-global.css | 15 + > .../prog/en/modules/ill/ill-requests.tt | 449 +++++++++++++++------ > 2 files changed, 339 insertions(+), 125 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css >index ba5f92036c..f8dbc7e671 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/staff-global.css >+++ b/koha-tmpl/intranet-tmpl/prog/css/staff-global.css >@@ -3052,6 +3052,13 @@ fieldset.rows + fieldset.action { > margin: 1em; > } > >+#interlibraryloans #column-toggle, >+#interlibraryloans #reset-toggle { >+ margin: 15px 0; >+ line-height: 1.5em; >+ font-weight: 700; >+} >+ > #ill-view-panel { > margin-top: 15px; > } >@@ -3072,3 +3079,11 @@ fieldset.rows + fieldset.action { > #ill-view-panel #requestattributes .label { > width: auto; > } >+ >+table#ill-requests { >+ width: 100% !important; >+} >+ >+table#ill-requests th { >+ text-transform: capitalize; >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >index 7ecbfd15b9..10ded63d41 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >@@ -10,121 +10,183 @@ > <script type="text/javascript"> > //<![CDATA[ > $(document).ready(function() { >- var myTable = $("#ill-requests").DataTable($.extend(true, {}, dataTablesDefaults, { >- "aoColumnDefs": [ // Last column shouldn't be sortable or searchable >- { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }, >- ], >- "aaSorting": [[ 8, "desc" ]], // Default sort, updated descending >- "processing": true, // Display a message when manipulating >- "language": { >- "loadingRecords": "Please wait - loading requests...", >- "zeroRecords": "No requests were found" >- }, >- "iDisplayLength": 10, // 10 results per page >- "sPaginationType": "full_numbers", // Pagination display >- "sAjaxDataProp": "", // Data is in the root object of the response >- "deferRender": true, // Improve performance on big datasets >- "ajax": { >- url: "/api/v1/illrequests?embed=metadata,patron,capabilities,branch", >- cache: true >- }, >- "columns": [ >- { >- data: 'orderid', >- className: 'orderid' >- }, >- { >- render: function(data, type, row) { >- return ( >- row.metadata.hasOwnProperty('Author') && >- row.metadata.Author.length > 0 >- ) ? row.metadata.Author : 'N/A'; >- }, >- className: 'title' >- }, >- { >- render: function(data, type, row) { >- return ( >- row.metadata.hasOwnProperty('Title') && >- row.metadata.Title.length > 0 >- ) ? row.metadata.Title : 'N/A'; >- }, >- className: 'title' >- }, >- { >- render: function(data, type, row) { >- return '<a title="View borrower details" ' + >- 'href="/cgi-bin/koha/members/moremember.pl?' + >- 'borrowernumber='+row.borrowernumber+'">' + >- row.patron.firstname + ' ' + row.patron.surname + >- '</a>'; >- }, >- className: 'borrower_name' >- }, >- { >- data: 'borrowernumber', >- className: 'borrowernumber' >- }, >- { >- data: 'biblio_id', >- className: 'biblio_id' >- }, >- { >- data: 'branch.branchname', >- className: 'branch_name' >- }, >- { >- render: function(data, type, row) { >- return row.capabilities[row.status].name; >- }, >- className: 'status' >- }, >- { >- data: 'updated', >- className: 'updated' >- }, >- { >- data: 'medium', >- className: 'medium' >- }, >- { >- data: 'cost', >- className: 'cost' >- }, >- { >- render: function(data, type, row) { >- return row.id_prefix + row.illrequest_id; >- }, >- className: 'request_id' >- }, >- { >- data: null, >- render: function(data, type, row) { >- return '<a class="btn btn-default btn-sm" ' + >- 'href="/cgi-bin/koha/ill/ill-requests.pl?' + >- 'method=illview&illrequest_id=' + >- row.illrequest_id + >- '">Manage request</a>' + >- '</div>' >+ >+ // Illview Datatable setup >+ >+ // Fields we don't want to display >+ var ignore = [ >+ 'accessurl', >+ 'backend', >+ 'completed', >+ 'branch', >+ 'capabilities', >+ 'cost', >+ 'medium', >+ 'notesopac', >+ 'notesstaff', >+ 'placed', >+ 'replied' >+ ]; >+ >+ // Fields we need to expand (flatten) >+ var expand = [ >+ 'metadata', >+ 'patron' >+ ]; >+ >+ // Expanded fields >+ // This is auto populated >+ var expanded = {}; >+ >+ // The core fields that should be displayed first >+ var core = [ >+ 'metadata_Author', >+ 'metadata_Title', >+ 'borrowernumber', >+ 'biblio_id', >+ 'branchcode', >+ 'status', >+ 'updated', >+ 'illrequest_id', >+ 'action' >+ ]; >+ >+ // Extra fields that we need to tack on to the end >+ var extra = [ 'action' ]; >+ >+ // Remove any fields we're ignoring >+ var removeIgnore = function(dataObj) { >+ dataObj.forEach(function(thisRow) { >+ ignore.forEach(function(thisIgnore) { >+ if (thisRow.hasOwnProperty(thisIgnore)) { >+ delete thisRow[thisIgnore]; >+ } >+ }); >+ }); >+ }; >+ >+ // Expand any fields we're expanding >+ var expandExpand = function(row) { >+ expand.forEach(function(thisExpand) { >+ if (row.hasOwnProperty(thisExpand)) { >+ if (!expanded.hasOwnProperty(thisExpand)) { >+ expanded[thisExpand] = []; > } >+ var expandObj = row[thisExpand]; >+ Object.keys(expandObj).forEach( >+ function(thisExpandCol) { >+ var expColName = thisExpand + '_' + thisExpandCol; >+ // Keep a list of fields that have been expanded >+ // so we can create toggle links for them >+ if (expanded[thisExpand].indexOf(expColName) == -1) { >+ expanded[thisExpand].push(expColName); >+ } >+ expandObj[expColName] = >+ expandObj[thisExpandCol]; >+ delete expandObj[thisExpandCol]; >+ } >+ ); >+ $.extend(true, row, expandObj); >+ delete row[thisExpand]; > } >- ] >- })); >- var filters = $('#ill-requests').data(); >- if (typeof filters !== 'undefined') { >- var filterNames = Object.keys(filters).filter( >- function(thisData) { >- return thisData.match(/^filter/); >+ }); >+ }; >+ >+ // Build a de-duped list of all column names >+ var allCols = {}; >+ core.map(function(thisCore) { >+ allCols[thisCore] = 1; >+ }); >+ var unionColumns = function(row) { >+ Object.keys(row).forEach(function(col) { >+ if (ignore.indexOf(col) == -1) { >+ allCols[col] = 1; > } >- ); >- filterNames.forEach(function(thisFilter) { >- var filterClass = "." + toColumnName(thisFilter); >- var regex = '^'+filters[thisFilter]+'$'; >- myTable.columns(filterClass).search(regex, true, false); > }); >- myTable.draw(); >+ }; >+ >+ // Some rows may not have fields that other rows have, >+ // so make sure all rows have the same fields >+ var fillMissing = function(row) { >+ Object.keys(allCols).forEach(function(thisCol) { >+ row[thisCol] = (!row.hasOwnProperty(thisCol)) ? >+ null : >+ row[thisCol]; >+ }); > } > >+ // Strip the expand prefix if it exists, we do this for display >+ var stripPrefix = function(value) { >+ expand.forEach(function(thisExpand) { >+ var regex = new RegExp(thisExpand + '_', 'g'); >+ value = value.replace(regex, ''); >+ }); >+ return value; >+ }; >+ >+ // Our 'render' function for borrowerlink >+ var createBorrowerLink = function(data, type, row) { >+ return '<a title="View borrower details" ' + >+ 'href="/cgi-bin/koha/members/moremember.pl?' + >+ 'borrowernumber='+row.patron_borrowernumber+'">' + >+ row.patron_firstname + ' ' + row.patron_surname + >+ '</a>'; >+ }; >+ >+ // Render function for request ID >+ var createRequestId = function(data, type, row) { >+ return row.id_prefix + row.illrequest_id; >+ }; >+ >+ // Render function for request status >+ var createStatus = function(data, type, row, meta) { >+ var origData = meta.settings.oInit.originalData; >+ if (origData.length > 0) { >+ return meta.settings.oInit.originalData[0].capabilities[ >+ row.status >+ ].name; >+ } else { >+ return ''; >+ } >+ }; >+ >+ // Render function for creating a row's action link >+ var createActionLink = function(data, type, row) { >+ return '<a class="btn btn-default btn-sm" ' + >+ 'href="/cgi-bin/koha/ill/ill-requests.pl?' + >+ 'method=illview&illrequest_id=' + >+ row.illrequest_id + >+ '">Manage request</a>' + >+ '</div>' >+ }; >+ >+ // Columns that require special treatment >+ var specialCols = { >+ action: { >+ name: '', >+ func: createActionLink >+ }, >+ borrowernumber: { >+ name: 'Borrower', >+ func: createBorrowerLink >+ }, >+ illrequest_id: { >+ name: 'Request number', >+ func: createRequestId >+ }, >+ status: { >+ name: 'Status', >+ func: createStatus >+ }, >+ biblio_id: { >+ name: 'Biblio number' >+ }, >+ branchcode: { >+ name: 'Branch code' >+ } >+ }; >+ >+ // Helper for handling prefilter column names > function toColumnName(myVal) { > return myVal > .replace(/^filter/, '') >@@ -132,10 +194,12 @@ > .replace(/^_/,'').toLowerCase(); > }; > >+ // Toggle request attributes in Illview > $('#toggle_requestattributes').click(function() { > $('#requestattributes').toggleClass('content_hidden'); > }); > >+ // Filter partner list > $('#partner_filter').keyup(function() { > var needle = $('#partner_filter').val(); > $('#partners > option').each(function() { >@@ -152,6 +216,149 @@ > }); > }); > >+ // Get our data from the API and process it prior to passing >+ // it to datatables >+ var ajax = $.ajax( >+ '/api/v1/illrequests?embed=metadata,patron,capabilities,branch' >+ ).done(function() { >+ var data = JSON.parse(ajax.responseText); >+ // Make a copy, we'll be removing columns next and need >+ // to be able to refer to data that has been removed >+ var dataCopy = $.extend(true, [], data); >+ // Remove all columns we're not interested in >+ removeIgnore(dataCopy); >+ // Expand columns that need it and create an array >+ // of all column names >+ $.each(dataCopy, function(k, row) { >+ expandExpand(row); >+ unionColumns(row); >+ }); >+ // Append any extra columns we need to tag on >+ if (extra.length > 0) { >+ extra.forEach(function(thisExtra) { >+ allCols[thisExtra] = 1; >+ }); >+ }; >+ // Different requests will have different columns, >+ // make sure they all have the same >+ $.each(dataCopy, function(k, row) { >+ fillMissing(row); >+ }); >+ >+ // Assemble an array of column definitions for passing >+ // to datatables >+ var colData = []; >+ Object.keys(allCols).forEach(function(thisCol) { >+ // We may have defined a pretty name for this column >+ var colName = ( >+ specialCols.hasOwnProperty(thisCol) && >+ specialCols[thisCol].hasOwnProperty('name') >+ ) ? >+ specialCols[thisCol].name : >+ thisCol; >+ // Create the table header for this column >+ var str = '<th>' + stripPrefix(colName) + '</th>'; >+ $(str).appendTo('#illview-header'); >+ // Create the base column object >+ var colObj = { >+ name: thisCol, >+ className: thisCol >+ }; >+ // We may need to process the data going in this >+ // column, so do it if necessary >+ if ( >+ specialCols.hasOwnProperty(thisCol) && >+ specialCols[thisCol].hasOwnProperty('func') >+ ) { >+ colObj.render = specialCols[thisCol].func; >+ } else { >+ colObj.data = thisCol >+ } >+ colData.push(colObj); >+ }); >+ >+ // Create the toggle links for all metadata fields >+ var links = []; >+ expanded.metadata.forEach(function(thisExpanded) { >+ if (core.indexOf(thisExpanded) == -1) { >+ links.push( >+ '<a href="#" class="toggle-vis" data-column="' + >+ thisExpanded + '">' + stripPrefix(thisExpanded) + >+ '</a>' >+ ); >+ } >+ }); >+ $('#column-toggle').append(links.join(' | ')); >+ >+ // Initialise the datatable >+ var myTable = $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, { >+ aoColumnDefs: [ // Last column shouldn't be sortable or searchable >+ { >+ aTargets: [ 'action' ], >+ bSortable: false, >+ bSearchable: false >+ }, >+ ], >+ aaSorting: [[ 6, 'desc' ]], // Default sort, updated descending >+ processing: true, // Display a message when manipulating >+ language: { >+ loadingRecords: "Please wait - loading requests...", >+ zeroRecords: "No requests were found" >+ }, >+ iDisplayLength: 10, // 10 results per page >+ sPaginationType: "full_numbers", // Pagination display >+ deferRender: true, // Improve performance on big datasets >+ data: dataCopy, >+ columns: colData, >+ originalData: data // Enable render functions to access >+ // our original data >+ })); >+ >+ // Reset columns to default >+ var resetColumns = function() { >+ Object.keys(allCols).forEach(function(thisCol) { >+ myTable.column(thisCol + ':name').visible(core.indexOf(thisCol) != -1); >+ }); >+ myTable.columns.adjust().draw(false); >+ }; >+ >+ // Handle the click event on a toggle link >+ $('a.toggle-vis').on('click', function(e) { >+ e.preventDefault(); >+ var column = myTable.column( >+ $(this).data('column') + ':name' >+ ); >+ column.visible(!column.visible()); >+ }); >+ >+ // Reset column toggling >+ $('#reset-toggle').click(function() { >+ resetColumns(); >+ }); >+ >+ // Handle a prefilter request and do the prefiltering >+ var filters = $('#ill-requests').data(); >+ if (typeof filters !== 'undefined') { >+ var filterNames = Object.keys(filters).filter( >+ function(thisData) { >+ return thisData.match(/^filter/); >+ } >+ ); >+ filterNames.forEach(function(thisFilter) { >+ var filterName = toColumnName(thisFilter) + ':name'; >+ var regex = '^'+filters[thisFilter]+'$'; >+ console.log(regex); >+ myTable.columns(filterName).search(regex, true, false); >+ }); >+ myTable.draw(); >+ } >+ >+ // Initialise column hiding >+ resetColumns(); >+ >+ } >+ ); >+ > }); > //]]> > </script> >@@ -442,29 +649,21 @@ > <h1>View ILL requests</h1> > <div id="results"> > <h3>Details for all requests</h3> >+ >+ <div id="column-toggle"> >+ Toggle additional columns: >+ </div> >+ <div id="reset-toggle"><a href="#">Reset toggled columns</a></div> >+ > <table > [% FOREACH filter IN prefilters %] > data-filter-[% filter.name %]="[% filter.value %]" > [% END %] > id="ill-requests"> > <thead> >- <tr> >- <th id="orderid">Order ID:</th> >- <th id="author">Author:</th> >- <th id="title">Title:</th> >- <th id="borrower_name">Borrower:</th> >- <th id="borrowernumber">Borrower number:</th> >- <th id="biblio_id">Biblio number:</th> >- <th id="branchcode">Branch:</th> >- <th id="status">Status:</th> >- <th id="updated">Last updated:</th> >- <th id="medium">Request type:</th> >- <th id="cost">Cost:</th> >- <th id="req_id">Request number:</th> >- <th id="link">Manage request:</th> >- </tr> >+ <tr id="illview-header"></tr> > </thead> >- <tbody> >+ <tbody id="illview-body"> > </tbody> > </table> > </div> >-- >2.12.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 7317
:
59893
|
59894
|
59895
|
59920
|
60485
|
60486
|
60487
|
60488
|
63081
|
63082
|
63083
|
63084
|
63085
|
63086
|
63087
|
63088
|
63089
|
63090
|
63113
|
63175
|
63176
|
63354
|
63421
|
63472
|
63475
|
65469
|
65470
|
65471
|
65472
|
65473
|
65474
|
65475
|
65476
|
66266
|
67242
|
67243
|
67244
|
67245
|
67246
|
67247
|
67248
|
67249
|
67250
|
67251
|
67252
|
67253
|
67254
|
67255
|
67256
|
67257
|
67258
|
67259
|
67260
|
67261
|
67262
|
67263
|
67264
|
67281
|
67282
|
67283
|
67284
|
67285
|
67286
|
67287
|
67288
|
67289
|
67290
|
67291
|
67292
|
67293
|
67294
|
67295
|
67296
|
67297
|
67298
|
67299
|
67300
|
67301
|
67302
|
67303
|
68185
|
68186
|
68328
|
68391
|
68406
|
68407
|
68408
|
68409
|
68418
|
68444
|
68445
|
68483
|
68484
|
68485
|
68487
|
68516
|
68517
|
68518
|
68519
|
68520
|
68521
|
68522
|
68523
|
68524
|
68525
|
68542
|
68543
|
68544
|
68545
|
68546
|
68547
|
68548
|
68549
|
68550
|
68551
|
68552
|
68558
|
68559
|
68560
|
68561
|
68562
|
68563
|
68564
|
68565
|
68566
|
68567
|
68858
|
68874
|
68877
|
68878
|
68885
|
68886
|
68921
|
68922
|
68926
|
68927
|
68928
|
68929
|
68931
|
68932
|
68933
|
68988
|
68989
|
68999
|
69000
|
69006
|
69008
|
69009
|
69012
|
69014
|
69044
|
69045
|
69046
|
69056
|
69059
|
69060
|
69061
|
69063
|
69064
|
69065
|
69066
|
69069
|
69070
|
69071
|
69074