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:
Senén Rodero Rodríguez
2023-11-22 21:32:37 +01:00
committed by Javi Martín
parent e7223ba865
commit 6a64f38d17
13 changed files with 96 additions and 106 deletions

View File

@@ -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 %>

View File

@@ -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