Fixes #140
Adds a new setting that allows defining what is considered a successful proposal.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
class Admin::SettingsController < Admin::BaseController
|
||||
helper_method :successful_proposal_setting, :successful_proposals
|
||||
|
||||
def index
|
||||
all_settings = Setting.all.group_by { |s| s.type }
|
||||
@@ -11,14 +12,14 @@ class Admin::SettingsController < Admin::BaseController
|
||||
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
|
||||
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")
|
||||
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')
|
||||
end
|
||||
|
||||
private
|
||||
@@ -27,4 +28,11 @@ class Admin::SettingsController < Admin::BaseController
|
||||
params.require(:setting).permit(:value)
|
||||
end
|
||||
|
||||
def successful_proposal_setting
|
||||
Setting.find_by(key: 'proposals.successful_proposal_id')
|
||||
end
|
||||
|
||||
def successful_proposals
|
||||
Proposal.successful
|
||||
end
|
||||
end
|
||||
@@ -6,16 +6,12 @@ class Setting < ActiveRecord::Base
|
||||
scope :banner_img, -> { where("key ilike ?", "banner-img.%")}
|
||||
|
||||
def type
|
||||
if feature_flag?
|
||||
'feature'
|
||||
elsif banner_style?
|
||||
'banner-style'
|
||||
elsif banner_img?
|
||||
'banner-img'
|
||||
else
|
||||
return 'feature' if feature_flag?
|
||||
return 'banner-style' if banner_style?
|
||||
return 'banner-img' if banner_img?
|
||||
return 'proposals' if proposals?
|
||||
'common'
|
||||
end
|
||||
end
|
||||
|
||||
def feature_flag?
|
||||
key.start_with?('feature.')
|
||||
@@ -33,6 +29,10 @@ class Setting < ActiveRecord::Base
|
||||
key.start_with?('banner-img.')
|
||||
end
|
||||
|
||||
def proposals?
|
||||
key.start_with?('proposals.')
|
||||
end
|
||||
|
||||
class << self
|
||||
def [](key)
|
||||
where(key: key).pluck(:value).first.presence
|
||||
|
||||
@@ -28,4 +28,8 @@
|
||||
<%= t("admin.settings.index.map.title") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li class="tabs-title" id="proposals-tab">
|
||||
<%= link_to t('admin.settings.index.proposals.title'), '#tab-proposals' %>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
21
app/views/admin/settings/_proposals.html.erb
Normal file
21
app/views/admin/settings/_proposals.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<h2><%= t('admin.settings.index.proposals.title') %></h2>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="small-12 medium-4">
|
||||
<strong><%= t("settings.#{successful_proposal_setting.key}") %></strong>
|
||||
</td>
|
||||
<td class="small-12 medium-8">
|
||||
<%= form_for(successful_proposal_setting, url: admin_setting_path(successful_proposal_setting), html: { id: "edit_#{dom_id(successful_proposal_setting)}"}) do |f| %>
|
||||
<div class="small-12 medium-6 large-9 column">
|
||||
<%= f.select :value, successful_proposals.collect { |p| [p.title, p.id] }, { include_blank: true, label: false }, label: false, id: dom_id(successful_proposal_setting) %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 large-3 column">
|
||||
<%= f.submit(t('admin.settings.index.update_setting'), class: "button hollow expanded") %>
|
||||
</div>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -21,4 +21,8 @@
|
||||
<div class="tabs-panel" id="tab-map-configuration">
|
||||
<%= render "map_configuration" %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-proposals">
|
||||
<%= render "proposals" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -982,6 +982,8 @@ en:
|
||||
update: Map configuration updated succesfully.
|
||||
form:
|
||||
submit: Update
|
||||
proposals:
|
||||
title: Proposal related settings
|
||||
shared:
|
||||
booths_search:
|
||||
button: Search
|
||||
|
||||
@@ -63,3 +63,5 @@ en:
|
||||
verification_offices_url: Verification offices URL
|
||||
min_age_to_participate: Minimum age needed to participate
|
||||
proposal_improvement_path: Proposal improvement info internal link
|
||||
proposals:
|
||||
successful_proposal_id: Successful proposal
|
||||
|
||||
@@ -982,6 +982,8 @@ es:
|
||||
update: La configuración del mapa se ha guardado correctamente.
|
||||
form:
|
||||
submit: Actualizar
|
||||
proposals:
|
||||
title: Ajustes para propuestas
|
||||
shared:
|
||||
booths_search:
|
||||
button: Buscar
|
||||
|
||||
@@ -63,3 +63,5 @@ es:
|
||||
verification_offices_url: URL oficinas verificación
|
||||
min_age_to_participate: Edad mínima para participar
|
||||
proposal_improvement_path: Link a información para mejorar propuestas
|
||||
proposals:
|
||||
successful_proposal_id: Propuesta exitosa
|
||||
|
||||
@@ -132,3 +132,5 @@ Setting['feature.homepage.widgets.feeds.proposals'] = true
|
||||
Setting['feature.homepage.widgets.feeds.debates'] = true
|
||||
Setting['feature.homepage.widgets.feeds.processes'] = true
|
||||
|
||||
# Proposals
|
||||
Setting['proposals.successful_proposal_id'] = nil
|
||||
|
||||
@@ -12,4 +12,9 @@ namespace :proposal_actions do
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Initialize successful proposal id setting'
|
||||
task initialize_successful_proposal_id: :environment do
|
||||
Setting['proposals.successful_proposal_id'] = nil
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user