From f51af78ed893ad8ae581314af333f0e23ed3928d Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Mon, 23 Dec 2024 10:25:21 +0100 Subject: [PATCH 01/19] Added locales and image to superspaces admin form --- app/cells/decidim/superspaces/superspace_g_cell.rb | 3 +++ app/commands/decidim/superspaces/admin/create_superspace.rb | 4 +++- app/commands/decidim/superspaces/admin/update_superspace.rb | 4 +++- app/forms/decidim/superspaces/admin/superspace_form.rb | 4 ++++ app/models/decidim/superspaces/superspace.rb | 4 ++++ .../decidim/superspaces/admin/superspaces/_form.html.erb | 6 ++++++ .../decidim/superspaces/admin/superspaces/index.html.erb | 4 ++++ .../decidim/superspaces/admin/superspaces/new.html.erb | 2 +- config/locales/en.yml | 1 + 9 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/cells/decidim/superspaces/superspace_g_cell.rb b/app/cells/decidim/superspaces/superspace_g_cell.rb index d1c9603..619d4dc 100644 --- a/app/cells/decidim/superspaces/superspace_g_cell.rb +++ b/app/cells/decidim/superspaces/superspace_g_cell.rb @@ -10,6 +10,9 @@ class SuperspaceGCell < Decidim::CardGCell def resource_path Decidim::Superspaces::Engine.routes.url_helpers.superspace_path(model) end + def resource_image_url + model.attached_uploader(:hero_image).url + end end end end diff --git a/app/commands/decidim/superspaces/admin/create_superspace.rb b/app/commands/decidim/superspaces/admin/create_superspace.rb index fed5a9e..bc8a89f 100644 --- a/app/commands/decidim/superspaces/admin/create_superspace.rb +++ b/app/commands/decidim/superspaces/admin/create_superspace.rb @@ -35,7 +35,9 @@ def call def create_superspace! attributes = { organization: form.current_organization, - title: form.title + title: form.title, + locale: form.locale, + hero_image: form.hero_image } @superspace = Decidim.traceability.create!( diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index c531bf5..494831c 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -38,7 +38,9 @@ def update_superspace! Decidim.traceability.update!( superspace, current_user, - title: form.title + title: form.title, + hero_image: form.hero_image, + locale: form.locale ) end end diff --git a/app/forms/decidim/superspaces/admin/superspace_form.rb b/app/forms/decidim/superspaces/admin/superspace_form.rb index 5a0e481..ca981db 100644 --- a/app/forms/decidim/superspaces/admin/superspace_form.rb +++ b/app/forms/decidim/superspaces/admin/superspace_form.rb @@ -8,8 +8,12 @@ class SuperspaceForm < Decidim::Form include TranslatableAttributes translatable_attribute :title, String + attribute :locale + attribute :hero_image validates :title, translatable_presence: true + validates :locale, presence: true + alias organization current_organization end diff --git a/app/models/decidim/superspaces/superspace.rb b/app/models/decidim/superspaces/superspace.rb index 46fa9af..e827a45 100644 --- a/app/models/decidim/superspaces/superspace.rb +++ b/app/models/decidim/superspaces/superspace.rb @@ -6,6 +6,10 @@ class Superspace < ApplicationRecord include Decidim::Loggable include Decidim::Traceable include Decidim::TranslatableResource + include Decidim::HasUploadValidations + + has_one_attached :hero_image + validates_upload :hero_image, uploader: Decidim::HeroImageUploader translatable_fields :title diff --git a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb index 7cbb278..460313d 100644 --- a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb @@ -3,5 +3,11 @@
<%= form.translated :text_field, :title, autofocus: true %>
+
+ <%= form.collection_select :locale, localized_locales(Decidim::available_locales), :id, :name, {:selected => current_locale} %> +
+
+ <%= form.upload :hero_image, button_class: "button button__sm button__transparent-secondary" %> +
diff --git a/app/views/decidim/superspaces/admin/superspaces/index.html.erb b/app/views/decidim/superspaces/admin/superspaces/index.html.erb index dd4a814..e368030 100644 --- a/app/views/decidim/superspaces/admin/superspaces/index.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/index.html.erb @@ -15,6 +15,7 @@ <%= t("models.superspace.fields.title", scope: "decidim.superspaces") %> + <%= t("models.superspace.fields.locale", scope: "decidim.superspaces") %> <%= t("models.superspace.fields.created_at", scope: "decidim.superspaces") %> <%= t("actions.title", scope: "decidim.superspaces.admin.superspaces") %> @@ -25,6 +26,9 @@ <%= translated_attribute(superspace.title) %>
+ + <%= superspace.locale %>
+ <%= l superspace.created_at, format: "%d/%m/%Y - %H:%M" %> diff --git a/app/views/decidim/superspaces/admin/superspaces/new.html.erb b/app/views/decidim/superspaces/admin/superspaces/new.html.erb index 05a1cb4..5b1cba4 100644 --- a/app/views/decidim/superspaces/admin/superspaces/new.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/new.html.erb @@ -6,7 +6,7 @@
- <%= decidim_form_for(@form, html: { class: "form form-defaults new_superspace" }) do |f| %> + <%= decidim_form_for(@form, html: { class: "form form-defaults new_superspace", multipart: true }) do |f| %>
<%= render partial: "form", object: f %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0590dbc..f4f245b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -42,6 +42,7 @@ en: fields: created_at: Created at title: Title + locale: Language superspaces: index: title: Superspaces From d990830067568fdbb20aa0c70f787484d022c65c Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Tue, 7 Jan 2025 09:12:25 +0100 Subject: [PATCH 02/19] Added participatory spaces associations --- .../superspaces/admin/create_superspace.rb | 19 ++++ .../superspaces/admin/update_superspace.rb | 62 ++++++++++++ .../superspaces/admin/superspace_form.rb | 2 + app/models/decidim/superspaces/superspace.rb | 6 ++ .../admin/superspaces/_form.html.erb | 95 +++++++++++++++++++ config/locales/en.yml | 2 + 6 files changed, 186 insertions(+) diff --git a/app/commands/decidim/superspaces/admin/create_superspace.rb b/app/commands/decidim/superspaces/admin/create_superspace.rb index bc8a89f..404ef2b 100644 --- a/app/commands/decidim/superspaces/admin/create_superspace.rb +++ b/app/commands/decidim/superspaces/admin/create_superspace.rb @@ -32,6 +32,21 @@ def call attr_reader :form, :current_user + def create_associations(assemblies_ids, participatory_processes_ids) + assemblies = Decidim::Assembly.where(id: assemblies_ids) + assemblies.each do |assembly| + @superspace.superspaces_participatory_spaces.create!( + participatory_space: assembly + ) + end + participatory_processes=Decidim::ParticipatoryProcess.where(id: participatory_processes_ids) + participatory_processes.each do |process| + @superspace.superspaces_participatory_spaces.create!( + participatory_space: process + ) + end + end + def create_superspace! attributes = { organization: form.current_organization, @@ -45,6 +60,10 @@ def create_superspace! current_user, attributes ) + + create_associations(form.assembly_ids,form.participatory_process_ids) + + end end end diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index 494831c..468949a 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -35,6 +35,9 @@ def call attr_reader :form, :superspace, :current_user def update_superspace! + + assembly_ids = form.assembly_ids + participatory_process_ids = form.participatory_process_ids Decidim.traceability.update!( superspace, current_user, @@ -42,6 +45,65 @@ def update_superspace! hero_image: form.hero_image, locale: form.locale ) + update_associations(assembly_ids,participatory_process_ids) + end + + private + + def update_associations(assembly_ids, process_ids) + if assembly_ids.present? + current_assemblies = @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::Assembly') + .pluck(:participatory_space_id) + + new_assemblies = assembly_ids + + ids_to_delete = current_assemblies - new_assemblies + @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::Assembly', participatory_space_id: ids_to_delete) + .destroy_all + + ids_to_add = new_assemblies - current_assemblies + + assemblies_to_add = Decidim::Assembly.where(id: ids_to_add) + + assemblies_to_add.each do |assembly| + @superspace.superspaces_participatory_spaces.create( + participatory_space: assembly + ) + end + else + @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::Assembly') + .destroy_all + end + + if process_ids.present? + current_processes = @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::ParticipatoryProcess') + .pluck(:participatory_space_id) + + new_processes = process_ids + + ids_to_delete = current_processes - new_processes + @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::ParticipatoryProcess', participatory_space_id: ids_to_delete) + .destroy_all + + ids_to_add = new_processes - current_processes + + processes_to_add = Decidim::ParticipatoryProcess.where(id: ids_to_add) + + processes_to_add.each do |process| + @superspace.superspaces_participatory_spaces.create( + participatory_space: process + ) + end + else + @superspace.superspaces_participatory_spaces + .where(participatory_space_type: 'Decidim::Assembly') + .destroy_all + end end end end diff --git a/app/forms/decidim/superspaces/admin/superspace_form.rb b/app/forms/decidim/superspaces/admin/superspace_form.rb index ca981db..54a4e77 100644 --- a/app/forms/decidim/superspaces/admin/superspace_form.rb +++ b/app/forms/decidim/superspaces/admin/superspace_form.rb @@ -10,6 +10,8 @@ class SuperspaceForm < Decidim::Form translatable_attribute :title, String attribute :locale attribute :hero_image + attribute :assembly_ids + attribute :participatory_process_ids validates :title, translatable_presence: true validates :locale, presence: true diff --git a/app/models/decidim/superspaces/superspace.rb b/app/models/decidim/superspaces/superspace.rb index e827a45..863eb1c 100644 --- a/app/models/decidim/superspaces/superspace.rb +++ b/app/models/decidim/superspaces/superspace.rb @@ -13,10 +13,16 @@ class Superspace < ApplicationRecord translatable_fields :title + has_many :superspaces_participatory_spaces, foreign_key: "decidim_superspaces_superspace_id" + belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization" + def participatory_spaces + superspaces_participatory_spaces.map(&:participatory_space) + end + def self.log_presenter_class_for(_log) = Decidim::Superspaces::AdminLog::SuperspacePresenter end end diff --git a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb index 460313d..5daf160 100644 --- a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb @@ -1,3 +1,48 @@ +
@@ -9,5 +54,55 @@
<%= form.upload :hero_image, button_class: "button button__sm button__transparent-secondary" %>
+
+
+
+
+ <%= t("assemblies", scope: "decidim.superspaces.models.superspace.fields") %> + +
+ <% Decidim::Assembly.where(organization: current_organization).each do |assembly| %> +
+ +
+ <% end %> +
+
+
+ +
+
+ <%= t("participatory_processes", scope: "decidim.superspaces.models.superspace.fields") %> + +
+ <% Decidim::ParticipatoryProcess.where(organization: current_organization).each do |process| %> +
+ +
+ <% end %> +
+
+
+
+ + +
diff --git a/config/locales/en.yml b/config/locales/en.yml index f4f245b..18cba05 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -43,6 +43,8 @@ en: created_at: Created at title: Title locale: Language + assemblies: Assemblies + participatory_processes: Participatory Processes superspaces: index: title: Superspaces From 8cf007c3339c5f21fc90dfde52910b8add056002 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Tue, 7 Jan 2025 09:14:43 +0100 Subject: [PATCH 03/19] Added basic layout for show --- app/views/decidim/superspaces/superspaces/show.html.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/decidim/superspaces/superspaces/show.html.erb b/app/views/decidim/superspaces/superspaces/show.html.erb index 2547650..b25d71c 100644 --- a/app/views/decidim/superspaces/superspaces/show.html.erb +++ b/app/views/decidim/superspaces/superspaces/show.html.erb @@ -14,5 +14,9 @@ <% end %> <%= render layout: "layouts/decidim/shared/layout_two_col" do %> - TODO: Add content here +
+ <% superspace.participatory_spaces.each do |participatory_space| %> + <%= card_for participatory_space, highlight: true, size: :g %> + <% end %> +
<% end %> From f9ccf5a5e747ab849d5a8d2c42c28d0450defe80 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Wed, 8 Jan 2025 08:53:36 +0100 Subject: [PATCH 04/19] Changed update command --- .../superspaces/admin/update_superspace.rb | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index 468949a..2ae2128 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -51,58 +51,24 @@ def update_superspace! private def update_associations(assembly_ids, process_ids) - if assembly_ids.present? - current_assemblies = @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::Assembly') - .pluck(:participatory_space_id) - - new_assemblies = assembly_ids - - ids_to_delete = current_assemblies - new_assemblies - @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::Assembly', participatory_space_id: ids_to_delete) - .destroy_all - - ids_to_add = new_assemblies - current_assemblies + @superspace.superspaces_participatory_spaces.destroy_all - assemblies_to_add = Decidim::Assembly.where(id: ids_to_add) - - assemblies_to_add.each do |assembly| - @superspace.superspaces_participatory_spaces.create( + if assembly_ids.present? + assemblies=Decidim::Assembly.where(id: assembly_ids) + assemblies.each do |assembly| + @superspace.superspaces_participatory_spaces.create!( participatory_space: assembly ) end - else - @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::Assembly') - .destroy_all end - + if process_ids.present? - current_processes = @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::ParticipatoryProcess') - .pluck(:participatory_space_id) - - new_processes = process_ids - - ids_to_delete = current_processes - new_processes - @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::ParticipatoryProcess', participatory_space_id: ids_to_delete) - .destroy_all - - ids_to_add = new_processes - current_processes - - processes_to_add = Decidim::ParticipatoryProcess.where(id: ids_to_add) - - processes_to_add.each do |process| - @superspace.superspaces_participatory_spaces.create( + processes=Decidim::ParticipatoryProcess.where(id: process_ids) + processes.each do |process| + @superspace.superspaces_participatory_spaces.create!( participatory_space: process ) end - else - @superspace.superspaces_participatory_spaces - .where(participatory_space_type: 'Decidim::Assembly') - .destroy_all end end end From 6cf0c6c02d9d670ef6ed7ab49d5e9b0607964713 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Wed, 8 Jan 2025 08:54:04 +0100 Subject: [PATCH 05/19] Added styles in admin form --- .../decidim/superspaces/superspaces.scss | 44 ++++++++++++++++ .../admin/superspaces/_form.html.erb | 51 ++----------------- .../superspaces/superspaces/show.html.erb | 4 +- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/app/packs/stylesheets/decidim/superspaces/superspaces.scss b/app/packs/stylesheets/decidim/superspaces/superspaces.scss index a954f51..d22288c 100644 --- a/app/packs/stylesheets/decidim/superspaces/superspaces.scss +++ b/app/packs/stylesheets/decidim/superspaces/superspaces.scss @@ -1 +1,45 @@ /* css for decidim_superspaces */ + +.participatory-spaces-group { + border: 1px solid #e8e8e8; + padding: 1rem; + margin-bottom: 2rem; + border-radius: 4px; + + legend { + font-weight: 600; + margin-bottom: 1rem; + padding: 0 0.5rem; + } + + .check-boxes { + max-height: 400px; + overflow-y: auto; + padding: 0.5rem; + } + + .check-box { + margin-bottom: 0.8rem; + + label { + display: flex; + align-items: center; + cursor: pointer; + + input[type="checkbox"] { + margin: 0 0.5rem 0 0; + } + + .participatory-space-title { + line-height: 1.2; + } + } + + &:hover { + .participatory-space-title { + color: var(--primary); + } + } + } +} + diff --git a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb index 5daf160..71ab105 100644 --- a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb @@ -1,55 +1,10 @@ -
<%= form.translated :text_field, :title, autofocus: true %>
- <%= form.collection_select :locale, localized_locales(Decidim::available_locales), :id, :name, {:selected => current_locale} %> + <%= form.collection_select :locale, localized_locales(Decidim::available_locales), :id, :name %>
<%= form.upload :hero_image, button_class: "button button__sm button__transparent-secondary" %> @@ -70,7 +25,7 @@ nil %> - <%= translated_attribute(assembly.slug) %> + <%= translated_attribute(assembly.title) %>
@@ -92,7 +47,7 @@ process.id %> - <%= translated_attribute(process.slug) %> + <%= translated_attribute(process.title) %>
diff --git a/app/views/decidim/superspaces/superspaces/show.html.erb b/app/views/decidim/superspaces/superspaces/show.html.erb index b25d71c..aa77c22 100644 --- a/app/views/decidim/superspaces/superspaces/show.html.erb +++ b/app/views/decidim/superspaces/superspaces/show.html.erb @@ -17,6 +17,6 @@
<% superspace.participatory_spaces.each do |participatory_space| %> <%= card_for participatory_space, highlight: true, size: :g %> - <% end %> + <% end %>
-<% end %> +<% end %> \ No newline at end of file From d18892f07a2f22b91472eee443aafb2bad4861bc Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Wed, 8 Jan 2025 09:55:20 +0100 Subject: [PATCH 06/19] Added section titles to superspace show --- app/models/decidim/superspaces/superspace.rb | 16 ++++++++++++++ .../superspaces/superspaces/show.html.erb | 22 ++++++++++++++----- config/locales/en.yml | 3 +++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/models/decidim/superspaces/superspace.rb b/app/models/decidim/superspaces/superspace.rb index 863eb1c..449b138 100644 --- a/app/models/decidim/superspaces/superspace.rb +++ b/app/models/decidim/superspaces/superspace.rb @@ -22,6 +22,22 @@ class Superspace < ApplicationRecord def participatory_spaces superspaces_participatory_spaces.map(&:participatory_space) end + + def assemblies + find_spaces_by_type("Decidim::Assembly") + end + + def participatory_processes + find_spaces_by_type("Decidim::ParticipatoryProcess") + end + + private + + def find_spaces_by_type(type) + spaces= superspaces_participatory_spaces.where(participatory_space_type: type) + + spaces.map(&:participatory_space) + end def self.log_presenter_class_for(_log) = Decidim::Superspaces::AdminLog::SuperspacePresenter end diff --git a/app/views/decidim/superspaces/superspaces/show.html.erb b/app/views/decidim/superspaces/superspaces/show.html.erb index aa77c22..a362183 100644 --- a/app/views/decidim/superspaces/superspaces/show.html.erb +++ b/app/views/decidim/superspaces/superspaces/show.html.erb @@ -14,9 +14,21 @@ <% end %> <%= render layout: "layouts/decidim/shared/layout_two_col" do %> -
- <% superspace.participatory_spaces.each do |participatory_space| %> - <%= card_for participatory_space, highlight: true, size: :g %> - <% end %> -
+ <% if superspace.assemblies.any? %> +
+

<%= t("assemblies", scope: "decidim.superspaces.superspaces.show") %>

+ <% superspace.assemblies.each do |assembly| %> + <%= card_for assembly, highlight: true, size: :g %> + <% end %> +
+ <% end %> + + <% if superspace.participatory_processes.any? %> +
+

<%= t("participatory_processes", scope: "decidim.superspaces.superspaces.show") %>

+ <% superspace.participatory_processes.each do |process| %> + <%= card_for process, highlight: true, size: :g %> + <% end %> +
+ <% end %> <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 18cba05..8d1f780 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,3 +48,6 @@ en: superspaces: index: title: Superspaces + show: + assemblies: Assemblies + participatory_processes: Participatory Processes From 40068cbbc3d35fce463190291235fe0bb197cad7 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Thu, 9 Jan 2025 13:02:47 +0100 Subject: [PATCH 07/19] Fixed rubocop issues --- .../decidim/superspaces/superspace_g_cell.rb | 3 ++- .../superspaces/admin/create_superspace.rb | 6 ++--- .../superspaces/admin/update_superspace.rb | 25 ++++++++----------- .../superspaces/admin/superspace_form.rb | 1 - app/models/decidim/superspaces/superspace.rb | 12 ++++----- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/app/cells/decidim/superspaces/superspace_g_cell.rb b/app/cells/decidim/superspaces/superspace_g_cell.rb index 619d4dc..c7b2fff 100644 --- a/app/cells/decidim/superspaces/superspace_g_cell.rb +++ b/app/cells/decidim/superspaces/superspace_g_cell.rb @@ -10,7 +10,8 @@ class SuperspaceGCell < Decidim::CardGCell def resource_path Decidim::Superspaces::Engine.routes.url_helpers.superspace_path(model) end - def resource_image_url + + def resource_image_url model.attached_uploader(:hero_image).url end end diff --git a/app/commands/decidim/superspaces/admin/create_superspace.rb b/app/commands/decidim/superspaces/admin/create_superspace.rb index 404ef2b..70d6159 100644 --- a/app/commands/decidim/superspaces/admin/create_superspace.rb +++ b/app/commands/decidim/superspaces/admin/create_superspace.rb @@ -39,7 +39,7 @@ def create_associations(assemblies_ids, participatory_processes_ids) participatory_space: assembly ) end - participatory_processes=Decidim::ParticipatoryProcess.where(id: participatory_processes_ids) + participatory_processes = Decidim::ParticipatoryProcess.where(id: participatory_processes_ids) participatory_processes.each do |process| @superspace.superspaces_participatory_spaces.create!( participatory_space: process @@ -61,9 +61,7 @@ def create_superspace! attributes ) - create_associations(form.assembly_ids,form.participatory_process_ids) - - + create_associations(form.assembly_ids, form.participatory_process_ids) end end end diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index 2ae2128..a5fed63 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -35,7 +35,6 @@ def call attr_reader :form, :superspace, :current_user def update_superspace! - assembly_ids = form.assembly_ids participatory_process_ids = form.participatory_process_ids Decidim.traceability.update!( @@ -45,30 +44,28 @@ def update_superspace! hero_image: form.hero_image, locale: form.locale ) - update_associations(assembly_ids,participatory_process_ids) + update_associations(assembly_ids, participatory_process_ids) end - private - def update_associations(assembly_ids, process_ids) @superspace.superspaces_participatory_spaces.destroy_all if assembly_ids.present? - assemblies=Decidim::Assembly.where(id: assembly_ids) - assemblies.each do |assembly| + assemblies = Decidim::Assembly.where(id: assembly_ids) + assemblies.each do |assembly| @superspace.superspaces_participatory_spaces.create!( participatory_space: assembly ) end end - - if process_ids.present? - processes=Decidim::ParticipatoryProcess.where(id: process_ids) - processes.each do |process| - @superspace.superspaces_participatory_spaces.create!( - participatory_space: process - ) - end + + return if process_ids.blank? + + processes = Decidim::ParticipatoryProcess.where(id: process_ids) + processes.each do |process| + @superspace.superspaces_participatory_spaces.create!( + participatory_space: process + ) end end end diff --git a/app/forms/decidim/superspaces/admin/superspace_form.rb b/app/forms/decidim/superspaces/admin/superspace_form.rb index 54a4e77..3e8601b 100644 --- a/app/forms/decidim/superspaces/admin/superspace_form.rb +++ b/app/forms/decidim/superspaces/admin/superspace_form.rb @@ -16,7 +16,6 @@ class SuperspaceForm < Decidim::Form validates :title, translatable_presence: true validates :locale, presence: true - alias organization current_organization end end diff --git a/app/models/decidim/superspaces/superspace.rb b/app/models/decidim/superspaces/superspace.rb index 449b138..6873592 100644 --- a/app/models/decidim/superspaces/superspace.rb +++ b/app/models/decidim/superspaces/superspace.rb @@ -13,7 +13,7 @@ class Superspace < ApplicationRecord translatable_fields :title - has_many :superspaces_participatory_spaces, foreign_key: "decidim_superspaces_superspace_id" + has_many :superspaces_participatory_spaces, foreign_key: "decidim_superspaces_superspace_id", dependent: :destroy belongs_to :organization, foreign_key: "decidim_organization_id", @@ -31,15 +31,15 @@ def participatory_processes find_spaces_by_type("Decidim::ParticipatoryProcess") end - private + def self.log_presenter_class_for(_log) = Decidim::Superspaces::AdminLog::SuperspacePresenter + + private def find_spaces_by_type(type) - spaces= superspaces_participatory_spaces.where(participatory_space_type: type) - + spaces = superspaces_participatory_spaces.where(participatory_space_type: type) + spaces.map(&:participatory_space) end - - def self.log_presenter_class_for(_log) = Decidim::Superspaces::AdminLog::SuperspacePresenter end end end From faeb00e0f2901f0db2f9f0c407ff0e24137bf994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Thu, 9 Jan 2025 13:08:22 +0100 Subject: [PATCH 08/19] Update app/commands/decidim/superspaces/admin/create_superspace.rb --- .../decidim/superspaces/admin/create_superspace.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/commands/decidim/superspaces/admin/create_superspace.rb b/app/commands/decidim/superspaces/admin/create_superspace.rb index 70d6159..ca8a0a5 100644 --- a/app/commands/decidim/superspaces/admin/create_superspace.rb +++ b/app/commands/decidim/superspaces/admin/create_superspace.rb @@ -33,14 +33,13 @@ def call attr_reader :form, :current_user def create_associations(assemblies_ids, participatory_processes_ids) - assemblies = Decidim::Assembly.where(id: assemblies_ids) - assemblies.each do |assembly| + Decidim::Assembly.where(id: assemblies_ids).each do |assembly| @superspace.superspaces_participatory_spaces.create!( participatory_space: assembly ) end - participatory_processes = Decidim::ParticipatoryProcess.where(id: participatory_processes_ids) - participatory_processes.each do |process| + + Decidim::ParticipatoryProcess.where(id: participatory_processes_ids).each do |process| @superspace.superspaces_participatory_spaces.create!( participatory_space: process ) From 0fca1f65ab1aa6bfbb5d371aa9edae887f803361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Thu, 9 Jan 2025 13:08:28 +0100 Subject: [PATCH 09/19] Update app/commands/decidim/superspaces/admin/update_superspace.rb --- app/commands/decidim/superspaces/admin/update_superspace.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index a5fed63..da4002f 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -51,8 +51,7 @@ def update_associations(assembly_ids, process_ids) @superspace.superspaces_participatory_spaces.destroy_all if assembly_ids.present? - assemblies = Decidim::Assembly.where(id: assembly_ids) - assemblies.each do |assembly| + Decidim::Assembly.where(id: assembly_ids).each do |assembly| @superspace.superspaces_participatory_spaces.create!( participatory_space: assembly ) From e43502d79ff765c3c78423c13da4cd5f72acd33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Thu, 9 Jan 2025 13:08:36 +0100 Subject: [PATCH 10/19] Update app/commands/decidim/superspaces/admin/update_superspace.rb --- app/commands/decidim/superspaces/admin/update_superspace.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/commands/decidim/superspaces/admin/update_superspace.rb b/app/commands/decidim/superspaces/admin/update_superspace.rb index da4002f..22a073f 100644 --- a/app/commands/decidim/superspaces/admin/update_superspace.rb +++ b/app/commands/decidim/superspaces/admin/update_superspace.rb @@ -60,8 +60,7 @@ def update_associations(assembly_ids, process_ids) return if process_ids.blank? - processes = Decidim::ParticipatoryProcess.where(id: process_ids) - processes.each do |process| + Decidim::ParticipatoryProcess.where(id: process_ids).each do |process| @superspace.superspaces_participatory_spaces.create!( participatory_space: process ) From 7c1ce46ec33d9e1c70adf932cbcaecfba08e6e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Bol=C3=ADvar?= Date: Thu, 9 Jan 2025 13:08:42 +0100 Subject: [PATCH 11/19] Update app/models/decidim/superspaces/superspace.rb --- app/models/decidim/superspaces/superspace.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/decidim/superspaces/superspace.rb b/app/models/decidim/superspaces/superspace.rb index 6873592..ff0643a 100644 --- a/app/models/decidim/superspaces/superspace.rb +++ b/app/models/decidim/superspaces/superspace.rb @@ -36,9 +36,7 @@ def self.log_presenter_class_for(_log) = Decidim::Superspaces::AdminLog::Supersp private def find_spaces_by_type(type) - spaces = superspaces_participatory_spaces.where(participatory_space_type: type) - - spaces.map(&:participatory_space) + superspaces_participatory_spaces.where(participatory_space_type: type).map(&:participatory_space) end end end From d0d25bab46ce1d1dc8c3f3871d22e915cb8f2f7d Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Thu, 9 Jan 2025 13:13:43 +0100 Subject: [PATCH 12/19] Fixed lint issues --- .../stylesheets/decidim/superspaces/superspaces.scss | 9 ++++----- .../decidim/superspaces/admin/superspaces/_form.html.erb | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/packs/stylesheets/decidim/superspaces/superspaces.scss b/app/packs/stylesheets/decidim/superspaces/superspaces.scss index d22288c..753b99b 100644 --- a/app/packs/stylesheets/decidim/superspaces/superspaces.scss +++ b/app/packs/stylesheets/decidim/superspaces/superspaces.scss @@ -5,7 +5,7 @@ padding: 1rem; margin-bottom: 2rem; border-radius: 4px; - + legend { font-weight: 600; margin-bottom: 1rem; @@ -20,16 +20,16 @@ .check-box { margin-bottom: 0.8rem; - + label { display: flex; align-items: center; cursor: pointer; - + input[type="checkbox"] { margin: 0 0.5rem 0 0; } - + .participatory-space-title { line-height: 1.2; } @@ -42,4 +42,3 @@ } } } - diff --git a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb index 71ab105..721eef9 100644 --- a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb @@ -56,8 +56,6 @@
- -
From a2365c88a3ab77871e849f43c675bc61a7dc4228 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Fri, 10 Jan 2025 10:42:10 +0100 Subject: [PATCH 13/19] Fixed command create_superspace tests --- .../superspaces/admin/create_superspace_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/commands/decidim/superspaces/admin/create_superspace_spec.rb b/spec/commands/decidim/superspaces/admin/create_superspace_spec.rb index 882f237..6c8fed7 100644 --- a/spec/commands/decidim/superspaces/admin/create_superspace_spec.rb +++ b/spec/commands/decidim/superspaces/admin/create_superspace_spec.rb @@ -11,13 +11,21 @@ module Admin let(:organization) { create(:organization) } let(:current_user) { create(:user, organization:) } let(:title) { "Superspace title" } + let(:locale) {"en"} + let(:hero_image) {nil} + let(:assembly_ids) {nil} + let(:participatory_process_ids) {nil} let(:invalid) { false } let(:form) do double( invalid?: invalid, title: { en: title }, - current_organization: organization + current_organization: organization, + hero_image: hero_image , + locale: locale, + assembly_ids: assembly_ids, + participatory_process_ids: participatory_process_ids ) end From 3a09ed1014933ca3db606cb3dc685a83c94e3707 Mon Sep 17 00:00:00 2001 From: Jose Illana Lope Date: Mon, 13 Jan 2025 11:49:36 +0100 Subject: [PATCH 14/19] Fixed error when creating a new superspace --- .../decidim/superspaces/admin/superspaces/_form.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb index 721eef9..8bfb6b1 100644 --- a/app/views/decidim/superspaces/admin/superspaces/_form.html.erb +++ b/app/views/decidim/superspaces/admin/superspaces/_form.html.erb @@ -20,7 +20,7 @@