diff --git a/views/reserve.erb b/views/reserve.erb index 001f8ebc41a49817d93cc7205a98277fdecbb08c..a26f5ce4fe977e450809957704995b05f674446c 100644 --- a/views/reserve.erb +++ b/views/reserve.erb @@ -12,7 +12,12 @@ unless reservation.nil? end start_hour += 12 if start_hour == 0 start_minute = reservation.start_time.in_time_zone.min -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"> <h3><%= reservation.nil? ? 'Reserve Time for ' : 'Edit Reservation for ' %><%= resource.name %></h3> @@ -26,7 +31,7 @@ end %> <label class="day-header"><%= day.strftime("%^a %-m/%d") %></label> <div class="time-labels"> <div class="time-chart"> - <% (12..47).each do |j| %> + <% (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> @@ -41,8 +46,8 @@ end %> if end_slot < 0 next end - top = (((res.start_time.in_time_zone - day.midnight) / 60 - 360) / 30) * 28 - height = res.length * 28 / 30 + top = (((res.start_time.in_time_zone - day.midnight) / 60 - 360) / 30) * HALF_HOUR_HEIGHT + height = res.length * HALF_HOUR_HEIGHT / 30 %> <div class="event-container" style="top: <%= top %>px;"> <div class="reservation <%= 'editing' if !reservation.nil? && reservation.id == res.id %>" @@ -66,7 +71,7 @@ end %> ends = space_hour.hours.map{|record| record[:end]} %> <% closeds = [] - (360..1439).each do |j| + (360..1199).each do |j| if starts.include?(j) closed_end = j closeds << [closed_start, closed_end] @@ -77,24 +82,28 @@ end %> closed_start = j end end - closed_end = 1440 + closed_end = 1200 closeds << [closed_start, closed_end] closeds.each do |closed| start_time = closed[0] %> <% 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 end - top = ((start_time - 360) / 30) * 20 - height = (end_time - start_time) * 20 / 30 + # calculate top based off of 6 am start + 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 height += top top = 0 - end - if top + height > 720 - height = 720 - top + end + # normalize the bottom to the bottom of the calendar at 8pm. + if top + height > (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT + height = (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT - top end %> <div class="status closed" title="Closed" style="top: <%= top %>px; height: <%= height %>px;"> @@ -106,18 +115,18 @@ end %> <% if record[:status] != 'open' && record[:status] != 'closed' %> <% start_time = record[:start] %> <% end_time = record[:end] %> - <% if [((end_time - 360) / 30).floor, 35].min < 0 + <% if [((end_time - SIX_AM_MINUTES) / 30).floor, 35].min < 0 next end - top = ((start_time - 360) / 30) * 20 - 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 if top < 0 height += top top = 0 end - if top + height > 720 - height = 720 - top - end + if top + height > (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT + height = (EIGHT_PM_MINUTES / 30) * HALF_HOUR_HEIGHT - top + end %> <div title="<%= record[:status].split('_').join(' ').capitalize_all %>" class="status <%= record[:status].downcase.split('_').join('-') %>" style="top: <%= top %>px; height: <%= height %>px;"> @@ -126,7 +135,7 @@ end %> <% end %> <% end %> <div> - <% (12..47).each do |j| %> + <% (12..39).each do |j| %> <div class="calendar-half-hour"> </div>