Skip to content

Commit

Permalink
Add ability to toggle your imports
Browse files Browse the repository at this point in the history
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
  • Loading branch information
little9 authored and bess committed Nov 4, 2019
1 parent fe99e1d commit f69ef97
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
8 changes: 6 additions & 2 deletions app/assets/stylesheets/zizia/_import_table.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.desc::after {
content: ''
content: ''
}
.asc::after {
content: ''
content: ''
}

.toggle-imports {
margin-bottom: 1em;
}
21 changes: 17 additions & 4 deletions app/controllers/zizia/csv_import_details_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="btn-group" role="group" aria-label="Table Visibility Controls">
<% 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 %>
</div>
1 change: 1 addition & 0 deletions app/views/zizia/csv_import_details/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h3>CSV Imports</h3>
<%= render 'toggle_my_imports' %>
<table class="table table-striped">
<tr>
<th><%= sortable 'id', 'ID' %></th>
Expand Down
29 changes: 24 additions & 5 deletions spec/dummy/spec/system/csv_import_details_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@
include Warden::Test::Helpers

RSpec.describe 'viewing the csv import detail page' do
let(:user) { FactoryBot.create(:admin, email: '[email protected]')}
let(:second_user) { FactoryBot.create(:user, email: '[email protected]') }
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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +95,7 @@

visit('/csv_import_details/index')
expect(page).to have_content('Next')

end

it 'has pagination at 10' do
Expand All @@ -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('[email protected]')
click_on 'View All Imports'
expect(page).to have_content('[email protected]')
end
end

0 comments on commit f69ef97

Please sign in to comment.