Skip to content

Commit

Permalink
Fix bulk update
Browse files Browse the repository at this point in the history
  • Loading branch information
hackartisan committed Jul 12, 2022
1 parent e2a0090 commit 491e7df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions app/controllers/bulk_edit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class BulkEditController < ApplicationController
delegate :search_builder, :repository, to: :search_service

def resources_edit
(solr_response, _document_list) = search_service.search_results do |search_builder|
search_builder.with(q: params["q"], f: params["f"])
(solr_response, _document_list) = search_service.search_results do |builder|
builder.with(edit_params)
end
@resources_count = solr_response["response"]["numFound"]
end
Expand All @@ -29,8 +29,17 @@ def resources_update

private

# used by search state to access filter fields
def blacklight_config
@blacklight_config ||= CatalogController.new.blacklight_config
end

def edit_params
params.permit(:q, f: {})
end

def search_params
params.permit(search_params: {})["search_params"]
@search_params ||= params.permit(search_params: {})["search_params"]
end

def load_collections
Expand All @@ -43,9 +52,12 @@ def batches
builder = initial_builder
[].tap do |arr|
loop do
response = repository.search(builder)
arr << response.documents.map(&:id)
break if (builder.page * builder.rows) >= response["response"]["numFound"]
(solr_response, document_list) = search_service.search_results do |_builder|
builder # use the builder we made
end

arr << document_list.map(&:id)
break if (builder.page * builder.rows) >= solr_response["response"]["numFound"]
builder.start = builder.rows * builder.page
builder.page += 1
end
Expand All @@ -54,8 +66,7 @@ def batches
end

def initial_builder
builder_params = { q: params["search_params"]["q"], f: params["search_params"]["f"] }
builder = search_builder.with(builder_params)
builder = search_builder.with(search_params)
builder.rows = params["batch_size"] || 50
builder
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/bulk_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
it "updates the object" do
collection2 = FactoryBot.create_for_repository(:collection)
visit bulk_edit_resources_edit_path("q" => "", "f[member_of_collection_titles_ssim][]" => "My Collection")
expect(page).to have_content "You searched for"
expect(page).to have_content "Bulk edit 1 resources"
page.check("mark_complete")
page.select collection2.title.first, from: "append_collection_ids", visible: false
accept_alert do
Expand Down

0 comments on commit 491e7df

Please sign in to comment.