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
|
class Admin::SettingsController < Admin::BaseController
|
||||||
|
helper_method :successful_proposal_setting, :successful_proposals
|
||||||
|
|
||||||
def index
|
def index
|
||||||
all_settings = Setting.all.group_by { |s| s.type }
|
all_settings = Setting.all.group_by { |s| s.type }
|
||||||
@@ -11,14 +12,14 @@ class Admin::SettingsController < Admin::BaseController
|
|||||||
def update
|
def update
|
||||||
@setting = Setting.find(params[:id])
|
@setting = Setting.find(params[:id])
|
||||||
@setting.update(settings_params)
|
@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
|
end
|
||||||
|
|
||||||
def update_map
|
def update_map
|
||||||
Setting["map_latitude"] = params[:latitude].to_f
|
Setting['map_latitude'] = params[:latitude].to_f
|
||||||
Setting["map_longitude"] = params[:longitude].to_f
|
Setting['map_longitude'] = params[:longitude].to_f
|
||||||
Setting["map_zoom"] = params[:zoom].to_i
|
Setting['map_zoom'] = params[:zoom].to_i
|
||||||
redirect_to admin_settings_path, notice: t("admin.settings.index.map.flash.update")
|
redirect_to admin_settings_path, notice: t('admin.settings.index.map.flash.update')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -27,4 +28,11 @@ class Admin::SettingsController < Admin::BaseController
|
|||||||
params.require(:setting).permit(:value)
|
params.require(:setting).permit(:value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def successful_proposal_setting
|
||||||
|
Setting.find_by(key: 'proposals.successful_proposal_id')
|
||||||
|
end
|
||||||
|
|
||||||
|
def successful_proposals
|
||||||
|
Proposal.successful
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -6,16 +6,12 @@ class Setting < ActiveRecord::Base
|
|||||||
scope :banner_img, -> { where("key ilike ?", "banner-img.%")}
|
scope :banner_img, -> { where("key ilike ?", "banner-img.%")}
|
||||||
|
|
||||||
def type
|
def type
|
||||||
if feature_flag?
|
return 'feature' if feature_flag?
|
||||||
'feature'
|
return 'banner-style' if banner_style?
|
||||||
elsif banner_style?
|
return 'banner-img' if banner_img?
|
||||||
'banner-style'
|
return 'proposals' if proposals?
|
||||||
elsif banner_img?
|
|
||||||
'banner-img'
|
|
||||||
else
|
|
||||||
'common'
|
'common'
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def feature_flag?
|
def feature_flag?
|
||||||
key.start_with?('feature.')
|
key.start_with?('feature.')
|
||||||
@@ -33,6 +29,10 @@ class Setting < ActiveRecord::Base
|
|||||||
key.start_with?('banner-img.')
|
key.start_with?('banner-img.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def proposals?
|
||||||
|
key.start_with?('proposals.')
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def [](key)
|
def [](key)
|
||||||
where(key: key).pluck(:value).first.presence
|
where(key: key).pluck(:value).first.presence
|
||||||
|
|||||||
@@ -28,4 +28,8 @@
|
|||||||
<%= t("admin.settings.index.map.title") %>
|
<%= t("admin.settings.index.map.title") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li class="tabs-title" id="proposals-tab">
|
||||||
|
<%= link_to t('admin.settings.index.proposals.title'), '#tab-proposals' %>
|
||||||
|
</li>
|
||||||
</ul>
|
</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">
|
<div class="tabs-panel" id="tab-map-configuration">
|
||||||
<%= render "map_configuration" %>
|
<%= render "map_configuration" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tabs-panel" id="tab-proposals">
|
||||||
|
<%= render "proposals" %>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -982,6 +982,8 @@ en:
|
|||||||
update: Map configuration updated succesfully.
|
update: Map configuration updated succesfully.
|
||||||
form:
|
form:
|
||||||
submit: Update
|
submit: Update
|
||||||
|
proposals:
|
||||||
|
title: Proposal related settings
|
||||||
shared:
|
shared:
|
||||||
booths_search:
|
booths_search:
|
||||||
button: Search
|
button: Search
|
||||||
|
|||||||
@@ -63,3 +63,5 @@ en:
|
|||||||
verification_offices_url: Verification offices URL
|
verification_offices_url: Verification offices URL
|
||||||
min_age_to_participate: Minimum age needed to participate
|
min_age_to_participate: Minimum age needed to participate
|
||||||
proposal_improvement_path: Proposal improvement info internal link
|
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.
|
update: La configuración del mapa se ha guardado correctamente.
|
||||||
form:
|
form:
|
||||||
submit: Actualizar
|
submit: Actualizar
|
||||||
|
proposals:
|
||||||
|
title: Ajustes para propuestas
|
||||||
shared:
|
shared:
|
||||||
booths_search:
|
booths_search:
|
||||||
button: Buscar
|
button: Buscar
|
||||||
|
|||||||
@@ -63,3 +63,5 @@ es:
|
|||||||
verification_offices_url: URL oficinas verificación
|
verification_offices_url: URL oficinas verificación
|
||||||
min_age_to_participate: Edad mínima para participar
|
min_age_to_participate: Edad mínima para participar
|
||||||
proposal_improvement_path: Link a información para mejorar propuestas
|
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.debates'] = true
|
||||||
Setting['feature.homepage.widgets.feeds.processes'] = 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Initialize successful proposal id setting'
|
||||||
|
task initialize_successful_proposal_id: :environment do
|
||||||
|
Setting['proposals.successful_proposal_id'] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user