From f69ef97d8ba7719e4ccc9abf6590ba3d47281c11 Mon Sep 17 00:00:00 2001 From: Jamie Little Date: Tue, 29 Oct 2019 13:24:31 -0500 Subject: [PATCH] Add ability to toggle your imports This adds a toggle that will allow you to choose to see all imports or only imports you have created. Connected to curationexperts/in-house#424 --- .../stylesheets/zizia/_import_table.scss | 8 +++-- .../zizia/csv_import_details_controller.rb | 21 +++++++++++--- .../_toggle_my_imports.html.erb | 7 +++++ .../zizia/csv_import_details/index.html.erb | 1 + .../system/csv_import_details_page_spec.rb | 29 +++++++++++++++---- 5 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 app/views/zizia/csv_import_details/_toggle_my_imports.html.erb diff --git a/app/assets/stylesheets/zizia/_import_table.scss b/app/assets/stylesheets/zizia/_import_table.scss index 3fb0946..e638048 100644 --- a/app/assets/stylesheets/zizia/_import_table.scss +++ b/app/assets/stylesheets/zizia/_import_table.scss @@ -1,6 +1,10 @@ .desc::after { - content: ' ▾' + content: ' ▾' } .asc::after { - content: ' ▴' + content: ' ▴' +} + +.toggle-imports { + margin-bottom: 1em; } diff --git a/app/controllers/zizia/csv_import_details_controller.rb b/app/controllers/zizia/csv_import_details_controller.rb index 716183d..461189f 100644 --- a/app/controllers/zizia/csv_import_details_controller.rb +++ b/app/controllers/zizia/csv_import_details_controller.rb @@ -1,20 +1,33 @@ # frozen_string_literal: true module Zizia class CsvImportDetailsController < ApplicationController - helper_method :sort_column, :sort_direction + helper_method :sort_column, :sort_direction, :user + load_and_authorize_resource with_themed_layout 'dashboard' def index - @csv_import_details = Zizia::CsvImportDetail.order(sort_column + ' ' + sort_direction).page csv_import_detail_params[:page] + @csv_import_details = if csv_import_detail_params[:user] && user_id + Zizia::CsvImportDetail + .order(sort_column + ' ' + sort_direction) + .where(depositor_id: user_id).page csv_import_detail_params[:page] + else + Zizia::CsvImportDetail + .order(sort_column + ' ' + sort_direction).page csv_import_detail_params[:page] + end 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 user_id + User.find_by(email: csv_import_detail_params[:user]).id + end + def sort_column Zizia::CsvImportDetail.column_names.include?(params[:sort]) ? params[:sort] : 'created_at' end @@ -24,7 +37,7 @@ def sort_direction end def csv_import_detail_params - params.permit(:id, :page, :sort, :direction) + params.permit(:id, :page, :sort, :direction, :user) end end end diff --git a/app/views/zizia/csv_import_details/_toggle_my_imports.html.erb b/app/views/zizia/csv_import_details/_toggle_my_imports.html.erb new file mode 100644 index 0000000..2f95e6b --- /dev/null +++ b/app/views/zizia/csv_import_details/_toggle_my_imports.html.erb @@ -0,0 +1,7 @@ +
+ <% if request.params[:user] %> + <%= link_to 'View All Imports', request.params.except(:user), class: 'btn btn-default toggle-imports view-all-imports' %> + <% else %> + <%= link_to 'View My Imports', request.params.merge(user: current_user.email), class: 'btn btn-default toggle-imports view-my-imports' %> + <% end %> +
diff --git a/app/views/zizia/csv_import_details/index.html.erb b/app/views/zizia/csv_import_details/index.html.erb index a40b917..2eedab8 100644 --- a/app/views/zizia/csv_import_details/index.html.erb +++ b/app/views/zizia/csv_import_details/index.html.erb @@ -1,4 +1,5 @@

CSV Imports

+<%= render 'toggle_my_imports' %> 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 df779ec..3f1a13d 100644 --- a/spec/dummy/spec/system/csv_import_details_page_spec.rb +++ b/spec/dummy/spec/system/csv_import_details_page_spec.rb @@ -2,23 +2,33 @@ include Warden::Test::Helpers RSpec.describe 'viewing the csv import detail page' do + let(:user) { FactoryBot.create(:admin, email: 'systems@curationexperts.com')} + let(:second_user) { FactoryBot.create(:user, email: 'user@curationexperts.com') } 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) } + let(:second_csv_import) { FactoryBot.create(:csv_import, id: 2, user_id: 2) } + 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, depositor_id: user.id) } + 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', depositor_id: user.id) } + let(:csv_import_detail_third) { FactoryBot.create(:csv_import_detail, created_at: Time.parse('Wed, 30 Oct 2019 14:20:02 UTC +00:00').utc, depositor_id: second_user.id, csv_import_id: 2) } before do user.save + second_user.save + csv_import.user_id = user.id csv_import.save + + second_csv_import.user_id = second_user.id + second_csv_import.save + csv_import_detail.each(&:save) csv_import_detail_second.save + csv_import_detail_third.save login_as user end it 'displays the metadata when you visit the page' do visit ('/csv_import_details/index') - expect(page).to have_content('CSV Imports ID') + expect(page).to have_content('ID') expect(page).to have_content('Status') expect(page).to have_content('undetermined') click_on '1' @@ -53,7 +63,7 @@ it 'displays the metadata when you visit the page' do visit ('/csv_import_details/index') - expect(page).to have_content('CSV Imports ID') + expect(page).to have_content('ID') click_on '1' expect(page).to have_content('Total Size') end @@ -85,6 +95,7 @@ visit('/csv_import_details/index') expect(page).to have_content('Next') + end it 'has pagination at 10' do @@ -93,4 +104,12 @@ click_on 'Next' expect(page).to have_content('Previous') end + + it 'allows you to view only your imports' do + visit('/csv_import_details/index') + click_on 'View My Imports' + expect(page).not_to have_content('user@curationexperts.com') + click_on 'View All Imports' + expect(page).to have_content('user@curationexperts.com') + end end
<%= sortable 'id', 'ID' %>