fixes conflicts with budgets

This commit is contained in:
rgarcia
2017-01-09 13:33:01 +01:00
36 changed files with 248 additions and 255 deletions

View File

@@ -462,7 +462,7 @@
word-break: break-word;
}
.proposal-show, .investment-project-show {
.proposal-show, .investment-project-show, .budget-investment-show {
.supports {
padding: $line-height/2 0 0;
@@ -712,6 +712,7 @@
}
.remove .icon-check-circle {
color: $budget;
display: block;
font-size: rem-calc(70);
line-height: rem-calc(70);
@@ -1030,7 +1031,6 @@
.amount-spent {
background: $success-bg;
color: $success-color;
font-weight: normal;
padding: $line-height/2;

View File

@@ -5,14 +5,16 @@ module Budgets
before_action :load_ballot
def show
authorize! :show, @ballot
render template: "budgets/ballot/show"
end
private
def load_ballot
@ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create
query = Budget::Ballot.where(user: current_user, budget: @budget)
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
end
end
end
end

View File

@@ -18,7 +18,7 @@ module Budgets
feature_flag :budgets
has_orders %w{most_voted newest oldest}, only: :show
has_orders ->(c){ c.instance_variable_get(:@budget).balloting? ? %w{random price} : %w{random confidence_score} }, only: :index
has_orders ->(c) { c.instance_variable_get(:@budget).investments_orders }, only: :index
invisible_captcha only: [:create, :update], honeypot: :subtitle, scope: :budget_investment
@@ -83,7 +83,7 @@ module Budgets
end
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :terms_of_service, :location, :tag_list)
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location, :terms_of_service)
end
def load_ballot

View File

@@ -66,14 +66,14 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
def valid_price_params?
if /\D/.match params[:budget_investment][:price]
@investment.errors.add(:price, I18n.t('budget.investments.wrong_price_format'))
@investment.errors.add(:price, I18n.t('budgets.investments.wrong_price_format'))
end
if /\D/.match params[:budget_investment][:price_first_year]
@investment.errors.add(:price_first_year, I18n.t('budget.investments.wrong_price_format'))
@investment.errors.add(:price_first_year, I18n.t('budgets.investments.wrong_price_format'))
end
@investment.errors.empty?
end
end
end

View File

@@ -1,17 +1,13 @@
module BudgetsHelper
def budget_phases_select_options
Budget::PHASES.map { |ph| [ t("budget.phase.#{ph}"), ph ] }
Budget::PHASES.map { |ph| [ t("budgets.phase.#{ph}"), ph ] }
end
def budget_currency_symbol_select_options
Budget::CURRENCY_SYMBOLS.map { |cs| [ cs, cs ] }
end
def heading_name(heading)
heading.present? ? heading.name : t("budget.headings.none")
end
def namespaced_budget_investment_path(investment, options={})
case namespace
when "management::budgets"

View File

@@ -76,7 +76,7 @@ class Budget < ActiveRecord::Base
end
def translated_phase
I18n.t "budget.phase.#{phase}"
I18n.t "budgets.phase.#{phase}"
end
def formatted_amount(amount)
@@ -94,6 +94,17 @@ class Budget < ActiveRecord::Base
formatted_amount(amount_spent(heading))
end
def investments_orders
case phase
when 'accepting', 'reviewing'
%w{random}
when 'balloting', 'reviewing_ballots'
%w{random price}
else
%w{random confidence_score}
end
end
private
def sanitize_descriptions

View File

@@ -25,7 +25,7 @@
<%= budget.name %>
</td>
<td class="small">
<%= t("budget.phase.#{budget.phase}") %>
<%= t("budgets.phase.#{budget.phase}") %>
</td>
<td class="small">
<%= link_to t("admin.budgets.index.budget_investments"), admin_budget_budget_investments_path(budget_id: budget.id) %>

View File

@@ -1,22 +1,24 @@
<div class="row ballot">
<div class="expanded budget no-margin-top padding">
<div class="row">
<%= render 'shared/back_link' %>
<%= render 'shared/back_link' %>
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
<div class="small-12 medium-8 column small-centered text-center">
<h2>
<%= t("budgets.ballots.show.voted_html",
count: @ballot.investments.count) %>
</h2>
<p>
<small>
<%= t("budgets.ballots.show.voted_info_html") %>
</small>
</p>
<div class="small-12 medium-8 column small-centered text-center">
<h2>
<%= t("budgets.ballots.show.voted_html",
count: @ballot.investments.count) %>
</h2>
<p>
<small>
<%= t("budgets.ballots.show.voted_info_html") %>
</small>
</p>
</div>
</div>
<hr>
</div>
<div class="row ballot">
<div class="margin-top">
<% @ballot.groups.each do |group| %>
<div id="<%= dom_id(group) %>"
@@ -34,9 +36,6 @@
<% else %>
<p>
<%= t("budgets.ballots.show.zero") %><br>
<%= link_to t("budgets.ballots.show.heading_link"),
budget_investments_path(budget, heading_id: heading.id),
data: { no_turbolink: true } %>
</p>
<% end %>

View File

@@ -9,7 +9,8 @@
class: "remove-investment-project",
method: :delete,
remote: true do %>
<span class="icon-x delete"></span>
<span class="sr-only"><%= t('budgets.ballots.show.remove') %></span>
<span class="icon-x delete"></span>
<% end %>
<% end %>
</li>

View File

@@ -3,7 +3,8 @@
</span>
<div class="progress" role="progressbar" tabindex="0"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
id="progress"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
<div class="progress-meter"
style="width:
<%= progress_bar_width(@budget.heading_price(@heading),
@@ -20,7 +21,7 @@
<p id="amount-spent" class="progress-meter-text spent-amount-text">
<%= @ballot.formatted_amount_spent(@heading) %>
<span id="amount-available" class="amount-available">
<%= t("budget.progress_bar.available") %>
<%= t("budgets.progress_bar.available") %>
<span><%= @ballot.formatted_amount_available(@heading) %></span>
</span>
</p>

View File

@@ -1,7 +1,7 @@
<div class="expanded budget no-margin-top padding">
<div class="row">
<div class="small-12 column">
<h1><%= t('budget.index.title') %></h1>
<h1><%= t('budgets.index.title') %></h1>
</div>
</div>
</div>
@@ -10,8 +10,8 @@
<div class="small-12 medium-9 column">
<table>
<thead>
<th><%= t('budget.index.name') %></th>
<th><%= t('budget.index.phase') %></th>
<th><%= Budget.human_attribute_name(:name) %></th>
<th><%= Budget.human_attribute_name(:phase) %></th>
</thead>
<tbody>
<% @budgets.each do |budget| %>

View File

@@ -3,8 +3,8 @@
<% if ballot.has_investment?(investment) %>
<div class="remove supported inline-block">
<span class="icon-check-circle bounceIn animated"
title="<%= t("budget.investments.investment.already_added") %>">
<span class="icon-check-circle"
title="<%= t("budgets.investments.investment.already_added") %>">
</span>
<p class="investment-project-amount">
<%= investment.formatted_price %>
@@ -27,12 +27,12 @@
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budget.investments.investment.add"),
<%= link_to t("budgets.investments.investment.add"),
budget_ballot_lines_url(investment_id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-support small expanded",
title: t('budget.investments.investment.support_title'),
title: t('budgets.investments.investment.support_title'),
method: :post,
remote: true %>
<% end %>
@@ -42,7 +42,7 @@
<% if reason.present? && !ballot.has_investment?(investment) %>
<div class="js-participation-not-allowed" style='display:none'>
<div class="js-participation-not-allowed participation-not-allowed" style='display:none'>
<p>
<%= t("budgets.ballots.reasons_for_not_balloting.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),

View File

@@ -3,8 +3,7 @@
<div class="row">
<div class="small-12 medium-8 column">
<%= f.label :heading_id, t("budget.investments.form.heading") %>
<%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: true, label: false} %>
<%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: true, } %>
</div>
<div class="small-12 column">
@@ -25,6 +24,10 @@
<%= f.text_field :location %>
</div>
<div class="small-12 column">
<%= f.text_field :organization_name %>
</div>
<div class="small-12 column">
<%= f.label :tag_list, t("budget.investments.form.tags_label") %>
<p class="note"><%= t("budget.investments.form.tags_instructions") %></p>
@@ -60,7 +63,7 @@
<% end %>
<div class="actions small-12 medium-6 large-4 end column">
<%= f.submit(class: "button expanded", value: t("budget.investments.form.submit_buttons.#{action_name}")) %>
<%= f.submit(nil, class: "button expanded") %>
</div>
</div>
<% end %>

View File

@@ -10,7 +10,7 @@
<% end %>
<% if can? :show, @ballot %>
<%= link_to t("budget.investments.header.check_ballot"),
<%= link_to t("budgets.investments.header.check_ballot"),
budget_ballot_path(@budget),
class: "button float-right" %>
<% end %>
@@ -20,13 +20,12 @@
<div class="row progress-votes">
<div class="small-12 column">
<div class="progress-bar-nav" data-fixed-bar>
<h1 class="inline-block"><%= @heading.name %></h1>
<div id="check-ballot" style="display: none;">
<% if can? :show, @ballot %>
<%= link_to t("budget.investments.header.check_ballot"),
<h1 class="inline-block margin-top"><%= @heading.name %></h1>
<% if can? :show, @ballot %>
<div id="check-ballot" style="display: none;">
<%= link_to t("budgets.investments.header.check_ballot"),
budget_ballot_path(@budget) %>
<% end %>
</div>
</div>
<% if @ballot.valid_heading?(@heading) %>
<div id="progress_bar" class="no-margin-top">
<%= render 'budgets/ballot/progress_bar' %>
@@ -34,13 +33,16 @@
<% else %>
<br>
<p class="callout warning inline-block">
<%= t("budget.investments.header.different_heading_assigned_html",
<%= t("budgets.investments.header.different_heading_assigned_html",
heading_link: link_to(
@assigned_heading.name,
budget_investments_path(@budget, heading: @assigned_heading))
) %>
</p>
<% end %>
<% else %>
<h2><%= @budget.formatted_heading_price(@heading) %></h2>
<% end %>
</div>
</div>
</div>
@@ -55,7 +57,7 @@
<%= t("shared.back") %>
<% end %>
<h1><%= t('budget.investments.index.title') %></h1>
<h1><%= t('budgets.investments.index.title') %></h1>
</div>
</div>
</div>

View File

@@ -6,7 +6,7 @@
<div class="budget-investment-content">
<% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %>
<span class="label-budget-investment float-left"><%= t("budget.investments.investment.title") %></span>
<span class="label-budget-investment float-left"><%= t("budgets.investments.investment.title") %></span>
<span class="icon-budget"></span>
<h3><%= link_to investment.title, namespaced_budget_investment_path(investment) %></h3>
<p class="investment-project-info">
@@ -16,7 +16,7 @@
<% if investment.author.hidden? || investment.author.erased? %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="author">
<%= t("budget.investments.show.author_deleted") %>
<%= t("budgets.investments.show.author_deleted") %>
</span>
<% else %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
@@ -32,10 +32,10 @@
<% end %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= heading_name(investment.heading) %>
<%= investment.heading.name %>
</p>
<div class="investment-project-description">
<p><%= link_to investment.description, namespaced_budget_investment_path(investment) %></p>
<p><%= investment.description %></p>
<div class="truncate"></div>
</div>
<%= render "shared/tags", taggable: investment, limit: 5 %>

View File

@@ -1,11 +1,5 @@
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
<ul class="breadcrumbs">
<li><%= link_to investment.budget.name, budget_path(investment.budget) %></a></li>
<li><%= investment.group.name %></a></li>
<li><%= investment.heading.name %></a></li>
</ul>
<div class="row">
<div class="small-12 medium-9 column">
<%= link_to :back, class: "back" do %>
@@ -21,17 +15,23 @@
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l investment.created_at.to_date %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= heading_name(investment.heading) %>
<%= investment.heading.name %>
</div>
<br>
<p id="investment_code">
<%= t("budget.investments.show.code_html", code: investment.id) %>
<%= t("budgets.investments.show.code_html", code: investment.id) %>
</p>
<% if investment.location.present? %>
<p id="investment_code">
<%= t("budget.investments.show.location_html", location: investment.location) %>
<p>
<%= t("budgets.investments.show.location_html", location: investment.location) %>
</p>
<% end %>
<% if investment.organization_name.present? %>
<p>
<%= t("budgets.investments.show.organization_name_html", name: investment.organization_name) %>
</p>
<% end %>
@@ -46,12 +46,12 @@
<% end %>
<% if investment.unfeasible? && investment.unfeasibility_explanation.present? %>
<h2><%= t('budget.investments.show.unfeasibility_explanation') %></h2>
<h2><%= t('budgets.investments.show.unfeasibility_explanation') %></h2>
<p><%= investment.unfeasibility_explanation %></p>
<% end %>
<% if investment.feasible? && investment.price_explanation.present? %>
<h2><%= t('budget.investments.show.price_explanation') %></h2>
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
<p><%= investment.price_explanation %></p>
<% end %>
</div>
@@ -59,7 +59,7 @@
<% if investment.should_show_aside? %>
<aside class="small-12 medium-3 column">
<div class="sidebar-divider"></div>
<h3><%= t("votes.supports") %></h3>
<h2><%= t("votes.supports") %></h2>
<div class="text-center">
<% if investment.should_show_votes? %>
@@ -82,7 +82,7 @@
</div>
<div class="sidebar-divider"></div>
<h3><%= t("budget.investments.show.share") %></h3>
<h2><%= t("budgets.investments.show.share") %></h2>
<div class="social-share-full">
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
@@ -96,5 +96,3 @@
</div>
</section>

View File

@@ -1,41 +1,45 @@
<div class="clear"></div>
<% if @budget.accepting? %>
<% if can?(:create, Budget::Investment.new(budget: @budget)) %>
<% if current_user && current_user.level_two_or_three_verified? %>
<%= link_to t("budget.investments.index.sidebar.create"), new_budget_investment_path, class: "button budget expanded" %>
<%= link_to t("budgets.investments.index.sidebar.create"), new_budget_investment_path, class: "button budget expanded" %>
<% else %>
<div class="callout warning">
<%= t("budget.investments.index.sidebar.verified_only",
verify: link_to(t("budget.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
<%= t("budgets.investments.index.sidebar.verified_only",
verify: link_to(t("budgets.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
</div>
<% end %>
<%= render "shared/tag_cloud", taggable: 'budget/investment' %>
<%= render 'categories' %>
<% end %>
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("budget.investments.index.sidebar.my_ballot") %></h2>
<% if @heading && @ballot.investments.by_heading(@heading.id).count > 0 %>
<p>
<em>
<%= t("budget.investments.index.sidebar.voted_html",
count: @ballot.investments.by_heading(@heading.id).count,
amount_spent: @ballot.formatted_amount_spent(@heading)) %>
</em>
</p>
<% else %>
<p><strong><%= t("budget.investments.index.sidebar.zero") %></strong></p>
<% end %>
<% if @heading && can?(:show, @ballot) %>
<ul class="ballot-list">
<% if @heading %>
<% @ballot.investments.by_heading(@heading.id).each do |investment| %>
<%= render 'budgets/ballot/investment_for_sidebar',
investment: investment,
investment_ids: @investment_ids %>
<% end %>
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("budgets.investments.index.sidebar.my_ballot") %></h2>
<% if @ballot.investments.by_heading(@heading.id).count > 0 %>
<p>
<em>
<%= t("budgets.investments.index.sidebar.voted_html",
count: @ballot.investments.by_heading(@heading.id).count,
amount_spent: @ballot.formatted_amount_spent(@heading)) %>
</em>
</p>
<% else %>
<p><strong><%= t("budgets.investments.index.sidebar.zero") %></strong></p>
<% end %>
</ul>
<p class="callout primary"><%= t("budget.investments.index.sidebar.voted_info") %></p>
<ul class="ballot-list">
<% if @heading %>
<% @ballot.investments.by_heading(@heading.id).each do |investment| %>
<%= render 'budgets/ballot/investment_for_sidebar',
investment: investment,
investment_ids: @investment_ids %>
<% end %>
<% end %>
</ul>
<p class="callout primary"><%= t("budgets.investments.index.sidebar.voted_info") %></p>
<% end %>

View File

@@ -5,29 +5,29 @@
<div class="supports js-participation">
<span class="total-supports <%= 'no-button' unless voting_allowed || user_voted_for %>">
<%= t("budget.investments.investment.supports", count: investment.total_votes) %>
<%= t("budgets.investments.investment.supports", count: investment.total_votes) %>
</span>
<div class="in-favor js-in-favor">
<% if user_voted_for %>
<div class="supported">
<%= t("budget.investments.investment.already_supported") %>
<div class="supported callout success">
<%= t("budgets.investments.investment.already_supported") %>
</div>
<% elsif investment.should_show_votes? %>
<%= link_to vote_url,
class: "button button-support small expanded",
title: t('budget.investments.investment.support_title'),
title: t('budgets.investments.investment.support_title'),
method: "post",
remote: true,
"aria-hidden" => css_for_aria_hidden(reason) do %>
<%= t("budget.investments.investment.give_support") %>
<%= t("budgets.investments.investment.give_support") %>
<% end %>
<% end %>
</div>
<% if reason.present? && !user_voted_for %>
<div class="js-participation-not-allowed" style='display:none' aria-hidden="false">
<div class="js-participation-not-allowed participation-not-allowed" style='display:none' aria-hidden="false">
<p>
<%= t("votes.budget_investments.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),

View File

@@ -1,8 +1,8 @@
<% provide :title do %><%= t('budget.investments.index.title') %><% end %>
<% provide :title do %><%= t('budgets.investments.index.title') %><% end %>
<% content_for :header_addon do %>
<%= render "shared/search_form",
search_path: budget_investments_path(budget_id: @budget.id, page: 1),
i18n_namespace: "budget.investments.index.search_form" %>
i18n_namespace: "budgets.investments.index.search_form" %>
<% end %>
<main id="budget-investments-main">
@@ -17,23 +17,23 @@
<div class="small-12 search-results margin-bottom">
<% if params[:unfeasible].present? %>
<h2><%= t("budget.investments.index.unfeasible") %></h2>
<h2><%= t("budgets.investments.index.unfeasible") %></h2>
<p>
<%= t("budget.investments.index.unfeasible_text",
definitions: link_to(t("budget.investments.index.unfeasible_text_definitions"), "https://decide.madrid.es/participatory_budget_info#20")).html_safe %>
<%= t("budgets.investments.index.unfeasible_text",
definitions: link_to(t("budgets.investments.index.unfeasible_text_definitions"), "https://decide.madrid.es/participatory_budget_info#20")).html_safe %>
</p>
<% end %>
<%= content_tag(:h2, t("budget.investments.index.by_heading", heading: @heading.name)) if @heading.present? %>
<%= content_tag(:h2, t("budgets.investments.index.by_heading", heading: @heading.name)) if @heading.present? %>
<% if params[:search].present? %>
<h2>
<%= page_entries_info @investments %>
<%= t("budget.investments.index.search_results", count: @investments.size, search_term: params[:search]) %>
<%= t("budgets.investments.index.search_results", count: @investments.size, search_term: params[:search]) %>
</h2>
<% end %>
</div>
<%= render('shared/order_links', i18n_namespace: "budget.investments.index") unless params[:unfeasible].present? %>
<%= render('shared/order_links', i18n_namespace: "budgets.investments.index") unless params[:unfeasible].present? %>
<% @investments.each do |investment| %>
<%= render partial: '/budgets/investments/investment', locals: {

View File

@@ -12,26 +12,26 @@
</div>
<div class="small-12 medium-3 column info padding" data-equalizer-watch>
<p>
<strong><%= t('budget.show.phase') %></strong>
<strong><%= t('budgets.show.phase') %></strong>
<br>
<%= t("budgets.phases.#{@budget.phase}") %>
<%= t("budgets.phase.#{@budget.phase}") %>
</p>
<% if @budget.accepting? %>
<% if can?(:create, Budget::Investment.new(budget: @budget))%>
<% if current_user %>
<% if current_user.level_two_or_three_verified? %>
<%= link_to t("budget.investments.index.sidebar.create"), new_budget_investment_path(@budget), class: "button margin-top expanded" %>
<%= link_to t("budgets.investments.index.sidebar.create"), new_budget_investment_path(@budget), class: "button margin-top expanded" %>
<% else %>
<div class="callout warning margin-top">
<%= t("budget.investments.index.sidebar.verified_only",
verify: link_to(t("budget.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
<%= t("budgets.investments.index.sidebar.verified_only",
verify: link_to(t("budgets.investments.index.sidebar.verify_account"), verification_path)).html_safe %>
</div>
<% end %>
<% else %>
<div class="callout primary margin-top">
<%= t("budget.investments.index.sidebar.not_logged_in",
sign_in: link_to(t("budget.investments.index.sidebar.sign_in"), new_user_session_path),
sign_up: link_to(t("budget.investments.index.sidebar.sign_up"), new_user_registration_path)).html_safe %>
<%= t("budgets.investments.index.sidebar.not_logged_in",
sign_in: link_to(t("budgets.investments.index.sidebar.sign_in"), new_user_session_path),
sign_up: link_to(t("budgets.investments.index.sidebar.sign_up"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% end %>
@@ -43,7 +43,7 @@
<div class="small-12 medium-9 column">
<table class="table-fixed">
<thead>
<th><%= t('budget.show.group') %></th>
<th><%= t('budgets.show.group') %></th>
</thead>
<tbody>
<% @budget.groups.each do |group| %>

View File

@@ -3,7 +3,7 @@
<%= form_tag search_path, method: :get do %>
<div class="input-group">
<label for="search_text" class="sr-only"><%= t("#{i18n_namespace}.title") %></label>
<input type="text" name="search" placeholder="<%= t("#{i18n_namespace}.placeholder") %>" class="input-group-field" value="<%= params[:search] %>" id="search_text">
<input type="text" name="search" placeholder='<%= t("#{i18n_namespace}.placeholder") %>' class="input-group-field" value="<%= params[:search] %>" id="search_text">
<div class="input-group-button">
<button type="submit" class="button" title="<%= t("#{i18n_namespace}.button") %>">
<span class="sr-only"><%= t("#{i18n_namespace}.button") %></span>

View File

@@ -18,7 +18,7 @@
<%= budget.name %>
</td>
<td>
<%= t("budget.phase.#{budget.phase}") %>
<%= t("budgets.phase.#{budget.phase}") %>
</td>
<td>
<%= @investments_with_valuation_open[budget.id] %>