Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass change_set to views #2144

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions app/helpers/hyrax/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ def has_collection_search_parameters?
params[:cq].present?
end

def button_for_remove_from_collection(collection, document, label = 'Remove From Collection')
render 'hyrax/dashboard/collections/button_remove_from_collection', collection: collection, label: label, document: document
# button for removing a batch from a collection
# @param change_set [Hyrax::CollectionChangeSet] ChangeSet to be updated
# @param document [SolrDocument]
# @param label [String] button label
def button_for_remove_from_collection(change_set, document, label = 'Remove From Collection')
form_for change_set, url: hyrax.dashboard_collection_path(change_set), method: :put, as: 'collection' do |f|
single_item_action_remove_form_fields(f, document)
f.submit label, class: "btn btn-primary collection-remove"
end
end

def button_for_remove_selected_from_collection(collection, label = 'Remove From Collection')
render 'hyrax/dashboard/collections/button_for_remove_selected_from_collection', collection: collection, label: label
# button for removing a batch from a collection
# @param change_set [Hyrax::CollectionChangeSet] ChangeSet to be updated
# @param label [String] button label
def button_for_remove_selected_from_collection(change_set, label = 'Remove From Collection')
form_for change_set, url: hyrax.dashboard_collection_path(change_set.id), method: :put do |f|
f.hidden_field :members, value: "remove"
f.submit label, class: "btn btn-primary collection-remove-selected submits-batches"
end
end

# add hidden fields to a form for removing a single document from a collection
Expand Down
3 changes: 3 additions & 0 deletions app/views/hyrax/collections/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<% # this template is used by Hyrax::CollectionsController and Hyrax::Dashboard::CollectionsController %>
<% # in the former case presenter is a Hyrax::CollectionPresenter %>
<% # and the latter it's a Hyrax::CollectionChangeSet %>
<%= form_for presenter, method: :get, class: "well form-search" do |f| %>
<label class="sr-only"><%= t('hyrax.collections.search_form.label', title: presenter.to_s) %></label>
<div class="input-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li data-behavior="batch-edit-select-none" data-state="on"><a href="#"><i class="glyphicon glyphicon-ok"></i> Select None</a></li>
<li data-behavior="batch-edit-select-page" data-state="off"><a href="#"><i class=""></i> Select Current Page</a></li>
<li><%= button_for_remove_selected_from_collection @collection %></li>
<li><%= button_for_remove_selected_from_collection @change_set %></li>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<% # change_set is a Hyrax::CollectionChangeSet or a Hyrax::CollectionPresenter %>

<div class="batch-info">
<%= render 'form_for_select_collection', user_collections: @user_collections %>

<% if params[:action] == "edit" && @response.response['numFound'] > 1 %>
<div class="batch-toggle">
<% session[:batch_edit_state] = "on" %>
<%= button_for_remove_selected_from_collection collection %>
<%= button_for_remove_selected_from_collection(change_set) %>
</div>
<% end %>
<div class="sort-toggle">
<%# kind of hacky way to get this to work on catalog and folder controllers. May be able to simple do {action: "index"} but I'm not sure -%>
<% if @response.response['numFound'] > 1 && !sort_fields.empty? %>
<%= form_tag collection_path(collection), method: :get, class: 'per_page form-horizontal' do %>
<%= form_tag collection_path(change_set), method: :get, class: 'per_page form-horizontal' do %>
<div class="form-group form-group-lg">
<fieldset class="col-xs-12 col-sm-9 col-md-8 col-lg-10">
<legend class="sr-only"><%= t('hyrax.sort_label') %></legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ul role="menu" class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu_<%= document.id %>">

<li role="menuitem" tabindex="-1">
<%= button_for_remove_from_collection(@collection, document, 'Remove from Collection') %>
<%= button_for_remove_from_collection(@change_set, document, 'Remove from Collection') %>
</li>

<li role="menuitem" tabindex="-1">
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/dashboard/collections/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
<div class="row m-t-3">
<h2 class="col-xs-12 col-sm-6"><%= t('hyrax.collection.edit.manage_items') %></h2>
<div class="col-xs-12 col-sm-6">
<%= render 'hyrax/collections/search_form', presenter: @collection %>
<%= render 'hyrax/collections/search_form', presenter: @change_set %>
</div>
</div>
<%= render 'hyrax/my/did_you_mean' %>
<%= render 'hyrax/my/facet_selected' %>
<%= render 'sort_and_per_page', collection: @collection if @response.response['numFound'] > 0 %>
<%= render 'sort_and_per_page', change_set: @change_set if @response.response['numFound'] > 0 %>
<%= render 'document_list', documents: @member_docs, document_list_format: "dashboard" %>
<%= render 'hyrax/collections/paginate' %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/dashboard/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="col-xs-6 col-md-5 col-lg-6"><%= render 'hyrax/collections/search_form', presenter: @presenter %></div>
</div>

<%= render 'sort_and_per_page', collection: @presenter %>
<%= render 'sort_and_per_page', change_set: @presenter %>

<%= render_document_index @member_docs %>

Expand Down
10 changes: 6 additions & 4 deletions spec/helpers/hyrax/collections_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@

describe "button_for_remove_from_collection" do
let(:item) { double(id: 'changeme:123') }
let(:change_set) { Hyrax::CollectionChangeSet.new(collection) }
let(:collection) { create_for_repository(:collection) }

it "generates a form that can remove the item" do
str = button_for_remove_from_collection collection, item
str = button_for_remove_from_collection change_set, item
doc = Nokogiri::HTML(str)
form = doc.xpath('//form').first
expect(form.attr('action')).to eq hyrax.dashboard_collection_path(collection)
Expand All @@ -83,7 +84,7 @@ class OtherCollection < Valkyrie::Resource
end

it "generates a form that can remove the item" do
str = button_for_remove_from_collection collection, item
str = button_for_remove_from_collection change_set, item
doc = Nokogiri::HTML(str)
form = doc.xpath('//form').first
expect(form.attr('action')).to eq hyrax.dashboard_collection_path(collection)
Expand All @@ -95,9 +96,10 @@ class OtherCollection < Valkyrie::Resource

describe "button_for_remove_selected_from_collection" do
let(:collection) { create_for_repository(:collection) }
let(:change_set) { Hyrax::CollectionChangeSet.new(collection) }

it "creates a button to the collections delete path" do
str = button_for_remove_selected_from_collection collection
str = button_for_remove_selected_from_collection change_set
doc = Nokogiri::HTML(str)
form = doc.xpath('//form').first
expect(form.attr('action')).to eq hyrax.dashboard_collection_path(collection)
Expand All @@ -107,7 +109,7 @@ class OtherCollection < Valkyrie::Resource
end

it "creates a button with my text" do
str = button_for_remove_selected_from_collection collection, "Remove My Button"
str = button_for_remove_selected_from_collection change_set, "Remove My Button"
doc = Nokogiri::HTML(str)
form = doc.css('form').first
expect(form.attr('action')).to eq hyrax.dashboard_collection_path(collection)
Expand Down