Skip to content
Snippets Groups Projects
calendar.erb 9.54 KiB
<% events_groups = events.group_by do |event|
	event.start_time.in_time_zone.strftime("%Y/%m/%d")
end 

HALF_HOUR_HEIGHT = 28 # pixel height of half-hour sections in calendar. DO NOT CHANGE RESPONSIVELY
SIX_AM_MINUTES = 360 # start time of calendar 
EIGHT_PM_MINUTES = 1200 # end time of calendar
%>

<div id="pagetitle">
	<h3>
		<%= @space.name %> Calendar
		<span class="dcf-subhead">See all our upcoming events!</span>
	</h3>
</div>

<div class="calendar">
	<div class="calendar-header">
		<a href="/<%= @space.url_name %>/calendar/?date=<%= (date-7.days).strftime('%Y-%m-%d') %><%= defined?(kiosk_mode) && kiosk_mode == 'true' ? '&kiosk_mode=true' : ''%>" id="prev-week" class="schedulericon-angle-circled-left dcf-txt-decor-none"><span class="dcf-sr-only">Previous Week</span></a>
		<a href="/<%= @space.url_name %>/calendar/?date=<%= (date+7.days).strftime('%Y-%m-%d') %><%= defined?(kiosk_mode) && kiosk_mode == 'true' ? '&kiosk_mode=true' : ''%>" id="next-week" class="schedulericon-angle-circled-right dcf-txt-decor-none"><span class="dcf-sr-only">next week</span></a>
		<h4 class="unl-font-sans">
		<%= month = sunday.strftime('%B %Y') %><%= (month2 = (sunday+6.days).strftime('%B %Y')) == month ? '' : " - #{month2}" %>
		</h4>
	</div>
	<div class="day-label-container">
		<% (1..5).each do |i| %>
			<% day = (sunday + i.days + 1.hour).midnight %>
			<label class="day-header"><%= day.strftime("%^a %-m/%d") %></label>
		<% end %>
	</div>
	<div class="calendar-container">
		<div class="time-labels">
			<div class="time-chart">
				<% (12..39).each do |j| %>
					<div class="calendar-half-hour">
						<label><%= "#{(j / 2) % 12 + (j==24 ? 12 : 0)} #{j>=24 ? 'PM': 'AM'}" if j % 2 == 0 %></label>
					</div>
				<% end %>
			</div>
		</div>
		<% (1..5).each do |i| %>
		<% day = (sunday + i.days + 1.hour).midnight %>
		<% slots = [0] * 36 %>
		<div class="calendar-day" data-day="<%= day.strftime("%Y/%m/%d") %>">
			<!-- <label class="day-header"><%= day.strftime("%^a %-m/%d") %></label> -->
			<div class="day-chart" title="Open">
				<% if week_hours.has_key?(i) %>
					<% # figure out where the closed divs need to be
						# we can assume that all records in this space_hour are non-intertwined
						closed_start = 0
						closed_end = 0
						starts = week_hours[i].hours.map{|record| record[:start]}
						ends = week_hours[i].hours.map{|record| record[:end]}
						%> <%
						closeds = []
						(360..1199).each do |j|
							if starts.include?(j)
								closed_end = j
								closeds << [closed_start, closed_end]
								closed_start = 0
								closed_end = 0
							end
							if ends.include?(j)
								closed_start = j
							end
						end 
						closed_end = 1200
						closeds << [closed_start, closed_end]

						closeds.each do |closed|