1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

use slot duration from the db setting

This commit is contained in:
Sylvain 2020-05-20 17:36:57 +02:00
parent a63340188b
commit ba4c39ca99
8 changed files with 11 additions and 14 deletions

View File

@ -2,7 +2,7 @@
# API Controller for resources of type Slot
# Slots are used to cut Availabilities into reservable slots. The duration of these slots is configured per
# availability by Availability.slot_duration, or otherwise globally by ApplicationHelper::SLOT_DURATION minutes
# availability by Availability.slot_duration, or otherwise globally by Setting.get('slot_duration')
class API::SlotsController < API::ApiController
before_action :authenticate_user!
before_action :set_slot, only: %i[update cancel]

View File

@ -4,9 +4,6 @@
module ApplicationHelper
require 'message_format'
## machine/spaces availabilities are divided in multiple slots of 60 minutes
SLOT_DURATION ||= Setting.get('slot_duration') || 60
##
# Verify if the provided attribute is in the provided attributes array, whatever it exists or not
# @param attributes {Array|nil}

View File

@ -89,7 +89,7 @@ class Availability < ApplicationRecord
def available_space_places
return unless available_type == 'space'
duration = slot_duration || ApplicationHelper::SLOT_DURATION
duration = slot_duration || Setting.get('slot_duration')
((end_at - start_at) / duration.minutes).to_i * nb_total_places
end
@ -162,7 +162,7 @@ class Availability < ApplicationRecord
def length_must_be_slot_multiple
return unless available_type == 'machines' || available_type == 'space'
duration = slot_duration || ApplicationHelper::SLOT_DURATION
duration = slot_duration || Setting.get('slot_duration')
return unless end_at < (start_at + duration.minutes)
errors.add(:end_at, I18n.t('availabilities.length_must_be_slot_multiple', MIN: duration))

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
# Time range, slicing an Availability.
# Its duration is defined by globally by ApplicationHelper::SLOT_DURATION but can be overridden per availability
# Its duration is defined by globally by Setting.get('slot_duration') but can be overridden per availability
# During a slot a Reservation is possible
# Only reserved slots are persisted in DB, others are instantiated on the fly
class Slot < ApplicationRecord

View File

@ -17,7 +17,7 @@ class Availabilities::AvailabilitiesService
slots = []
availabilities.each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i|
next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current || user.admin?
@ -44,7 +44,7 @@ class Availabilities::AvailabilitiesService
slots = []
availabilities.each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i|
next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current || user.admin?

View File

@ -15,7 +15,7 @@ class Availabilities::PublicAvailabilitiesService
.where(lock: false)
slots = []
availabilities.each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
a.machines.each do |machine|
next unless machine_ids&.include?(machine.id.to_s)
@ -46,7 +46,7 @@ class Availabilities::PublicAvailabilitiesService
slots = []
availabilities.each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
space = a.spaces.first
((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i|
next unless (a.start_at + (i * slot_duration).minutes) > DateTime.current

View File

@ -31,7 +31,7 @@
Fablab.fablabWithoutWallet = ('<%= Rails.application.secrets.fablab_without_wallet %>' === 'true');
Fablab.bookSlotAtSameTime = ('<%= Setting.get('book_overlapping_slots') %>' === 'true');
Fablab.eventsInCalendar = ('<%= Rails.application.secrets.events_in_calendar %>' === 'true');
Fablab.slotDuration = parseInt("<%= ApplicationHelper::SLOT_DURATION %>", 10);
Fablab.slotDuration = parseInt("<%= Setting.get('slot_duration') %>", 10);
Fablab.featureTourDisplay = "<%= Rails.application.secrets.feature_tour_display %>";
Fablab.disqusShortname = "<%= Rails.application.secrets.disqus_shortname %>";
Fablab.defaultHost = "<%= Rails.application.secrets.default_host %>";

View File

@ -16,7 +16,7 @@ wb.add_worksheet(name: t('export_availabilities.machines')) do |sheet|
# data rows
@availabilities.where(available_type: 'machines').order(:start_at).each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
a.machines.each do |m|
((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i|
start_at = a.start_at + (i * slot_duration).minutes
@ -84,7 +84,7 @@ if Rails.application.secrets.fablab_without_spaces != 'false'
# data rows
@availabilities.where(available_type: 'space').order(:start_at).each do |a|
slot_duration = a.slot_duration || ApplicationHelper::SLOT_DURATION
slot_duration = a.slot_duration || Setting.get('slot_duration')
((a.end_at - a.start_at) / slot_duration.minutes).to_i.times do |i|
start_at = a.start_at + (i * slot_duration).minutes
end_at = a.start_at + (i * slot_duration).minutes + slot_duration.minutes