Skip to content

Commit

Permalink
Add batch actions to all/managed works page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Dixon committed Jan 12, 2018
1 parent af46dda commit c39dd24
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 48 deletions.
4 changes: 0 additions & 4 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ def on_the_dashboard?
params[:controller].match(%r{^hyrax/dashboard|hyrax/my})
end

def on_my_works?
params[:controller].match(%r{^hyrax/my/works})
end

def number_of_works(user = current_user)
Hyrax::WorkRelation.new.where(DepositSearchBuilder.depositor_field => user.user_key).count
rescue RSolr::Error::ConnectionRefused
Expand Down
1 change: 1 addition & 0 deletions app/views/hyrax/dashboard/works/_default_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<caption class="sr-only"><%= t("hyrax.dashboard.my.sr.listing") %> <%= application_name %></caption>
<thead>
<tr>
<th class="check-all"><label for="check_all" class="sr-only"><%= t("hyrax.dashboard.my.sr.check_all_label") %></label><%= render_check_all %></th>
<th><%= t("hyrax.dashboard.my.heading.title") %></th>
<th class="date"><%= t("hyrax.dashboard.my.heading.date_uploaded") %></th>
<th><%= t("blacklight.search.fields.facet.suppressed_bsi") %></th>
Expand Down
4 changes: 4 additions & 0 deletions app/views/hyrax/dashboard/works/_list_works.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<tr id="document_<%= document.id %>">
<td>
<label for="batch_document_<%= document.id %>" class="sr-only"><%=t("hyrax.dashboard.my.sr.batch_checkbox")%></label>
<%= render 'hyrax/batch_select/add_button', document: document %>&nbsp;
</td>
<td>
<div class='media'>
<%= link_to [main_app, document], class: 'media-left', 'aria-hidden' => true do %>
Expand Down
16 changes: 1 addition & 15 deletions app/views/hyrax/my/_search_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,4 @@
</div>
</div>

<% if on_my_works? %>
<div class="batch-info">
<%= render 'hyrax/dashboard/collections/form_for_select_collection', user_collections: @user_collections if params[:controller] != 'hyrax/my/collections' %>

<div class="batch-toggle">
<% session[:batch_edit_state] = "on" %>
<div class="button_to-inline">
<%= button_to "Edit Selected", hyrax.edit_batch_edits_path, method: :get, class: "btn btn-update btn-primary hidden submits-batches", data: { behavior: 'batch-edit' }, id: 'batch-edit' %>
</div>
<%= batch_delete %>
<%= button_tag "Add to Collection", class: 'btn btn-primary submits-batches submits-batches-add',
data: { toggle: "modal", target: "#collection-list-container" } %>
</div>
</div>
<% end %>
<%= render 'batch_actions' %>
5 changes: 5 additions & 0 deletions app/views/hyrax/my/collections/_batch_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="batch-info">
<div class="batch-toggle">
<button id="delete-collections-button" class="btn btn-danger delete-collections-button"><%= t("hyrax.dashboard.my.action.delete_collections") %></button>
</div>
</div>
2 changes: 0 additions & 2 deletions app/views/hyrax/my/collections/_default_group.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<button id="delete-collections-button" class="btn btn-danger delete-collections-button"><%= t("hyrax.dashboard.my.action.delete_collections") %></button>

<table class="table table-striped collections-list-table">
<caption class="sr-only"><%= t("hyrax.dashboard.my.sr.listing") %> <%= application_name %></caption>
<thead>
Expand Down
14 changes: 14 additions & 0 deletions app/views/hyrax/my/works/_batch_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="batch-info">
<%= render 'hyrax/dashboard/collections/form_for_select_collection', user_collections: @user_collections %>

<div class="batch-toggle">
<% session[:batch_edit_state] = "on" %>
<div class="button_to-inline">
<%= button_to t('hyrax.dashboard.my.action.edit_selected'), hyrax.edit_batch_edits_path, method: :get, class: "btn btn-update btn-primary hidden submits-batches", data: { behavior: 'batch-edit' }, id: 'batch-edit' %>
</div>
<%= batch_delete %>
<%= button_tag t('hyrax.dashboard.my.action.add_to_collection'),
class: 'btn btn-primary submits-batches submits-batches-add',
data: { toggle: "modal", target: "#collection-list-container" } %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/hyrax/my/works/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul class="nav nav-tabs" id="my_nav" role="navigation">
<span class="sr-only">You are currently listing your works. You have <%= @response.docs.count %> <%= 'work'.pluralize(@response.docs.count)%> </span>
<li<%= ' class="active"'.html_safe if current_page?(hyrax.dashboard_works_path(locale: nil)) %>>
<%= link_to t("hyrax.dashboard.#{current_ability.admin? ? 'all' : 'managed'}.works"), hyrax.dashboard_works_path %>
<%= link_to t("hyrax.dashboard.#{current_ability.admin? ? 'all' : 'managed'}.works"), hyrax.dashboard_works_path, data: { turbolinks: false } %>
</li>
<li<%= ' class="active"'.html_safe if current_page?(hyrax.my_works_path(locale: nil)) %>>
<%= link_to t('hyrax.dashboard.my.works'), hyrax.my_works_path, data: { turbolinks: false } %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ en:
edit_admin_set: "Edit collection" # use same term for admin sets and collections
edit_collection: "Edit collection"
edit_collection_deny: "You do not have sufficient privileges to edit this collection."
edit_selected: "Edit Selected"
edit_work: "Edit Work"
highlight: "Highlight Work on Profile"
nesting_not_allowed: "Collections of this type do not support nesting."
Expand Down
19 changes: 15 additions & 4 deletions spec/controllers/hyrax/batch_edits_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
describe "#edit" do
let(:one) { create(:work, creator: ["Fred"], title: ["abc"], language: ['en']) }
let(:two) { create(:work, creator: ["Wilma"], title: ["abc2"], publisher: ['Rand McNally'], language: ['en'], resource_type: ['bar']) }
let(:three) { create(:work, creator: ["Dino"], title: ["abc3"]) }

before do
controller.batch = [one.id, two.id]
controller.batch = [one.id, two.id, three.id]
expect(controller).to receive(:can?).with(:edit, one.id).and_return(true)
expect(controller).to receive(:can?).with(:edit, two.id).and_return(true)
expect(controller).to receive(:can?).with(:edit, three.id).and_return(false)
end

it "is successful" do
Expand All @@ -29,26 +31,33 @@
describe "update" do
let(:user) { build(:user) }
let!(:one) do
create(:generic_work, creator: ["Fred"], title: ["abc"], language: ['en'], user: user)
create(:work, creator: ["Fred"], title: ["abc"], language: ['en'], user: user)
end

let!(:two) do
create(:generic_work, creator: ["Fred"], title: ["abc"], language: ['en'], user: user)
create(:work, creator: ["Fred"], title: ["abc"], language: ['en'], user: user)
end

let!(:three) do
create(:work, creator: ["Fred"], title: ["abc"], language: ['en'])
end

let(:mycontroller) { "hyrax/my/works" }

before do
# TODO: why aren't we just submitting batch_document_ids[] as a parameter?
controller.batch = [one.id, two.id]
controller.batch = [one.id, two.id, three.id]
expect(controller).to receive(:can?).with(:edit, one.id).and_return(true)
expect(controller).to receive(:can?).with(:edit, two.id).and_return(true)
expect(controller).to receive(:can?).with(:edit, three.id).and_return(false)
end

it "is successful" do
put :update, params: { update_type: "delete_all" }
expect(response).to redirect_to(dashboard_path(locale: 'en'))
expect { GenericWork.find(one.id) }.to raise_error(Ldp::Gone)
expect { GenericWork.find(two.id) }.to raise_error(Ldp::Gone)
expect(GenericWork).to exist(three.id)
end

it "redirects to the return controller" do
Expand All @@ -61,13 +70,15 @@
expect(response).to be_redirect
expect(GenericWork.find(one.id).subject).to eq ["zzz"]
expect(GenericWork.find(two.id).subject).to eq ["zzz"]
expect(GenericWork.find(three.id).subject).to be_empty
end

it "updates permissions" do
put :update, params: { update_type: "update", visibility: "authenticated" }
expect(response).to be_redirect
expect(GenericWork.find(one.id).visibility).to eq "authenticated"
expect(GenericWork.find(two.id).visibility).to eq "authenticated"
expect(GenericWork.find(three.id).visibility).to eq "restricted"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

it "adds docs to the collection and adds the collection id to the documents in the collection" do
post :create, params: {
batch_document_ids: [asset1.id],
batch_document_ids: [asset1.id, unowned_asset.id],
collection: collection_attrs
}

Expand Down
6 changes: 3 additions & 3 deletions spec/features/dashboard/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
it "attaches the works", :js do
visit '/dashboard/my/works'
first('input#check_all').click
click_button "Add to Collection" # opens the modal
click_button "Add to collection" # opens the modal
# since there is only one collection, it's not necessary to choose a radio button
click_button "Update Collection"
expect(page).to have_content "Works in this Collection"
Expand Down Expand Up @@ -460,14 +460,14 @@
visit "/dashboard/collections/#{collection1.id}"
click_link 'Add existing works'
first('input#check_all').click
click_button "Add to Collection"
click_button "Add to collection"
expect(page).to have_css("input#id_#{collection1.id}[checked='checked']")
expect(page).not_to have_css("input#id_#{collection2.id}[checked='checked']")

visit "/dashboard/collections/#{collection2.id}"
click_link 'Add existing works'
first('input#check_all').click
click_button "Add to Collection"
click_button "Add to collection"
expect(page).not_to have_css("input#id_#{collection1.id}[checked='checked']")
expect(page).to have_css("input#id_#{collection2.id}[checked='checked']")

Expand Down
11 changes: 0 additions & 11 deletions spec/helpers/hyrax/dashboard_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@
end
end

describe "#on_my_works" do
it "returns false when the controller isn't my works" do
allow(helper).to receive(:params).and_return(controller: "hyrax/my/collections")
expect(helper).not_to be_on_my_works
end
it "returns true when the controller is my works" do
allow(helper).to receive(:params).and_return(controller: "hyrax/my/works")
expect(helper).to be_on_my_works
end
end

describe "#number_of_works" do
let(:conn) { ActiveFedora::SolrService.instance.conn }
let(:user1) { User.new(email: "abc@test") }
Expand Down
12 changes: 5 additions & 7 deletions spec/views/hyrax/my/_search_header.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@

context "on my works page" do
before do
allow(view).to receive(:on_my_works?).and_return(true)
view.lookup_context.prefixes.push "hyrax/my/works"
render 'hyrax/my/search_header', current_tab: 'works'
end
it "has buttons" do
expect(rendered).to have_selector('input[value="Delete Selected"]')
expect(rendered).to have_selector('button', text: 'Add to Collection')
expect(rendered).to have_selector('button', text: 'Add to collection')
expect(rendered).to have_selector('input[value="Edit Selected"]')
end
end

context "not on my works page (i.e. one of the collections index pages)" do
context "on my collections page" do
before do
allow(view).to receive(:on_my_works?).and_return(false)
view.lookup_context.prefixes.push "hyrax/my/collections"
render 'hyrax/my/search_header', current_tab: 'shared'
end
it "has buttons" do
expect(rendered).not_to have_selector('input[value="Delete Selected"]')
expect(rendered).not_to have_selector('button', text: 'Add to Collection')
expect(rendered).not_to have_selector('input[value="Edit Selected"]')
expect(rendered).to have_selector('button', text: 'Delete collections')
end
end
end

0 comments on commit c39dd24

Please sign in to comment.