diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index 4c4b2370c..074bf6a8f 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -17,10 +17,6 @@ class Budget investments.sum(:price).to_i end - def formatted_amount_spent(heading) - budget.formatted_amount(amount_spent(heading)) - end - def has_lines_in_group?(group) groups.include?(group) end @@ -67,7 +63,9 @@ class Budget def voting_style @voting_style ||= voting_style_class.new(self) 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 private diff --git a/app/models/budget/voting_styles/base.rb b/app/models/budget/voting_styles/base.rb index 48de3a032..e407641db 100644 --- a/app/models/budget/voting_styles/base.rb +++ b/app/models/budget/voting_styles/base.rb @@ -4,4 +4,43 @@ class Budget::VotingStyles::Base def initialize(ballot) @ballot = ballot 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 diff --git a/app/models/budget/voting_styles/knapsack.rb b/app/models/budget/voting_styles/knapsack.rb index 6c056115e..815a19102 100644 --- a/app/models/budget/voting_styles/knapsack.rb +++ b/app/models/budget/voting_styles/knapsack.rb @@ -4,14 +4,30 @@ class Budget::VotingStyles::Knapsack < Budget::VotingStyles::Base end def amount_available(heading) - ballot.budget.heading_price(heading) - amount_spent(heading) + amount_limit(heading) - amount_spent(heading) end 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 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 diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb index e288111a9..e8e79300f 100644 --- a/app/views/budgets/ballot/_ballot.html.erb +++ b/app/views/budgets/ballot/_ballot.html.erb @@ -26,14 +26,12 @@

<%= group.name %> - <%= heading.name %>

- <%= link_to sanitize(t("budgets.ballots.show.remaining", - amount: @ballot.formatted_amount_available(heading))), + <%= link_to sanitize(@ballot.amount_available_info(heading)), budget_group_path(@budget, group) %> <% if @ballot.has_lines_in_group?(group) %>

- <%= sanitize(t("budgets.ballots.show.amount_spent", - amount: @ballot.formatted_amount_spent(heading))) %> + <%= sanitize(@ballot.amount_spent_info(heading)) %>

<% else %>

diff --git a/app/views/budgets/ballot/_progress_bar.html.erb b/app/views/budgets/ballot/_progress_bar.html.erb index 4c7035b41..06206b7da 100644 --- a/app/views/budgets/ballot/_progress_bar.html.erb +++ b/app/views/budgets/ballot/_progress_bar.html.erb @@ -1,5 +1,5 @@ - <%= @budget.formatted_heading_price(@heading) %> + <%= sanitize(@ballot.amount_limit_info(@heading)) %>

- <%= 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"), budget_ballot_path(@budget)))) %>

@@ -39,11 +39,7 @@ <% if @ballot.investments.by_heading(@heading.id).count > 0 %>

- - <%= sanitize(t("budgets.investments.index.sidebar.voted", - count: @ballot.investments.by_heading(@heading.id).count, - amount_spent: @ballot.formatted_amount_spent(@heading))) %> - + <%= sanitize(@ballot.voted_info(@heading)) %>

<% elsif @assigned_heading.present? %>

diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 29706ed60..f03a38d09 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -127,6 +127,7 @@ ignore_unused: - "budgets.phase.*" - "budgets.investments.index.orders.*" - "budgets.index.section_header.*" + - "budgets.investments.index.sidebar.voted_info.*" - "activerecord.*" - "activemodel.*" - "attributes.*" diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 6dad9ade6..8047f44ad 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -3,8 +3,12 @@ en: ballots: show: title: Your ballot - amount_spent: "Amount spent %{amount}" - remaining: "You still have %{amount} to invest." + amount_available: + knapsack: "You still have %{amount} to invest." + amount_spent: + knapsack: "Amount spent %{amount}" + amount_limit: + knapsack: "%{amount}" no_balloted_group_yet: "You have not voted on this group yet, go vote!" remove: Remove vote voted: @@ -84,10 +88,12 @@ en: other: " containing the term '%{search_term}'" sidebar: my_ballot: My ballot - voted: - one: "You voted one proposal with a cost of %{amount_spent}" - other: "You voted %{count} proposals with a cost of %{amount_spent}" - change_vote_info: "You can %{link} at any time until the close of this phase. No need to spend all the money available." + voted_info: + knapsack: + one: "You voted one proposal with a cost of %{amount_spent}" + other: "You voted %{count} proposals with a cost of %{amount_spent}" + 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" 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." diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 5b0c3c918..9ccc52159 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -3,8 +3,12 @@ es: ballots: show: title: Mis votos - amount_spent: "Coste total %{amount}" - remaining: "Te quedan %{amount} para invertir" + amount_available: + knapsack: "Te quedan %{amount} para invertir" + amount_spent: + knapsack: "Coste total %{amount}" + amount_limit: + knapsack: "%{amount}" no_balloted_group_yet: "Todavía no has votado proyectos de este grupo, ¡vota!" remove: Quitar voto voted: @@ -84,10 +88,12 @@ es: other: " que contienen '%{search_term}'" sidebar: my_ballot: Mis votos - voted: - one: "Has votado un proyecto por un valor de %{amount_spent}" - other: "Has votado %{count} proyectos por un valor de %{amount_spent}" - change_vote_info: "Puedes %{link} en cualquier momento hasta el cierre de esta fase. No hace falta que gastes todo el dinero disponible." + voted_info: + knapsack: + one: "Has votado un proyecto por un valor de %{amount_spent}" + other: "Has votado %{count} proyectos por un valor de %{amount_spent}" + 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" 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."