Use admin table settings component to render featured settings
Now, with the same template we can render all kind of settings.
This commit is contained in:
committed by
Javi Martín
parent
e7223ba865
commit
6a64f38d17
@@ -1,6 +0,0 @@
|
||||
.admin .featured-settings-table {
|
||||
|
||||
td {
|
||||
max-width: $global-width / 3;
|
||||
}
|
||||
}
|
||||
13
app/assets/stylesheets/admin/settings/table.scss
Normal file
13
app/assets/stylesheets/admin/settings/table.scss
Normal file
@@ -0,0 +1,13 @@
|
||||
.admin {
|
||||
.featured-settings-table {
|
||||
td {
|
||||
max-width: $global-width / 3;
|
||||
}
|
||||
}
|
||||
|
||||
.mixed-settings-table {
|
||||
td {
|
||||
width: 50%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,25 @@
|
||||
<table>
|
||||
<table class="<%= table_class %>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= display_setting_name(setting_name) %></th>
|
||||
<th><%= t("admin.settings.setting_value") %></th>
|
||||
<th><%= key_header %></th>
|
||||
<th><%= value_header %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% settings.each do |setting| %>
|
||||
<tr>
|
||||
<td class="small-6">
|
||||
<strong><%= t("settings.#{setting.key}") %></strong>
|
||||
<td>
|
||||
<strong id="<%= dom_id(setting, :title) %>"><%= t("settings.#{setting.key}") %></strong>
|
||||
<br>
|
||||
<span id="<%= dom_id(setting, :description) %>" class="small">
|
||||
<%= t("settings.#{setting.key}_description", default: t("admin.settings.no_description")) %>
|
||||
</span>
|
||||
</td>
|
||||
<td class="small-6">
|
||||
<td>
|
||||
<% 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 %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<table class="featured-settings-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.settings.setting") %></th>
|
||||
<th><%= t("admin.settings.index.features.enabled") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% features.each do |feature| %>
|
||||
<tr>
|
||||
<td>
|
||||
<strong id="<%= dom_id(feature, :title) %>"><%= t("settings.#{feature.key}") %></strong>
|
||||
<br>
|
||||
<span class="small" id="<%= dom_id(feature, :description) %>">
|
||||
<%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<%= render Admin::Settings::FeaturedSettingsFormComponent.new(feature, tab: tab) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2><%= t("admin.settings.index.feature_flags") %></h2>
|
||||
|
||||
<%= 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") %>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<h2><%= t("admin.settings.index.participation_processes") %></h2>
|
||||
|
||||
<%= 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") %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<% if feature?(:sdg) %>
|
||||
<h2><%= t("admin.settings.index.sdg.title") %></h2>
|
||||
|
||||
<%= 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 %>
|
||||
<div class="callout primary">
|
||||
<%= t("admin.settings.index.sdg.how_to_enable") %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<h2 class="inline-block"><%= t("admin.site_customization.content_blocks.index.title") %></h2>
|
||||
|
||||
<%= render "admin/settings/settings_table", settings: @html_settings, setting_name: "setting" %>
|
||||
<%= render Admin::Settings::TableComponent.new(settings: @html_settings, setting_name: "setting") %>
|
||||
|
||||
<h3><%= t("admin.site_customization.content_blocks.information") %></h3>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user