Skip to content
Snippets Groups Projects
Commit 40a3bbe4 authored by Tyler Lemburg's avatar Tyler Lemburg
Browse files

Fix some numbers on calendar view

parent 723df688
No related branches found
No related tags found
No related merge requests found
<% events_groups = events.group_by do |event| <% events_groups = events.group_by do |event|
event.start_time.in_time_zone.strftime("%Y/%m/%d") event.start_time.in_time_zone.strftime("%Y/%m/%d")
end %> 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"> <div id="pagetitle">
<h3> <h3>
...@@ -73,18 +78,22 @@ end %> ...@@ -73,18 +78,22 @@ end %>
closeds.each do |closed| closeds.each do |closed|
start_time = closed[0] %> start_time = closed[0] %>
<% end_time = closed[1] %> <% end_time = closed[1] %>
<% <%
if [((end_time - 360) / 30).floor, 35].min < 0 # if the end time is before 6 am, skip.
if ((end_time - SIX_AM_MINUTES) / 30).floor < 0
next next
end end
top = ((start_time - 360) / 30) * 20 # calculate top based off of 6 am start
height = (end_time - start_time) * 20 / 30 top = ((start_time - SIX_AM_MINUTES) / 30) * HALF_HOUR_HEIGHT
height = (end_time - start_time) * HALF_HOUR_HEIGHT / 30
# normalize top to 0, reduce height to accomodate
if top < 0 if top < 0
height += top height += top
top = 0 top = 0
end end
if top + height > 720 # normalize the bottom to the bottom of the calendar at 8pm.
height = 720 - top if top + height > (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT
height = (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT - top
end end
%> %>
<div class="status closed" title="Closed" style="top: <%= top %>px; height: <%= height %>px;"> <div class="status closed" title="Closed" style="top: <%= top %>px; height: <%= height %>px;">
...@@ -97,17 +106,17 @@ end %> ...@@ -97,17 +106,17 @@ end %>
<% if record[:status] != 'open' && record[:status] != 'closed' %> <% if record[:status] != 'open' && record[:status] != 'closed' %>
<% start_time = record[:start] %> <% start_time = record[:start] %>
<% end_time = record[:end] %> <% end_time = record[:end] %>
<% if [((end_time - 360) / 30).floor, 35].min < 0 <% if ((end_time - SIX_AM_MINUTES) / 30).floor < 0
next next
end end
top = ((start_time - 360) / 30) * 20 top = ((start_time - SIX_AM_MINUTES) / 30) * HALF_HOUR_HEIGHT
height = (end_time - start_time) * 20 / 30 height = (end_time - start_time) * HALF_HOUR_HEIGHT / 30
if top < 0 if top < 0
height += top height += top
top = 0 top = 0
end end
if top + height > 720 if top + height > (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT
height = 720 - top height = (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT - top
end end
%> %>
<div title="<%= record[:status].split('_').join(' ').capitalize_all %>" class="status <%= record[:status].downcase.split('_').join('-') %>" style="top: <%= top %>px; height: <%= height %>px;"> <div title="<%= record[:status].split('_').join(' ').capitalize_all %>" class="status <%= record[:status].downcase.split('_').join('-') %>" style="top: <%= top %>px; height: <%= height %>px;">
...@@ -120,8 +129,8 @@ end %> ...@@ -120,8 +129,8 @@ end %>
<% day_events = events_groups[day.strftime("%Y/%m/%d")] %> <% day_events = events_groups[day.strftime("%Y/%m/%d")] %>
<% unless day_events.nil? %> <% unless day_events.nil? %>
<% day_events.sort{|a, b| a.start_time <=> b.start_time}.each do |res| %> <% day_events.sort{|a, b| a.start_time <=> b.start_time}.each do |res| %>
<% start_slot = [(((res.start_time.in_time_zone - day.midnight) / 60 - 360) / 30).floor, 0].max <% start_slot = [(((res.start_time.in_time_zone - day.midnight) / 60 - SIX_AM_MINUTES) / 30).floor, 0].max
end_slot = [(((res.end_time.in_time_zone - day.midnight) / 60 - 360) / 30).floor, 35].min end_slot = [(((res.end_time.in_time_zone - day.midnight) / 60 - SIX_AM_MINUTES) / 30).floor, 35].min
if end_slot < 0 if end_slot < 0
next next
end end
...@@ -130,8 +139,8 @@ end %> ...@@ -130,8 +139,8 @@ end %>
over = slots[k] if slots[k] > over over = slots[k] if slots[k] > over
end end
over = [over,3].min over = [over,3].min
top = (((res.start_time.in_time_zone - day.midnight) / 60 - 360) / 30) * 28 top = (((res.start_time.in_time_zone - day.midnight) / 60 - SIX_AM_MINUTES) / 30) * HALF_HOUR_HEIGHT
height = res.length * 28 / 30 height = res.length * HALF_HOUR_HEIGHT / 30
top_overflow = false top_overflow = false
bottom_overflow = false bottom_overflow = false
if top < 0 if top < 0
...@@ -139,8 +148,8 @@ end %> ...@@ -139,8 +148,8 @@ end %>
top = 0 top = 0
top_overflow = true top_overflow = true
end end
if top + height > 720 if top + height > (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT
height = 720 - top height = (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT - top
bottom_overflow = true bottom_overflow = true
events_groups[(day + 1.day).strftime("%Y/%m/%d")] ||= [] events_groups[(day + 1.day).strftime("%Y/%m/%d")] ||= []
events_groups[(day + 1.day).strftime("%Y/%m/%d")] << res events_groups[(day + 1.day).strftime("%Y/%m/%d")] << res
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment