mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
Merge remote-tracking branch 'origin/reserve_slots_passed' into dev
This commit is contained in:
commit
146ba97766
@ -112,12 +112,19 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs',
|
||||
* Switch the user's view from the reservation agenda to the plan subscription
|
||||
*/
|
||||
$scope.showPlans = function () {
|
||||
// first, we ensure that a user was selected (admin) or logged (member)
|
||||
if (Object.keys($scope.user).length > 0) {
|
||||
// first, we ensure that a user was selected (admin) or logged (member)
|
||||
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;
|
||||
} else {
|
||||
} else if (!isSelectedUser){
|
||||
// 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'));
|
||||
} 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
|
||||
def machines(machine_id, user)
|
||||
machine = Machine.friendly.find(machine_id)
|
||||
reservations = reservations(machine)
|
||||
reservations = reservations(machine, user)
|
||||
availabilities = availabilities(machine, 'machines', user)
|
||||
|
||||
slots = []
|
||||
availabilities.each do |a|
|
||||
((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(
|
||||
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
|
||||
def spaces(space_id, user)
|
||||
space = Space.friendly.find(space_id)
|
||||
reservations = reservations(space)
|
||||
reservations = reservations(space, user)
|
||||
availabilities = availabilities(space, 'space', user)
|
||||
|
||||
slots = []
|
||||
availabilities.each do |a|
|
||||
((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(
|
||||
start_at: a.start_at + (i * ApplicationHelper::SLOT_DURATION).minutes,
|
||||
@ -69,7 +69,7 @@ class Availabilities::AvailabilitiesService
|
||||
# first, we get the already-made reservations
|
||||
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.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
|
||||
availabilities = training_availabilities(training_id, user)
|
||||
@ -91,18 +91,18 @@ class Availabilities::AvailabilitiesService
|
||||
user.trainings.size.positive? && subscription_year?(user)
|
||||
end
|
||||
|
||||
def reservations(reservable)
|
||||
def reservations(reservable, user)
|
||||
Reservation.where('reservable_type = ? and reservable_id = ?', reservable.class.name, reservable.id)
|
||||
.includes(:slots, statistic_profile: [user: [:profile]])
|
||||
.references(:slots, :user)
|
||||
.where('slots.start_at > ?', DateTime.current)
|
||||
.where('slots.start_at > ?', user.admin? ? 1.month.ago : DateTime.current)
|
||||
end
|
||||
|
||||
def availabilities(reservable, type, user)
|
||||
if user.admin?
|
||||
reservable.availabilities
|
||||
.includes(:tags)
|
||||
.where('end_at > ? AND available_type = ?', DateTime.current, type)
|
||||
.where('end_at > ? AND available_type = ?', 1.month.ago, type)
|
||||
.where(lock: false)
|
||||
else
|
||||
end_at = @maximum_visibility[:other]
|
||||
@ -123,10 +123,10 @@ class Availabilities::AvailabilitiesService
|
||||
end
|
||||
|
||||
# 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?
|
||||
availabilities.includes(:tags, :slots, trainings: [:machines])
|
||||
.where('availabilities.start_at > ?', DateTime.current)
|
||||
.where('availabilities.start_at > ?', 1.month.ago)
|
||||
.where(lock: false)
|
||||
# 2) an user (he cannot see availabilities further than 1 (or 3) months)
|
||||
else
|
||||
|
@ -429,6 +429,7 @@ en:
|
||||
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'
|
||||
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"
|
||||
confirmation_required: "Confirmation required"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
confirmation_required: "Confirmación requerida"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
confirmation_required: "Confirmation requise"
|
||||
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"
|
||||
to_date: "até" # context: date. eg: 'from 01/01 to 01/05'
|
||||
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"
|
||||
confirmation_required: "Confirmação é obrigatória"
|
||||
do_you_really_want_to_cancel_this_reservation: "Você realmente quer cancelar essa reserva?"
|
||||
|
Loading…
x
Reference in New Issue
Block a user