Refactor Admin settings tabs

- Rename partial views for tabs.
- Extract tables settings to reuse across the tabs.
This commit is contained in:
Julian Herrero
2019-03-13 12:16:25 +01:00
parent 9ed6aae348
commit c0d2776e8d
6 changed files with 21 additions and 19 deletions

View File

@@ -1,9 +1,9 @@
class Admin::SettingsController < Admin::BaseController
def index
all_settings = Setting.all.group_by { |s| s.type }
@settings = all_settings["common"]
@feature_flags = all_settings["feature"]
all_settings = Setting.all.group_by { |setting| setting.type }
@configuration_settings = all_settings["configuration"]
@feature_settings = all_settings["feature"]
end
def update

View File

@@ -0,0 +1,3 @@
<h2><%= t("admin.settings.index.title") %></h2>
<%= render "settings_table", settings: @configuration_settings %>

View File

@@ -1,5 +1,3 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<table>
<thead>
<tr>
@@ -9,18 +7,18 @@
</tr>
</thead>
<tbody>
<% @feature_flags.each do |feature_flag| %>
<% features.each do |feature| %>
<tr>
<td class="small-8">
<strong><%= t("settings.#{feature_flag.key}") %></strong>
<strong><%= t("settings.#{feature.key}") %></strong>
<br>
<span class="small">
<%= t("settings.#{feature_flag.key}_description", default: t("admin.settings.no_description")) %>
<%= t("settings.#{feature.key}_description", default: t("admin.settings.no_description")) %>
</span>
</td>
<td>
<% if feature_flag.enabled? %>
<% if feature.enabled? %>
<span class="enabled">
<strong>
<%= t ("admin.settings.index.features.enabled") %>
@@ -34,11 +32,11 @@
</td>
<td class="text-right">
<%= form_for(feature_flag, url: admin_setting_path(feature_flag), html: { id: "edit_#{dom_id(feature_flag)}"}) do |f| %>
<%= form_for(feature, url: admin_setting_path(feature), html: { id: "edit_#{dom_id(feature)}"}) do |f| %>
<%= f.hidden_field :value, id: dom_id(feature_flag), value: (feature_flag.enabled? ? "" : "active") %>
<%= f.submit(t("admin.settings.index.features.#{feature_flag.enabled? ? 'disable' : 'enable'}"),
class: "button expanded #{feature_flag.enabled? ? 'hollow alert' : 'success'}",
<%= f.hidden_field :value, id: dom_id(feature), value: (feature.enabled? ? "" : "active") %>
<%= f.submit(t("admin.settings.index.features.#{feature.enabled? ? 'disable' : 'enable'}"),
class: "button expanded #{feature.enabled? ? 'hollow alert' : 'success'}",
data: {confirm: t("admin.actions.confirm")}) %>
<% end %>
</td>

View File

@@ -0,0 +1,3 @@
<h2><%= t("admin.settings.index.feature_flags") %></h2>
<%= render "featured_settings_table", features: @feature_settings %>

View File

@@ -1,5 +1,3 @@
<h2><%= t("admin.settings.index.title") %></h2>
<table>
<thead>
<tr>
@@ -8,7 +6,7 @@
</tr>
</thead>
<tbody>
<% @settings.each do |setting| %>
<% settings.each do |setting| %>
<tr>
<td class="small-6">
<strong><%= t("settings.#{setting.key}") %></strong>

View File

@@ -3,14 +3,14 @@
<%= render "filter_subnav" %>
<div class="tabs-panel is-active" id="tab-configuration">
<%= render "configuration" %>
<%= render "configuration_settings_tab" %>
</div>
<div class="tabs-panel" id="tab-feature-flags">
<%= render "feature_flags" %>
<%= render "features_tab" %>
</div>
<div class="tabs-panel" id="tab-map-configuration">
<%= render "map_configuration" %>
<%= render "map_configuration_tab" %>
</div>
</div>