Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL Resource Scheduler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeff Sturek
UNL Resource Scheduler
Commits
58142083
Commit
58142083
authored
7 years ago
by
Tyler R Lemburg
Browse files
Options
Downloads
Patches
Plain Diff
Make reserve pages respect resource hours in front of space hours if present
parent
d9372991
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
models/resource.rb
+51
-0
51 additions, 0 deletions
models/resource.rb
routes/resources.rb
+16
-78
16 additions, 78 deletions
routes/resources.rb
views/reserve.erb
+1
-1
1 addition, 1 deletion
views/reserve.erb
with
68 additions
and
79 deletions
models/resource.rb
+
51
−
0
View file @
58142083
...
...
@@ -4,10 +4,13 @@ require 'models/resource_authorization'
require
'models/resource_class'
require
'models/resource_field'
require
'models/resource_field_data'
require
'models/resource_hour'
require
'models/space_hour'
class
Resource
<
ActiveRecord
::
Base
belongs_to
:service_space
has_many
:reservations
,
dependent: :destroy
has_many
:resource_hours
,
dependent: :destroy
has_many
:resource_approvers
,
dependent: :destroy
has_many
:resource_authorizations
,
dependent: :destroy
belongs_to
:resource_class
...
...
@@ -41,4 +44,52 @@ class Resource < ActiveRecord::Base
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
\ No newline at end of file
This diff is collapsed.
Click to expand it.
routes/resources.rb
+
16
−
78
View file @
58142083
...
...
@@ -38,27 +38,7 @@ get '/:service_space_url_name/resources/:resource_id/calendar/?' do
# get the reservations for this week
reservations
=
Reservation
.
includes
(
:event
,
:user
).
where
(
:resource_id
=>
resource
.
id
).
in_week
(
date
).
all
# get the space's hours for the week
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
erb
:resource_calendar
,
:layout
=>
:fixed
,
:locals
=>
{
:date
=>
date
,
...
...
@@ -84,17 +64,9 @@ get '/:service_space_url_name/resources/:resource_id/reserve/?' do
end
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
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
space_hour
=
week_hours
[
date
.
in_time_zone
.
wday
]
available_start_times
=
[]
# calculate the available start times for reservation
...
...
@@ -158,17 +130,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
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
# is there a one_off
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
space_hour
=
week_hours
[
date
.
in_time_zone
.
wday
]
unless
space_hour
.
nil?
# figure out where the closed sections need to be
...
...
@@ -335,18 +299,9 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
new_end
=
new_start
+
params
[
:length
].
to_i
.
minutes
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
# is there a one_off
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
space_hour
=
week_hours
[
date
.
in_time_zone
.
wday
]
unless
space_hour
.
nil?
# figure out where the closed sections need to be
...
...
@@ -461,17 +416,9 @@ get '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservati
end
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
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
space_hour
=
week_hours
[
date
.
in_time_zone
.
wday
]
available_start_times
=
[]
# calculate the available start times for reservation
...
...
@@ -538,18 +485,9 @@ post '/:service_space_url_name/resources/:resource_id/edit_reservation/:reservat
end_time
=
start_time
+
params
[
:length
].
to_i
.
minutes
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
# is there a one_off
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
week_hours
=
resource
.
get_weeks_available_hours
(
date
)
space_hour
=
week_hours
[
date
.
in_time_zone
.
wday
]
unless
space_hour
.
nil?
# figure out where the closed sections need to be
...
...
This diff is collapsed.
Click to expand it.
views/reserve.erb
+
1
−
1
View file @
58142083
...
...
@@ -33,7 +33,7 @@ EIGHT_PM_MINUTES = 1200 # end time of calendar
<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>
<label>
<%=
"
#{
(
j
/
2
)
%
12
+
(
j
==
24
?
12
:
0
)
}
#{
j
>=
24
?
'PM'
:
'AM'
}
"
if
j
%
2
==
0
%>
</label>
</div>
<%
end
%>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment