mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-22 16:54:15 +01:00
Merge remote-tracking branch 'origin/reserve_slots_passed' into dev
This commit is contained in:
commit
146ba97766
@ -113,11 +113,18 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
|||||||
*/
|
*/
|
||||||
$scope.showPlans = function () {
|
$scope.showPlans = function () {
|
||||||
// first, we ensure that a user was selected (admin) or logged (member)
|
// first, we ensure that a user was selected (admin) or logged (member)
|
||||||
if (Object.keys($scope.user).length > 0) {
|
const isSelectedUser = Object.keys($scope.user).length > 0;
|
||||||
|
// all slots are in future
|
||||||
|
const areFutureSlots = _.every($scope.events.reserved, function(s) {
|
||||||
|
return s.start.isAfter();
|
||||||
|
});
|
||||||
|
if (isSelectedUser && areFutureSlots) {
|
||||||
return $scope.modePlans = true;
|
return $scope.modePlans = true;
|
||||||
} else {
|
} else if (!isSelectedUser){
|
||||||
// otherwise we alert, this error musn't occur when the current user hasn't the admin role
|
// otherwise we alert, this error musn't occur when the current user hasn't the admin role
|
||||||
return growl.error(_t('app.shared.cart.please_select_a_member_first'));
|
return growl.error(_t('app.shared.cart.please_select_a_member_first'));
|
||||||
|
} else if (!areFutureSlots){
|
||||||
|
return growl.error(_t('app.shared.cart.unable_to_select_plant_if_slots_in_the_past'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,13 +12,13 @@ class Availabilities::AvailabilitiesService
|
|||||||
# list all slots for the given machine, with reservations info, relatives to the given user
|
# list all slots for the given machine, with reservations info, relatives to the given user
|
||||||
def machines(machine_id, user)
|
def machines(machine_id, user)
|
||||||
machine = Machine.friendly.find(machine_id)
|
machine = Machine.friendly.find(machine_id)
|
||||||
reservations = reservations(machine)
|
reservations = reservations(machine, user)
|
||||||
availabilities = availabilities(machine, 'machines', user)
|
availabilities = availabilities(machine, 'machines', user)
|
||||||
|
|
||||||
slots = []
|
slots = []
|
||||||
availabilities.each do |a|
|
availabilities.each do |a|
|
||||||
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
||||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current
|
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current || user.admin?
|
||||||
|
|
||||||
slot = Slot.new(
|
slot = Slot.new(
|
||||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||||
@ -38,13 +38,13 @@ class Availabilities::AvailabilitiesService
|
|||||||
# list all slots for the given space, with reservations info, relatives to the given user
|
# list all slots for the given space, with reservations info, relatives to the given user
|
||||||
def spaces(space_id, user)
|
def spaces(space_id, user)
|
||||||
space = Space.friendly.find(space_id)
|
space = Space.friendly.find(space_id)
|
||||||
reservations = reservations(space)
|
reservations = reservations(space, user)
|
||||||
availabilities = availabilities(space, 'space', user)
|
availabilities = availabilities(space, 'space', user)
|
||||||
|
|
||||||
slots = []
|
slots = []
|
||||||
availabilities.each do |a|
|
availabilities.each do |a|
|
||||||
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
((a.end_at - a.start_at) / ApplicationHelper::SLOT_DURATION.minutes).to_i.times do |i|
|
||||||
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current
|
next unless (a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes) > DateTime.current || user.admin?
|
||||||
|
|
||||||
slot = Slot.new(
|
slot = Slot.new(
|
||||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||||
@ -69,7 +69,7 @@ class Availabilities::AvailabilitiesService
|
|||||||
# first, we get the already-made reservations
|
# first, we get the already-made reservations
|
||||||
reservations = user.reservations.where("reservable_type = 'Training'")
|
reservations = user.reservations.where("reservable_type = 'Training'")
|
||||||
reservations = reservations.where('reservable_id = :id', id: training_id.to_i) if training_id.is_number?
|
reservations = reservations.where('reservable_id = :id', id: training_id.to_i) if training_id.is_number?
|
||||||
reservations = reservations.joins(:slots).where('slots.start_at > ?', DateTime.current)
|
reservations = reservations.joins(:slots).where('slots.start_at > ?', @current_user.admin? ? 1.month.ago : DateTime.current)
|
||||||
|
|
||||||
# visible availabilities depends on multiple parameters
|
# visible availabilities depends on multiple parameters
|
||||||
availabilities = training_availabilities(training_id, user)
|
availabilities = training_availabilities(training_id, user)
|
||||||
@ -91,18 +91,18 @@ class Availabilities::AvailabilitiesService
|
|||||||
user.trainings.size.positive? && subscription_year?(user)
|
user.trainings.size.positive? && subscription_year?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reservations(reservable)
|
def reservations(reservable, user)
|
||||||
Reservation.where('reservable_type = ? and reservable_id = ?', reservable.class.name, reservable.id)
|
Reservation.where('reservable_type = ? and reservable_id = ?', reservable.class.name, reservable.id)
|
||||||
.includes(:slots, statistic_profile: [user: [:profile]])
|
.includes(:slots, statistic_profile: [user: [:profile]])
|
||||||
.references(:slots, :user)
|
.references(:slots, :user)
|
||||||
.where('slots.start_at > ?', DateTime.current)
|
.where('slots.start_at > ?', user.admin? ? 1.month.ago : DateTime.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
def availabilities(reservable, type, user)
|
def availabilities(reservable, type, user)
|
||||||
if user.admin?
|
if user.admin?
|
||||||
reservable.availabilities
|
reservable.availabilities
|
||||||
.includes(:tags)
|
.includes(:tags)
|
||||||
.where('end_at > ? AND available_type = ?', DateTime.current, type)
|
.where('end_at > ? AND available_type = ?', 1.month.ago, type)
|
||||||
.where(lock: false)
|
.where(lock: false)
|
||||||
else
|
else
|
||||||
end_at = @maximum_visibility[:other]
|
end_at = @maximum_visibility[:other]
|
||||||
@ -123,10 +123,10 @@ class Availabilities::AvailabilitiesService
|
|||||||
end
|
end
|
||||||
|
|
||||||
# who made the request?
|
# who made the request?
|
||||||
# 1) an admin (he can see all future availabilities)
|
# 1) an admin (he can see all avaialbilities of 1 month ago and future)
|
||||||
if @current_user.admin?
|
if @current_user.admin?
|
||||||
availabilities.includes(:tags, :slots, trainings: [:machines])
|
availabilities.includes(:tags, :slots, trainings: [:machines])
|
||||||
.where('availabilities.start_at > ?', DateTime.current)
|
.where('availabilities.start_at > ?', 1.month.ago)
|
||||||
.where(lock: false)
|
.where(lock: false)
|
||||||
# 2) an user (he cannot see availabilities further than 1 (or 3) months)
|
# 2) an user (he cannot see availabilities further than 1 (or 3) months)
|
||||||
else
|
else
|
||||||
|
@ -429,6 +429,7 @@ en:
|
|||||||
your_booking_slot_was_successfully_moved_from_: "Your booking slot was successfully moved from"
|
your_booking_slot_was_successfully_moved_from_: "Your booking slot was successfully moved from"
|
||||||
to_date: "to" # context: date. eg: 'from 01/01 to 01/05'
|
to_date: "to" # context: date. eg: 'from 01/01 to 01/05'
|
||||||
please_select_a_member_first: 'Please select a member first'
|
please_select_a_member_first: 'Please select a member first'
|
||||||
|
unable_to_select_plant_if_slots_in_the_past: 'Unable to select a plan if have selected slots in the past'
|
||||||
unable_to_change_the_reservation: "Unable to change the reservation"
|
unable_to_change_the_reservation: "Unable to change the reservation"
|
||||||
confirmation_required: "Confirmation required"
|
confirmation_required: "Confirmation required"
|
||||||
do_you_really_want_to_cancel_this_reservation: "Do you really want to cancel this reservation?"
|
do_you_really_want_to_cancel_this_reservation: "Do you really want to cancel this reservation?"
|
||||||
|
@ -429,6 +429,7 @@ es:
|
|||||||
your_booking_slot_was_successfully_moved_from_: "Tu reserva de espacio ha sido reemplazada con éxito"
|
your_booking_slot_was_successfully_moved_from_: "Tu reserva de espacio ha sido reemplazada con éxito"
|
||||||
to_date: "a" # context: date. eg: 'from 01/01 to 01/05'
|
to_date: "a" # context: date. eg: 'from 01/01 to 01/05'
|
||||||
please_select_a_member_first: "Por favor, selecciona un miembro de la lista"
|
please_select_a_member_first: "Por favor, selecciona un miembro de la lista"
|
||||||
|
unable_to_select_plant_if_slots_in_the_past: 'No se puede seleccionar un plan si ha seleccionado espacios en el pasado'
|
||||||
unable_to_change_the_reservation: "Imposible cambiar reserva"
|
unable_to_change_the_reservation: "Imposible cambiar reserva"
|
||||||
confirmation_required: "Confirmación requerida"
|
confirmation_required: "Confirmación requerida"
|
||||||
do_you_really_want_to_cancel_this_reservation: "¿Está seguro de querer cancelar la reserva?"
|
do_you_really_want_to_cancel_this_reservation: "¿Está seguro de querer cancelar la reserva?"
|
||||||
|
@ -429,6 +429,7 @@ fr:
|
|||||||
your_booking_slot_was_successfully_moved_from_: "Votre créneau de réservation a bien été déplacé du"
|
your_booking_slot_was_successfully_moved_from_: "Votre créneau de réservation a bien été déplacé du"
|
||||||
to_date: "au" # context: date. eg: 'from 01/01 to 01/05'
|
to_date: "au" # context: date. eg: 'from 01/01 to 01/05'
|
||||||
please_select_a_member_first: "Veuillez tout d'abord sélectionner un membre"
|
please_select_a_member_first: "Veuillez tout d'abord sélectionner un membre"
|
||||||
|
unable_to_select_plant_if_slots_in_the_past: "Impossible de selectionner un abonnement s'il y a des créneaux passés"
|
||||||
unable_to_change_the_reservation: "Impossible de modifier la réservation"
|
unable_to_change_the_reservation: "Impossible de modifier la réservation"
|
||||||
confirmation_required: "Confirmation requise"
|
confirmation_required: "Confirmation requise"
|
||||||
do_you_really_want_to_cancel_this_reservation: "Êtes-vous sur de vouloir annuler cette réservation ?"
|
do_you_really_want_to_cancel_this_reservation: "Êtes-vous sur de vouloir annuler cette réservation ?"
|
||||||
|
@ -429,6 +429,7 @@ pt:
|
|||||||
your_booking_slot_was_successfully_moved_from_: "Seu slot de reserva foi movido com sucesso para"
|
your_booking_slot_was_successfully_moved_from_: "Seu slot de reserva foi movido com sucesso para"
|
||||||
to_date: "até" # context: date. eg: 'from 01/01 to 01/05'
|
to_date: "até" # context: date. eg: 'from 01/01 to 01/05'
|
||||||
please_select_a_member_first: "Por favor selecione o membro primeiramente"
|
please_select_a_member_first: "Por favor selecione o membro primeiramente"
|
||||||
|
unable_to_select_plant_if_slots_in_the_past: 'Não foi possível selecionar um plano se houver slots selecionados no passado'
|
||||||
unable_to_change_the_reservation: "Não permitido alterar esta reserva"
|
unable_to_change_the_reservation: "Não permitido alterar esta reserva"
|
||||||
confirmation_required: "Confirmação é obrigatória"
|
confirmation_required: "Confirmação é obrigatória"
|
||||||
do_you_really_want_to_cancel_this_reservation: "Você realmente quer cancelar essa reserva?"
|
do_you_really_want_to_cancel_this_reservation: "Você realmente quer cancelar essa reserva?"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user