Skip to content

Commit

Permalink
Merge pull request #2062 from manyfold3d/fix-bulk-edit
Browse files Browse the repository at this point in the history
Fix bulk editing bugs
  • Loading branch information
Floppy authored Apr 21, 2024
2 parents 25fddf2 + cacdc50 commit 2805368
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,12 @@ def bulk_update

add_tags = Set.new(hash.delete(:add_tags))
remove_tags = Set.new(hash.delete(:remove_tags))

params[:models].each_pair do |id, selected|
if selected == "1"
model = policy_scope(Model).find(id)
if model&.update(hash)
existing_tags = Set.new(model.tag_list)
model.tag_list = existing_tags + add_tags - remove_tags
model.save
end
ids = params[:models].select { |k, v| v == "1" }.keys
policy_scope(Model).find(ids).each do |model|
if model&.update(hash)
existing_tags = Set.new(model.tag_list)
model.tag_list = existing_tags + add_tags - remove_tags
model.save
end
end
redirect_back_or_to edit_models_path(@filters), notice: t(".success")
Expand Down
2 changes: 1 addition & 1 deletion app/views/model_files/bulk_edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= render partial: "breadcrumb" %>
<h1>Bulk Edit <%= ModelFile.model_name.human.pluralize %></h1>

<%= form_with url: library_model_model_files_path(@library, @model), method: :patch do |form| %>
<%= form_with url: bulk_update_library_model_model_files_path(@library, @model), method: :patch do |form| %>

<h3>Select files to change:</h3>

Expand Down

0 comments on commit 2805368

Please sign in to comment.