Disable calculating winners during balloting

Calculating winners before the balloting is over is useless (results
aren't published at that point) and can lead to the wrong results since
users are still voting and results might change.

And we were showing the button to calculate winners even when a budget
had finished. However, in this case the action to calculate winners did
nothing, which resulted in administrators seeing nothing happened after
pressing the button.
This commit is contained in:
Javi Martín
2021-08-30 15:11:02 +02:00
parent 2b709f1a36
commit 0a14337580
11 changed files with 81 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
<% if display_button? %>
<% if can?(:calculate_winners, budget) %>
<%= render Admin::ActionComponent.new(
:calculate_winners,
budget,
@@ -9,6 +9,7 @@
<%= t("admin.budgets.winners.calculate") %>
</span>
<div class="callout warning clear">
<%= t("admin.budget_investments.index.cannot_calculate_winners") %>
<%= t("admin.budget_investments.index.cannot_calculate_winners",
phase: t("budgets.phase.reviewing_ballots")) %>
</div>
<% end %>

View File

@@ -1,5 +1,6 @@
class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
attr_reader :budget, :from_investments
delegate :can?, to: :helpers
def initialize(budget, from_investments: false)
@budget = budget
@@ -8,10 +9,6 @@ class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
private
def display_button?
budget.balloting_or_later?
end
def text
if budget.investments.winners.empty?
t("admin.budgets.winners.calculate")