Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New settings page #42

Merged
29 changes: 15 additions & 14 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@ class Admin::SettingsController < Admin::BaseController
:poster_feature_short_title_setting, :poster_feature_description_setting

def index
all_settings = Setting.all.group_by { |setting| setting.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"]
@settings_sections = ["configuration", "process", "feature", "map", "uploads", "proposals", "remote_census"].freeze
end

def update
@setting = Setting.find(params[:id])
@setting.update(settings_params)
redirect_to request_referer, notice: t("admin.settings.flash.updated")
redirect_to request.referer, notice: t("admin.settings.flash.updated")
end

def update_map
Expand All @@ -43,6 +34,12 @@ def update_content_types
redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
end

def show
@settings = extract_settings(params[:id])

render params[:id]
end

private

def settings_params
Expand All @@ -53,8 +50,12 @@ def content_type_params
params.permit(:jpg, :png, :gif, :pdf, :doc, :docx, :xls, :xlsx, :csv, :zip)
end

def request_referer
return request.referer + params[:setting][:tab] if params[:setting][:tab]
request.referer
def extract_settings(parent_key)
all_settings = Setting.all.group_by { |setting| setting.type }
if parent_key == "remote_census"
Senen marked this conversation as resolved.
Show resolved Hide resolved
[all_settings["remote_census.general"]] + [all_settings["remote_census.request"]] + [all_settings["remote_census.response"]]
else
all_settings[params[:id]]
end
end
end
8 changes: 0 additions & 8 deletions app/helpers/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@ def setting
@all_settings ||= Hash[ Setting.all.map{|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
3 changes: 0 additions & 3 deletions app/views/admin/settings/_configuration_settings_tab.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/admin/settings/_featured_settings_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%= form_for(feature, url: admin_setting_path(feature), html: { id: "edit_#{dom_id(feature)}"}) do |f| %>
<%= f.hidden_field :tab, value: tab if defined?(tab) %>
<%= 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"}",
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/settings/_featured_settings_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</td>

<td class="text-right">
<%= render "admin/settings/featured_settings_form", feature: feature, tab: tab %>
<%= render "admin/settings/featured_settings_form", feature: feature %>
</td>
</tr>
<% end %>
Expand Down
3 changes: 0 additions & 3 deletions app/views/admin/settings/_features_tab.html.erb

This file was deleted.

50 changes: 0 additions & 50 deletions app/views/admin/settings/_filter_subnav.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/admin/settings/_images_and_documents_tab.html.erb

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/admin/settings/_proposals_dashboard.html.erb

This file was deleted.

11 changes: 0 additions & 11 deletions app/views/admin/settings/_remote_census_configuration_tab.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions app/views/admin/settings/_settings_sections_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<tr id="<%= setting_section %>-section">
<td class="small-9">
<strong><%= t("admin.settings.index.#{setting_section}.title") %></strong>
<br>
<span class="small">
<%= t("admin.settings.index.#{setting_section}.description") %>
</span>
</td>
<td class="small-3">
<%= link_to t("admin.actions.configure"), admin_setting_path("#{setting_section}"), class: "button hollow" %>
</td>
</tr>
2 changes: 1 addition & 1 deletion app/views/admin/settings/_settings_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<table>
<thead>
<tr>
<th><%= display_setting_name(setting_name) %></th>
<th><%= t("admin.settings.setting_name") %></th>
<th><%= t("admin.settings.setting_value") %></th>
</tr>
</thead>
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/settings/configuration.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.configuration.title") %></h2>

<%= render "settings_table", settings: @settings %>
4 changes: 4 additions & 0 deletions app/views/admin/settings/feature.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.feature.title") %></h2>

<%= render "featured_settings_table", features: @settings %>
38 changes: 8 additions & 30 deletions app/views/admin/settings/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
<h1><%= t("admin.settings.index.title") %></h1>
<div class="tabs-content" data-tabs-content="settings-tabs">
<%= render "filter_subnav" %>

<div class="tabs-panel is-active" id="tab-configuration">
<%= render "configuration_settings_tab" %>
</div>

<div class="tabs-panel" id="tab-participation-processes">
<%= render "participation_processes_tab" %>
</div>

<div class="tabs-panel" id="tab-feature-flags">
<%= render "features_tab" %>
</div>

<div class="tabs-panel" id="tab-map-configuration">
<%= render "map_configuration_tab" %>
</div>

<div class="tabs-panel" id="tab-images-and-documents">
<%= render "images_and_documents_tab" %>
</div>

<div class="tabs-panel" id="tab-proposals">
<%= render "proposals_dashboard" %>
</div>

<div class="tabs-panel" id="tab-remote-census-configuration">
<%= render "remote_census_configuration_tab" %>
</div>
<div>
<table>
<tbody>
<% @settings_sections.each do |setting_section| %>
<%= render "settings_sections_list", setting_section: setting_section %>
<% end %>
</tbody>
</table>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<%= back_link_to admin_settings_path %>
<% if feature?(:map) %>
<h2><%= t("admin.settings.index.map.title") %></h2>

<%= render "settings_table", settings: @map_configuration_settings, setting_name: "setting", tab: "#tab-map-configuration" %>
<%= render "settings_table", settings: @settings %>

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

Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/settings/process.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.process.title") %></h2>

<%= render "featured_settings_table", features: @settings %>
4 changes: 4 additions & 0 deletions app/views/admin/settings/proposals.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.proposals.title") %></h2>

<%= render "settings_table", settings: @settings %>
13 changes: 13 additions & 0 deletions app/views/admin/settings/remote_census.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.remote_census.title") %></h2>

<% if feature?(:remote_census) %>
<% @settings.each do |setting_group| %>
<h2><%= t("admin.settings.index.remote_census.#{setting_group.first.key.split(".").second}") %></h2>
<%= render "settings_table", settings: setting_group %>
<% end %>
<% else %>
<div class="callout primary">
<%= t("admin.settings.index.remote_census.how_to_enable") %>
</div>
<% end %>
4 changes: 4 additions & 0 deletions app/views/admin/settings/uploads.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= back_link_to admin_settings_path %>
<h2><%= t("admin.settings.index.uploads.title") %></h2>

<%= render "settings_table", settings: @settings %>
Original file line number Diff line number Diff line change
Expand Up @@ -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/settings_table", settings: @html_settings %>

<h3><%= t("admin.site_customization.content_blocks.information") %></h3>

Expand Down
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ ignore_unused:
- landings.cambia_tu_ciudad.*
- "seeds.settings.*"
- "dashboard.polls.*.submit"
- "admin.settings.index.remote_census.*"
####
## Exclude these keys from the `i18n-tasks eq-base" report:
# ignore_eq_base:
Expand Down
39 changes: 25 additions & 14 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1293,32 +1293,43 @@ en:
updated: Value updated
index:
title: Settings
general: Configuration settings
update_setting: Update
participation_processes: "Participation processes"
images_and_documents: "Images and documents"
feature_flags: Features
features:
enabled: "Feature enabled"
disabled: "Feature disabled"
enable: "Enable"
disable: "Disable"
configuration:
title: Configuration settings
description: List of general configurations to customize the application.
process:
title: Participation processes
description: Selects the participation processes that will be available in the application.
uploads:
title: Images and documents
description: Customize the characteristics of the application attachments.
feature:
title: Features
description: Activates/deactivates the different functionalities offered by the application.
map:
title: Map configuration
description: Allows you to update the geolocation of the application, and define the zoom of the map that will be shown to users.
help: Here you can customize the way the map is displayed to users. Drag map marker or click anywhere over the map, set desired zoom and click button "Update".
flash:
update: Map configuration updated succesfully.
form:
submit: Update
how_to_enable: 'To show the map to users you must enable "Proposals and budget investments geolocation" on "Features" tab.'
dashboard:
proposals:
title: Proposals dashboard
description: Allows configuring the main fields to offer users a control panel for their proposals.
remote_census:
title: Remote Census configuration
description: Allow configure remote census (SOAP)
how_to_enable: 'To configure remote census (SOAP) you must enable "Configure connection to remote census (SOAP)" on "Features" tab.'
remote_census_general_name: General Information
remote_census_request_name: Request Data
remote_census_response_name: Response Data
general: General Information
request: Request Data
response: Response Data
update_setting: Update
features:
enabled: "Feature enabled"
disabled: "Feature disabled"
enable: "Enable"
disable: "Disable"
setting: Feature
setting_actions: Actions
setting_name: Setting
Expand Down
Loading