Skip to content

Commit 413d2e4

Browse files
authored
Merge pull request #3430 from fhp/real-bulk-edit
Add "Update All Models" functionality to bulk edit models
2 parents 6754ec8 + 10b3db7 commit 413d2e4

File tree

12 files changed

+123
-12
lines changed

12 files changed

+123
-12
lines changed

app/controllers/models_controller.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,17 @@ def bulk_update
139139
organize = hash.delete(:organize) == "1"
140140
add_tags = Set.new(hash.delete(:add_tags))
141141
remove_tags = Set.new(hash.delete(:remove_tags))
142-
ids = params[:models].select { |k, v| v == "1" }.keys
143-
policy_scope(Model).where(public_id: ids).find_each do |model|
142+
143+
models_to_update = if params[:commit] == t("models.bulk_edit.update_all")
144+
# If "Update All Models" was clicked, update all models in the filtered set
145+
filtered_models(@filters)
146+
else
147+
# If "Update Selected Models" was clicked, only update checked models
148+
ids = params[:models].select { |k, v| v == "1" }.keys
149+
policy_scope(Model).where(public_id: ids)
150+
end
151+
152+
models_to_update.find_each do |model|
144153
if model&.update(hash)
145154
existing_tags = Set.new(model.tag_list)
146155
model.tag_list = existing_tags + add_tags - remove_tags

app/views/models/bulk_edit.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<%= form.hidden_field :library, value: @filters[:library] if @filters[:library] %>
5959
<%= form.hidden_field :creator, value: @filters[:creator] if @filters[:creator] %>
6060
<%= form.submit translate(".submit"), class: "btn btn-primary" %>
61+
<%= form.submit translate(".update_all"), class: "btn btn-secondary" %>
6162

6263
</div>
6364
<% if !@filters.empty? %>

config/locales/models/de.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ de:
1010
select_all: Alle Modelle auswählen
1111
submit: Ausgewählte Modelle aktualisieren
1212
title: Modelle massenweise bearbeiten
13+
update_all: Alle Modelle aktualisieren
1314
bulk_fields:
1415
add_tags: Tags hinzufügen
1516
bulk_update:

config/locales/models/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ en:
1010
select_all: Select all models
1111
submit: Update Selected Models
1212
title: Bulk Edit Models
13+
update_all: Update All Models
1314
bulk_fields:
1415
add_tags: Add tags
1516
bulk_update:

config/locales/models/es.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ es:
1010
select_all: Seleccione todos los modelos
1111
submit: Actualizar modelos seleccionados
1212
title: Edición masiva de modelos
13+
update_all: Actualizar todos los modelos
1314
bulk_fields:
1415
add_tags: Añadir etiquetas
1516
bulk_update:

config/locales/models/fr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fr:
1010
select_all: Sélectionner tous les modèles
1111
submit: Mettre à jour les modèles sélectionnés
1212
title: Modifier les modèles en lot
13+
update_all: Mettre à jour tous les modèles
1314
bulk_fields:
1415
add_tags: Ajouter des étiquettes
1516
bulk_update:

config/locales/models/pl.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pl:
1010
select_all: Zaznacz wszystkie modele
1111
submit: Aktualizuj zaznaczone modele
1212
title: Edytuj zbiorczo modele
13+
update_all: Aktualizuj wszystkie modele
1314
bulk_fields:
1415
add_tags: Dodaj tagi
1516
bulk_update:

spec/factories/creator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FactoryBot.define do
22
factory :creator do
3-
name { Faker::Name.name }
3+
sequence(:name) { |n| "Creator #{n}" }
4+
sequence(:public_id) { |n| "creator_#{n}" }
45
end
56
end

spec/factories/library.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FactoryBot.define do
22
factory :library do
3+
sequence(:name) { |n| "Library #{n}" }
4+
sequence(:public_id) { |n| "library_#{n}" }
35
path {
46
dir = Dir.mktmpdir(Faker::File.file_name, "/tmp")
57
at_exit { FileUtils.remove_entry(dir) }

spec/factories/model.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
FactoryBot.define do
22
factory :model do
3+
sequence(:name) { |n| "Model #{n}" }
34
library
4-
name { Faker::Creature::Animal.name }
5+
sequence(:public_id) { |n| "model_#{n}" }
56
path { Faker::File.dir }
67
license { "MIT" }
8+
9+
trait :with_tags do
10+
transient do
11+
tags_count { 2 }
12+
end
13+
14+
after(:create) do |model, evaluator|
15+
evaluator.tags_count.times do |i|
16+
model.tag_list.add("tag_#{i}")
17+
end
18+
model.save
19+
end
20+
end
21+
22+
trait :needs_organizing do
23+
after(:create) do |model|
24+
model.update!(needs_organizing: true)
25+
end
26+
end
27+
28+
trait :sensitive do
29+
sensitive { true }
30+
end
31+
32+
trait :with_creator do
33+
creator
34+
end
35+
36+
trait :with_collection do
37+
collection
38+
end
739
end
840
end

0 commit comments

Comments
 (0)