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.general") %>

-<%= render "settings_table", settings: @configuration_settings, setting_name: "setting", tab: "#tab-configuration" %> +<%= render Admin::Settings::TableComponent.new(settings: @configuration_settings, setting_name: "setting", tab: "#tab-configuration") %> 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 2b8b6ef89..adbf4159a 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 "settings_table", settings: @uploads_settings, setting_name: "setting" %> +<%= render Admin::Settings::TableComponent.new(settings: @uploads_settings, setting_name: "setting") %> diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb index fd8110989..e4b324e5d 100644 --- a/app/views/admin/settings/_map_configuration_tab.html.erb +++ b/app/views/admin/settings/_map_configuration_tab.html.erb @@ -1,7 +1,7 @@ <% if feature?(:map) %>

<%= t("admin.settings.index.map.title") %>

- <%= render "settings_table", settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration" %> + <%= render Admin::Settings::TableComponent.new(settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration") %>

<%= 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.dashboard.title") %>

-<%= render "settings_table", settings: @proposals_settings, setting_name: "setting", tab: "#tab-proposals" %> +<%= render Admin::Settings::TableComponent.new(settings: @proposals_settings, setting_name: "setting", tab: "#tab-proposals") %> diff --git a/app/views/admin/settings/_remote_census_configuration_tab.html.erb b/app/views/admin/settings/_remote_census_configuration_tab.html.erb index 6a136bd42..cdfba13d2 100644 --- a/app/views/admin/settings/_remote_census_configuration_tab.html.erb +++ b/app/views/admin/settings/_remote_census_configuration_tab.html.erb @@ -1,9 +1,9 @@ <% if feature?(:remote_census) %>

<%= t("admin.settings.index.remote_census.title") %>

- <%= render "settings_table", settings: @remote_census_general_settings, setting_name: "remote_census_general_name", tab: "#tab-remote-census-configuration" %> - <%= render "settings_table", settings: @remote_census_request_settings, setting_name: "remote_census_request_name", tab: "#tab-remote-census-configuration" %> - <%= render "settings_table", settings: @remote_census_response_settings, setting_name: "remote_census_response_name", tab: "#tab-remote-census-configuration" %> + <%= render Admin::Settings::TableComponent.new(settings: @remote_census_general_settings, setting_name: "remote_census_general_name", tab: "#tab-remote-census-configuration") %> + <%= render Admin::Settings::TableComponent.new(settings: @remote_census_request_settings, setting_name: "remote_census_request_name", tab: "#tab-remote-census-configuration") %> + <%= render Admin::Settings::TableComponent.new(settings: @remote_census_response_settings, setting_name: "remote_census_response_name", tab: "#tab-remote-census-configuration") %> <% else %>
<%= t("admin.settings.index.remote_census.how_to_enable") %> diff --git a/spec/components/admin/settings/table_component_spec.rb b/spec/components/admin/settings/table_component_spec.rb new file mode 100644 index 000000000..f30ed2416 --- /dev/null +++ b/spec/components/admin/settings/table_component_spec.rb @@ -0,0 +1,28 @@ +require "rails_helper" + +describe Admin::Settings::TableComponent do + describe "#display_setting_name" do + it "returns correct table header" do + settings = Setting.limit(2) + + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "setting" + + expect(page).to have_content("Setting") + + setting_name = "remote_census_general_name" + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + + expect(page).to have_content("General Information") + + setting_name = "remote_census_request_name" + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + + expect(page).to have_content("Request Data") + + setting_name = "remote_census_response_name" + render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + + expect(page).to have_content("Response Data") + end + end +end diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index f07a97f10..f7bd9835a 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -24,13 +24,4 @@ RSpec.describe SettingsHelper do expect(feature?("f4")).to be nil end end - - describe "#display_setting_name" do - it "returns correct setting_name" do - expect(display_setting_name("setting")).to eq("Setting") - expect(display_setting_name("remote_census_general_name")).to eq("General Information") - expect(display_setting_name("remote_census_request_name")).to eq("Request Data") - expect(display_setting_name("remote_census_response_name")).to eq("Response Data") - end - end end From c9e3b8903d05c37464e89292c6c11086cf6c6b1d 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 10:19:58 +0100 Subject: [PATCH 02/19] Extract setting content types form to a component --- .../admin/settings/content_types_form_component.html.erb} | 0 .../admin/settings/content_types_form_component.rb | 8 ++++++++ app/components/admin/settings/table_component.html.erb | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) rename app/{views/admin/settings/_content_types_settings_form.html.erb => components/admin/settings/content_types_form_component.html.erb} (100%) create mode 100644 app/components/admin/settings/content_types_form_component.rb diff --git a/app/views/admin/settings/_content_types_settings_form.html.erb b/app/components/admin/settings/content_types_form_component.html.erb similarity index 100% rename from app/views/admin/settings/_content_types_settings_form.html.erb rename to app/components/admin/settings/content_types_form_component.html.erb diff --git a/app/components/admin/settings/content_types_form_component.rb b/app/components/admin/settings/content_types_form_component.rb new file mode 100644 index 000000000..e38302856 --- /dev/null +++ b/app/components/admin/settings/content_types_form_component.rb @@ -0,0 +1,8 @@ +class Admin::Settings::ContentTypesFormComponent < ApplicationComponent + attr_reader :setting + delegate :dom_id, to: :helpers + + def initialize(setting) + @setting = setting + end +end diff --git a/app/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb index b3015525f..c261893b8 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/content_types_settings_form", setting: setting %> + <%= render Admin::Settings::ContentTypesFormComponent.new(setting) %> <% else %> <% if defined?(tab) %> <%= render "admin/settings/settings_form", setting: setting, tab: tab %> From 65c61891832895256ba51e97d090544456e49c9d 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 10:26:46 +0100 Subject: [PATCH 03/19] Extract setting text form to a component --- app/components/admin/settings/table_component.html.erb | 6 +----- .../admin/settings/text_form_component.html.erb} | 2 +- app/components/admin/settings/text_form_component.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) rename app/{views/admin/settings/_settings_form.html.erb => components/admin/settings/text_form_component.html.erb} (96%) create mode 100644 app/components/admin/settings/text_form_component.rb diff --git a/app/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb index c261893b8..cf486f499 100644 --- a/app/components/admin/settings/table_component.html.erb +++ b/app/components/admin/settings/table_component.html.erb @@ -19,11 +19,7 @@ <% if setting.content_type? %> <%= render Admin::Settings::ContentTypesFormComponent.new(setting) %> <% else %> - <% if defined?(tab) %> - <%= render "admin/settings/settings_form", setting: setting, tab: tab %> - <% else %> - <%= render "admin/settings/settings_form", setting: setting %> - <% end %> + <%= render Admin::Settings::TextFormComponent.new(setting, tab: tab) %> <% end %> diff --git a/app/views/admin/settings/_settings_form.html.erb b/app/components/admin/settings/text_form_component.html.erb similarity index 96% rename from app/views/admin/settings/_settings_form.html.erb rename to app/components/admin/settings/text_form_component.html.erb index 464713004..70b11d291 100644 --- a/app/views/admin/settings/_settings_form.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 defined?(tab) %> + <%= f.hidden_field :tab, id: dom_id(setting, :tab), value: tab if tab %>
<%= f.text_area :value, label: false, diff --git a/app/components/admin/settings/text_form_component.rb b/app/components/admin/settings/text_form_component.rb new file mode 100644 index 000000000..9234c0fb7 --- /dev/null +++ b/app/components/admin/settings/text_form_component.rb @@ -0,0 +1,9 @@ +class Admin::Settings::TextFormComponent < ApplicationComponent + attr_reader :setting, :tab + delegate :dom_id, to: :helpers + + def initialize(setting, tab: nil) + @setting = setting + @tab = tab + end +end From e7223ba86565013b950c655bb044876b6470f94a 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:15:03 +0100 Subject: [PATCH 04/19] Extract interactive map form to a component --- .../admin/settings/map_form_component.html.erb} | 0 app/components/admin/settings/map_form_component.rb | 2 ++ app/views/admin/settings/_map_configuration_tab.html.erb | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) rename app/{views/admin/settings/_map_form.html.erb => components/admin/settings/map_form_component.html.erb} (100%) create mode 100644 app/components/admin/settings/map_form_component.rb diff --git a/app/views/admin/settings/_map_form.html.erb b/app/components/admin/settings/map_form_component.html.erb similarity index 100% rename from app/views/admin/settings/_map_form.html.erb rename to app/components/admin/settings/map_form_component.html.erb diff --git a/app/components/admin/settings/map_form_component.rb b/app/components/admin/settings/map_form_component.rb new file mode 100644 index 000000000..29e5f5372 --- /dev/null +++ b/app/components/admin/settings/map_form_component.rb @@ -0,0 +1,2 @@ +class Admin::Settings::MapFormComponent < ApplicationComponent +end diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb index e4b324e5d..9f0d4ab71 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 "map_form" %> + <%= render Admin::Settings::MapFormComponent.new %> <% else %>
<%= t("admin.settings.index.map.how_to_enable") %> From 6a64f38d178e136e87fc0164854798d38f92761c 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: Wed, 22 Nov 2023 21:32:37 +0100 Subject: [PATCH 05/19] Use admin table settings component to render featured settings Now, with the same template we can render all kind of settings. --- .../settings/featured_settings_table.scss | 6 -- .../stylesheets/admin/settings/table.scss | 13 +++++ .../admin/settings/table_component.html.erb | 14 +++-- .../admin/settings/table_component.rb | 22 +++++++- app/models/setting.rb | 14 ++--- .../_featured_settings_table.html.erb | 25 --------- .../admin/settings/_features_tab.html.erb | 2 +- .../_participation_processes_tab.html.erb | 2 +- .../settings/_sdg_configuration_tab.html.erb | 2 +- app/views/admin/settings/update.js.erb | 2 +- .../content_blocks/index.html.erb | 2 +- .../admin/settings/table_component_spec.rb | 42 +++++++++++++- spec/models/setting_spec.rb | 56 ++----------------- 13 files changed, 96 insertions(+), 106 deletions(-) delete mode 100644 app/assets/stylesheets/admin/settings/featured_settings_table.scss create mode 100644 app/assets/stylesheets/admin/settings/table.scss delete mode 100644 app/views/admin/settings/_featured_settings_table.html.erb diff --git a/app/assets/stylesheets/admin/settings/featured_settings_table.scss b/app/assets/stylesheets/admin/settings/featured_settings_table.scss deleted file mode 100644 index ef0df6709..000000000 --- a/app/assets/stylesheets/admin/settings/featured_settings_table.scss +++ /dev/null @@ -1,6 +0,0 @@ -.admin .featured-settings-table { - - td { - max-width: $global-width / 3; - } -} diff --git a/app/assets/stylesheets/admin/settings/table.scss b/app/assets/stylesheets/admin/settings/table.scss new file mode 100644 index 000000000..e41467509 --- /dev/null +++ b/app/assets/stylesheets/admin/settings/table.scss @@ -0,0 +1,13 @@ +.admin { + .featured-settings-table { + td { + max-width: $global-width / 3; + } + } + + .mixed-settings-table { + td { + width: 50%; + } + } +} diff --git a/app/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb index cf486f499..b3b088d43 100644 --- a/app/components/admin/settings/table_component.html.erb +++ b/app/components/admin/settings/table_component.html.erb @@ -1,23 +1,25 @@ - +
- - + + <% settings.each do |setting| %> - - + + + diff --git a/app/components/admin/settings/row_component.rb b/app/components/admin/settings/row_component.rb new file mode 100644 index 000000000..777477487 --- /dev/null +++ b/app/components/admin/settings/row_component.rb @@ -0,0 +1,22 @@ +class Admin::Settings::RowComponent < ApplicationComponent + attr_reader :key, :tab, :type + delegate :dom_id, to: :helpers + + def initialize(key, type: :text, tab: nil) + @key = key + @type = type + @tab = tab + end + + def setting + @setting ||= Setting.find_by!(key: key) + end + + def content_type_setting? + type == :content_type + end + + def featured_setting? + type == :feature + end +end diff --git a/app/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb index 40ead146c..5543be032 100644 --- a/app/components/admin/settings/table_component.html.erb +++ b/app/components/admin/settings/table_component.html.erb @@ -6,25 +6,6 @@ - <% settings.each do |setting| %> - - - - - <% end %> + <%= content %>
<%= 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 @@ - - - - - - - - - <% features.each do |feature| %> - - - - - - <% end %> - - diff --git a/app/views/admin/settings/_features_tab.html.erb b/app/views/admin/settings/_features_tab.html.erb index 52fdae2e9..2043b33cf 100644 --- a/app/views/admin/settings/_features_tab.html.erb +++ b/app/views/admin/settings/_features_tab.html.erb @@ -1,3 +1,3 @@

<%= 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 %> -
diff --git a/app/components/admin/settings/table_component.rb b/app/components/admin/settings/table_component.rb index 3c7e3fc6e..de1c2e0fa 100644 --- a/app/components/admin/settings/table_component.rb +++ b/app/components/admin/settings/table_component.rb @@ -1,11 +1,9 @@ class Admin::Settings::TableComponent < ApplicationComponent - attr_reader :settings, :setting_name, :tab - delegate :dom_id, to: :helpers + attr_reader :setting_name, :table_class - def initialize(settings:, setting_name:, tab: nil) - @settings = settings + def initialize(setting_name:, table_class: "mixed-settings-table") @setting_name = setting_name - @tab = tab + @table_class = table_class end def key_header @@ -25,12 +23,4 @@ class Admin::Settings::TableComponent < ApplicationComponent 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/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 2778ad3eb..2ee26ca2e 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -1,16 +1,5 @@ class Admin::SettingsController < Admin::BaseController def index - all_settings = Setting.all.group_by(&:type) - @configuration_settings = all_settings["configuration"] - @feature_settings = all_settings["feature"] - @participation_processes_settings = all_settings["process"] - @map_configuration_settings = all_settings["map"] - @proposals_settings = all_settings["proposals"] - @remote_census_general_settings = all_settings["remote_census.general"] - @remote_census_request_settings = all_settings["remote_census.request"] - @remote_census_response_settings = all_settings["remote_census.response"] - @uploads_settings = all_settings["uploads"] - @sdg_settings = all_settings["sdg"] end def update diff --git a/app/controllers/admin/site_customization/content_blocks_controller.rb b/app/controllers/admin/site_customization/content_blocks_controller.rb index d553c1446..7384551f9 100644 --- a/app/controllers/admin/site_customization/content_blocks_controller.rb +++ b/app/controllers/admin/site_customization/content_blocks_controller.rb @@ -9,8 +9,6 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati def index @content_blocks = SiteCustomization::ContentBlock.order(:name, :locale) @headings_content_blocks = Budget::ContentBlock.all - all_settings = Setting.all.group_by(&:type) - @html_settings = all_settings["html"] end def create diff --git a/app/models/setting.rb b/app/models/setting.rb index 626091f66..a1cd0e211 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -11,14 +11,6 @@ class Setting < ApplicationRecord value.present? end - def content_type? - 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/_configuration_settings_tab.html.erb b/app/views/admin/settings/_configuration_settings_tab.html.erb index 228709f2e..8c1db1bcb 100644 --- a/app/views/admin/settings/_configuration_settings_tab.html.erb +++ b/app/views/admin/settings/_configuration_settings_tab.html.erb @@ -1,3 +1,14 @@

<%= t("admin.settings.index.general") %>

-<%= render Admin::Settings::TableComponent.new(settings: @configuration_settings, setting_name: "setting", tab: "#tab-configuration") %> +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% %w[official_level_1_name official_level_2_name official_level_3_name official_level_4_name + official_level_5_name max_ratio_anon_votes_on_debates max_votes_for_debate_edit + max_votes_for_proposal_edit comments_body_max_length proposal_code_prefix votes_for_proposal_success + months_to_archive_proposals email_domain_for_officials facebook_handle instagram_handle + telegram_handle twitter_handle twitter_hashtag youtube_handle org_name meta_title meta_description + meta_keywords proposal_notification_minimum_interval_in_days direct_message_max_per_day mailer_from_name + mailer_from_address min_age_to_participate hot_score_period_in_days related_content_score_threshold + featured_proposals_number feature.dashboard.notification_emails postal_codes].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-configuration") %> + <% end %> +<% end %> diff --git a/app/views/admin/settings/_features_tab.html.erb b/app/views/admin/settings/_features_tab.html.erb index 2043b33cf..f85a08226 100644 --- a/app/views/admin/settings/_features_tab.html.erb +++ b/app/views/admin/settings/_features_tab.html.erb @@ -1,3 +1,13 @@

<%= t("admin.settings.index.feature_flags") %>

-<%= render Admin::Settings::TableComponent.new(settings: @feature_settings, setting_name: "feature", tab: "#tab-feature-flags") %> +<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> + <% %w[feature.featured_proposals feature.facebook_login feature.google_login feature.twitter_login + feature.wordpress_login feature.public_stats feature.signature_sheets feature.user.recommendations + feature.user.recommendations_on_debates feature.user.recommendations_on_proposals + feature.user.skip_verification feature.community feature.map feature.allow_attached_documents + feature.allow_images feature.help_page feature.remote_translations feature.translation_interface + feature.remote_census feature.valuation_comment_notification feature.graphql_api feature.sdg + feature.machine_learning feature.remove_investments_supports].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-feature-flags") %> + <% end %> +<% end %> 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 0b059aa6a..95144d27c 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,14 @@

<%= t("admin.settings.index.images_and_documents") %>

-<%= render Admin::Settings::TableComponent.new(settings: @uploads_settings, setting_name: "setting", tab: "#tab-images-and-documents") %> +<% tab = "#tab-images-and-documents" %> +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <%= render Admin::Settings::RowComponent.new("uploads.images.title.min_length", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.images.title.max_length", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.images.min_width", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.images.min_height", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.images.max_size", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.images.content_types", type: :content_type, tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.documents.max_amount", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.documents.max_size", tab: tab) %> + <%= render Admin::Settings::RowComponent.new("uploads.documents.content_types", type: :content_type, tab: tab) %> +<% end %> diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/views/admin/settings/_map_configuration_tab.html.erb index 77130f0a2..38a6f5438 100644 --- a/app/views/admin/settings/_map_configuration_tab.html.erb +++ b/app/views/admin/settings/_map_configuration_tab.html.erb @@ -1,11 +1,16 @@ <% if feature?(:map) %>

<%= t("admin.settings.index.map.title") %>

- <%= render Admin::Settings::TableComponent.new(settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration") %> + <% tab = "#tab-map-configuration" %> + <%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% %w[map.latitude map.longitude map.zoom].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> + <% end %>

<%= t("admin.settings.index.map.help") %>

- <%= render Admin::Settings::MapFormComponent.new(tab: "#tab-map-configuration") %> + <%= render Admin::Settings::MapFormComponent.new(tab: tab) %> <% else %>
<%= t("admin.settings.index.map.how_to_enable") %> diff --git a/app/views/admin/settings/_participation_processes_tab.html.erb b/app/views/admin/settings/_participation_processes_tab.html.erb index 7ff7f1b45..8afd8dd1e 100644 --- a/app/views/admin/settings/_participation_processes_tab.html.erb +++ b/app/views/admin/settings/_participation_processes_tab.html.erb @@ -1,3 +1,7 @@

<%= t("admin.settings.index.participation_processes") %>

-<%= render Admin::Settings::TableComponent.new(settings: @participation_processes_settings, setting_name: "feature", tab: "#tab-participation-processes") %> +<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> + <% %w[process.debates process.proposals process.polls process.budgets process.legislation].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-participation-processes") %> + <% end %> +<% end %> diff --git a/app/views/admin/settings/_proposals_dashboard.html.erb b/app/views/admin/settings/_proposals_dashboard.html.erb index ebdca806c..5975c045a 100644 --- a/app/views/admin/settings/_proposals_dashboard.html.erb +++ b/app/views/admin/settings/_proposals_dashboard.html.erb @@ -1,3 +1,9 @@

<%= t("admin.settings.index.dashboard.title") %>

-<%= render Admin::Settings::TableComponent.new(settings: @proposals_settings, setting_name: "setting", tab: "#tab-proposals") %> +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% %w[proposals.successful_proposal_id proposals.poll_short_title proposals.poll_description + proposals.poll_link proposals.email_short_title proposals.email_description + proposals.poster_short_title proposals.poster_description].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-proposals") %> + <% end %> +<% end %> diff --git a/app/views/admin/settings/_remote_census_configuration_tab.html.erb b/app/views/admin/settings/_remote_census_configuration_tab.html.erb index cdfba13d2..bec6c59c1 100644 --- a/app/views/admin/settings/_remote_census_configuration_tab.html.erb +++ b/app/views/admin/settings/_remote_census_configuration_tab.html.erb @@ -1,9 +1,24 @@ <% if feature?(:remote_census) %>

<%= t("admin.settings.index.remote_census.title") %>

- <%= render Admin::Settings::TableComponent.new(settings: @remote_census_general_settings, setting_name: "remote_census_general_name", tab: "#tab-remote-census-configuration") %> - <%= render Admin::Settings::TableComponent.new(settings: @remote_census_request_settings, setting_name: "remote_census_request_name", tab: "#tab-remote-census-configuration") %> - <%= render Admin::Settings::TableComponent.new(settings: @remote_census_response_settings, setting_name: "remote_census_response_name", tab: "#tab-remote-census-configuration") %> + <% tab = "#tab-remote-census-configuration" %> + <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_general_name") do %> + <%= render Admin::Settings::RowComponent.new("remote_census.general.endpoint", tab: tab) %> + <% end %> + <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_request_name") do %> + <% %w[remote_census.request.method_name remote_census.request.structure + remote_census.request.document_type remote_census.request.document_number + remote_census.request.date_of_birth remote_census.request.postal_code].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> + <% end %> + <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_response_name") do %> + <% %w[remote_census.response.date_of_birth remote_census.response.postal_code + remote_census.response.district remote_census.response.gender remote_census.response.name + remote_census.response.surname remote_census.response.valid].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> + <% end %> <% else %>
<%= t("admin.settings.index.remote_census.how_to_enable") %> diff --git a/app/views/admin/settings/_sdg_configuration_tab.html.erb b/app/views/admin/settings/_sdg_configuration_tab.html.erb index 149908bd3..795798c18 100644 --- a/app/views/admin/settings/_sdg_configuration_tab.html.erb +++ b/app/views/admin/settings/_sdg_configuration_tab.html.erb @@ -1,7 +1,11 @@ <% if feature?(:sdg) %>

<%= t("admin.settings.index.sdg.title") %>

- <%= render Admin::Settings::TableComponent.new(settings: @sdg_settings, setting_name: "feature", tab: "#tab-sdg-configuration") %> + <%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> + <% %w[sdg.process.debates sdg.process.proposals sdg.process.polls sdg.process.budgets sdg.process.legislation].each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-sdg-configuration") %> + <% end %> + <% end %> <% else %>
<%= t("admin.settings.index.sdg.how_to_enable") %> 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 8f6ffae3f..03fd96248 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,10 @@

<%= t("admin.site_customization.content_blocks.index.title") %>

-<%= render Admin::Settings::TableComponent.new(settings: @html_settings, setting_name: "setting") %> +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <%= render Admin::Settings::RowComponent.new("html.per_page_code_body") %> + <%= render Admin::Settings::RowComponent.new("html.per_page_code_head") %> +<% end %>

<%= 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 8f7b7e3ac..6868e912e 100644 --- a/spec/components/admin/settings/table_component_spec.rb +++ b/spec/components/admin/settings/table_component_spec.rb @@ -3,28 +3,23 @@ require "rails_helper" describe Admin::Settings::TableComponent 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" + render_inline Admin::Settings::TableComponent.new setting_name: "feature" expect(page).to have_content("Feature") - render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "setting" + render_inline Admin::Settings::TableComponent.new setting_name: "setting" expect(page).to have_content("Setting") - setting_name = "remote_census_general_name" - render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_general_name" expect(page).to have_content("General Information") - setting_name = "remote_census_request_name" - render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_request_name" expect(page).to have_content("Request Data") - setting_name = "remote_census_response_name" - render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: setting_name + render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_response_name" expect(page).to have_content("Response Data") end @@ -32,35 +27,28 @@ describe Admin::Settings::TableComponent do 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" + render_inline Admin::Settings::TableComponent.new setting_name: "feature" expect(page).to have_content("Enabled") - render_inline Admin::Settings::TableComponent.new settings: settings, setting_name: "setting" + render_inline Admin::Settings::TableComponent.new 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")] + it "returns the `mixed-settings-table` by default" do + render_inline Admin::Settings::TableComponent.new setting_name: "feature" - 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") + expect(page).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")] + it "returns the given table_class" do + render_inline Admin::Settings::TableComponent.new setting_name: "feature", table_class: "my-table-class" - 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") + expect(page).not_to have_css(".mixed-settings-table") + expect(page).to have_css(".my-table-class") end end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 655ade457..d31c4ef3c 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -27,15 +27,6 @@ describe Setting do end end - 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 - describe "#enabled?" do it "is true if value is present" do setting = Setting.create!(key: "feature.whatever", value: 1) @@ -57,16 +48,6 @@ describe Setting do end end - describe "#content_type?" do - it "returns true if the last part of the key is content_types" do - expect(Setting.create!(key: "key_name.content_types").content_type?).to be true - end - - it "returns false if the last part of the key is not content_types" do - expect(Setting.create!(key: "key_name.whatever").content_type?).to be false - end - end - describe "#content_type_group" do it "returns the group for content_types settings" do images = Setting.create!(key: "update.images.content_types") diff --git a/spec/system/admin/settings_spec.rb b/spec/system/admin/settings_spec.rb index ad37d80cd..83c4369b3 100644 --- a/spec/system/admin/settings_spec.rb +++ b/spec/system/admin/settings_spec.rb @@ -2,24 +2,18 @@ require "rails_helper" describe "Admin settings", :admin do scenario "Index" do - create(:setting, key: "super.users.first") - create(:setting, key: "super.users.second") - create(:setting, key: "super.users.third") - visit admin_settings_path - expect(page).to have_content "First" - expect(page).to have_content "Second" - expect(page).to have_content "Third" + expect(page).to have_content "Level 1 public official" + expect(page).to have_content "Maximum ratio of anonymous votes per Debate" + expect(page).to have_content "Comments body max length" end scenario "Update" do - create(:setting, key: "super.users.first") - visit admin_settings_path - within "tr", text: "First" do - fill_in "First", with: "Super Users of level 1" + within "tr", text: "Level 1 public official" do + fill_in "Level 1 public official", with: "Super Users of level 1" click_button "Update" end @@ -173,13 +167,11 @@ describe "Admin settings", :admin do end scenario "On #tab-remote-census-configuration" do - create(:setting, key: "remote_census.general.whatever") - visit admin_settings_path find("#remote-census-tab").click - within "tr", text: "Whatever" do - fill_in "Whatever", with: "New value" + within "tr", text: "Endpoint" do + fill_in "Endpoint", with: "example.org/webservice" click_button "Update" end @@ -189,13 +181,10 @@ describe "Admin settings", :admin do end scenario "On #tab-configuration" do - Setting.create!(key: "whatever") - visit admin_settings_path - find("#tab-configuration").click - within "tr", text: "Whatever" do - fill_in "Whatever", with: "New value" + within "tr", text: "Level 1 public official" do + fill_in "Level 1 public official", with: "Super Users of level 1" click_button "Update" end @@ -209,13 +198,11 @@ describe "Admin settings", :admin do end scenario "On #tab-map-configuration" do - Setting.create!(key: "map.whatever") - visit admin_settings_path click_link "Map configuration" - within "tr", text: "Whatever" do - fill_in "Whatever", with: "New value" + within "tr", text: "Latitude" do + fill_in "Latitude", with: "-3.636" click_button "Update" end @@ -236,13 +223,11 @@ describe "Admin settings", :admin do end scenario "On #tab-proposals" do - Setting.create!(key: "proposals.whatever") - visit admin_settings_path find("#proposals-tab").click - within "tr", text: "Whatever" do - fill_in "Whatever", with: "New value" + within "tr", text: "Polls description" do + fill_in "Polls description", with: "Polls description" click_button "Update" end @@ -251,22 +236,18 @@ describe "Admin settings", :admin do end scenario "On #tab-participation-processes" do - Setting.create!(key: "process.whatever") - visit admin_settings_path find("#participation-processes-tab").click - within("tr", text: "Whatever") { click_button "No" } + within("tr", text: "Debates") { click_button "Yes" } expect(page).to have_current_path(admin_settings_path) expect(page).to have_css("div#tab-participation-processes.is-active") end scenario "On #tab-feature-flags" do - Setting.create!(key: "feature.whatever") - visit admin_settings_path find("#features-tab").click - within("tr", text: "Whatever") { click_button "No" } + within("tr", text: "Featured proposals") { click_button "No" } expect(page).to have_current_path(admin_settings_path) expect(page).to have_css("div#tab-feature-flags.is-active") @@ -274,15 +255,13 @@ describe "Admin settings", :admin do scenario "On #tab-sdg-configuration" do Setting["feature.sdg"] = true - Setting.create!(key: "sdg.whatever") - visit admin_settings_path click_link "SDG configuration" - within("tr", text: "Whatever") do - click_button "No" + within("tr", text: "Related SDG in debates") do + click_button "Yes" - expect(page).to have_button "Yes" + expect(page).to have_button "No" end expect(page).to have_current_path(admin_settings_path) From 684a83051591a97f011fdfc7e24ab781a34aecb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:23:53 +0100 Subject: [PATCH 10/19] Extract participation processes tab partial to a component --- .../participation_processes_tab_component.html.erb} | 2 +- .../settings/participation_processes_tab_component.rb | 11 +++++++++++ app/views/admin/settings/index.html.erb | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) rename app/{views/admin/settings/_participation_processes_tab.html.erb => components/admin/settings/participation_processes_tab_component.html.erb} (74%) create mode 100644 app/components/admin/settings/participation_processes_tab_component.rb diff --git a/app/views/admin/settings/_participation_processes_tab.html.erb b/app/components/admin/settings/participation_processes_tab_component.html.erb similarity index 74% rename from app/views/admin/settings/_participation_processes_tab.html.erb rename to app/components/admin/settings/participation_processes_tab_component.html.erb index 8afd8dd1e..6e7f93ebb 100644 --- a/app/views/admin/settings/_participation_processes_tab.html.erb +++ b/app/components/admin/settings/participation_processes_tab_component.html.erb @@ -1,7 +1,7 @@

<%= t("admin.settings.index.participation_processes") %>

<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> - <% %w[process.debates process.proposals process.polls process.budgets process.legislation].each do |key| %> + <% settings.each do |key| %> <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-participation-processes") %> <% end %> <% end %> diff --git a/app/components/admin/settings/participation_processes_tab_component.rb b/app/components/admin/settings/participation_processes_tab_component.rb new file mode 100644 index 000000000..44405c723 --- /dev/null +++ b/app/components/admin/settings/participation_processes_tab_component.rb @@ -0,0 +1,11 @@ +class Admin::Settings::ParticipationProcessesTabComponent < ApplicationComponent + def settings + %w[ + process.debates + process.proposals + process.polls + process.budgets + process.legislation + ] + end +end diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 04d6afd93..cddc58f0d 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -7,7 +7,7 @@
- <%= render "participation_processes_tab" %> + <%= render Admin::Settings::ParticipationProcessesTabComponent.new %>
From 347a9d3d5baae61e1235451e911ecff5d203d6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:33:27 +0100 Subject: [PATCH 11/19] Extract remote census configuration tab partial to a component --- .../remote_census_tab_component.html.erb} | 13 +++---- .../settings/remote_census_tab_component.rb | 34 +++++++++++++++++++ app/views/admin/settings/index.html.erb | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) rename app/{views/admin/settings/_remote_census_configuration_tab.html.erb => components/admin/settings/remote_census_tab_component.html.erb} (51%) create mode 100644 app/components/admin/settings/remote_census_tab_component.rb diff --git a/app/views/admin/settings/_remote_census_configuration_tab.html.erb b/app/components/admin/settings/remote_census_tab_component.html.erb similarity index 51% rename from app/views/admin/settings/_remote_census_configuration_tab.html.erb rename to app/components/admin/settings/remote_census_tab_component.html.erb index bec6c59c1..5fee65e6e 100644 --- a/app/views/admin/settings/_remote_census_configuration_tab.html.erb +++ b/app/components/admin/settings/remote_census_tab_component.html.erb @@ -1,21 +1,18 @@ <% if feature?(:remote_census) %>

<%= t("admin.settings.index.remote_census.title") %>

- <% tab = "#tab-remote-census-configuration" %> <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_general_name") do %> - <%= render Admin::Settings::RowComponent.new("remote_census.general.endpoint", tab: tab) %> + <% general_settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> <% end %> <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_request_name") do %> - <% %w[remote_census.request.method_name remote_census.request.structure - remote_census.request.document_type remote_census.request.document_number - remote_census.request.date_of_birth remote_census.request.postal_code].each do |key| %> + <% request_settings.each do |key| %> <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> <% end %> <% end %> <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_response_name") do %> - <% %w[remote_census.response.date_of_birth remote_census.response.postal_code - remote_census.response.district remote_census.response.gender remote_census.response.name - remote_census.response.surname remote_census.response.valid].each do |key| %> + <% response_settings.each do |key| %> <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> <% end %> <% end %> diff --git a/app/components/admin/settings/remote_census_tab_component.rb b/app/components/admin/settings/remote_census_tab_component.rb new file mode 100644 index 000000000..2fd4df6a7 --- /dev/null +++ b/app/components/admin/settings/remote_census_tab_component.rb @@ -0,0 +1,34 @@ +class Admin::Settings::RemoteCensusTabComponent < ApplicationComponent + def tab + "#tab-remote-census-configuration" + end + + def general_settings + %w[ + remote_census.general.endpoint + ] + end + + def request_settings + %w[ + remote_census.request.method_name + remote_census.request.structure + remote_census.request.document_type + remote_census.request.document_number + remote_census.request.date_of_birth + remote_census.request.postal_code + ] + end + + def response_settings + %w[ + remote_census.response.date_of_birth + remote_census.response.postal_code + remote_census.response.district + remote_census.response.gender + remote_census.response.name + remote_census.response.surname + remote_census.response.valid + ] + end +end diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index cddc58f0d..f8397c9e5 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -27,7 +27,7 @@
- <%= render "remote_census_configuration_tab" %> + <%= render Admin::Settings::RemoteCensusTabComponent.new %>
From 726019616f7f983007d6c2d4da4072c3c44fbe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:37:21 +0100 Subject: [PATCH 12/19] Extract configuration settings tab partial to a component --- .../configuration_tab_component.html.erb | 7 ++++ .../settings/configuration_tab_component.rb | 38 +++++++++++++++++++ .../_configuration_settings_tab.html.erb | 14 ------- app/views/admin/settings/index.html.erb | 2 +- 4 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 app/components/admin/settings/configuration_tab_component.html.erb create mode 100644 app/components/admin/settings/configuration_tab_component.rb delete mode 100644 app/views/admin/settings/_configuration_settings_tab.html.erb diff --git a/app/components/admin/settings/configuration_tab_component.html.erb b/app/components/admin/settings/configuration_tab_component.html.erb new file mode 100644 index 000000000..3ec85c6ad --- /dev/null +++ b/app/components/admin/settings/configuration_tab_component.html.erb @@ -0,0 +1,7 @@ +

<%= t("admin.settings.index.general") %>

+ +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-configuration") %> + <% end %> +<% end %> diff --git a/app/components/admin/settings/configuration_tab_component.rb b/app/components/admin/settings/configuration_tab_component.rb new file mode 100644 index 000000000..c62175090 --- /dev/null +++ b/app/components/admin/settings/configuration_tab_component.rb @@ -0,0 +1,38 @@ +class Admin::Settings::ConfigurationTabComponent < ApplicationComponent + def settings + %w[ + official_level_1_name + official_level_2_name + official_level_3_name + official_level_4_name + official_level_5_name + max_ratio_anon_votes_on_debates + max_votes_for_debate_edit + max_votes_for_proposal_edit + comments_body_max_length + proposal_code_prefix + votes_for_proposal_success + months_to_archive_proposals + email_domain_for_officials + facebook_handle + instagram_handle + telegram_handle + twitter_handle + twitter_hashtag + youtube_handle + org_name + meta_title + meta_description + meta_keywords + proposal_notification_minimum_interval_in_days + direct_message_max_per_day + mailer_from_name + mailer_from_address + min_age_to_participate + hot_score_period_in_days + related_content_score_threshold + featured_proposals_number + postal_codes + ] + end +end diff --git a/app/views/admin/settings/_configuration_settings_tab.html.erb b/app/views/admin/settings/_configuration_settings_tab.html.erb deleted file mode 100644 index 8c1db1bcb..000000000 --- a/app/views/admin/settings/_configuration_settings_tab.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

<%= t("admin.settings.index.general") %>

- -<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> - <% %w[official_level_1_name official_level_2_name official_level_3_name official_level_4_name - official_level_5_name max_ratio_anon_votes_on_debates max_votes_for_debate_edit - max_votes_for_proposal_edit comments_body_max_length proposal_code_prefix votes_for_proposal_success - months_to_archive_proposals email_domain_for_officials facebook_handle instagram_handle - telegram_handle twitter_handle twitter_hashtag youtube_handle org_name meta_title meta_description - meta_keywords proposal_notification_minimum_interval_in_days direct_message_max_per_day mailer_from_name - mailer_from_address min_age_to_participate hot_score_period_in_days related_content_score_threshold - featured_proposals_number feature.dashboard.notification_emails postal_codes].each do |key| %> - <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-configuration") %> - <% end %> -<% end %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index f8397c9e5..0f22f76a0 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -3,7 +3,7 @@ <%= render "filter_subnav" %>
- <%= render "configuration_settings_tab" %> + <%= render Admin::Settings::ConfigurationTabComponent.new %>
From 6876f080a28a6b07742b237682d445ff6f41b935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:40:26 +0100 Subject: [PATCH 13/19] Extract features tab partial to a component --- .../settings/features_tab_component.html.erb | 7 +++++ .../admin/settings/features_tab_component.rb | 31 +++++++++++++++++++ .../admin/settings/_features_tab.html.erb | 13 -------- app/views/admin/settings/index.html.erb | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 app/components/admin/settings/features_tab_component.html.erb create mode 100644 app/components/admin/settings/features_tab_component.rb delete mode 100644 app/views/admin/settings/_features_tab.html.erb diff --git a/app/components/admin/settings/features_tab_component.html.erb b/app/components/admin/settings/features_tab_component.html.erb new file mode 100644 index 000000000..9cfb5f2b4 --- /dev/null +++ b/app/components/admin/settings/features_tab_component.html.erb @@ -0,0 +1,7 @@ +

<%= t("admin.settings.index.feature_flags") %>

+ +<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> + <% settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-feature-flags") %> + <% end %> +<% end %> diff --git a/app/components/admin/settings/features_tab_component.rb b/app/components/admin/settings/features_tab_component.rb new file mode 100644 index 000000000..64e0ffce2 --- /dev/null +++ b/app/components/admin/settings/features_tab_component.rb @@ -0,0 +1,31 @@ +class Admin::Settings::FeaturesTabComponent < ApplicationComponent + def settings + %w[ + feature.featured_proposals + feature.facebook_login + feature.google_login + feature.twitter_login + feature.wordpress_login + feature.public_stats + feature.signature_sheets + feature.user.recommendations + feature.user.recommendations_on_debates + feature.user.recommendations_on_proposals + feature.user.skip_verification + feature.community + feature.map + feature.allow_attached_documents + feature.allow_images + feature.help_page + feature.remote_translations + feature.translation_interface + feature.remote_census + feature.valuation_comment_notification + feature.graphql_api + feature.sdg + feature.machine_learning + feature.remove_investments_supports + feature.dashboard.notification_emails + ] + end +end diff --git a/app/views/admin/settings/_features_tab.html.erb b/app/views/admin/settings/_features_tab.html.erb deleted file mode 100644 index f85a08226..000000000 --- a/app/views/admin/settings/_features_tab.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -

<%= t("admin.settings.index.feature_flags") %>

- -<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> - <% %w[feature.featured_proposals feature.facebook_login feature.google_login feature.twitter_login - feature.wordpress_login feature.public_stats feature.signature_sheets feature.user.recommendations - feature.user.recommendations_on_debates feature.user.recommendations_on_proposals - feature.user.skip_verification feature.community feature.map feature.allow_attached_documents - feature.allow_images feature.help_page feature.remote_translations feature.translation_interface - feature.remote_census feature.valuation_comment_notification feature.graphql_api feature.sdg - feature.machine_learning feature.remove_investments_supports].each do |key| %> - <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-feature-flags") %> - <% end %> -<% end %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 0f22f76a0..8caea8827 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -11,7 +11,7 @@
- <%= render "features_tab" %> + <%= render Admin::Settings::FeaturesTabComponent.new %>
From f56dc654f3c15d1e25272ea854825da0d3101a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:44:07 +0100 Subject: [PATCH 14/19] Extract map configuration tab partial to a component --- .../admin/settings/map_tab_component.html.erb} | 3 +-- app/components/admin/settings/map_tab_component.rb | 13 +++++++++++++ app/views/admin/settings/index.html.erb | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) rename app/{views/admin/settings/_map_configuration_tab.html.erb => components/admin/settings/map_tab_component.html.erb} (82%) create mode 100644 app/components/admin/settings/map_tab_component.rb diff --git a/app/views/admin/settings/_map_configuration_tab.html.erb b/app/components/admin/settings/map_tab_component.html.erb similarity index 82% rename from app/views/admin/settings/_map_configuration_tab.html.erb rename to app/components/admin/settings/map_tab_component.html.erb index 38a6f5438..c353d58b3 100644 --- a/app/views/admin/settings/_map_configuration_tab.html.erb +++ b/app/components/admin/settings/map_tab_component.html.erb @@ -1,9 +1,8 @@ <% if feature?(:map) %>

<%= t("admin.settings.index.map.title") %>

- <% tab = "#tab-map-configuration" %> <%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> - <% %w[map.latitude map.longitude map.zoom].each do |key| %> + <% settings.each do |key| %> <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> <% end %> <% end %> diff --git a/app/components/admin/settings/map_tab_component.rb b/app/components/admin/settings/map_tab_component.rb new file mode 100644 index 000000000..702721eb4 --- /dev/null +++ b/app/components/admin/settings/map_tab_component.rb @@ -0,0 +1,13 @@ +class Admin::Settings::MapTabComponent < ApplicationComponent + def tab + "#tab-map-configuration" + end + + def settings + %w[ + map.latitude + map.longitude + map.zoom + ] + end +end diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 8caea8827..daf1fc2d2 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -15,7 +15,7 @@
- <%= render "map_configuration_tab" %> + <%= render Admin::Settings::MapTabComponent.new %>
From 75180de8e6d1dda7d738ee3ef3bb3afbd39be36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 16:59:01 +0100 Subject: [PATCH 15/19] Extract images and documents tab partial to a component --- ...mages_and_documents_tab_component.html.erb | 12 ++++++++++ .../images_and_documents_tab_component.rb | 22 +++++++++++++++++++ .../_images_and_documents_tab.html.erb | 14 ------------ app/views/admin/settings/index.html.erb | 2 +- 4 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 app/components/admin/settings/images_and_documents_tab_component.html.erb create mode 100644 app/components/admin/settings/images_and_documents_tab_component.rb delete mode 100644 app/views/admin/settings/_images_and_documents_tab.html.erb diff --git a/app/components/admin/settings/images_and_documents_tab_component.html.erb b/app/components/admin/settings/images_and_documents_tab_component.html.erb new file mode 100644 index 000000000..52d6c9e7b --- /dev/null +++ b/app/components/admin/settings/images_and_documents_tab_component.html.erb @@ -0,0 +1,12 @@ +

<%= t("admin.settings.index.images_and_documents") %>

+ +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% images_settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> + <%= render Admin::Settings::RowComponent.new("uploads.images.content_types", type: :content_type, tab: tab) %> + <% documents_settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: tab) %> + <% end %> + <%= render Admin::Settings::RowComponent.new("uploads.documents.content_types", type: :content_type, tab: tab) %> +<% end %> diff --git a/app/components/admin/settings/images_and_documents_tab_component.rb b/app/components/admin/settings/images_and_documents_tab_component.rb new file mode 100644 index 000000000..c3ca8b172 --- /dev/null +++ b/app/components/admin/settings/images_and_documents_tab_component.rb @@ -0,0 +1,22 @@ +class Admin::Settings::ImagesAndDocumentsTabComponent < ApplicationComponent + def tab + "#tab-images-and-documents" + end + + def images_settings + %w[ + uploads.images.title.min_length + uploads.images.title.max_length + uploads.images.min_width + uploads.images.min_height + uploads.images.max_size + ] + end + + def documents_settings + %w[ + uploads.documents.max_amount + uploads.documents.max_size + ] + end +end diff --git a/app/views/admin/settings/_images_and_documents_tab.html.erb b/app/views/admin/settings/_images_and_documents_tab.html.erb deleted file mode 100644 index 95144d27c..000000000 --- a/app/views/admin/settings/_images_and_documents_tab.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

<%= t("admin.settings.index.images_and_documents") %>

- -<% tab = "#tab-images-and-documents" %> -<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> - <%= render Admin::Settings::RowComponent.new("uploads.images.title.min_length", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.images.title.max_length", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.images.min_width", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.images.min_height", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.images.max_size", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.images.content_types", type: :content_type, tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.documents.max_amount", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.documents.max_size", tab: tab) %> - <%= render Admin::Settings::RowComponent.new("uploads.documents.content_types", type: :content_type, tab: tab) %> -<% end %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index daf1fc2d2..e90ccdbf6 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -19,7 +19,7 @@
- <%= render "images_and_documents_tab" %> + <%= render Admin::Settings::ImagesAndDocumentsTabComponent.new %>
From f32d7edcf3b100e1fa79cb0a4183fb55b5ce7e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 17:01:34 +0100 Subject: [PATCH 16/19] Extract proposals dashboard tab partial to a component --- .../proposals_dashboard_tab_component.html.erb | 7 +++++++ .../settings/proposals_dashboard_tab_component.rb | 14 ++++++++++++++ .../admin/settings/_proposals_dashboard.html.erb | 9 --------- app/views/admin/settings/index.html.erb | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 app/components/admin/settings/proposals_dashboard_tab_component.html.erb create mode 100644 app/components/admin/settings/proposals_dashboard_tab_component.rb delete mode 100644 app/views/admin/settings/_proposals_dashboard.html.erb diff --git a/app/components/admin/settings/proposals_dashboard_tab_component.html.erb b/app/components/admin/settings/proposals_dashboard_tab_component.html.erb new file mode 100644 index 000000000..393f26651 --- /dev/null +++ b/app/components/admin/settings/proposals_dashboard_tab_component.html.erb @@ -0,0 +1,7 @@ +

<%= t("admin.settings.index.dashboard.title") %>

+ +<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> + <% settings.each do |key| %> + <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-proposals") %> + <% end %> +<% end %> diff --git a/app/components/admin/settings/proposals_dashboard_tab_component.rb b/app/components/admin/settings/proposals_dashboard_tab_component.rb new file mode 100644 index 000000000..2a7c99297 --- /dev/null +++ b/app/components/admin/settings/proposals_dashboard_tab_component.rb @@ -0,0 +1,14 @@ +class Admin::Settings::ProposalsDashboardTabComponent < ApplicationComponent + def settings + %w[ + proposals.successful_proposal_id + proposals.poll_short_title + proposals.poll_description + proposals.poll_link + proposals.email_short_title + proposals.email_description + proposals.poster_short_title + proposals.poster_description + ] + end +end diff --git a/app/views/admin/settings/_proposals_dashboard.html.erb b/app/views/admin/settings/_proposals_dashboard.html.erb deleted file mode 100644 index 5975c045a..000000000 --- a/app/views/admin/settings/_proposals_dashboard.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

<%= t("admin.settings.index.dashboard.title") %>

- -<%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %> - <% %w[proposals.successful_proposal_id proposals.poll_short_title proposals.poll_description - proposals.poll_link proposals.email_short_title proposals.email_description - proposals.poster_short_title proposals.poster_description].each do |key| %> - <%= render Admin::Settings::RowComponent.new(key, tab: "#tab-proposals") %> - <% end %> -<% end %> diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index e90ccdbf6..9055019eb 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -23,7 +23,7 @@
- <%= render "proposals_dashboard" %> + <%= render Admin::Settings::ProposalsDashboardTabComponent.new %>
From 047cb2b76cce6786fbf499ab6ffe14c4f92c596c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 18 Jan 2024 17:04:09 +0100 Subject: [PATCH 17/19] Extract SDG configuration tab partial to a component --- .../sdg_configuration_tab_component.html.erb} | 2 +- .../admin/settings/sdg_configuration_tab_component.rb | 11 +++++++++++ app/views/admin/settings/index.html.erb | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) rename app/{views/admin/settings/_sdg_configuration_tab.html.erb => components/admin/settings/sdg_configuration_tab_component.html.erb} (77%) create mode 100644 app/components/admin/settings/sdg_configuration_tab_component.rb diff --git a/app/views/admin/settings/_sdg_configuration_tab.html.erb b/app/components/admin/settings/sdg_configuration_tab_component.html.erb similarity index 77% rename from app/views/admin/settings/_sdg_configuration_tab.html.erb rename to app/components/admin/settings/sdg_configuration_tab_component.html.erb index 795798c18..73ddbe987 100644 --- a/app/views/admin/settings/_sdg_configuration_tab.html.erb +++ b/app/components/admin/settings/sdg_configuration_tab_component.html.erb @@ -2,7 +2,7 @@

<%= t("admin.settings.index.sdg.title") %>

<%= render Admin::Settings::TableComponent.new(setting_name: "feature", table_class: "featured-settings-table") do %> - <% %w[sdg.process.debates sdg.process.proposals sdg.process.polls sdg.process.budgets sdg.process.legislation].each do |key| %> + <% settings.each do |key| %> <%= render Admin::Settings::RowComponent.new(key, type: :feature, tab: "#tab-sdg-configuration") %> <% end %> <% end %> diff --git a/app/components/admin/settings/sdg_configuration_tab_component.rb b/app/components/admin/settings/sdg_configuration_tab_component.rb new file mode 100644 index 000000000..975570375 --- /dev/null +++ b/app/components/admin/settings/sdg_configuration_tab_component.rb @@ -0,0 +1,11 @@ +class Admin::Settings::SDGConfigurationTabComponent < ApplicationComponent + def settings + %w[ + sdg.process.debates + sdg.process.proposals + sdg.process.polls + sdg.process.budgets + sdg.process.legislation + ] + end +end diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb index 9055019eb..7eadd3e52 100644 --- a/app/views/admin/settings/index.html.erb +++ b/app/views/admin/settings/index.html.erb @@ -31,6 +31,6 @@
- <%= render "sdg_configuration_tab" %> + <%= render Admin::Settings::SDGConfigurationTabComponent.new %>
From 6c4f917e2a5e6e798bfa1a90355339bbd03502c8 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, 11 Dec 2023 13:10:08 +0100 Subject: [PATCH 18/19] [EXP] Show all admin settings tabs when javascript is disabled Otherwise administrators cannot access the settings from other tabs. --- app/views/layouts/_no_script.html.erb | 7 +++++++ app/views/layouts/admin.html.erb | 1 + 2 files changed, 8 insertions(+) create mode 100644 app/views/layouts/_no_script.html.erb diff --git a/app/views/layouts/_no_script.html.erb b/app/views/layouts/_no_script.html.erb new file mode 100644 index 000000000..3ef670aed --- /dev/null +++ b/app/views/layouts/_no_script.html.erb @@ -0,0 +1,7 @@ + diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 7f434cde3..7049c9aa5 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -2,6 +2,7 @@ > <%= render "layouts/common_head", default_title: "Admin" %> + <%= render "layouts/no_script" %> <%= content_for :head %> From ea0cedec72e869f4cb9d5ea11d2e9266e26b9bdf 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, 11 Dec 2023 13:11:59 +0100 Subject: [PATCH 19/19] [EXP] Make AJAX settings work when javascript is disabled Otherwise we get a AuthenticityToken exception. I was nor able to write a test to verify this change. --- .../admin/settings/featured_settings_form_component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fb73a042b..be2fa16a8 100644 --- a/app/components/admin/settings/featured_settings_form_component.html.erb +++ b/app/components/admin/settings/featured_settings_form_component.html.erb @@ -1,4 +1,4 @@ -<%= form_for([:admin, feature], remote: remote?, html: { class: "featured-settings-form" }) do |f| %> +<%= form_for([:admin, feature], remote: remote?, authenticity_token: true, html: { class: "featured-settings-form" }) do |f| %> <%= 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") %>