2019-04-04 09:33:41 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Helpers methods about calendar availabilities
|
2016-06-28 12:45:41 +02:00
|
|
|
module AvailabilityHelper
|
|
|
|
MACHINE_COLOR = '#e4cd78'
|
|
|
|
TRAINING_COLOR = '#bd7ae9'
|
2017-02-15 13:18:03 +01:00
|
|
|
SPACE_COLOR = '#3fc7ff'
|
2016-06-28 12:45:41 +02:00
|
|
|
EVENT_COLOR = '#dd7e6b'
|
|
|
|
IS_RESERVED_BY_CURRENT_USER = '#b2e774'
|
2022-07-12 17:46:01 +02:00
|
|
|
IS_FULL = '#eeeeee'
|
2016-06-28 12:45:41 +02:00
|
|
|
|
|
|
|
def availability_border_color(availability)
|
2017-02-15 13:18:03 +01:00
|
|
|
case availability.available_type
|
2019-04-04 09:33:41 +02:00
|
|
|
when 'machines'
|
|
|
|
MACHINE_COLOR
|
|
|
|
when 'training'
|
|
|
|
TRAINING_COLOR
|
|
|
|
when 'space'
|
|
|
|
SPACE_COLOR
|
|
|
|
else
|
|
|
|
EVENT_COLOR
|
2016-06-28 12:45:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-19 14:39:41 +01:00
|
|
|
# @param slot [Slot]
|
2023-02-24 15:16:57 +01:00
|
|
|
# @param reservable [Machine]
|
2023-01-19 14:39:41 +01:00
|
|
|
# @param customer [User]
|
2023-02-24 15:16:57 +01:00
|
|
|
def machines_slot_border_color(slot, reservable = nil, customer = nil)
|
|
|
|
if slot.reserved?(reservable)
|
|
|
|
slot.reserved_by?(customer&.id, [reservable]) ? IS_RESERVED_BY_CURRENT_USER : IS_FULL
|
2017-02-23 17:45:55 +01:00
|
|
|
else
|
|
|
|
MACHINE_COLOR
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def space_slot_border_color(slot)
|
2023-01-19 11:34:48 +01:00
|
|
|
if slot.reserved?
|
2017-02-27 16:15:27 +01:00
|
|
|
IS_RESERVED_BY_CURRENT_USER
|
2022-07-12 17:46:01 +02:00
|
|
|
elsif slot.full?
|
|
|
|
IS_FULL
|
2017-02-23 17:45:55 +01:00
|
|
|
else
|
|
|
|
SPACE_COLOR
|
|
|
|
end
|
2016-06-28 12:45:41 +02:00
|
|
|
end
|
|
|
|
|
2016-06-29 17:37:22 +02:00
|
|
|
def trainings_events_border_color(availability)
|
2023-01-19 11:34:48 +01:00
|
|
|
if availability.reserved?
|
2016-06-28 12:45:41 +02:00
|
|
|
IS_RESERVED_BY_CURRENT_USER
|
2022-06-29 10:30:17 +02:00
|
|
|
elsif availability.full?
|
2022-07-12 17:46:01 +02:00
|
|
|
IS_FULL
|
2016-06-28 12:45:41 +02:00
|
|
|
else
|
2017-02-23 17:45:55 +01:00
|
|
|
case availability.available_type
|
2019-04-04 09:33:41 +02:00
|
|
|
when 'training'
|
|
|
|
TRAINING_COLOR
|
|
|
|
when 'event'
|
|
|
|
EVENT_COLOR
|
|
|
|
when 'space'
|
|
|
|
SPACE_COLOR
|
|
|
|
else
|
|
|
|
'#000'
|
2016-06-29 17:37:22 +02:00
|
|
|
end
|
2016-06-28 12:45:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|