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

Merge branch 'resource-specific-hours' into 'master'

Resource specific hours

See merge request !5
parents 39cb3695 58142083
No related branches found
No related tags found
No related merge requests found
require 'active_record'
class AddResourceHours < ActiveRecord::Migration
def change
create_table :resource_hours do |t|
t.integer :resource_id
t.integer :day_of_week
t.datetime :effective_date
t.boolean :one_off
t.string :hours
end
end
end
\ No newline at end of file
...@@ -4,10 +4,13 @@ require 'models/resource_authorization' ...@@ -4,10 +4,13 @@ require 'models/resource_authorization'
require 'models/resource_class' require 'models/resource_class'
require 'models/resource_field' require 'models/resource_field'
require 'models/resource_field_data' require 'models/resource_field_data'
require 'models/resource_hour'
require 'models/space_hour'
class Resource < ActiveRecord::Base class Resource < ActiveRecord::Base
belongs_to :service_space belongs_to :service_space
has_many :reservations, dependent: :destroy has_many :reservations, dependent: :destroy
has_many :resource_hours, dependent: :destroy
has_many :resource_approvers, dependent: :destroy has_many :resource_approvers, dependent: :destroy
has_many :resource_authorizations, dependent: :destroy has_many :resource_authorizations, dependent: :destroy
belongs_to :resource_class belongs_to :resource_class
...@@ -33,4 +36,60 @@ class Resource < ActiveRecord::Base ...@@ -33,4 +36,60 @@ class Resource < ActiveRecord::Base
end end
end end
end end
def edit_hours_href
"/#{service_space.url_name}/admin/resources/#{id}/hours/"
end
def add_hours_href
"/#{service_space.url_name}/admin/resources/#{id}/hours/create/"
end
def get_weeks_available_hours(date)
sunday = date.in_time_zone.week_start
# get the space's hours for the week
space_hours = SpaceHour.where(:service_space_id => service_space.id)
.where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a
space_hours_days = space_hours.group_by do |space_hour|
space_hour.day_of_week
end
resource_hours = ResourceHour.where(:resource_id => id)
.where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a
resource_hours_days = resource_hours.group_by do |resource_hour|
resource_hour.day_of_week
end
week_hours = {}
space_hours_days.each do |number_of_days, array|
this_day = (sunday + number_of_days.days + 1.hour).midnight
# find the correct hour record to use for this day
array.each do |space_hour|
if space_hour.effective_date.in_time_zone.midnight == this_day.in_time_zone.midnight || (!space_hour.one_off && space_hour.effective_date.in_time_zone.midnight <= this_day.in_time_zone.midnight)
week_hours[number_of_days] = space_hour
break
end
end
end
resource_hours_days.each do |number_of_days, array|
this_day = (sunday + number_of_days.days + 1.hour).midnight
# find the correct hour record to use for this day
array.each do |resource_hour|
if resource_hour.effective_date.in_time_zone.midnight == this_day.in_time_zone.midnight || (!resource_hour.one_off && resource_hour.effective_date.in_time_zone.midnight <= this_day.in_time_zone.midnight)
week_hours[number_of_days] = resource_hour
break
end
end
end
return week_hours
end
end end
\ No newline at end of file
require 'active_record'
class ResourceHour < ActiveRecord::Base
serialize :hours, Array
end
\ No newline at end of file
...@@ -2,4 +2,27 @@ require 'active_record' ...@@ -2,4 +2,27 @@ require 'active_record'
class SpaceHour < ActiveRecord::Base class SpaceHour < ActiveRecord::Base
serialize :hours, Array serialize :hours, Array
def self.get_weeks_hours(date, hours)
# get the hours for this week to show
sunday = date.week_start
hours_days = hours.group_by do |space_hour|
space_hour.day_of_week
end
week_hours = {}
hours_days.each do |number_of_days, array|
this_day = (sunday + number_of_days.days + 1.hour).midnight
# find the correct hour record to use for this day
array.each do |space_hour|
if space_hour.effective_date.in_time_zone.midnight == this_day.in_time_zone.midnight || (!space_hour.one_off && space_hour.effective_date.in_time_zone.midnight <= this_day.in_time_zone.midnight)
week_hours[number_of_days] = space_hour
break
end
end
end
return week_hours
end
end end
\ No newline at end of file
...@@ -20,23 +20,7 @@ get '/:service_space_url_name/admin/hours/?' do ...@@ -20,23 +20,7 @@ get '/:service_space_url_name/admin/hours/?' do
.where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S')) .where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a .order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a
hours_days = hours.group_by do |space_hour| week_hours = SpaceHour.get_weeks_hours(date, hours)
space_hour.day_of_week
end
week_hours = {}
hours_days.each do |number_of_days, array|
this_day = (sunday + number_of_days.days + 1.hour).midnight
# find the correct hour record to use for this day
array.each do |space_hour|
if space_hour.effective_date.in_time_zone.midnight == this_day.in_time_zone.midnight || (!space_hour.one_off && space_hour.effective_date.in_time_zone.midnight <= this_day.in_time_zone.midnight)
week_hours[number_of_days] = space_hour
break
end
end
end
upcoming_hours = SpaceHour.where(:service_space_id => @space.id) upcoming_hours = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date >= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S')) .where('effective_date >= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where('effective_date <= ?', (date+31.days).utc.strftime('%Y-%m-%d %H:%M:%S')) .where('effective_date <= ?', (date+31.days).utc.strftime('%Y-%m-%d %H:%M:%S'))
......
require 'models/resource' require 'models/resource'
require 'models/permission' require 'models/permission'
require 'models/resource_hour'
before '/:service_space_url_name/admin/resources*' do before '/:service_space_url_name/admin/resources*' do
unless @user.has_permission?(Permission::MANAGE_RESOURCES, @space) unless @user.has_permission?(Permission::MANAGE_RESOURCES, @space)
...@@ -82,6 +83,249 @@ post '/:service_space_url_name/admin/resources/:resource_id/edit/?' do ...@@ -82,6 +83,249 @@ post '/:service_space_url_name/admin/resources/:resource_id/edit/?' do
redirect @space.admin_resources_href redirect @space.admin_resources_href
end end
get '/:service_space_url_name/admin/resources/:resource_id/hours/?' do
@breadcrumbs << {:text => 'Admin Resources', :href => @space.admin_resources_href} << {:text => 'Edit Resource Hours'}
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
# get the hours for this week to show
date = params[:date].nil? ? Time.now.in_time_zone.midnight : Time.parse(params[:date]).in_time_zone.midnight
sunday = date.week_start
hours = ResourceHour.where(:resource_id => resource.id)
.where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a
week_hours = SpaceHour.get_weeks_hours(date, hours)
upcoming_hours = ResourceHour.where(:resource_id => resource.id)
.where('effective_date >= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where('effective_date <= ?', (date+31.days).utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:effective_date).all
erb :'admin/edit_resource_hours', :layout => :fixed, :locals => {
:weeks_hours => week_hours,
:upcoming_hours => upcoming_hours,
:sunday => sunday,
:date => date,
:resource => resource
}
end
get '/:service_space_url_name/admin/resources/:resource_id/hours/create/?' do
@breadcrumbs << {:text => 'Admin Resources', :href => @space.admin_resources_href} << {:text => 'Add Resource Hours'}
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
# show a form for setting a weekly schedule for a day or a one-off
erb :'admin/new_resource_hours', :layout => :fixed, :locals => {
:resource => resource,
:resource_hour => ResourceHour.new,
:hours => session.delete(:hours)
}
end
post '/:service_space_url_name/admin/resources/:resource_id/hours/create/?' do
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
# basically put the inputted data into the database
eff_date = calculate_time(params[:effective_date], 0, 0, 'am').in_time_zone.midnight
day_of_week = params[:day_of_week] == 'one_off' ? eff_date.wday : params[:day_of_week]
# Sort records by start
hours_params = JSON.parse(params[:hours])
hours_params.map! do |record|
start_time = calculate_time(eff_date.strftime('%Y-%m-%d'), record['start_hour'], record['start_minute'], record['start_am_pm'])
end_time = calculate_time(eff_date.strftime('%Y-%m-%d'), record['end_hour'], record['end_minute'], record['end_am_pm'])
{
:status => record['status'],
:start => start_time.hour * 60 + start_time.min,
:end => end_time.hour * 60 + end_time.min
}
end.sort! do |a,b|
a[:start] <=> b[:start]
end
hours_params.each do |record|
if record[:start] > record[:end]
# error here, this is invalid
flash :danger, 'Improper Hours', "Your end times must each be after their start time."
session[:hours] = hours_params
redirect "#{resource.add_hours_href}"
end
end
# check that record starts and ends do not overlap.
zones = []
hours_params.each do |record|
zones.each do |zone|
if zone.include?(record[:start]) || zone.include?(record[:end])
# record starts or ends inside of zone, invalid
flash :danger, 'Improper Hours', "Your hours for this day must not overlap."
session[:hours] = hours_params
redirect "#{resource.add_hours_href}"
elsif zone.min < record[:start] && zone.max > record[:end]
# new record covers entire zone, invalid
flash :danger, 'Improper Hours', "Your hours for this day must not overlap."
session[:hours] = hours_params
redirect "#{resource.add_hours_href}"
end
end
# add this record to the zones
zones << (record[:start]..record[:end])
end
ResourceHour.create({
:resource_id => resource.id,
:day_of_week => day_of_week,
:effective_date => eff_date,
:one_off => params[:day_of_week] == 'one_off',
:hours => hours_params
})
flash :success, 'Hours Saved', "Your hours effective #{eff_date.strftime('%B %d, %Y')} have been saved."
session.delete :hours
redirect resource.edit_hours_href
end
get '/:service_space_url_name/admin/resources/:resource_id/hours/:hour_id/edit/?' do
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
resource_hour = ResourceHour.where(:resource_id => resource.id, :id => params[:hour_id]).first
if resource_hour.nil?
flash :error, 'Not Found', 'Those hours were not found.'
redirect resource.edit_hours_href
end
# show form for editing
erb :'admin/new_resource_hours', :layout => :fixed, :locals => {
:resource => resource,
:resource_hour => session.delete(:resource_hour) || resource_hour,
:hours => session.delete(:hours) || resource_hour.hours
}
end
post '/:service_space_url_name/admin/resources/:resource_id/hours/:hour_id/edit/?' do
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
resource_hour = ResourceHour.where(:resource_id => resource.id, :id => params[:hour_id]).first
if resource_hour.nil?
flash :error, 'Not Found', 'Those hours were not found.'
redirect resource.edit_hours_href
end
# basically put the inputted data into the database
eff_date = calculate_time(params[:effective_date], 0, 0, 'am').in_time_zone.midnight
day_of_week = params[:day_of_week] == 'one_off' ? eff_date.wday : params[:day_of_week]
resource_hour.day_of_week = day_of_week
resource_hour.effective_date = eff_date
resource_hour.one_off = params[:day_of_week] == 'one_off'
# Sort records by start
hours_params = JSON.parse(params[:hours])
hours_params.map! do |record|
start_time = calculate_time(eff_date.strftime('%Y-%m-%d'), record['start_hour'], record['start_minute'], record['start_am_pm'])
end_time = calculate_time(eff_date.strftime('%Y-%m-%d'), record['end_hour'], record['end_minute'], record['end_am_pm'])
{
:status => record['status'],
:start => start_time.hour * 60 + start_time.min,
:end => end_time.hour * 60 + end_time.min
}
end.sort! do |a,b|
a[:start] <=> b[:start]
end
hours_params.each do |record|
if record[:start] > record[:end]
# error here, this is invalid
flash :danger, 'Improper Hours', "Your end times must each be after their start time."
session[:resource_hour] = resource_hour
session[:hours] = hours_params
redirect "#{resource.edit_hours_href}#{resource_hour.id}/edit/"
end
end
# check that record starts and ends do not overlap.
zones = []
hours_params.each do |record|
zones.each do |zone|
if zone.include?(record[:start]) || zone.include?(record[:end])
# record starts or ends inside of zone, invalid
flash :danger, 'Improper Hours', "Your hours for this day must not overlap."
session[:hours] = hours_params
session[:resource_hour] = resource_hour
redirect "#{resource.edit_hours_href}#{resource_hour.id}/edit/"
elsif zone.min < record[:start] && zone.max > record[:end]
# new record covers entire zone, invalid
flash :danger, 'Improper Hours', "Your hours for this day must not overlap."
session[:hours] = hours_params
session[:resource_hour] = resource_hour
redirect "#{resource.edit_hours_href}#{resource_hour.id}/edit/"
end
end
# add this record to the zones
zones << (record[:start]..record[:end])
end
resource_hour.update({
:resource_id => resource.id,
:day_of_week => day_of_week,
:effective_date => eff_date,
:one_off => params[:day_of_week] == 'one_off',
:hours => hours_params
})
flash :success, 'Hours Saved', "Your hours effective #{eff_date.strftime('%B %d, %Y')} have been saved."
session.delete :hours
redirect resource.edit_hours_href
end
post '/:service_space_url_name/admin/resources/:resource_id/hours/:hour_id/delete/?' do
# check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
if resource.nil?
flash(:alert, 'Not Found', 'That resource does not exist.')
redirect @space.admin_resources_href
end
resource_hour = ResourceHour.find_by(:id => params[:hour_id], :resource_id => resource.id)
if resource_hour.nil?
# that space hour does not exist
flash(:danger, 'Not Found', 'That hours record does not exist.')
redirect resource.edit_hours_href
end
resource_hour.delete
flash(:success, 'Hours Change Deleted', "This hours change has been removed.")
redirect resource.edit_hours_href
end
post '/:service_space_url_name/admin/resources/:resource_id/delete/?' do post '/:service_space_url_name/admin/resources/:resource_id/delete/?' do
# check that this is a valid resource # check that this is a valid resource
resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id) resource = Resource.find_by(:id => params[:resource_id], :service_space_id => @space.id)
......
...@@ -38,27 +38,7 @@ get '/:service_space_url_name/resources/:resource_id/calendar/?' do ...@@ -38,27 +38,7 @@ get '/:service_space_url_name/resources/:resource_id/calendar/?' do
# get the reservations for this week # get the reservations for this week
reservations = Reservation.includes(:event, :user).where(:resource_id => resource.id).in_week(date).all reservations = Reservation.includes(:event, :user).where(:resource_id => resource.id).in_week(date).all
# get the space's hours for the week week_hours = resource.get_weeks_available_hours(date)
hours = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date < ?', (sunday+1.week+1.hour).midnight.utc.strftime('%Y-%m-%d %H:%M:%S'))
.order(:day_of_week, :effective_date => :desc, :id => :desc).all.to_a
hours_days = hours.group_by do |space_hour|
space_hour.day_of_week
end
week_hours = {}
hours_days.each do |number_of_days, array|
this_day = (sunday + number_of_days.days + 1.hour).midnight
# find the correct hour record to use for this day
array.each do |space_hour|
if space_hour.effective_date.in_time_zone.midnight == this_day.in_time_zone.midnight || (!space_hour.one_off && space_hour.effective_date.in_time_zone.midnight <= this_day.in_time_zone.midnight)
week_hours[number_of_days] = space_hour
break
end
end
end
erb :resource_calendar, :layout => :fixed, :locals => { erb :resource_calendar, :layout => :fixed, :locals => {
:date => date, :date => date,
...@@ -84,17 +64,9 @@ get '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -84,17 +64,9 @@ get '/:service_space_url_name/resources/:resource_id/reserve/?' do
end end
date = params[:date].nil? ? Time.now.midnight.in_time_zone : Time.parse(params[:date]).midnight.in_time_zone date = params[:date].nil? ? Time.now.midnight.in_time_zone : Time.parse(params[:date]).midnight.in_time_zone
# get the studio's hours for this day
# is there a one_off week_hours = resource.get_weeks_available_hours(date)
space_hour = SpaceHour.where(:service_space_id => @space.id) space_hour = week_hours[date.in_time_zone.wday]
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
available_start_times = [] available_start_times = []
# calculate the available start times for reservation # calculate the available start times for reservation
...@@ -158,17 +130,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -158,17 +130,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
date = start_time.midnight date = start_time.midnight
# validate that the requested time slot falls within the open hours of the day # validate that the requested time slot falls within the open hours of the day
# get the studio's hours for this day
# is there a one_off week_hours = resource.get_weeks_available_hours(date)
space_hour = SpaceHour.where(:service_space_id => @space.id) space_hour = week_hours[date.in_time_zone.wday]
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
unless space_hour.nil? unless space_hour.nil?
# figure out where the closed sections need to be # figure out where the closed sections need to be
...@@ -335,18 +299,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -335,18 +299,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
new_end = new_start + params[:length].to_i.minutes new_end = new_start + params[:length].to_i.minutes
date = new_start.midnight date = new_start.midnight
# validate that the requested time slot falls within the open hours of the day
# get the studio's hours for this day week_hours = resource.get_weeks_available_hours(date)
# is there a one_off space_hour = week_hours[date.in_time_zone.wday]
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
unless space_hour.nil? unless space_hour.nil?
# figure out where the closed sections need to be # figure out where the closed sections need to be
...@@ -461,17 +416,9 @@ get '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservati ...@@ -461,17 +416,9 @@ get '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservati
end end
date = params[:date].nil? ? reservation.start_time.in_time_zone.midnight : Time.parse(params[:date]).midnight.in_time_zone date = params[:date].nil? ? reservation.start_time.in_time_zone.midnight : Time.parse(params[:date]).midnight.in_time_zone
# get the studio's hours for this day
# is there a one_off week_hours = resource.get_weeks_available_hours(date)
space_hour = SpaceHour.where(:service_space_id => @space.id) space_hour = week_hours[date.in_time_zone.wday]
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
available_start_times = [] available_start_times = []
# calculate the available start times for reservation # calculate the available start times for reservation
...@@ -538,18 +485,9 @@ post '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservat ...@@ -538,18 +485,9 @@ post '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservat
end_time = start_time + params[:length].to_i.minutes end_time = start_time + params[:length].to_i.minutes
date = start_time.midnight date = start_time.midnight
# validate that the requested time slot falls within the open hours of the day
# get the studio's hours for this day week_hours = resource.get_weeks_available_hours(date)
# is there a one_off space_hour = week_hours[date.in_time_zone.wday]
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date = ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => true).first
if space_hour.nil?
space_hour = SpaceHour.where(:service_space_id => @space.id)
.where('effective_date <= ?', date.utc.strftime('%Y-%m-%d %H:%M:%S'))
.where(:day_of_week => date.wday).where(:one_off => false)
.order(:effective_date => :desc, :id => :desc).first
end
unless space_hour.nil? unless space_hour.nil?
# figure out where the closed sections need to be # figure out where the closed sections need to be
......
<div id="pagetitle">
<h3>
This Week's Hours for <%= resource.name %>
<span class="wdn-subhead"><%= "#{sunday.strftime("%m/%d")} - #{(sunday+6.days).strftime("%m/%d")}" %></span>
</h3>
</div>
<div style="margin-bottom: 16px;">
<a href="<%= resource.edit_hours_href %>?date=<%= (date-7.days).strftime('%Y-%m-%d') %>" class="wdn-button wdn-button-triad" id="prev-week">&lt; PREV</a>
<a href="<%= resource.edit_hours_href %>?date=<%= (date+7.days).strftime('%Y-%m-%d') %>" class="wdn-button wdn-button-triad" style="float: right;" id="next-week">NEXT &gt;</a>
</div>
<table>
<thead>
<tr>
<th>Day</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<% (0..6).each do |i| %>
<% day = (sunday + i.days + 1.hour).midnight %>
<tr>
<td>
<%= day.strftime('%a %m/%d') %>
</td>
<td>
<% if weeks_hours.has_key?(i) %>
<%= weeks_hours[i].hours.map do |record|
start_time = day + record[:start].minutes
end_time = day + record[:end].minutes
"#{record[:status].capitalize_all}: #{start_time.strftime('%l:%M %P')} - #{end_time.strftime('%l:%M %P')}"
end.join(', ') %>
<% else %>
Defers to Service Space Hours
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<h3>
Upcoming Changes
</h3>
<a class="wdn-button wdn-button-brand" href="<%= resource.add_hours_href %>">Add Hours Change</a><br><br>
<table>
<thead>
<tr>
<th>Day</th>
<th>Hours</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% upcoming_hours.each do |resource_hour| %>
<tr>
<td>
<%= resource_hour.effective_date.strftime('%a %m/%d') %>
</td>
<td>
<% if resource_hour.one_off %>
<%= resource_hour.hours.map do |record|
start_time = resource_hour.effective_date.in_time_zone + record[:start].minutes
end_time = resource_hour.effective_date.in_time_zone + record[:end].minutes
"#{record[:status].capitalize_all}: #{start_time.strftime('%l:%M %P')} - #{end_time.strftime('%l:%M %P')}"
end.join(', ') %>
<% else %>
<strong><%= %w(Sundays Mondays Tuesdays Wednesdays Thursdays Fridays Saturdays)[resource_hour.day_of_week] %></strong> change to:&nbsp;&nbsp;
<%= resource_hour.hours.map do |record|
start_time = resource_hour.effective_date.in_time_zone + record[:start].minutes
end_time = resource_hour.effective_date.in_time_zone + record[:end].minutes
"#{record[:status].capitalize_all}: #{start_time.strftime('%l:%M %P')} - #{end_time.strftime('%l:%M %P')}"
end.join(', ') %>
<% end %>
</td>
<td class="table-actions">
<a class="wdn-button wdn-button-brand" href="<%= @space.admin_resources_href %><%= resource.id %>/hours/<%= resource_hour.id %>/edit/">Edit</a>
<form class="delete-space-hour delete-form" action="<%= @space.admin_resources_href %><%= resource.id %>/hours/<%= resource_hour.id %>/delete/" method="POST">
<button type="submit" class="wdn-button">Remove</button>
</form>
</td>
</tr>
<% end %>
</tbody>
</table>
<script type="text/javascript">
require(['jquery'], function($) {
$(document).ready(function() {
$('.delete-space-hour').submit(function (submit) {
if (!window.confirm('Are you sure you want to remove this hours change?')) {
submit.preventDefault();
}
});
});
});
</script>
\ No newline at end of file
<div id="pagetitle">
<h3>Set New Hours for <%= resource.name %></h3>
</div>
<form id="create-hours" action="" method="POST">
<div class="wdn-grid-set">
<div class="bp1-wdn-col-one-half">
<label for="day-of-week">Day Of Week</label>
<select id="day-of-week" name="day_of_week">
<% (weekdays = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)).each_index do |i| %>
<option <%= 'selected="selected"' if resource_hour.day_of_week == i && !resource_hour.one_off %> value="<%= i %>"><%= weekdays[i] %></option>
<% end %>
<option <%= 'selected="selected"' if resource_hour.one_off %> value="one_off">Set hours for a single day</option>
</select>
<label for="effective-date">Effective Date</label>
<div class="date-time-select">
<span class="wdn-icon-calendar"></span>
<input style="width: 90%;" id="effective-date" name="effective_date" title="Effective Date" type="text" class="datepicker" value="<%= (resource_hour.effective_date || Time.now).strftime('%m/%d/%Y') %>" />
</div>
</div>
</div>
<fieldset>
<legend>Hours</legend>
<label>This resource will not be reservable for any hours not indicated here.</label>
<input type="text" class="hidden" name="hours" id="hours" />
<div id="hours-container">
<% hours = [{:status => 'open', :start => 540, :end => 1020}] if hours.nil? %>
<% hours.each_index do |x| %>
<% record = hours[x] %>
<div id="base-hours-<%=x%>" class="date-time-select hours-record">
<select class="hours-type">
<option <%= 'selected="selected"' if record[:status] == 'open' %> value="open">Open</option>
<option <%= 'selected="selected"' if record[:status] == 'open_without_reservations' %> value="open_without_reservations">Open but Reservations are Not Allowed</option>
<option <%= 'selected="selected"' if record[:status] == 'closed' %> value="closed">Closed</option>
</select>
<label>from</label>
<select class="start-time-hour" title="Start Time Hour">
<option value=""></option>
<% (1..12).each do |i| %>
<option <%= 'selected="selected"' if [y = record[:start] / 60, y+12, y-12].include?(i) %> value="<%= i %>"><%= i %></option>
<% end %>
</select> :
<select class="start-time-minute"title="Start Time Minute">
<option value=""></option>
<% (0..11).each do |i| %>
<option <%= 'selected="selected"' if record[:start] % 60 == i*5 %> value="<%= i * 5 %>"><%= (i*5).to_s.rjust(2, '0') %></option>
<% end %>
</select>
<div class="am_pm">
<input <%= 'checked="checked"' if record[:start] < 720 %> class="start-time-am-pm" title="AM" type="radio" value="am" name="<%= z = String.token %>">AM<br>
<input <%= 'checked="checked"' if record[:start] >= 720 %> class="start-time-am-pm" title="PM" type="radio" value="pm" name="<%= z %>">PM
</div>&nbsp;
<label>until</label>
&nbsp;
<select class="end-time-hour" title="End Time Hour">
<option value=""></option>
<% (1..12).each do |i| %>
<option <%= 'selected="selected"' if [y = record[:end] / 60, y+12, y-12].include?(i) %> value="<%= i %>"><%= i %></option>
<% end %>
</select> :
<select class="end-time-minute"title="End Time Minute">
<option value=""></option>
<% (0..11).each do |i| %>
<option <%= 'selected="selected"' if record[:end] % 60 == i*5 %> value="<%= i * 5 %>"><%= (i*5).to_s.rjust(2, '0') %></option>
<% end %>
</select>
<div class="am_pm">
<input <%= 'checked="checked"' if record[:end] < 720 %> class="end-time-am-pm" title="AM" type="radio" value="am" name="<%= z = String.token %>">AM<br>
<input <%= 'checked="checked"' if record[:end] >= 720 %> class="end-time-am-pm" title="PM" type="radio" value="pm" name="<%= z %>">PM
</div>
&nbsp;
<button title="Remove" type="button" class="<%= 'hidden' if x == 0 %> remove-hours wdn-button">&times;</button>
</div>
<% end %>
</div>
<button id="add-hours" type="button" class="wdn-button wdn-button-complement">Add Hours</button>
</fieldset>
<button type="submit" class="wdn-button wdn-button-brand">Submit</button>
</form>
<script type="text/javascript">
WDN.initializePlugin('jqueryui', [function() {
$ = require('jquery');
$('.datepicker').datepicker();
$("LINK[href^='//unlcms.unl.edu/wdn/templates_4.0/scripts/plugins/ui/css/jquery-ui.min.css']").remove();
$('#hours-container').on('click', '.remove-hours', function(click) {
click.preventDefault();
$(this).closest('.hours-record').remove();
});
$('#add-hours').click(function (click) {
click.preventDefault();
var random1 = Math.random().toString(36).substring(7);
var random2 = Math.random().toString(36).substring(7);
var element = $('#base-hours-0').clone();
element.find('.remove-hours').removeClass('hidden');
element.find('.start-time-am-pm').attr('name', random1);
element.find('.end-time-am-pm').attr('name', random2);
$('#hours-container').append(element);
});
$('#create-hours').submit(function (submit) {
var hours = []
$.each($('.hours-record'), function (index, element) {
element = $(element);
hours.push({
status: element.find('.hours-type').val(),
start_hour: element.find('.start-time-hour').val(),
start_minute: element.find('.start-time-minute').val(),
start_am_pm: element.find('.start-time-am-pm:checked').val(),
end_hour: element.find('.end-time-hour').val(),
end_minute: element.find('.end-time-minute').val(),
end_am_pm: element.find('.end-time-am-pm:checked').val(),
});
});
$('#hours').val(JSON.stringify(hours));
});
}]);
</script>
\ No newline at end of file
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
</td> </td>
<td class="table-actions"> <td class="table-actions">
<a href="/<%= @space.url_name %>/admin/resources/<%= resource.id %>/edit/" class="wdn-button wdn-button-brand">Edit</a> <a href="/<%= @space.url_name %>/admin/resources/<%= resource.id %>/edit/" class="wdn-button wdn-button-brand">Edit</a>
<a href="/<%= @space.url_name %>/admin/resources/<%= resource.id %>/hours/" class="wdn-button wdn-button-triad">Set Hours</a>
<form method="POST" action="/<%= @space.url_name %>/admin/resources/<%= resource.id %>/delete/" class="delete-form delete-resource"> <form method="POST" action="/<%= @space.url_name %>/admin/resources/<%= resource.id %>/delete/" class="delete-form delete-resource">
<button class="wdn-button" type="submit">Delete</button> <button class="wdn-button" type="submit">Delete</button>
</form> </form>
......
...@@ -33,7 +33,7 @@ EIGHT_PM_MINUTES = 1200 # end time of calendar ...@@ -33,7 +33,7 @@ EIGHT_PM_MINUTES = 1200 # end time of calendar
<div class="time-chart"> <div class="time-chart">
<% (12..39).each do |j| %> <% (12..39).each do |j| %>
<div class="calendar-half-hour"> <div class="calendar-half-hour">
<label><%= "#{(j / 2) % 12 + (j==24?12:0)} #{j>=24?'PM':'AM'}" if j % 2 == 0 %></label> <label><%= "#{(j / 2) % 12 + (j==24?12:0)} #{j>=24? 'PM': 'AM'}" if j % 2 == 0 %></label>
</div> </div>
<% end %> <% end %>
</div> </div>
......
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