mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) 2 people can book the same machine slot
Also: fix reservation change behavior
This commit is contained in:
parent
d05a6373be
commit
0d072291c7
@ -480,6 +480,7 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
|
||||
*/
|
||||
$scope.markSlotAsModifying = function () {
|
||||
$scope.selectedEvent.backgroundColor = '#eee';
|
||||
$scope.selectedEvent.oldTitle = $scope.selectedEvent.title;
|
||||
$scope.selectedEvent.title = _t('app.logged.machines_reserve.i_change');
|
||||
updateEvents($scope.selectedEvent);
|
||||
};
|
||||
@ -508,8 +509,8 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
|
||||
const save = {
|
||||
slotId: $scope.events.modifiable.slot_id,
|
||||
borderColor: $scope.events.modifiable.borderColor,
|
||||
user: angular.copy($scope.events.modifiable.user),
|
||||
title: (!$scope.events.modifiable.user || $scope.currentUser.id === $scope.events.modifiable.user.id) ? _t('app.logged.machines_reserve.i_ve_reserved') : _t('app.logged.machines_reserve.not_available')
|
||||
users: angular.copy($scope.events.modifiable.users),
|
||||
title: (!$scope.events.modifiable.users || $scope.events.modifiable.users.map(u => u.id).includes($scope.currentUser.id)) ? _t('app.logged.machines_reserve.i_ve_reserved') : _t('app.logged.machines_reserve.not_available')
|
||||
};
|
||||
|
||||
$scope.events.modifiable.backgroundColor = 'white';
|
||||
@ -526,7 +527,7 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
|
||||
$scope.events.placable.slot_id = save.slotId;
|
||||
$scope.events.placable.is_reserved = true;
|
||||
$scope.events.placable.can_modify = true;
|
||||
$scope.events.placable.user = angular.copy(save.user);
|
||||
$scope.events.placable.users = angular.copy(save.users);
|
||||
updateEvents($scope.events.placable);
|
||||
|
||||
refetchCalendar();
|
||||
@ -540,7 +541,7 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
|
||||
$scope.events.placable.backgroundColor = 'white';
|
||||
$scope.events.placable.title = '';
|
||||
}
|
||||
$scope.events.modifiable.title = $scope.currentUser.id === $scope.events.modifiable.user.id ? _t('app.logged.machines_reserve.i_ve_reserved') : _t('app.logged.machines_reserve.not_available');
|
||||
$scope.events.modifiable.title = $scope.events.modifiable.oldTitle;
|
||||
$scope.events.modifiable.backgroundColor = 'white';
|
||||
|
||||
updateEvents($scope.events.placable, $scope.events.modifiable);
|
||||
@ -727,7 +728,7 @@ Application.Controllers.controller('ReserveMachineController', ['$scope', '$tran
|
||||
angular.forEach(reservation.slots, function (s) {
|
||||
if (slot.start.isSame(s.start_at)) {
|
||||
slot.slot_id = s.id;
|
||||
slot.user = user;
|
||||
slot.users = [user];
|
||||
}
|
||||
});
|
||||
updateEvents(slot);
|
||||
|
@ -124,16 +124,16 @@ class Availability < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def available_places_per_slot
|
||||
def available_places_per_slot(reservable = nil)
|
||||
case available_type
|
||||
when 'training'
|
||||
nb_total_places || trainings.map(&:nb_total_places).max
|
||||
nb_total_places || reservable&.nb_total_places || trainings.map(&:nb_total_places).max
|
||||
when 'event'
|
||||
event.nb_total_places
|
||||
when 'space'
|
||||
nb_total_places || spaces.map(&:default_places).max
|
||||
nb_total_places || reservable&.default_places || spaces.map(&:default_places).max
|
||||
when 'machines'
|
||||
machines.count
|
||||
reservable.nil? ? machines.count : 1
|
||||
else
|
||||
raise TypeError
|
||||
end
|
||||
|
@ -12,8 +12,8 @@ class Slot < ApplicationRecord
|
||||
|
||||
attr_accessor :is_reserved, :machine, :space, :title, :can_modify, :current_user_slots_reservations_ids
|
||||
|
||||
def full?
|
||||
availability_places = availability.available_places_per_slot
|
||||
def full?(reservable = nil)
|
||||
availability_places = availability.available_places_per_slot(reservable)
|
||||
return false if availability_places.nil?
|
||||
|
||||
slots_reservations.where(canceled_at: nil).count >= availability_places
|
||||
|
@ -6,7 +6,7 @@ json.title slot.title
|
||||
json.start slot.start_at.iso8601
|
||||
json.end slot.end_at.iso8601
|
||||
json.is_reserved slot.is_reserved
|
||||
json.is_completed slot.full?
|
||||
json.is_completed slot.full?(reservable)
|
||||
json.backgroundColor 'white'
|
||||
|
||||
json.availability_id slot.availability_id
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@slots) do |slot|
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role, reservable: @machine
|
||||
json.borderColor machines_slot_border_color(slot)
|
||||
|
||||
json.machine do
|
||||
|
@ -40,16 +40,17 @@ json.array!(@availabilities) do |availability|
|
||||
end
|
||||
json.is_reserved availability.is_reserved
|
||||
json.is_completed availability.full?
|
||||
if availability.availability.available_type == 'machines'
|
||||
case availability.availability.available_type
|
||||
when 'machines'
|
||||
json.machine_ids availability.availability.machines.map(&:id)
|
||||
json.borderColor machines_slot_border_color(availability)
|
||||
elsif availability.availability.available_type == 'space'
|
||||
when 'space'
|
||||
json.space_id availability.availability.space.first.id
|
||||
json.borderColor space_slot_border_color(availability)
|
||||
elsif availability.availability.available_type == 'training'
|
||||
when 'training'
|
||||
json.training_id availability.availability.trainings.first.id
|
||||
json.borderColor trainings_events_border_color(availability)
|
||||
elsif availability.availability.available_type == 'event'
|
||||
when 'event'
|
||||
json.event_id availability.availability.event.id
|
||||
json.borderColor trainings_events_border_color(availability)
|
||||
else
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@slots) do |slot|
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role, reservable: @space
|
||||
json.is_completed slot.full?
|
||||
json.borderColor space_slot_border_color(slot)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@slots) do |slot|
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role
|
||||
json.partial! 'api/availabilities/slot', slot: slot, operator_role: @operator_role, reservable: slot.availability.trainings.first
|
||||
json.borderColor trainings_events_border_color(slot.availability)
|
||||
|
||||
json.is_completed slot.full?
|
||||
|
Loading…
x
Reference in New Issue
Block a user