<% 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
new file mode 100644
index 000000000..264d679b0
--- /dev/null
+++ b/app/components/admin/settings/content_types_form_component.rb
@@ -0,0 +1,9 @@
+class Admin::Settings::ContentTypesFormComponent < ApplicationComponent
+ attr_reader :setting, :tab
+ delegate :dom_id, to: :helpers
+
+ def initialize(setting, tab: nil)
+ @setting = setting
+ @tab = tab
+ end
+end
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..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,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 %>
+<%= 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") %>
<%= f.button text, options %>
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 @@
+
+
+<%= 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/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 @@
+
+
+<%= 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/_map_form.html.erb b/app/components/admin/settings/map_form_component.html.erb
similarity index 96%
rename from app/views/admin/settings/_map_form.html.erb
rename to app/components/admin/settings/map_form_component.html.erb
index c71b412a0..7a0f00a95 100644
--- a/app/views/admin/settings/_map_form.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
new file mode 100644
index 000000000..81209a7ee
--- /dev/null
+++ b/app/components/admin/settings/map_form_component.rb
@@ -0,0 +1,7 @@
+class Admin::Settings::MapFormComponent < ApplicationComponent
+ attr_reader :tab
+
+ def initialize(tab: nil)
+ @tab = tab
+ end
+end
diff --git a/app/components/admin/settings/map_tab_component.html.erb b/app/components/admin/settings/map_tab_component.html.erb
new file mode 100644
index 000000000..c353d58b3
--- /dev/null
+++ b/app/components/admin/settings/map_tab_component.html.erb
@@ -0,0 +1,17 @@
+<% if feature?(:map) %>
+
<%= t("admin.settings.index.map.title") %>
+
+ <%= render Admin::Settings::TableComponent.new(setting_name: "setting") do %>
+ <% settings.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) %>
+<% else %>
+
+ <%= t("admin.settings.index.map.how_to_enable") %>
+
+<% 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/components/admin/settings/participation_processes_tab_component.html.erb b/app/components/admin/settings/participation_processes_tab_component.html.erb
new file mode 100644
index 000000000..6e7f93ebb
--- /dev/null
+++ b/app/components/admin/settings/participation_processes_tab_component.html.erb
@@ -0,0 +1,7 @@
+
<%= t("admin.settings.index.participation_processes") %>
+
+<%= 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-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/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/components/admin/settings/remote_census_tab_component.html.erb b/app/components/admin/settings/remote_census_tab_component.html.erb
new file mode 100644
index 000000000..5fee65e6e
--- /dev/null
+++ b/app/components/admin/settings/remote_census_tab_component.html.erb
@@ -0,0 +1,23 @@
+<% if feature?(:remote_census) %>
+
<%= t("admin.settings.index.remote_census.title") %>
+
+ <%= render Admin::Settings::TableComponent.new(setting_name: "remote_census_general_name") do %>
+ <% 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 %>
+ <% 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 %>
+ <% response_settings.each do |key| %>
+ <%= render Admin::Settings::RowComponent.new(key, tab: tab) %>
+ <% end %>
+ <% end %>
+<% else %>
+
+ <%= t("admin.settings.index.remote_census.how_to_enable") %>
+
+<% 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/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 %>
+ |
+
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/sdg_configuration_tab_component.html.erb b/app/components/admin/settings/sdg_configuration_tab_component.html.erb
new file mode 100644
index 000000000..73ddbe987
--- /dev/null
+++ b/app/components/admin/settings/sdg_configuration_tab_component.html.erb
@@ -0,0 +1,13 @@
+<% if feature?(:sdg) %>
+
<%= t("admin.settings.index.sdg.title") %>
+
+ <%= 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-sdg-configuration") %>
+ <% end %>
+ <% end %>
+<% else %>
+
+ <%= t("admin.settings.index.sdg.how_to_enable") %>
+
+<% 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/components/admin/settings/table_component.html.erb b/app/components/admin/settings/table_component.html.erb
new file mode 100644
index 000000000..5543be032
--- /dev/null
+++ b/app/components/admin/settings/table_component.html.erb
@@ -0,0 +1,11 @@
+
+
+
+ | <%= key_header %> |
+ <%= value_header %> |
+
+
+
+ <%= content %>
+
+
diff --git a/app/components/admin/settings/table_component.rb b/app/components/admin/settings/table_component.rb
new file mode 100644
index 000000000..de1c2e0fa
--- /dev/null
+++ b/app/components/admin/settings/table_component.rb
@@ -0,0 +1,26 @@
+class Admin::Settings::TableComponent < ApplicationComponent
+ attr_reader :setting_name, :table_class
+
+ def initialize(setting_name:, table_class: "mixed-settings-table")
+ @setting_name = setting_name
+ @table_class = table_class
+ end
+
+ 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
+end
diff --git a/app/views/admin/settings/_settings_form.html.erb b/app/components/admin/settings/text_form_component.html.erb
similarity index 86%
rename from app/views/admin/settings/_settings_form.html.erb
rename to app/components/admin/settings/text_form_component.html.erb
index 464713004..63117e49f 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) %>
+ <%= hidden_field_tag :tab, 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
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index 3e8c023ca..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
@@ -27,7 +16,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
@@ -37,7 +26,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
@@ -55,8 +44,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/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/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/models/setting.rb b/app/models/setting.rb
index fb2219066..a1cd0e211 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -7,24 +7,10 @@ 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
- def content_type?
- key.split(".").last == "content_types"
- 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
deleted file mode 100644
index b33fa9371..000000000
--- a/app/views/admin/settings/_configuration_settings_tab.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
<%= t("admin.settings.index.general") %>
-
-<%= render "settings_table", settings: @configuration_settings, setting_name: "setting", tab: "#tab-configuration" %>
diff --git a/app/views/admin/settings/_featured_settings_table.html.erb b/app/views/admin/settings/_featured_settings_table.html.erb
deleted file mode 100644
index 649d43cec..000000000
--- a/app/views/admin/settings/_featured_settings_table.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
- | <%= t("admin.settings.setting") %> |
- <%= t("admin.settings.index.features.enabled") %> |
-
-
-
- <% features.each do |feature| %>
-
-
- <%= t("settings.#{feature.key}") %>
-
-
- <%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
-
- |
-
-
- <%= render Admin::Settings::FeaturedSettingsFormComponent.new(feature, tab: tab) %>
- |
-
- <% 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 52fdae2e9..000000000
--- a/app/views/admin/settings/_features_tab.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
<%= t("admin.settings.index.feature_flags") %>
-
-<%= render "featured_settings_table", features: @feature_settings, tab: "#tab-feature-flags" %>
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 2b8b6ef89..000000000
--- a/app/views/admin/settings/_images_and_documents_tab.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
<%= t("admin.settings.index.images_and_documents") %>
-
-<%= render "settings_table", 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
deleted file mode 100644
index fd8110989..000000000
--- a/app/views/admin/settings/_map_configuration_tab.html.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-<% if feature?(:map) %>
-
<%= t("admin.settings.index.map.title") %>
-
- <%= render "settings_table", settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration" %>
-
-
<%= t("admin.settings.index.map.help") %>
-
- <%= render "map_form" %>
-<% else %>
-
- <%= t("admin.settings.index.map.how_to_enable") %>
-
-<% end %>
diff --git a/app/views/admin/settings/_participation_processes_tab.html.erb b/app/views/admin/settings/_participation_processes_tab.html.erb
deleted file mode 100644
index 01878c51d..000000000
--- a/app/views/admin/settings/_participation_processes_tab.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
<%= t("admin.settings.index.participation_processes") %>
-
-<%= render "featured_settings_table", features: @participation_processes_settings, tab: "#tab-participation-processes" %>
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 eae3243c4..000000000
--- a/app/views/admin/settings/_proposals_dashboard.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-
<%= t("admin.settings.index.dashboard.title") %>
-
-<%= render "settings_table", 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
deleted file mode 100644
index 6a136bd42..000000000
--- a/app/views/admin/settings/_remote_census_configuration_tab.html.erb
+++ /dev/null
@@ -1,11 +0,0 @@
-<% 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" %>
-<% else %>
-
- <%= t("admin.settings.index.remote_census.how_to_enable") %>
-
-<% end %>
diff --git a/app/views/admin/settings/_sdg_configuration_tab.html.erb b/app/views/admin/settings/_sdg_configuration_tab.html.erb
deleted file mode 100644
index e931b67e1..000000000
--- a/app/views/admin/settings/_sdg_configuration_tab.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<% if feature?(:sdg) %>
-
<%= t("admin.settings.index.sdg.title") %>
-
- <%= render "featured_settings_table", features: @sdg_settings, tab: "#tab-sdg-configuration" %>
-<% else %>
-
- <%= t("admin.settings.index.sdg.how_to_enable") %>
-
-<% end %>
diff --git a/app/views/admin/settings/_settings_table.html.erb b/app/views/admin/settings/_settings_table.html.erb
deleted file mode 100644
index b3015525f..000000000
--- a/app/views/admin/settings/_settings_table.html.erb
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
- | <%= display_setting_name(setting_name) %> |
- <%= t("admin.settings.setting_value") %> |
-
-
-
- <% settings.each do |setting| %>
-
-
- <%= t("settings.#{setting.key}") %>
-
-
- <%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %>
-
- |
-
- <% if setting.content_type? %>
- <%= render "admin/settings/content_types_settings_form", setting: setting %>
- <% else %>
- <% if defined?(tab) %>
- <%= render "admin/settings/settings_form", setting: setting, tab: tab %>
- <% else %>
- <%= render "admin/settings/settings_form", setting: setting %>
- <% end %>
- <% end %>
- |
-
- <% end %>
-
-
diff --git a/app/views/admin/settings/index.html.erb b/app/views/admin/settings/index.html.erb
index 04d6afd93..7eadd3e52 100644
--- a/app/views/admin/settings/index.html.erb
+++ b/app/views/admin/settings/index.html.erb
@@ -3,34 +3,34 @@
<%= render "filter_subnav" %>
- <%= render "configuration_settings_tab" %>
+ <%= render Admin::Settings::ConfigurationTabComponent.new %>
- <%= render "participation_processes_tab" %>
+ <%= render Admin::Settings::ParticipationProcessesTabComponent.new %>
- <%= render "features_tab" %>
+ <%= render Admin::Settings::FeaturesTabComponent.new %>
- <%= render "map_configuration_tab" %>
+ <%= render Admin::Settings::MapTabComponent.new %>
- <%= render "images_and_documents_tab" %>
+ <%= render Admin::Settings::ImagesAndDocumentsTabComponent.new %>
- <%= render "proposals_dashboard" %>
+ <%= render Admin::Settings::ProposalsDashboardTabComponent.new %>
- <%= render "remote_census_configuration_tab" %>
+ <%= render Admin::Settings::RemoteCensusTabComponent.new %>
- <%= render "sdg_configuration_tab" %>
+ <%= render Admin::Settings::SDGConfigurationTabComponent.new %>
diff --git a/app/views/admin/settings/update.js.erb b/app/views/admin/settings/update.js.erb
index 503ef165d..57d75bc95 100644
--- a/app/views/admin/settings/update.js.erb
+++ b/app/views/admin/settings/update.js.erb
@@ -1,11 +1,11 @@
var form = $("<%= j render Admin::Settings::FeaturedSettingsFormComponent.new(
@setting,
- tab: params[:setting][:tab],
+ tab: params[:tab],
describedby: params[:setting][:describedby]
) %>");
$("#" + 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..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/settings_table", 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/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 %>
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..6868e912e
--- /dev/null
+++ b/spec/components/admin/settings/table_component_spec.rb
@@ -0,0 +1,54 @@
+require "rails_helper"
+
+describe Admin::Settings::TableComponent do
+ describe "#key_header" do
+ it "returns correct table header for the setting name colums" do
+ render_inline Admin::Settings::TableComponent.new setting_name: "feature"
+
+ expect(page).to have_content("Feature")
+
+ render_inline Admin::Settings::TableComponent.new setting_name: "setting"
+
+ expect(page).to have_content("Setting")
+
+ render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_general_name"
+
+ expect(page).to have_content("General Information")
+
+ render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_request_name"
+
+ expect(page).to have_content("Request Data")
+
+ render_inline Admin::Settings::TableComponent.new setting_name: "remote_census_response_name"
+
+ expect(page).to have_content("Response Data")
+ end
+ end
+
+ describe "#value_header" do
+ it "returns correct table header for the setting interface column" do
+ render_inline Admin::Settings::TableComponent.new setting_name: "feature"
+
+ expect(page).to have_content("Enabled")
+
+ render_inline Admin::Settings::TableComponent.new setting_name: "setting"
+
+ expect(page).to have_content("Value")
+ end
+ end
+
+ describe "#table_class" do
+ it "returns the `mixed-settings-table` by default" do
+ render_inline Admin::Settings::TableComponent.new setting_name: "feature"
+
+ expect(page).to have_css(".mixed-settings-table")
+ end
+
+ it "returns the given table_class" do
+ render_inline Admin::Settings::TableComponent.new setting_name: "feature", table_class: "my-table-class"
+
+ expect(page).not_to have_css(".mixed-settings-table")
+ expect(page).to have_css(".my-table-class")
+ 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
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb
index f573505bf..d31c4ef3c 100644
--- a/spec/models/setting_spec.rb
+++ b/spec/models/setting_spec.rb
@@ -27,59 +27,6 @@ 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"
- end
- end
-
describe "#enabled?" do
it "is true if value is present" do
setting = Setting.create!(key: "feature.whatever", value: 1)
@@ -101,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 8639a1820..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,29 +198,36 @@ 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
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
- 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
@@ -240,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")
@@ -263,20 +255,30 @@ 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)
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