Skip to content

Commit

Permalink
Rendering queue of Transfers via DataTables
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernhardt committed Apr 28, 2021
1 parent 076eb7f commit 27f9060
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/views/transfer/_empty.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<tr class="empty">
<td colspan="6">There were no transfers matching your parameters.
</tr>
8 changes: 8 additions & 0 deletions app/views/transfer/_transfer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<tr>
<td data-sort="<%= transfer.created_at %>"><%= link_to transfer.created_at.in_time_zone('Eastern Time (US & Canada)').strftime('%b %-d, %Y<br>%l:%M %p').html_safe, url_for(transfer) %></td>
<td data-sort="<%= transfer.grad_date %>"><%= transfer.graduation_month[...3] %> <%= transfer.graduation_year %></td>
<td><%= transfer.department.name_dw %></td>
<td><%= transfer.user.display_name %></td>
<td><%= transfer.files.count %></td>
<td><%= transfer.note.present? ? "<span title='#{transfer.note}'>#{transfer.note[..10]}...</span>".html_safe : "" %></td>
</tr>
64 changes: 63 additions & 1 deletion app/views/transfer/select.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
<p>This is the transfer select view.</p>
<%= content_for(:title, "Transfer Processing | MIT Libraries") %>

<% content_for :additional_js do %>
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<% end %>

<link href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css" rel="stylesheet">

<h3 class="title title-page">Transfer Processing Queue</h3>

<div id="term-list" class="filter-row">
<button data-filter="*">Show<br>all</button>
</div>

<table class="table" id="transferQueue">
<thead>
<tr>
<th scope="col">Transfer date</th>
<th scope="col">Degree date</th>
<th scope="col">Department</th>
<th scope="col">Dept. Admin</th>
<th scope="col">Files</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<%= render(partial: 'transfer/transfer', collection: @transfers) || render('empty') %>
</tbody>
</table>

<script type="text/javascript">
$(document).ready( function () {
if( document.getElementById('transferQueue').getElementsByClassName('empty').length === 0 ) {
var table = $('#transferQueue').DataTable({
"order": [[ 1, "asc" ]]
});

// Populate filter buttons with found values
var terms = [...new Set( table.columns(1).data()[0] )];
terms.forEach(element => {
document
.getElementById("term-list")
.insertAdjacentHTML("beforeend", `
<button data-filter="${element}">${element.replace(' ', '<br>')}</button>
`);
});

// Perform filtering when buttons are clicked
$(".filter-row button").click(function() {
var needle = $(this).data("filter");
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
return ( data[1] === needle || needle === "*" )
? true
: false
}
);
table.draw();
$.fn.dataTable.ext.search.pop();
});
}
});
</script>
8 changes: 7 additions & 1 deletion app/views/transfer/show.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<%= content_for(:title, "Thesis Transfer Submission | MIT Libraries") %>
<%= content_for(:title, "Transfer Processing | MIT Libraries") %>

<h3 class="title title-page">Transfer file list</h3>

<p><%= link_to "Back to Transfer queue", transfer_select_path %></p>

<p>This will be the display of all files in this Transfer, for processing into Thesis records.</p>
5 changes: 0 additions & 5 deletions test/fixtures/transfers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ alsovalid:
department: one
grad_date: 2020-05-01
user: thesis_admin

baduser:
department: one
grad_date: 2020-05-01
user: invalid
4 changes: 3 additions & 1 deletion test/models/transfer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class TransferTest < ActiveSupport::TestCase
end

test 'needs valid user' do
@transfer = transfers(:baduser)
@transfer = transfers(:valid)
assert @transfer.valid?
@transfer.user = nil
assert @transfer.invalid?
end

Expand Down

0 comments on commit 27f9060

Please sign in to comment.