diff --git a/app/assets/stylesheets/zizia/_import_table.scss b/app/assets/stylesheets/zizia/_import_table.scss new file mode 100644 index 0000000..3fb0946 --- /dev/null +++ b/app/assets/stylesheets/zizia/_import_table.scss @@ -0,0 +1,6 @@ +.desc::after { + content: ' ▾' +} +.asc::after { + content: ' ▴' +} diff --git a/app/assets/stylesheets/zizia/zizia.scss b/app/assets/stylesheets/zizia/zizia.scss index f426d59..5e5b9eb 100644 --- a/app/assets/stylesheets/zizia/zizia.scss +++ b/app/assets/stylesheets/zizia/zizia.scss @@ -1,6 +1,7 @@ @import 'file_upload'; @import 'field_guide'; @import 'new'; +@import 'import_table'; .btn { white-space:normal !important; diff --git a/app/controllers/zizia/csv_import_details_controller.rb b/app/controllers/zizia/csv_import_details_controller.rb index ebb0b95..716183d 100644 --- a/app/controllers/zizia/csv_import_details_controller.rb +++ b/app/controllers/zizia/csv_import_details_controller.rb @@ -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 diff --git a/app/helpers/zizia/application_helper.rb b/app/helpers/zizia/application_helper.rb index 0249b06..99d0a2f 100644 --- a/app/helpers/zizia/application_helper.rb +++ b/app/helpers/zizia/application_helper.rb @@ -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']] diff --git a/app/views/zizia/csv_import_details/index.html.erb b/app/views/zizia/csv_import_details/index.html.erb index fddab5e..a40b917 100644 --- a/app/views/zizia/csv_import_details/index.html.erb +++ b/app/views/zizia/csv_import_details/index.html.erb @@ -1,9 +1,9 @@

CSV Imports

- + - + @@ -23,7 +23,7 @@ <%= csv_import_detail.created_at.strftime("%B %-d, %Y %H:%M") %> <% end %> diff --git a/spec/dummy/spec/system/csv_import_details_page_spec.rb b/spec/dummy/spec/system/csv_import_details_page_spec.rb index 19c09c6..df779ec 100644 --- a/spec/dummy/spec/system/csv_import_details_page_spec.rb +++ b/spec/dummy/spec/system/csv_import_details_page_spec.rb @@ -4,6 +4,7 @@ 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 @@ -11,6 +12,7 @@ csv_import.user_id = user.id csv_import.save csv_import_detail.each(&:save) + csv_import_detail_second.save login_as user end @@ -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') @@ -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 diff --git a/spec/dummy/spec/system/import_from_csv_spec.rb b/spec/dummy/spec/system/import_from_csv_spec.rb index 3edae4a..c14720a 100644 --- a/spec/dummy/spec/system/import_from_csv_spec.rb +++ b/spec/dummy/spec/system/import_from_csv_spec.rb @@ -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
ID<%= sortable 'id', 'ID' %> Associated UserDate<%= sortable 'created_at', 'Date' %> CSV File Number of Works Number of Files - <%= csv_import_detail.csv_import.manifest %> + <%= File.basename(csv_import_detail.csv_import.manifest.to_s) %> <%= csv_import_detail.pre_ingest_works.count %> @@ -38,7 +38,7 @@ <%= csv_import_detail.status %> - <%= csv_import_detail.update_actor_stack %> + <%= human_update_actor_stack(csv_import_detail.update_actor_stack) %>