Extract methods showing voting style information
The idea is that different voting styles will display different information messages.
This commit is contained in:
@@ -17,10 +17,6 @@ class Budget
|
|||||||
investments.sum(:price).to_i
|
investments.sum(:price).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def formatted_amount_spent(heading)
|
|
||||||
budget.formatted_amount(amount_spent(heading))
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_lines_in_group?(group)
|
def has_lines_in_group?(group)
|
||||||
groups.include?(group)
|
groups.include?(group)
|
||||||
end
|
end
|
||||||
@@ -67,7 +63,9 @@ class Budget
|
|||||||
def voting_style
|
def voting_style
|
||||||
@voting_style ||= voting_style_class.new(self)
|
@voting_style ||= voting_style_class.new(self)
|
||||||
end
|
end
|
||||||
delegate :amount_available, :amount_spent, :enough_money?, :formatted_amount_available,
|
delegate :amount_available, :amount_available_info, :amount_spent, :amount_spent_info,
|
||||||
|
:amount_limit_info, :change_vote_info, :enough_money?, :formatted_amount_available,
|
||||||
|
:formatted_amount_limit, :formatted_amount_spent, :voted_info,
|
||||||
to: :voting_style
|
to: :voting_style
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -4,4 +4,43 @@ class Budget::VotingStyles::Base
|
|||||||
def initialize(ballot)
|
def initialize(ballot)
|
||||||
@ballot = ballot
|
@ballot = ballot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
self.class.name.split("::").last.underscore
|
||||||
|
end
|
||||||
|
|
||||||
|
def change_vote_info(link:)
|
||||||
|
I18n.t("budgets.investments.index.sidebar.change_vote_info.#{name}", link: link)
|
||||||
|
end
|
||||||
|
|
||||||
|
def voted_info(heading)
|
||||||
|
I18n.t("budgets.investments.index.sidebar.voted_info.#{name}",
|
||||||
|
count: investments(heading).count,
|
||||||
|
amount_spent: ballot.budget.formatted_amount(investments_price(heading)))
|
||||||
|
end
|
||||||
|
|
||||||
|
def amount_available_info(heading)
|
||||||
|
I18n.t("budgets.ballots.show.amount_available.#{name}",
|
||||||
|
amount: formatted_amount_available(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
def amount_spent_info(heading)
|
||||||
|
I18n.t("budgets.ballots.show.amount_spent.#{name}",
|
||||||
|
amount: formatted_amount_spent(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
def amount_limit_info(heading)
|
||||||
|
I18n.t("budgets.ballots.show.amount_limit.#{name}",
|
||||||
|
amount: formatted_amount_limit(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def investments(heading)
|
||||||
|
ballot.investments.by_heading(heading.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def investments_price(heading)
|
||||||
|
investments(heading).sum(:price).to_i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,14 +4,30 @@ class Budget::VotingStyles::Knapsack < Budget::VotingStyles::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def amount_available(heading)
|
def amount_available(heading)
|
||||||
ballot.budget.heading_price(heading) - amount_spent(heading)
|
amount_limit(heading) - amount_spent(heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
def amount_spent(heading)
|
def amount_spent(heading)
|
||||||
ballot.investments.by_heading(heading.id).sum(:price).to_i
|
investments_price(heading)
|
||||||
|
end
|
||||||
|
|
||||||
|
def amount_limit(heading)
|
||||||
|
ballot.budget.heading_price(heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
def formatted_amount_available(heading)
|
def formatted_amount_available(heading)
|
||||||
ballot.budget.formatted_amount(amount_available(heading))
|
format(amount_available(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
def formatted_amount_spent(heading)
|
||||||
|
format(amount_spent(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
def formatted_amount_limit(heading)
|
||||||
|
format(amount_limit(heading))
|
||||||
|
end
|
||||||
|
|
||||||
|
def format(amount)
|
||||||
|
ballot.budget.formatted_amount(amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,14 +26,12 @@
|
|||||||
<h3>
|
<h3>
|
||||||
<%= group.name %> - <%= heading.name %>
|
<%= group.name %> - <%= heading.name %>
|
||||||
</h3>
|
</h3>
|
||||||
<%= link_to sanitize(t("budgets.ballots.show.remaining",
|
<%= link_to sanitize(@ballot.amount_available_info(heading)),
|
||||||
amount: @ballot.formatted_amount_available(heading))),
|
|
||||||
budget_group_path(@budget, group) %>
|
budget_group_path(@budget, group) %>
|
||||||
</div>
|
</div>
|
||||||
<% if @ballot.has_lines_in_group?(group) %>
|
<% if @ballot.has_lines_in_group?(group) %>
|
||||||
<h4 class="amount-spent text-right">
|
<h4 class="amount-spent text-right">
|
||||||
<%= sanitize(t("budgets.ballots.show.amount_spent",
|
<%= sanitize(@ballot.amount_spent_info(heading)) %>
|
||||||
amount: @ballot.formatted_amount_spent(heading))) %>
|
|
||||||
</h4>
|
</h4>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<span class="total-amount">
|
<span class="total-amount">
|
||||||
<%= @budget.formatted_heading_price(@heading) %>
|
<%= sanitize(@ballot.amount_limit_info(@heading)) %>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div class="progress" role="progressbar" tabindex="0"
|
<div class="progress" role="progressbar" tabindex="0"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<% if @heading && can?(:show, @ballot) %>
|
<% if @heading && can?(:show, @ballot) %>
|
||||||
<p class="callout">
|
<p class="callout">
|
||||||
<%= sanitize(t("budgets.investments.index.sidebar.change_vote_info",
|
<%= sanitize(@ballot.change_vote_info(
|
||||||
link: link_to(t("budgets.investments.index.sidebar.change_vote_link"),
|
link: link_to(t("budgets.investments.index.sidebar.change_vote_link"),
|
||||||
budget_ballot_path(@budget)))) %>
|
budget_ballot_path(@budget)))) %>
|
||||||
</p>
|
</p>
|
||||||
@@ -39,11 +39,7 @@
|
|||||||
|
|
||||||
<% if @ballot.investments.by_heading(@heading.id).count > 0 %>
|
<% if @ballot.investments.by_heading(@heading.id).count > 0 %>
|
||||||
<p>
|
<p>
|
||||||
<em>
|
<em><%= sanitize(@ballot.voted_info(@heading)) %></em>
|
||||||
<%= sanitize(t("budgets.investments.index.sidebar.voted",
|
|
||||||
count: @ballot.investments.by_heading(@heading.id).count,
|
|
||||||
amount_spent: @ballot.formatted_amount_spent(@heading))) %>
|
|
||||||
</em>
|
|
||||||
</p>
|
</p>
|
||||||
<% elsif @assigned_heading.present? %>
|
<% elsif @assigned_heading.present? %>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ ignore_unused:
|
|||||||
- "budgets.phase.*"
|
- "budgets.phase.*"
|
||||||
- "budgets.investments.index.orders.*"
|
- "budgets.investments.index.orders.*"
|
||||||
- "budgets.index.section_header.*"
|
- "budgets.index.section_header.*"
|
||||||
|
- "budgets.investments.index.sidebar.voted_info.*"
|
||||||
- "activerecord.*"
|
- "activerecord.*"
|
||||||
- "activemodel.*"
|
- "activemodel.*"
|
||||||
- "attributes.*"
|
- "attributes.*"
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ en:
|
|||||||
ballots:
|
ballots:
|
||||||
show:
|
show:
|
||||||
title: Your ballot
|
title: Your ballot
|
||||||
amount_spent: "Amount spent <span>%{amount}</span>"
|
amount_available:
|
||||||
remaining: "You still have <span>%{amount}</span> to invest."
|
knapsack: "You still have <span>%{amount}</span> to invest."
|
||||||
|
amount_spent:
|
||||||
|
knapsack: "Amount spent <span>%{amount}</span>"
|
||||||
|
amount_limit:
|
||||||
|
knapsack: "%{amount}"
|
||||||
no_balloted_group_yet: "You have not voted on this group yet, go vote!"
|
no_balloted_group_yet: "You have not voted on this group yet, go vote!"
|
||||||
remove: Remove vote
|
remove: Remove vote
|
||||||
voted:
|
voted:
|
||||||
@@ -84,10 +88,12 @@ en:
|
|||||||
other: " containing the term <strong>'%{search_term}'</strong>"
|
other: " containing the term <strong>'%{search_term}'</strong>"
|
||||||
sidebar:
|
sidebar:
|
||||||
my_ballot: My ballot
|
my_ballot: My ballot
|
||||||
voted:
|
voted_info:
|
||||||
|
knapsack:
|
||||||
one: "<strong>You voted one proposal with a cost of %{amount_spent}</strong>"
|
one: "<strong>You voted one proposal with a cost of %{amount_spent}</strong>"
|
||||||
other: "<strong>You voted %{count} proposals with a cost of %{amount_spent}</strong>"
|
other: "<strong>You voted %{count} proposals with a cost of %{amount_spent}</strong>"
|
||||||
change_vote_info: "You can %{link} at any time until the close of this phase. No need to spend all the money available."
|
change_vote_info:
|
||||||
|
knapsack: "You can %{link} at any time until the close of this phase. No need to spend all the money available."
|
||||||
change_vote_link: "change your vote"
|
change_vote_link: "change your vote"
|
||||||
different_heading_assigned: "You have active votes in another heading: %{heading_link}"
|
different_heading_assigned: "You have active votes in another heading: %{heading_link}"
|
||||||
change_ballot: "If your change your mind you can remove your votes in %{check_ballot} and start again."
|
change_ballot: "If your change your mind you can remove your votes in %{check_ballot} and start again."
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ es:
|
|||||||
ballots:
|
ballots:
|
||||||
show:
|
show:
|
||||||
title: Mis votos
|
title: Mis votos
|
||||||
amount_spent: "Coste total <span>%{amount}</span>"
|
amount_available:
|
||||||
remaining: "Te quedan <span>%{amount}</span> para invertir"
|
knapsack: "Te quedan <span>%{amount}</span> para invertir"
|
||||||
|
amount_spent:
|
||||||
|
knapsack: "Coste total <span>%{amount}</span>"
|
||||||
|
amount_limit:
|
||||||
|
knapsack: "%{amount}"
|
||||||
no_balloted_group_yet: "Todavía no has votado proyectos de este grupo, ¡vota!"
|
no_balloted_group_yet: "Todavía no has votado proyectos de este grupo, ¡vota!"
|
||||||
remove: Quitar voto
|
remove: Quitar voto
|
||||||
voted:
|
voted:
|
||||||
@@ -84,10 +88,12 @@ es:
|
|||||||
other: " que contienen <strong>'%{search_term}'</strong>"
|
other: " que contienen <strong>'%{search_term}'</strong>"
|
||||||
sidebar:
|
sidebar:
|
||||||
my_ballot: Mis votos
|
my_ballot: Mis votos
|
||||||
voted:
|
voted_info:
|
||||||
|
knapsack:
|
||||||
one: "<strong>Has votado un proyecto por un valor de %{amount_spent}</strong>"
|
one: "<strong>Has votado un proyecto por un valor de %{amount_spent}</strong>"
|
||||||
other: "<strong>Has votado %{count} proyectos por un valor de %{amount_spent}</strong>"
|
other: "<strong>Has votado %{count} proyectos por un valor de %{amount_spent}</strong>"
|
||||||
change_vote_info: "Puedes %{link} en cualquier momento hasta el cierre de esta fase. No hace falta que gastes todo el dinero disponible."
|
change_vote_info:
|
||||||
|
knapsack: "Puedes %{link} en cualquier momento hasta el cierre de esta fase. No hace falta que gastes todo el dinero disponible."
|
||||||
change_vote_link: "cambiar tus votos"
|
change_vote_link: "cambiar tus votos"
|
||||||
different_heading_assigned: "Ya apoyaste proyectos de otra sección del presupuesto: %{heading_link}"
|
different_heading_assigned: "Ya apoyaste proyectos de otra sección del presupuesto: %{heading_link}"
|
||||||
change_ballot: "Si cambias de opinión puedes borrar tus votos en %{check_ballot} y volver a empezar."
|
change_ballot: "Si cambias de opinión puedes borrar tus votos en %{check_ballot} y volver a empezar."
|
||||||
|
|||||||
Reference in New Issue
Block a user