Class: Collavre::PlansTimelineComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/collavre/plans_timeline_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plans:, calendar_events: Collavre::CalendarEvent.none) ⇒ PlansTimelineComponent

Accepts pre-filtered plans and calendar_events from the controller



4
5
6
7
8
9
# File 'app/components/collavre/plans_timeline_component.rb', line 4

def initialize(plans:, calendar_events: Collavre::CalendarEvent.none)
  @start_date = Date.current - 30
  @end_date = Date.current + 30
  @plans = plans
  @calendar_events = calendar_events
end

Instance Attribute Details

#calendar_eventsObject (readonly)

Returns the value of attribute calendar_events.



11
12
13
# File 'app/components/collavre/plans_timeline_component.rb', line 11

def calendar_events
  @calendar_events
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



11
12
13
# File 'app/components/collavre/plans_timeline_component.rb', line 11

def end_date
  @end_date
end

#plansObject (readonly)

Returns the value of attribute plans.



11
12
13
# File 'app/components/collavre/plans_timeline_component.rb', line 11

def plans
  @plans
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



11
12
13
# File 'app/components/collavre/plans_timeline_component.rb', line 11

def start_date
  @start_date
end

Instance Method Details

#plan_dataObject

Called after component enters render context - safe to use helpers here



14
15
16
# File 'app/components/collavre/plans_timeline_component.rb', line 14

def plan_data
  @plan_data ||= @plans.map { |plan| plan_item(plan) } + @calendar_events.map { |event| calendar_item(event) }
end