class Candl::AgendaModel
Attributes
agenda_grouped_events[RW]
api_key[RW]
calendar_id[RW]
days_shift_coefficient[RW]
display_day_count[RW]
google_calendar_base_path[RW]
initialization_successful[RW]
Attributes one needs to access from the “outside”
maps_query_host[RW]
maps_query_parameter[RW]
Public Class Methods
emphasize_date(check_date, emphasized_date, emphasized, regular)
click to toggle source
helps apply styling to a special date
# File lib/candl/agenda_model.rb, line 99 def self.emphasize_date(check_date, emphasized_date, emphasized, regular) check_date.to_date == emphasized_date.to_date ? emphasized : regular end
new(config, current_shift_factor, date_today = Date.today)
click to toggle source
Minimal json conifg for agenda_model example: config = { \
calendar: { \ google_calendar_api_host_base_path: "https://www.googleapis.com/calendar/v3/calendars/", \ calendar_id: "schau-hnh%40web.de", \ api_key: "AIzaSyB5F1X5hBi8vPsmt1itZTpMluUAjytf6hI" \ }, \ agenda: { \ display_day_count: 14, \ days_shift_coefficient: 7 \ }, \ month: { \ summary_teaser_length_in_characters: 42, \ delta_start_of_weekday_from_sunday: 1 \ }, \ general: { \ maps_query_host: "https://www.google.de/maps", \ maps_query_parameter: "q", \ cache_update_interval_in_s: 7200 \ } \
}
# File lib/candl/agenda_model.rb, line 32 def initialize(config, current_shift_factor, date_today = Date.today) self.google_calendar_base_path = config[:calendar][:google_calendar_api_host_base_path] ||= "https://www.googleapis.com/calendar/v3/calendars/" self.calendar_id = config[:calendar][:calendar_id] self.api_key = config[:calendar][:api_key] self.display_day_count = config[:agenda][:display_day_count] ||= 14 self.days_shift_coefficient = config[:agenda][:days_shift_coefficient] ||= 7 self.maps_query_host = config[:general][:maps_query_host] ||= "https://www.google.de/maps" self.maps_query_parameter = config[:general][:maps_query_parameter] ||= "q" from = current_start_date(current_shift_factor, date_today) to = current_end_date(current_shift_factor, date_today) calendar_adress = { path: google_calendar_base_path, id: calendar_id, key: api_key } result = EventLoaderModel.get_events(calendar_adress, from, to, :agenda) events = result[:events] self.initialization_successful = result[:success] self.agenda_grouped_events = get_days_grouped_events(events) end
summary_title(event)
click to toggle source
build a short event summary (for popups etc.)
# File lib/candl/agenda_model.rb, line 104 def self.summary_title(event) event.summary.to_s.force_encoding("UTF-8") + "\n" + event.location.to_s.force_encoding("UTF-8") + "\n" + event.description.to_s.force_encoding("UTF-8") end
Public Instance Methods
address_to_maps_path(address)
click to toggle source
build a google maps path from the adress details
# File lib/candl/agenda_model.rb, line 109 def address_to_maps_path(address) ActionDispatch::Http::URL.path_for path: maps_query_host, params: Hash[maps_query_parameter.to_s, address.force_encoding("UTF-8").gsub(" ", "+")] end
current_end_date(current_shift_factor, today_date = Date.today)
click to toggle source
date of current end day of agenda
# File lib/candl/agenda_model.rb, line 94 def current_end_date(current_shift_factor, today_date = Date.today) today_date + (current_shift_factor.to_i * days_shift_coefficient + display_day_count).days end
current_shift_for_agenda(current_shift_factor)
click to toggle source
current shift factor for switching between calendar views from agenda to agenda
# File lib/candl/agenda_model.rb, line 74 def current_shift_for_agenda(current_shift_factor) current_shift_factor end
current_shift_for_month(current_shift_factor, today_date = Date.today)
click to toggle source
current shift factor for switching between calendar views from agenda to month
# File lib/candl/agenda_model.rb, line 79 def current_shift_for_month(current_shift_factor, today_date = Date.today) date_span = (current_end_date(current_shift_factor, today_date) - current_start_date(current_shift_factor, today_date)).to_i midway_date = (current_start_date(current_shift_factor, today_date) + (date_span / 2)) current_month_shift = ((midway_date.year * 12 + midway_date.month) - (today_date.year * 12 + today_date.month)).to_i current_month_shift end
current_start_date(current_shift_factor, today_date = Date.today)
click to toggle source
date of current start day of agenda
# File lib/candl/agenda_model.rb, line 89 def current_start_date(current_shift_factor, today_date = Date.today) today_date + (current_shift_factor.to_i * days_shift_coefficient).days end
path(page_path, params = {})
click to toggle source
builds base path of current view
# File lib/candl/agenda_model.rb, line 56 def path(page_path, params = {}) ActionDispatch::Http::URL.path_for path: page_path, params: {v: 'a'}.merge(params) end
previous_path(page_path, current_shift_factor)
click to toggle source
builds path to previous/upcoming week
# File lib/candl/agenda_model.rb, line 61 def previous_path(page_path, current_shift_factor) week_shift_path(page_path, current_shift_factor, -1) end
upcoming_path(page_path, current_shift_factor)
click to toggle source
# File lib/candl/agenda_model.rb, line 65 def upcoming_path(page_path, current_shift_factor) week_shift_path(page_path, current_shift_factor, +1) end
week_shift_path(page_path, current_shift_factor, shift_factor)
click to toggle source
# File lib/candl/agenda_model.rb, line 69 def week_shift_path(page_path, current_shift_factor, shift_factor) path(page_path , s: (current_shift_factor.to_i + shift_factor.to_i).to_s) end
Private Instance Methods
get_days_grouped_events(events)
click to toggle source
load events for agenda view grouped by day
# File lib/candl/agenda_model.rb, line 129 def get_days_grouped_events(events) events.group_by { |event| event.dtstart.to_date } end