Files
grecia/app/components/budgets/investments_list_component.rb
decabeza 4a9aae9806 Add groups index page
When render the investment list component with the link "see all
investments", now we redirect to groups index page when a budget has
multiple headings.
2021-08-09 21:45:29 +02:00

29 lines
656 B
Ruby

class Budgets::InvestmentsListComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
def investments(limit: 9)
case budget.phase
when "accepting", "reviewing"
budget.investments.sample(limit)
when "selecting", "valuating", "publishing_prices"
budget.investments.feasible.sample(limit)
when "balloting", "reviewing_ballots"
budget.investments.selected.sample(limit)
else
budget.investments.none
end
end
def see_all_path
if budget.single_heading?
budget_investments_path(budget)
else
budget_groups_path(budget)
end
end
end