Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #821 from consul/spending_proposals
Spending proposals
- Loading branch information
Showing
48 changed files
with
942 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Admin::SpendingProposalsController < Admin::BaseController | ||
has_filters %w{unresolved accepted rejected}, only: :index | ||
|
||
load_and_authorize_resource | ||
|
||
def index | ||
@spending_proposals = @spending_proposals.includes([:geozone]).send(@current_filter).order(created_at: :desc).page(params[:page]) | ||
end | ||
|
||
def show | ||
end | ||
|
||
def accept | ||
@spending_proposal.accept | ||
redirect_to request.query_parameters.merge(action: :index) | ||
end | ||
|
||
def reject | ||
@spending_proposal.reject | ||
redirect_to request.query_parameters.merge(action: :index) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ def block_user | |
Activity.log(current_user, :block, @user) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class SpendingProposalsController < ApplicationController | ||
before_action :authenticate_user!, except: [:index] | ||
|
||
load_and_authorize_resource | ||
|
||
def index | ||
end | ||
|
||
def new | ||
@spending_proposal = SpendingProposal.new | ||
@featured_tags = ActsAsTaggableOn::Tag.where(featured: true) | ||
end | ||
|
||
def create | ||
@spending_proposal = SpendingProposal.new(spending_proposal_params) | ||
@spending_proposal.author = current_user | ||
|
||
if @spending_proposal.save_with_captcha | ||
redirect_to spending_proposals_path, notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.spending_proposal", count: 1)) | ||
else | ||
@featured_tags = ActsAsTaggableOn::Tag.where(featured: true) | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def spending_proposal_params | ||
params.require(:spending_proposal).permit(:title, :description, :external_url, :geozone_id, :terms_of_service, :captcha, :captcha_key) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module GeozonesHelper | ||
|
||
def geozone_name(geozonable) | ||
geozonable.geozone ? geozonable.geozone.name : t("geozones.none") | ||
end | ||
|
||
def geozone_select_options | ||
Geozone.all.order(name: :asc).collect { |g| [ g.name, g.id ] } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Geozone < ActiveRecord::Base | ||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class SpendingProposal < ActiveRecord::Base | ||
include Measurable | ||
include Sanitizable | ||
|
||
apply_simple_captcha | ||
|
||
RESOLUTIONS = ["accepted", "rejected"] | ||
|
||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' | ||
belongs_to :geozone | ||
|
||
validates :title, presence: true | ||
validates :author, presence: true | ||
validates :description, presence: true | ||
|
||
validates :title, length: { in: 4..SpendingProposal.title_max_length } | ||
validates :description, length: { maximum: SpendingProposal.description_max_length } | ||
validates :resolution, inclusion: { in: RESOLUTIONS, allow_nil: true } | ||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create | ||
|
||
scope :accepted, -> { where(resolution: "accepted") } | ||
scope :rejected, -> { where(resolution: "rejected") } | ||
scope :unresolved, -> { where(resolution: nil) } | ||
|
||
def accept | ||
update_attribute(:resolution, "accepted") | ||
end | ||
|
||
def reject | ||
update_attribute(:resolution, "rejected") | ||
end | ||
|
||
def accepted? | ||
resolution == "accepted" | ||
end | ||
|
||
def rejected? | ||
resolution == "rejected" | ||
end | ||
|
||
def unresolved? | ||
resolution.blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<h2><%= t("admin.spending_proposals.index.title") %></h2> | ||
|
||
<%= render 'shared/filter_subnav', i18n_namespace: "admin.spending_proposals.index" %> | ||
|
||
<h3><%= page_entries_info @spending_proposals %></h3> | ||
|
||
<table> | ||
<% @spending_proposals.each do |spending_proposal| %> | ||
<tr id="<%= dom_id(spending_proposal) %>"> | ||
<td> | ||
<strong><%= link_to spending_proposal.title, admin_spending_proposal_path(spending_proposal) %></strong> | ||
</td> | ||
<td> | ||
<%= geozone_name(spending_proposal) %> | ||
</td> | ||
<td> | ||
<% unless spending_proposal.accepted? %> | ||
<%= link_to t("admin.spending_proposals.actions.accept"), | ||
accept_admin_spending_proposal_path(spending_proposal, request.query_parameters), | ||
method: :put, | ||
data: { confirm: t("admin.actions.confirm") }, | ||
class: "button radius tiny success no-margin" %> | ||
<% end %> | ||
<% unless spending_proposal.rejected? %> | ||
<%= link_to t("admin.spending_proposals.actions.reject"), | ||
reject_admin_spending_proposal_path(spending_proposal, request.query_parameters), | ||
method: :put, | ||
data: { confirm: t("admin.actions.confirm") }, | ||
class: "button radius tiny warning right" %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<%= paginate @spending_proposals %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<h2><%= @spending_proposal.title %></h2> | ||
|
||
<%= safe_html_with_links @spending_proposal.description.html_safe %> | ||
<% if @spending_proposal.external_url.present? %> | ||
<p><%= text_with_links @spending_proposal.external_url %></p> | ||
<% end %> | ||
|
||
<p><%= t("admin.spending_proposals.show.by") %>: <%= link_to @spending_proposal.author.name, admin_user_path(@spending_proposal.author) %></p> | ||
<p><%= t("admin.spending_proposals.show.geozone") %>: <%= geozone_name(@spending_proposal) %></p> | ||
<p><%= l @spending_proposal.created_at, format: :datetime %></p> | ||
|
||
<p> | ||
<% unless @spending_proposal.accepted? %> | ||
<%= link_to t("admin.spending_proposals.actions.accept"), | ||
accept_admin_spending_proposal_path(@spending_proposal), | ||
method: :put, | ||
data: { confirm: t("admin.actions.confirm") }, | ||
class: "button radius tiny success no-margin" %> | ||
<% end %> | ||
<% unless @spending_proposal.rejected? %> | ||
<%= link_to t("admin.spending_proposals.actions.reject"), | ||
reject_admin_spending_proposal_path(@spending_proposal), | ||
method: :put, | ||
data: { confirm: t("admin.actions.confirm") }, | ||
class: "button radius tiny warning" %> | ||
<% end %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="page row-full"> | ||
<div class="row"> | ||
<div class="menu small-12 medium-3 column"> | ||
<i class="icon-angle-left left"></i> | ||
<%= link_to t("spending_proposals.new.back_link"), "/more_information", class: 'left back' %> | ||
<ul class="clear"> | ||
<li> | ||
<a href="#i">Explicación detallada del proceso</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="text small-12 medium-9 column"> | ||
<h1>¿Cómo funcionan los presupuestos ciudadanos?</h1> | ||
|
||
<h2 id="i">Explicación detallada del proceso</h2> | ||
<p>Próximamente se podrá encontrar aquí una descripción del proceso de participación ciudadana en los presupuestos.</p> | ||
|
||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<%= form_for(@spending_proposal, url: form_url) do |f| %> | ||
<%= render 'shared/errors', resource: @spending_proposal %> | ||
|
||
<div class="row"> | ||
<div class="small-12 column"> | ||
<%= f.label :title, t("spending_proposals.form.title") %> | ||
<%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("spending_proposals.form.title"), label: false %> | ||
</div> | ||
|
||
<div class="ckeditor small-12 column"> | ||
<%= f.label :description, t("spending_proposals.form.description") %> | ||
<%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> | ||
</div> | ||
|
||
<div class="small-12 column"> | ||
<%= f.label :external_url, t("spending_proposals.form.external_url") %> | ||
<%= f.text_field :external_url, placeholder: t("spending_proposals.form.external_url"), label: false %> | ||
</div> | ||
|
||
<div class="small-12 column"> | ||
<%= f.label :geozone_id, t("spending_proposals.form.geozone") %> | ||
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %> | ||
</div> | ||
|
||
<div class="small-12 column"> | ||
<% if @spending_proposal.new_record? %> | ||
<%= f.label :terms_of_service do %> | ||
<%= f.check_box :terms_of_service, label: false %> | ||
<span class="checkbox"> | ||
<%= t("form.accept_terms", | ||
policy: link_to(t("form.policy"), "/privacy", target: "blank"), | ||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> | ||
</span> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="small-12 column"> | ||
<%= f.simple_captcha input_html: { required: false } %> | ||
</div> | ||
|
||
<div class="actions small-12 column"> | ||
<%= f.submit(class: "button radius", value: t("spending_proposals.form.submit_buttons.#{action_name}")) %> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% provide :title do %><%= t('spending_proposals.index.title') %><% end %> | ||
<div class="page row-full"> | ||
<div class="row"> | ||
<div class="more-information text small-12 medium-8 column"> | ||
<h1><%= t('spending_proposals.index.title') %></h1> | ||
|
||
<p><%= t('spending_proposals.index.text') %></p> | ||
|
||
<% if can? :create, SpendingProposal %> | ||
<%= link_to t('spending_proposals.index.create_link'), new_spending_proposal_path, class: 'button radius' %> | ||
<% else %> | ||
<p><%= t('spending_proposals.index.verified_only', verify_account: link_to(t('spending_proposals.index.verify_account'), verification_path)).html_safe %></p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.