From 57c257e91c5b397975f63a02a1adc02b4c263a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:00:35 +0100 Subject: [PATCH 01/19] Extract settings table partial to a component --- .../admin/settings/table_component.html.erb} | 0 .../admin/settings/table_component.rb | 18 ++++++++++++ app/helpers/settings_helper.rb | 8 ------ .../_configuration_settings_tab.html.erb | 2 +- .../_images_and_documents_tab.html.erb | 2 +- .../settings/_map_configuration_tab.html.erb | 2 +- .../settings/_proposals_dashboard.html.erb | 2 +- .../_remote_census_configuration_tab.html.erb | 6 ++-- .../admin/settings/table_component_spec.rb | 28 +++++++++++++++++++ spec/helpers/settings_helper_spec.rb | 9 ------ 10 files changed, 53 insertions(+), 24 deletions(-) rename app/{views/admin/settings/_settings_table.html.erb => components/admin/settings/table_component.html.erb} (100%) create mode 100644 app/components/admin/settings/table_component.rb create mode 100644 spec/components/admin/settings/table_component_spec.rb diff --git a/app/views/admin/settings/_settings_table.html.erb b/app/components/admin/settings/table_component.html.erb similarity index 100% rename from app/views/admin/settings/_settings_table.html.erb rename to app/components/admin/settings/table_component.html.erb diff --git a/app/components/admin/settings/table_component.rb b/app/components/admin/settings/table_component.rb new file mode 100644 index 000000000..23f7997d3 --- /dev/null +++ b/app/components/admin/settings/table_component.rb @@ -0,0 +1,18 @@ +class Admin::Settings::TableComponent < ApplicationComponent + attr_reader :settings, :setting_name, :tab + delegate :dom_id, to: :helpers + + def initialize(settings:, setting_name:, tab: nil) + @settings = settings + @setting_name = setting_name + @tab = tab + end + + def display_setting_name(setting_name) + if setting_name == "setting" + t("admin.settings.setting_name") + else + t("admin.settings.#{setting_name}") + end + end +end diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index a37d9299e..ccd248e63 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -15,12 +15,4 @@ module SettingsHelper def setting @all_settings ||= Setting.all.to_h { |s| [s.key, s.value.presence] } end - - def display_setting_name(setting_name) - if setting_name == "setting" - t("admin.settings.setting_name") - else - t("admin.settings.#{setting_name}") - end - end end diff --git a/app/views/admin/settings/_configuration_settings_tab.html.erb b/app/views/admin/settings/_configuration_settings_tab.html.erb index b33fa9371..228709f2e 100644 --- a/app/views/admin/settings/_configuration_settings_tab.html.erb +++ b/app/views/admin/settings/_configuration_settings_tab.html.erb @@ -1,3 +1,3 @@
<%= t("admin.settings.index.map.help") %>
diff --git a/app/views/admin/settings/_proposals_dashboard.html.erb b/app/views/admin/settings/_proposals_dashboard.html.erb index eae3243c4..ebdca806c 100644 --- a/app/views/admin/settings/_proposals_dashboard.html.erb +++ b/app/views/admin/settings/_proposals_dashboard.html.erb @@ -1,3 +1,3 @@<%= t("admin.settings.index.map.help") %>
- <%= render "map_form" %> + <%= render Admin::Settings::MapFormComponent.new %> <% else %>| <%= display_setting_name(setting_name) %> | -<%= t("admin.settings.setting_value") %> | +<%= key_header %> | +<%= value_header %> | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| - <%= t("settings.#{setting.key}") %> + |
+ <%= t("settings.#{setting.key}") %>
<%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %> |
- + |
<% if setting.content_type? %>
<%= render Admin::Settings::ContentTypesFormComponent.new(setting) %>
+ <% elsif setting.feature? %>
+ <%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, tab: tab) %>
<% else %>
<%= render Admin::Settings::TextFormComponent.new(setting, tab: tab) %>
<% end %>
diff --git a/app/components/admin/settings/table_component.rb b/app/components/admin/settings/table_component.rb
index 23f7997d3..3c7e3fc6e 100644
--- a/app/components/admin/settings/table_component.rb
+++ b/app/components/admin/settings/table_component.rb
@@ -8,11 +8,29 @@ class Admin::Settings::TableComponent < ApplicationComponent
@tab = tab
end
- def display_setting_name(setting_name)
- if setting_name == "setting"
+ def key_header
+ if setting_name == "feature"
+ t("admin.settings.setting")
+ elsif setting_name == "setting"
t("admin.settings.setting_name")
else
t("admin.settings.#{setting_name}")
end
end
+
+ def value_header
+ if setting_name == "feature"
+ t("admin.settings.index.features.enabled")
+ else
+ t("admin.settings.setting_value")
+ end
+ end
+
+ def table_class
+ if settings.all?(&:feature?)
+ "featured-settings-table"
+ else
+ "mixed-settings-table"
+ end
+ end
end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index fb2219066..626091f66 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -7,16 +7,6 @@ class Setting < ApplicationRecord
key.split(".").first
end
- def type
- if %w[feature process proposals map html homepage uploads sdg machine_learning].include? prefix
- prefix
- elsif %w[remote_census].include? prefix
- key.rpartition(".").first
- else
- "configuration"
- end
- end
-
def enabled?
value.present?
end
@@ -25,6 +15,10 @@ class Setting < ApplicationRecord
key.split(".").last == "content_types"
end
+ def feature?
+ %w[feature process sdg].include?(prefix)
+ end
+
def content_type_group
key.split(".").second
end
diff --git a/app/views/admin/settings/_featured_settings_table.html.erb b/app/views/admin/settings/_featured_settings_table.html.erb
deleted file mode 100644
index 649d43cec..000000000
--- a/app/views/admin/settings/_featured_settings_table.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-
<%= t("admin.settings.index.feature_flags") %>-<%= render "featured_settings_table", features: @feature_settings, tab: "#tab-feature-flags" %> +<%= render Admin::Settings::TableComponent.new(settings: @feature_settings, setting_name: "feature", tab: "#tab-feature-flags") %> diff --git a/app/views/admin/settings/_participation_processes_tab.html.erb b/app/views/admin/settings/_participation_processes_tab.html.erb index 01878c51d..7ff7f1b45 100644 --- a/app/views/admin/settings/_participation_processes_tab.html.erb +++ b/app/views/admin/settings/_participation_processes_tab.html.erb @@ -1,3 +1,3 @@<%= t("admin.settings.index.participation_processes") %>-<%= render "featured_settings_table", features: @participation_processes_settings, tab: "#tab-participation-processes" %> +<%= render Admin::Settings::TableComponent.new(settings: @participation_processes_settings, setting_name: "feature", tab: "#tab-participation-processes") %> diff --git a/app/views/admin/settings/_sdg_configuration_tab.html.erb b/app/views/admin/settings/_sdg_configuration_tab.html.erb index e931b67e1..149908bd3 100644 --- a/app/views/admin/settings/_sdg_configuration_tab.html.erb +++ b/app/views/admin/settings/_sdg_configuration_tab.html.erb @@ -1,7 +1,7 @@ <% if feature?(:sdg) %><%= t("admin.settings.index.sdg.title") %>- <%= render "featured_settings_table", features: @sdg_settings, tab: "#tab-sdg-configuration" %> + <%= render Admin::Settings::TableComponent.new(settings: @sdg_settings, setting_name: "feature", tab: "#tab-sdg-configuration") %> <% else %>
<%= t("admin.settings.index.sdg.how_to_enable") %>
diff --git a/app/views/admin/settings/update.js.erb b/app/views/admin/settings/update.js.erb
index 503ef165d..a18526d08 100644
--- a/app/views/admin/settings/update.js.erb
+++ b/app/views/admin/settings/update.js.erb
@@ -6,6 +6,6 @@ var form = $("<%= j render Admin::Settings::FeaturedSettingsFormComponent.new(
$("#" + form.attr("id")).html(form.html()).find("[type='submit']").focus();
-<% if @setting.type == "feature" || @setting.type == "process" %>
+<% if @setting.prefix == "feature" || @setting.prefix == "process" %>
$("#side_menu").html("<%= j render Admin::MenuComponent.new %>").foundation();
<% end %>
diff --git a/app/views/admin/site_customization/content_blocks/index.html.erb b/app/views/admin/site_customization/content_blocks/index.html.erb
index 11c3a8493..8f6ffae3f 100644
--- a/app/views/admin/site_customization/content_blocks/index.html.erb
+++ b/app/views/admin/site_customization/content_blocks/index.html.erb
@@ -6,7 +6,7 @@
<%= t("admin.site_customization.content_blocks.index.title") %>-<%= render "admin/settings/settings_table", settings: @html_settings, setting_name: "setting" %> +<%= render Admin::Settings::TableComponent.new(settings: @html_settings, setting_name: "setting") %><%= t("admin.site_customization.content_blocks.information") %>diff --git a/spec/components/admin/settings/table_component_spec.rb b/spec/components/admin/settings/table_component_spec.rb index f30ed2416..8f7b7e3ac 100644 --- a/spec/components/admin/settings/table_component_spec.rb +++ b/spec/components/admin/settings/table_component_spec.rb @@ -1,10 +1,14 @@ require "rails_helper" describe Admin::Settings::TableComponent do - describe "#display_setting_name" do - it "returns correct table header" do + describe "#key_header" do + it "returns correct table header for the setting name colums" do settings = Setting.limit(2) + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "feature" + + expect(page).to have_content("Feature") + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "setting" expect(page).to have_content("Setting") @@ -25,4 +29,38 @@ describe Admin::Settings::TableComponent do expect(page).to have_content("Response Data") end end + + describe "#value_header" do + it "returns correct table header for the setting interface column" do + settings = Setting.limit(2) + + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "feature" + + expect(page).to have_content("Enabled") + + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "setting" + + expect(page).to have_content("Value") + end + end + + describe "#table_class" do + it "returns a CSS class when all given settings are features, otherwise returns a mixed class" do + settings = [Setting.find_by(key: "feature.map"), Setting.find_by(key: "process.debates")] + + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "feature" + + expect(page).to have_css(".featured-settings-table") + expect(page).not_to have_css(".mixed-settings-table") + end + + it "returns a CSS class when all given settings are features, otherwise returns a mixed class" do + settings = [Setting.find_by(key: "feature.map"), Setting.find_by(key: "mailer_from_name")] + + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "feature" + + expect(page).not_to have_css(".featured-settings-table") + expect(page).to have_css(".mixed-settings-table") + end + end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index f573505bf..655ade457 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -27,56 +27,12 @@ describe Setting do end end - describe "#type" do - it "returns the key prefix for 'process' settings" do - process_setting = Setting.create!(key: "process.whatever") - expect(process_setting.type).to eq "process" - end - - it "returns the key prefix for 'feature' settings" do - feature_setting = Setting.create!(key: "feature.whatever") - expect(feature_setting.type).to eq "feature" - end - - it "returns the key prefix for 'map' settings" do - map_setting = Setting.create!(key: "map.whatever") - expect(map_setting.type).to eq "map" - end - - it "returns the key prefix for 'html' settings" do - html_setting = Setting.create!(key: "html.whatever") - expect(html_setting.type).to eq "html" - end - - it "returns the key prefix for 'homepage' settings" do - homepage_setting = Setting.create!(key: "homepage.whatever") - expect(homepage_setting.type).to eq "homepage" - end - - it "returns the key prefix for 'sdg' settings" do - sdg_setting = Setting.create!(key: "sdg.whatever") - - expect(sdg_setting.type).to eq "sdg" - end - - it "returns the key prefix for 'remote_census.general' settings" do - remote_census_general_setting = Setting.create!(key: "remote_census.general.whatever") - expect(remote_census_general_setting.type).to eq "remote_census.general" - end - - it "returns the key prefix for 'remote_census_request' settings" do - remote_census_request_setting = Setting.create!(key: "remote_census.request.whatever") - expect(remote_census_request_setting.type).to eq "remote_census.request" - end - - it "returns the key prefix for 'remote_census_response' settings" do - remote_census_response_setting = Setting.create!(key: "remote_census.response.whatever") - expect(remote_census_response_setting.type).to eq "remote_census.response" - end - - it "returns 'configuration' for the rest of the settings" do - configuration_setting = Setting.create!(key: "whatever") - expect(configuration_setting.type).to eq "configuration" + describe "#feature?" do + it "returns true if the key prefix is process, feature or sdg" do + expect(Setting.find_by!(key: "process.debates").feature?).to be true + expect(Setting.find_by!(key: "feature.map").feature?).to be true + expect(Setting.find_by!(key: "sdg.process.debates").feature?).to be true + expect(Setting.find_by!(key: "uploads.documents.max_size").feature?).to be false end end From 1fb351425ff67b75097d54963b8b7007ff563a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:53:05 +0100 Subject: [PATCH 06/19] Use a plain tab param Instead of using a setting nested param `setting[:tab]`. We only need the tab param when rendering settings in the administration section. This change will make it easier rendering the correct tab after updating settings. --- .../admin/settings/featured_settings_form_component.html.erb | 2 +- app/components/admin/settings/text_form_component.html.erb | 2 +- app/controllers/admin/settings_controller.rb | 4 +--- app/views/admin/settings/update.js.erb | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/components/admin/settings/featured_settings_form_component.html.erb b/app/components/admin/settings/featured_settings_form_component.html.erb index e1b8840c9..fb73a042b 100644 --- a/app/components/admin/settings/featured_settings_form_component.html.erb +++ b/app/components/admin/settings/featured_settings_form_component.html.erb @@ -1,5 +1,5 @@ <%= form_for([:admin, feature], remote: remote?, html: { class: "featured-settings-form" }) do |f| %> - <%= f.hidden_field :tab, id: dom_id(feature, :tab), value: tab if tab %> + <%= hidden_field_tag :tab, tab if tab %> <%= f.hidden_field :describedby, id: dom_id(feature, :describedby), value: describedby if describedby %> <%= f.hidden_field :value, id: dom_id(feature, :value), value: (enabled? ? "" : "active") %> <%= f.button text, options %> diff --git a/app/components/admin/settings/text_form_component.html.erb b/app/components/admin/settings/text_form_component.html.erb index 70b11d291..63117e49f 100644 --- a/app/components/admin/settings/text_form_component.html.erb +++ b/app/components/admin/settings/text_form_component.html.erb @@ -1,5 +1,5 @@ <%= form_for([:admin, setting]) do |f| %> - <%= f.hidden_field :tab, id: dom_id(setting, :tab), value: tab if tab %> + <%= hidden_field_tag :tab, tab if tab %>
<%= f.text_area :value,
label: false,
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index 3e8c023ca..d9a2d6690 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -55,8 +55,6 @@ class Admin::SettingsController < Admin::BaseController
end
def request_referer
- return request.referer + params[:setting][:tab] if params[:setting][:tab]
-
- request.referer
+ request.referer + params[:tab].to_s
end
end
diff --git a/app/views/admin/settings/update.js.erb b/app/views/admin/settings/update.js.erb
index a18526d08..57d75bc95 100644
--- a/app/views/admin/settings/update.js.erb
+++ b/app/views/admin/settings/update.js.erb
@@ -1,6 +1,6 @@
var form = $("<%= j render Admin::Settings::FeaturedSettingsFormComponent.new(
@setting,
- tab: params[:setting][:tab],
+ tab: params[:tab],
describedby: params[:setting][:describedby]
) %>");
From cb91a7421db64b9d7e9c169f6b0e23788d3aaa4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?=
<15726+Senen@users.noreply.github.com>
Date: Mon, 27 Nov 2023 11:54:15 +0100
Subject: [PATCH 07/19] Fix upload settings redirection
---
.../settings/content_types_form_component.html.erb | 1 +
.../admin/settings/content_types_form_component.rb | 5 +++--
.../admin/settings/table_component.html.erb | 2 +-
app/controllers/admin/settings_controller.rb | 2 +-
.../settings/_images_and_documents_tab.html.erb | 2 +-
spec/system/admin/settings_spec.rb | 12 ++++++++++++
6 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/app/components/admin/settings/content_types_form_component.html.erb b/app/components/admin/settings/content_types_form_component.html.erb
index 458f9d8e8..c838a1658 100644
--- a/app/components/admin/settings/content_types_form_component.html.erb
+++ b/app/components/admin/settings/content_types_form_component.html.erb
@@ -1,5 +1,6 @@
<%= form_tag admin_update_content_types_path, method: :put, id: "edit_#{dom_id(setting)}" do %>
<%= hidden_field_tag "id", setting.id, id: dom_id(setting, :id) %>
+ <%= hidden_field_tag :tab, tab if tab %>
<% group = setting.content_type_group %>
diff --git a/app/components/admin/settings/content_types_form_component.rb b/app/components/admin/settings/content_types_form_component.rb
index e38302856..264d679b0 100644
--- a/app/components/admin/settings/content_types_form_component.rb
+++ b/app/components/admin/settings/content_types_form_component.rb
@@ -1,8 +1,9 @@
class Admin::Settings::ContentTypesFormComponent < ApplicationComponent
- attr_reader :setting
+ attr_reader :setting, :tab
delegate :dom_id, to: :helpers
- def initialize(setting)
+ def initialize(setting, tab: nil)
@setting = setting
+ @tab = tab
end
end
diff --git a/app/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb
index b3b088d43..40ead146c 100644
--- a/app/components/admin/settings/table_component.html.erb
+++ b/app/components/admin/settings/table_component.html.erb
@@ -17,7 +17,7 @@
|
<% if setting.content_type? %>
- <%= render Admin::Settings::ContentTypesFormComponent.new(setting) %>
+ <%= render Admin::Settings::ContentTypesFormComponent.new(setting, tab: tab) %>
<% elsif setting.feature? %>
<%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, tab: tab) %>
<% else %>
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index d9a2d6690..13496e212 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -37,7 +37,7 @@ class Admin::SettingsController < Admin::BaseController
Setting.mime_types[group][content_type]
end
setting.update! value: mime_type_values.join(" ")
- redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
+ redirect_to request_referer, notice: t("admin.settings.flash.updated")
end
private
diff --git a/app/views/admin/settings/_images_and_documents_tab.html.erb b/app/views/admin/settings/_images_and_documents_tab.html.erb
index adbf4159a..0b059aa6a 100644
--- a/app/views/admin/settings/_images_and_documents_tab.html.erb
+++ b/app/views/admin/settings/_images_and_documents_tab.html.erb
@@ -1,3 +1,3 @@
<%= t("admin.settings.index.images_and_documents") %>-<%= render Admin::Settings::TableComponent.new(settings: @uploads_settings, setting_name: "setting") %> +<%= render Admin::Settings::TableComponent.new(settings: @uploads_settings, setting_name: "setting", tab: "#tab-images-and-documents") %> diff --git a/spec/system/admin/settings_spec.rb b/spec/system/admin/settings_spec.rb index 8639a1820..035752740 100644 --- a/spec/system/admin/settings_spec.rb +++ b/spec/system/admin/settings_spec.rb @@ -277,6 +277,18 @@ describe "Admin settings", :admin do expect(page).to have_current_path(admin_settings_path) expect(page).to have_css("h2", exact_text: "SDG configuration") end + + scenario "On #tab-images-and-documents" do + Setting["feature.sdg"] = true + visit admin_settings_path(anchor: "tab-images-and-documents") + within("tr", text: "Maximum number of documents") do + fill_in "Maximum number of documents", with: 5 + click_button "Update" + end + + expect(page).to have_current_path(admin_settings_path) + expect(page).to have_field("Maximum number of documents", with: 5) + end end describe "Skip verification" do From 91c3bde36bf4b2c5a36ff8a7c191aad77c635f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:22:15 +0100 Subject: [PATCH 08/19] Fix map settings redirection --- .../admin/settings/map_form_component.html.erb | 1 + app/components/admin/settings/map_form_component.rb | 5 +++++ app/controllers/admin/settings_controller.rb | 2 +- .../admin/settings/_map_configuration_tab.html.erb | 2 +- spec/system/admin/settings_spec.rb | 11 +++++++++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/components/admin/settings/map_form_component.html.erb b/app/components/admin/settings/map_form_component.html.erb index c71b412a0..7a0f00a95 100644 --- a/app/components/admin/settings/map_form_component.html.erb +++ b/app/components/admin/settings/map_form_component.html.erb @@ -20,6 +20,7 @@ <%= hidden_field_tag :latitude, Setting["map.latitude"] %> <%= hidden_field_tag :longitude, Setting["map.longitude"] %> <%= hidden_field_tag :zoom, Setting["map.zoom"] %> + <%= hidden_field_tag :tab, tab if tab %>
<%= submit_tag t("admin.settings.index.map.form.submit"),
diff --git a/app/components/admin/settings/map_form_component.rb b/app/components/admin/settings/map_form_component.rb
index 29e5f5372..81209a7ee 100644
--- a/app/components/admin/settings/map_form_component.rb
+++ b/app/components/admin/settings/map_form_component.rb
@@ -1,2 +1,7 @@
class Admin::Settings::MapFormComponent < ApplicationComponent
+ attr_reader :tab
+
+ def initialize(tab: nil)
+ @tab = tab
+ end
end
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index 13496e212..2778ad3eb 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -27,7 +27,7 @@ class Admin::SettingsController < Admin::BaseController
Setting["map.latitude"] = params[:latitude].to_f
Setting["map.longitude"] = params[:longitude].to_f
Setting["map.zoom"] = params[:zoom].to_i
- redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update")
+ redirect_to request_referer, notice: t("admin.settings.index.map.flash.update")
end
def update_content_types
diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb
index 9f0d4ab71..77130f0a2 100644
--- a/app/views/admin/settings/_map_configuration_tab.html.erb
+++ b/app/views/admin/settings/_map_configuration_tab.html.erb
@@ -5,7 +5,7 @@
<%= t("admin.settings.index.map.help") %> - <%= render Admin::Settings::MapFormComponent.new %> + <%= render Admin::Settings::MapFormComponent.new(tab: "#tab-map-configuration") %> <% else %>
<%= t("admin.settings.index.map.how_to_enable") %>
diff --git a/spec/system/admin/settings_spec.rb b/spec/system/admin/settings_spec.rb
index 035752740..ad37d80cd 100644
--- a/spec/system/admin/settings_spec.rb
+++ b/spec/system/admin/settings_spec.rb
@@ -222,6 +222,17 @@ describe "Admin settings", :admin do
expect(page).to have_current_path(admin_settings_path)
expect(page).to have_css("div#tab-map-configuration.is-active")
end
+
+ scenario "On #tab-map-configuration when using the interactive map" do
+ visit admin_settings_path(anchor: "tab-map-configuration")
+ within "#map-form" do
+ click_button "Update"
+ end
+
+ expect(page).to have_content("Map configuration updated successfully.")
+ expect(page).to have_current_path(admin_settings_path)
+ expect(page).to have_css("div#tab-map-configuration.is-active")
+ end
end
scenario "On #tab-proposals" do
From f8835debae8050021aaf10d301fa69e88ae93024 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?=
<15726+Senen@users.noreply.github.com>
Date: Thu, 7 Dec 2023 17:06:42 +0100
Subject: [PATCH 09/19] Move logic from key definition to views
Before this change, two important things depend on the format of each key,
where to render it in the administration panel and which kind of interface
to use for each setting. Following this strategy led us to a very complex
code, very difficult to maintain or modify. So, we do not want to depend
on the setting key structure anymore to decide how or where to render each
setting.
With this commit, we get rid of the key format-based rules. Now we render
each setting explicitly passing to it the type and the tab where it belongs.
---
.../admin/settings/row_component.html.erb | 18 ++++++
.../admin/settings/row_component.rb | 22 +++++++
.../admin/settings/table_component.html.erb | 21 +------
.../admin/settings/table_component.rb | 16 +-----
app/controllers/admin/settings_controller.rb | 11 ----
.../content_blocks_controller.rb | 2 -
app/models/setting.rb | 8 ---
.../_configuration_settings_tab.html.erb | 13 ++++-
.../admin/settings/_features_tab.html.erb | 12 +++-
.../_images_and_documents_tab.html.erb | 13 ++++-
.../settings/_map_configuration_tab.html.erb | 9 ++-
.../_participation_processes_tab.html.erb | 6 +-
.../settings/_proposals_dashboard.html.erb | 8 ++-
.../_remote_census_configuration_tab.html.erb | 21 ++++++-
.../settings/_sdg_configuration_tab.html.erb | 6 +-
.../content_blocks/index.html.erb | 5 +-
.../admin/settings/table_component_spec.rb | 40 +++++--------
spec/models/setting_spec.rb | 19 -------
spec/system/admin/settings_spec.rb | 57 ++++++-------------
19 files changed, 157 insertions(+), 150 deletions(-)
create mode 100644 app/components/admin/settings/row_component.html.erb
create mode 100644 app/components/admin/settings/row_component.rb
diff --git a/app/components/admin/settings/row_component.html.erb b/app/components/admin/settings/row_component.html.erb
new file mode 100644
index 000000000..d5ef631d5
--- /dev/null
+++ b/app/components/admin/settings/row_component.html.erb
@@ -0,0 +1,18 @@
+
+ <%= t("settings.#{setting.key}") %>
+ |
+ + + <%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %> + +
+ <% if content_type_setting? %>
+ <%= render Admin::Settings::ContentTypesFormComponent.new(setting, tab: tab) %>
+ <% elsif featured_setting? %>
+ <%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, tab: tab) %>
+ <% else %>
+ <%= render Admin::Settings::TextFormComponent.new(setting, tab: tab) %>
+ <% end %>
+ |
+ | ||||
|
- <%= t("settings.#{setting.key}") %>
- - - <%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %> - - |
- - <% if setting.content_type? %> - <%= render Admin::Settings::ContentTypesFormComponent.new(setting, tab: tab) %> - <% elsif setting.feature? %> - <%= render Admin::Settings::FeaturedSettingsFormComponent.new(setting, tab: tab) %> - <% else %> - <%= render Admin::Settings::TextFormComponent.new(setting, tab: tab) %> - <% end %> - | -
<%= t("admin.settings.index.map.help") %>
- <%= render Admin::Settings::MapFormComponent.new(tab: "#tab-map-configuration") %> + <%= render Admin::Settings::MapFormComponent.new(tab: tab) %> <% else %>