2022-07-18 17:17:21 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-28 18:58:44 +02:00
|
|
|
json.array!(@availabilities) do |availability|
|
|
|
|
json.id availability.id
|
|
|
|
json.start availability.start_at.iso8601
|
|
|
|
json.end availability.end_at.iso8601
|
2016-07-01 12:31:59 +02:00
|
|
|
json.textColor 'black'
|
2016-06-28 18:58:44 +02:00
|
|
|
json.backgroundColor 'white'
|
2022-07-18 17:17:21 +02:00
|
|
|
# availability object (for weeks/months views)
|
2017-02-28 11:59:48 +01:00
|
|
|
if availability.instance_of? Availability
|
2016-07-14 18:36:52 +02:00
|
|
|
json.title availability.title(@title_filter)
|
2022-07-18 17:17:21 +02:00
|
|
|
json.event_id availability.event.id if availability.available_type == 'event'
|
|
|
|
json.training_id availability.trainings.first.id if availability.available_type == 'training'
|
|
|
|
json.space_id availability.spaces.first.id if availability.available_type == 'space'
|
|
|
|
json.machines_ids availability.machines.map(&:id) if availability.available_type == 'machines'
|
2016-06-28 18:58:44 +02:00
|
|
|
json.available_type availability.available_type
|
|
|
|
json.tag_ids availability.tag_ids
|
|
|
|
json.tags availability.tags do |t|
|
|
|
|
json.id t.id
|
|
|
|
json.name t.name
|
|
|
|
end
|
2016-06-29 17:37:22 +02:00
|
|
|
|
2022-07-18 17:17:21 +02:00
|
|
|
json.is_completed availability.full?
|
|
|
|
json.is_reserved availability.is_reserved
|
|
|
|
json.borderColor availability_border_color(availability)
|
|
|
|
if availability.is_reserved && !availability.current_user_slots_reservations_ids.empty?
|
|
|
|
json.title "#{availability.title}' - #{t('trainings.i_ve_reserved')}"
|
|
|
|
elsif availability.full?
|
|
|
|
json.title "#{availability.title} - #{t('trainings.completed')}"
|
|
|
|
json.borderColor AvailabilityHelper::IS_FULL
|
2016-06-29 17:37:22 +02:00
|
|
|
end
|
|
|
|
|
2022-07-18 17:17:21 +02:00
|
|
|
# slot object ( here => availability = slot ), for daily view
|
2017-02-28 11:59:48 +01:00
|
|
|
elsif availability.instance_of? Slot
|
2016-07-14 18:36:52 +02:00
|
|
|
json.title availability.title
|
2016-06-28 18:58:44 +02:00
|
|
|
json.tag_ids availability.availability.tag_ids
|
|
|
|
json.tags availability.availability.tags do |t|
|
|
|
|
json.id t.id
|
|
|
|
json.name t.name
|
|
|
|
end
|
2022-07-18 17:17:21 +02:00
|
|
|
json.is_reserved availability.is_reserved
|
|
|
|
json.is_completed availability.full?
|
2022-07-20 11:22:00 +02:00
|
|
|
case availability.availability.available_type
|
|
|
|
when 'machines'
|
2022-07-18 17:17:21 +02:00
|
|
|
json.machine_ids availability.availability.machines.map(&:id)
|
2017-02-28 11:59:48 +01:00
|
|
|
json.borderColor machines_slot_border_color(availability)
|
2022-07-20 11:22:00 +02:00
|
|
|
when 'space'
|
2022-07-26 12:12:59 +02:00
|
|
|
json.space_id availability.availability.spaces.first.id
|
2017-02-28 11:59:48 +01:00
|
|
|
json.borderColor space_slot_border_color(availability)
|
2022-07-20 11:22:00 +02:00
|
|
|
when 'training'
|
2022-07-18 17:17:21 +02:00
|
|
|
json.training_id availability.availability.trainings.first.id
|
2022-09-14 10:34:12 +02:00
|
|
|
json.borderColor trainings_events_border_color(availability.availability)
|
2022-07-20 11:22:00 +02:00
|
|
|
when 'event'
|
2022-07-18 17:17:21 +02:00
|
|
|
json.event_id availability.availability.event.id
|
2022-09-14 10:34:12 +02:00
|
|
|
json.borderColor trainings_events_border_color(availability.availability)
|
2017-02-28 11:59:48 +01:00
|
|
|
else
|
|
|
|
json.title 'Unknown slot'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
json.title 'Unknown object'
|
2016-06-28 18:58:44 +02:00
|
|
|
end
|
|
|
|
end
|