Class: TimeTable::TimetableCalendarHelper::TimetableCalendar
- Inherits:
-
Object
- Object
- TimeTable::TimetableCalendarHelper::TimetableCalendar
- Defined in:
- app/helpers/time_table/timetable_calendar_helper.rb
Constant Summary collapse
- MAX_NUMBER_OF_DAYS =
7
Instance Attribute Summary collapse
-
#calendar_boundaries ⇒ Object
Returns the value of attribute calendar_boundaries.
-
#current_date_range ⇒ Object
Returns the value of attribute current_date_range.
-
#multi_timetable ⇒ Object
Returns the value of attribute multi_timetable.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
- #calendar_end_boundary ⇒ Object
- #calendar_limit ⇒ Object
- #calendar_start_boundary ⇒ Object
- #current_end_date ⇒ Object (also: #end_date)
- #current_number_of_days ⇒ Object (also: #number_of_days)
-
#current_start_date ⇒ Object
(also: #start_date)
ATTRIBUTE READERS ##.
- #disabled_nav_link(text = nil, **params, &block) ⇒ Object
-
#initialize(bounds:, range: 7, query_params: {}, view: nil) ⇒ TimetableCalendar
constructor
A new instance of TimetableCalendar.
- #link_to(*args, **params, &block) ⇒ Object
-
#months_string ⇒ Object
INFORMATION ##.
- #next_link(text = nil, **params, &block) ⇒ Object
-
#previous_link(text = nil, **params, &block) ⇒ Object
NAVIGATION LINKS ##.
-
#query_link(text = nil, query:, **params, &block) ⇒ Object
QUERY LINKS ##.
-
#render_days(&block) ⇒ Object
HEADER RENDERING ##.
- #set_multi_timetable(**options) ⇒ Object
Constructor Details
#initialize(bounds:, range: 7, query_params: {}, view: nil) ⇒ TimetableCalendar
Returns a new instance of TimetableCalendar.
49 50 51 52 53 54 55 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 49 def initialize(bounds:, range: 7, query_params: {}, view: nil) @calendar_boundaries = bounds @query_params = query_params @view = view @current_date_range = get_bounded_date_range(range) end |
Instance Attribute Details
#calendar_boundaries ⇒ Object
Returns the value of attribute calendar_boundaries.
43 44 45 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 43 def calendar_boundaries @calendar_boundaries end |
#current_date_range ⇒ Object
Returns the value of attribute current_date_range.
43 44 45 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 43 def current_date_range @current_date_range end |
#multi_timetable ⇒ Object
Returns the value of attribute multi_timetable.
43 44 45 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 43 def @multi_timetable end |
#query_params ⇒ Object
Returns the value of attribute query_params.
43 44 45 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 43 def query_params @query_params end |
#view ⇒ Object
Returns the value of attribute view.
43 44 45 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 43 def view @view end |
Instance Method Details
#calendar_end_boundary ⇒ Object
165 166 167 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 165 def calendar_end_boundary @calendar_end_boundary ||= calendar_boundaries.last end |
#calendar_limit ⇒ Object
169 170 171 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 169 def calendar_limit @calendar_limit ||= calendar_boundaries.count end |
#calendar_start_boundary ⇒ Object
161 162 163 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 161 def calendar_start_boundary @calendar_start_boundary ||= calendar_boundaries.first end |
#current_end_date ⇒ Object Also known as: end_date
149 150 151 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 149 def current_end_date @current_end_date ||= @current_date_range.last end |
#current_number_of_days ⇒ Object Also known as: number_of_days
155 156 157 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 155 def current_number_of_days @current_number_of_days ||= @current_date_range.count end |
#current_start_date ⇒ Object Also known as: start_date
ATTRIBUTE READERS ##
143 144 145 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 143 def current_start_date @current_start_date ||= @current_date_range.first end |
#disabled_nav_link(text = nil, **params, &block) ⇒ Object
130 131 132 133 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 130 def disabled_nav_link(text = nil, **params, &block) params[:class] = "#{params[:class]} disabled" link_to(text, "", **params, &block) end |
#link_to(*args, **params, &block) ⇒ Object
135 136 137 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 135 def link_to(*args, **params, &block) @view.link_to *args.compact, **params, &block end |
#months_string ⇒ Object
INFORMATION ##
79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 79 def months_string if current_start_date.year == current_end_date.year if current_start_date.month == current_end_date.month "#{current_start_date.strftime('%B %Y')}" else "#{current_start_date.strftime('%B')} - #{current_end_date.strftime('%B %Y')}" end else "#{current_start_date.strftime('%B %Y')} - #{current_end_date.strftime('%B %Y')}" end end |
#next_link(text = nil, **params, &block) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 119 def next_link(text = nil, **params, &block) if current_start_date + current_number_of_days.days > calendar_end_boundary return disabled_nav_link(text, **params, &block) end next_day = current_start_date + current_number_of_days.days next_day = calendar_end_boundary - current_number_of_days.days + 1 if next_day + current_number_of_days.days > calendar_end_boundary link_to(text, @query_params.merge(start_date: next_day), **params, &block) end |
#previous_link(text = nil, **params, &block) ⇒ Object
NAVIGATION LINKS ##
108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 108 def previous_link(text = nil, **params, &block) if current_start_date == calendar_start_boundary return disabled_nav_link(text, **params, &block) end previous_day = current_start_date - current_number_of_days previous_day = calendar_start_boundary if previous_day < calendar_start_boundary link_to(text, @query_params.merge(start_date: previous_day), **params, &block) end |
#query_link(text = nil, query:, **params, &block) ⇒ Object
QUERY LINKS ##
95 96 97 98 99 100 101 102 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 95 def query_link(text = nil, query:, **params, &block) active = query.reduce(true) do |acc, (key, value)| acc && send(key) == value end params[:class] = "#{params[:class]} active" if active link_to(text, @query_params.merge(query), **params, &block) end |
#render_days(&block) ⇒ Object
HEADER RENDERING ##
65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/time_table/timetable_calendar_helper.rb', line 65 def render_days(&block) @view.content_tag :div, class: "timetable-headers" do @view.concat(current_date_range.map do |day| @view.content_tag :div, class: "timetable-header" do yield(day) end end.join("").html_safe) end end |