Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 7fe3e8a

Browse files
committed
#12 rails functions written, returning data, just need js functions to handle them
1 parent de26345 commit 7fe3e8a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

app/models/equipment_model.rb

+23-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def photos
157157
self.documents.images
158158
end
159159

160-
def available?(date_range) #This does not actually return true or false, but rather the number available.
160+
def available?(date_range) # This does not actually return true or false, but rather the number available.
161161
qualification_met = true
162-
if ((a = BlackOut.date_is_blacked_out(date_range.first)) && a.black_out_type_is_hard) || ((a = BlackOut.date_is_blacked_out(date_range.last)) && a.black_out_type_is_hard) #If start or end of range is blacked out, and that is a hard blackout.
162+
if ((a = BlackOut.date_is_blacked_out(date_range.first)) && a.black_out_type_is_hard) || ((a = BlackOut.date_is_blacked_out(date_range.last)) && a.black_out_type_is_hard) # If start or end of range is blacked out, and that is a hard blackout.
163163
return 0
164164
end
165165
overall_count = self.equipment_objects.size
@@ -170,7 +170,7 @@ def available?(date_range) #This does not actually return true or false, but rat
170170
overall_count
171171
end
172172

173-
def model_restricted?(reserver_id) #Returns 0 if the reserver is ineligible to checkout the model.
173+
def model_restricted?(reserver_id) # Returns 0 if the reserver is ineligible to check out the model.
174174
qualification_met = false
175175
unless (Requirement.where(:equipment_model_id => self.id)).empty?
176176
qualification_met = true
@@ -188,6 +188,7 @@ def available_count(date)
188188
# get the total number of objects of this kind
189189
# then subtract the total quantity currently checked out, reserved, or overdue
190190
# TODO: the system does not account for early checkouts; but early checkouts are no longer possible, so non-issue?
191+
# Note that reserved_count also includes the number of reservations currently checked out
191192

192193
reserved_count = Reservation.where("checked_in IS NULL and equipment_model_id = ? and start_date <= ? and due_date >= ?", self.id, date.to_time.utc, date.to_time.utc).size
193194
overdue_count = Reservation.where("checked_in IS NULL and checked_out IS NOT NULL and equipment_model_id = ? and due_date <= ?", self.id, Date.today.to_time.utc).size
@@ -202,5 +203,24 @@ def available_object_select_options
202203
def fake_category_id
203204
self
204205
end
206+
207+
def max_available(date_range)
208+
max_count = 0 # initialize
209+
date_range.each do |date|
210+
if available_count(date) > max_count
211+
max_count = available_count(date)
212+
end
213+
end
214+
return max_count
215+
end
216+
217+
def calendar_data(date_range)
218+
availability_hash = {} # initialize
219+
date_range.each do |date|
220+
# associate each day with the available_count for that day
221+
availability_hash[date] = available_count(date)
222+
end
223+
return availability_hash
224+
end
205225

206226
end

0 commit comments

Comments
 (0)