Class: Decidim::Meetings::MeetingMonthCell
- Inherits:
-
ViewModel
- Object
- ViewModel
- Decidim::Meetings::MeetingMonthCell
- Defined in:
- app/cells/decidim/meetings/meeting_month_cell.rb
Instance Method Summary collapse
- #abbr_day_names ⇒ Object
- #beginning_of_week ⇒ Object
- #day_class(date) ⇒ Object
- #day_names ⇒ Object
- #events ⇒ Object
- #first_day_of_month?(date) ⇒ Boolean
- #first_meeting ⇒ Object
- #first_week_date_rotation ⇒ Object
- #meetings_in_this_month? ⇒ Boolean
- #month_days ⇒ Object
- #month_name ⇒ Object
- #show ⇒ Object
- #start_date ⇒ Object
- #weeks ⇒ Object
Instance Method Details
#abbr_day_names ⇒ Object
32 33 34 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 32 def abbr_day_names @abbr_day_names ||= I18n.t("date.abbr_day_names").rotate(first_week_date_rotation) end |
#beginning_of_week ⇒ Object
51 52 53 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 51 def beginning_of_week @beginning_of_week ||= [:beginning_of_week] || Date.beginning_of_week end |
#day_class(date) ⇒ Object
44 45 46 47 48 49 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 44 def day_class(date) return "is-today" if date == Date.current return if events.exclude?(date) "is-#{date < Date.current ? "past" : "upcoming"}-event" end |
#day_names ⇒ Object
36 37 38 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 36 def day_names @day_names ||= I18n.t("date.day_names").rotate(first_week_date_rotation) end |
#events ⇒ Object
59 60 61 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 59 def events [:events] || meetings.select { |meeting| meeting.start_time.month == month }.map { |meeting| meeting.start_time.to_date } end |
#first_day_of_month?(date) ⇒ Boolean
40 41 42 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 40 def first_day_of_month?(date) date.day == 1 end |
#first_meeting ⇒ Object
63 64 65 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 63 def first_meeting @first_meeting ||= meetings.first end |
#first_week_date_rotation ⇒ Object
67 68 69 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 67 def first_week_date_rotation @first_week_date_rotation ||= Date::DAYS_INTO_WEEK[beginning_of_week.to_sym].to_i end |
#meetings_in_this_month? ⇒ Boolean
14 15 16 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 14 def meetings_in_this_month? meetings.collect(&:start_time).map { |date| date.strftime("%m").to_i }.any? month end |
#month_days ⇒ Object
18 19 20 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 18 def month_days start_date.to_date.all_month end |
#month_name ⇒ Object
28 29 30 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 28 def month_name @month_name ||= I18n.t("date.month_names")[month] end |
#show ⇒ Object
10 11 12 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 10 def show render if meetings_in_this_month? end |
#start_date ⇒ Object
55 56 57 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 55 def start_date [:start_date] || first_meeting.start_time end |
#weeks ⇒ Object
22 23 24 25 26 |
# File 'app/cells/decidim/meetings/meeting_month_cell.rb', line 22 def weeks month_days.group_by do |day| (1 - first_week_date_rotation).days.since(day).cweek end.values end |