Skip to content

Commit

Permalink
Initial sortable tables (#52)
Browse files Browse the repository at this point in the history
This adds server-side sorting for the
columns on the `zizia_csv_import_details` table.

Sorting the additional headers will require more
complex queries or a different solution.

Connected to curationexperts/in-house#420
  • Loading branch information
little9 authored and bess committed Oct 31, 2019
1 parent c436d29 commit fe99e1d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/zizia/_import_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.desc::after {
content: ''
}
.asc::after {
content: ''
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/zizia/zizia.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import 'file_upload';
@import 'field_guide';
@import 'new';
@import 'import_table';

.btn {
white-space:normal !important;
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/zizia/csv_import_details_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# frozen_string_literal: true
module Zizia
class CsvImportDetailsController < ApplicationController
helper_method :sort_column, :sort_direction
load_and_authorize_resource
with_themed_layout 'dashboard'

def index
@csv_import_details = Zizia::CsvImportDetail.order(:id).page csv_import_detail_params[:page]
@csv_import_details = Zizia::CsvImportDetail.order(sort_column + ' ' + sort_direction).page csv_import_detail_params[:page]
end

def show
@csv_import_detail = Zizia::CsvImportDetail.find(csv_import_detail_params["id"])
@csv_import_detail = Zizia::CsvImportDetail.find(csv_import_detail_params['id'])
end

private

def sort_column
Zizia::CsvImportDetail.column_names.include?(params[:sort]) ? params[:sort] : 'created_at'
end

def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'desc'
end

def csv_import_detail_params
params.permit(:id, :page)
params.permit(:id, :page, :sort, :direction)
end
end
end
20 changes: 20 additions & 0 deletions app/helpers/zizia/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# frozen_string_literal: true
module Zizia
module ApplicationHelper
def human_update_actor_stack(update_actor_stack)
case update_actor_stack
when 'HyraxDelete'
'Overwrite All Files & Metadata'
when 'HyraxMetadataOnly'
'Update Existing Metadata, create new works'
when 'HyraxOnlyNew'
'Ignore Existing Works, new works only'
else
'Unknown'
end
end

def sortable(column, title = nil)
title ||= column.titleize
css_class = column == sort_column ? "current #{sort_direction}" : nil
direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'
link_to title, { sort: column, direction: direction }, class: css_class
end

def collections_for_select
ActiveFedora::SolrService.query('has_model_ssim:Collection').map do |c|
[c['title_tesim'][0], c['id']]
Expand Down
8 changes: 4 additions & 4 deletions app/views/zizia/csv_import_details/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h3>CSV Imports</h3>
<table class="table table-striped">
<tr>
<th>ID</th>
<th><%= sortable 'id', 'ID' %></th>
<th>Associated User</th>
<th>Date</th>
<th><%= sortable 'created_at', 'Date' %></th>
<th>CSV File</th>
<th>Number of Works</th>
<th>Number of Files</th>
Expand All @@ -23,7 +23,7 @@
<%= csv_import_detail.created_at.strftime("%B %-d, %Y %H:%M") %>
</td>
<td>
<%= csv_import_detail.csv_import.manifest %>
<%= File.basename(csv_import_detail.csv_import.manifest.to_s) %>
</td>
<td>
<%= csv_import_detail.pre_ingest_works.count %>
Expand All @@ -38,7 +38,7 @@
<%= csv_import_detail.status %>
</td>
<td>
<%= csv_import_detail.update_actor_stack %>
<%= human_update_actor_stack(csv_import_detail.update_actor_stack) %>
</td>
</tr>
<% end %>
Expand Down
30 changes: 29 additions & 1 deletion spec/dummy/spec/system/csv_import_details_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
RSpec.describe 'viewing the csv import detail page' do
let(:csv_import) { FactoryBot.create(:csv_import) }
let(:csv_import_detail) { FactoryBot.create_list(:csv_import_detail, 12, created_at: Time.parse('Tue, 29 Oct 2019 14:20:02 UTC +00:00').utc) }
let(:csv_import_detail_second) { FactoryBot.create(:csv_import_detail, created_at: Time.parse('Thur, 31 Oct 2019 14:20:02 UTC +00:00').utc, status: 'zippy', update_actor_stack: 'ZiziaTesting') }
let(:user) { FactoryBot.create(:admin) }

before do
user.save
csv_import.user_id = user.id
csv_import.save
csv_import_detail.each(&:save)
csv_import_detail_second.save
login_as user
end

Expand All @@ -23,6 +25,32 @@
expect(page).to have_content('Total Size')
end

it 'has links to sort' do
visit ('/csv_import_details/index')
expect(page).to have_content ('Unknown')
click_on('Date')
expect(page.current_url).to match(/index\?direction\=asc\&locale\=en\&sort\=created_at/)
expect(page).not_to have_content('Unknown')
visit('/csv_import_details/index?direction=desc&locale=en&sort=created_at')
expect(page).to have_content('Unknown')
end

it 'has a sortable id' do
visit('/csv_import_details/index?direction=desc&locale=en&sort=id')
expect(page).to have_link '13'
end

it 'has a sortable status' do
pending 'status is always undetermined currently'
visit('/csv_import_details/index?direction=asc&locale=en&sort=status')
expect(page).to have_content 'zippy'
end

it 'has a sortable date' do
visit('/csv_import_details/index?direction=desc&locale=en&sort=created_at')
expect(page).to have_content 'October 31'
end

it 'displays the metadata when you visit the page' do
visit ('/csv_import_details/index')
expect(page).to have_content('CSV Imports ID')
Expand All @@ -45,7 +73,7 @@
it 'displays the overwrite behavior type' do
visit ('/csv_import_details/index')
expect(page).to have_content('Overwrite Behavior Type')
expect(page).to have_content('HyraxMetadataOnly')
expect(page).to have_content('Update Existing Metadata, create new works')
end

it 'has the dashboard layout' do
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/spec/system/import_from_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
# Viewing additional details after an import
visit "/csv_import_details/index"
expect(page).to have_content('Total Size')
find(:xpath, '//*[@id="content-wrapper"]/div[2]/table/tbody/tr[2]/td[1]/a').click
find(:xpath, '//*[@id="content-wrapper"]/div[2]/table/tbody/tr[3]/td[1]/a').click
expect(page).to have_content('dog.jpg')
expect(page).to have_content('5.74 MB')
end
Expand Down

0 comments on commit fe99e1d

Please sign in to comment.