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.
24 lines
549 B
Ruby
24 lines
549 B
Ruby
class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
|
|
attr_reader :budget, :from_investments
|
|
delegate :can?, to: :helpers
|
|
|
|
def initialize(budget, from_investments: false)
|
|
@budget = budget
|
|
@from_investments = from_investments
|
|
end
|
|
|
|
private
|
|
|
|
def text
|
|
if budget.investments.winners.empty?
|
|
t("admin.budgets.winners.calculate")
|
|
else
|
|
t("admin.budgets.winners.recalculate")
|
|
end
|
|
end
|
|
|
|
def html_class
|
|
"button hollow float-right clear" if from_investments
|
|
end
|
|
end
|