Extract calculate winners button to a component
This way we remove some duplication.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
class Admin::Budgets::CalculateWinnersButtonComponent < ApplicationComponent
|
||||
attr_reader :budget, :from_investments
|
||||
|
||||
def initialize(budget, from_investments: false)
|
||||
@budget = budget
|
||||
@from_investments = from_investments
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def display_button?
|
||||
budget.balloting_or_later?
|
||||
end
|
||||
|
||||
def text
|
||||
if budget.investments.winners.empty?
|
||||
t("admin.budgets.winners.calculate")
|
||||
else
|
||||
t("admin.budgets.winners.recalculate")
|
||||
end
|
||||
end
|
||||
|
||||
def html_class
|
||||
if from_investments
|
||||
"button hollow float-right clear"
|
||||
else
|
||||
"button hollow"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user