mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
(feat) Ability to filter uniq slots reserved in admin calendar
This commit is contained in:
parent
a740d984ee
commit
29b92475bb
@ -163,10 +163,19 @@ class API::AvailabilitiesController < API::ApiController
|
||||
end
|
||||
|
||||
def filter_availabilites(availabilities)
|
||||
availabilities.delete_if(&method(:remove_full?))
|
||||
availabilities_filterd = availabilities
|
||||
availabilities_filterd = availabilities.delete_if(&method(:remove_full?)) if params[:dispo] == 'false'
|
||||
|
||||
availabilities_filterd = availabilities.delete_if(&method(:remove_empty?)) if params[:reserved] == 'true'
|
||||
|
||||
availabilities_filterd
|
||||
end
|
||||
|
||||
def remove_full?(availability)
|
||||
params[:dispo] == 'false' && (availability.is_reserved || (availability.try(:full?) && availability.full?))
|
||||
availability.try(:full?) && availability.full?
|
||||
end
|
||||
|
||||
def remove_empty?(availability)
|
||||
availability.try(:empty?) && availability.empty?
|
||||
end
|
||||
end
|
||||
|
@ -376,7 +376,8 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
|
||||
machines: isSelectAll('machines', scope),
|
||||
spaces: isSelectAll('spaces', scope),
|
||||
evt: filter.evt,
|
||||
dispo: filter.dispo
|
||||
dispo: filter.dispo,
|
||||
reserved: filter.reserved
|
||||
});
|
||||
scope.machinesGroupByCategory.forEach(c => c.checked = _.every(c.machines, 'checked'));
|
||||
// remove all
|
||||
@ -395,7 +396,8 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
|
||||
machines: isSelectAll('machines', $scope),
|
||||
spaces: isSelectAll('spaces', $scope),
|
||||
evt: true,
|
||||
dispo: true
|
||||
dispo: true,
|
||||
reserved: false
|
||||
};
|
||||
|
||||
// toggle to select all formation/machine
|
||||
@ -444,7 +446,7 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
|
||||
return $scope.filterAvailabilities;
|
||||
}
|
||||
},
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'machinesGroupByCategory', 'spaces', 'filter', 'toggleFilter', 'filterAvailabilities', function ($scope, $uibModalInstance, trainings, machines, machinesGroupByCategory, spaces, filter, toggleFilter, filterAvailabilities) {
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'machinesGroupByCategory', 'spaces', 'filter', 'toggleFilter', 'filterAvailabilities', 'AuthService', function ($scope, $uibModalInstance, trainings, machines, machinesGroupByCategory, spaces, filter, toggleFilter, filterAvailabilities, AuthService) {
|
||||
$scope.trainings = trainings;
|
||||
$scope.machines = machines;
|
||||
$scope.machinesGroupByCategory = machinesGroupByCategory;
|
||||
@ -464,6 +466,8 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
|
||||
|
||||
$scope.filterAvailabilities = filter => filterAvailabilities(filter, $scope);
|
||||
|
||||
$scope.isAuthorized = AuthService.isAuthorized;
|
||||
|
||||
return $scope.close = function (e) {
|
||||
$uibModalInstance.dismiss();
|
||||
return e.stopPropagation();
|
||||
@ -476,7 +480,7 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
|
||||
const t = $scope.trainings.filter(t => t.checked).map(t => t.id);
|
||||
const m = $scope.machines.filter(m => m.checked).map(m => m.id);
|
||||
const s = $scope.spaces.filter(s => s.checked).map(s => s.id);
|
||||
return { t, m, s, evt: $scope.filter.evt, dispo: $scope.filter.dispo };
|
||||
return { t, m, s, evt: $scope.filter.evt, dispo: $scope.filter.dispo, reserved: $scope.filter.reserved };
|
||||
};
|
||||
|
||||
const availabilitySourceUrl = () => `/api/availabilities?${$.param(getFilter())}`;
|
||||
|
@ -159,7 +159,7 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
||||
return $scope.filterAvailabilities;
|
||||
}
|
||||
},
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'machinesGroupByCategory', 'spaces', 'externals', 'filter', 'toggleFilter', 'filterAvailabilities', function ($scope, $uibModalInstance, trainings, machines, machinesGroupByCategory, spaces, externals, filter, toggleFilter, filterAvailabilities) {
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'machinesGroupByCategory', 'spaces', 'externals', 'filter', 'toggleFilter', 'filterAvailabilities', 'AuthService', function ($scope, $uibModalInstance, trainings, machines, machinesGroupByCategory, spaces, externals, filter, toggleFilter, filterAvailabilities, AuthService) {
|
||||
$scope.trainings = trainings;
|
||||
$scope.machines = machines;
|
||||
$scope.machinesGroupByCategory = machinesGroupByCategory;
|
||||
@ -180,6 +180,8 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
|
||||
|
||||
$scope.filterAvailabilities = filter => filterAvailabilities(filter, $scope);
|
||||
|
||||
$scope.isAuthorized = AuthService.isAuthorized;
|
||||
|
||||
return $scope.close = function (e) {
|
||||
$uibModalInstance.dismiss();
|
||||
return e.stopPropagation();
|
||||
|
@ -1,3 +1,17 @@
|
||||
<div class="row m-b" ng-if="isAuthorized(['admin', 'manager'])">
|
||||
<h3 class="col-md-8 col-sm-8 col-xs-8 text-black" translate>{{ 'app.shared.calendar.show_reserved_uniq' }}</h3>
|
||||
<div class="col-md-4 col-sm-4 col-xs-4">
|
||||
<input bs-switch
|
||||
ng-model="filter.reserved"
|
||||
type="checkbox"
|
||||
switch-size="small"
|
||||
switch-on-text="{{ 'app.shared.buttons.yes' | translate }}"
|
||||
switch-off-text="{{ 'app.shared.buttons.no' | translate }}"
|
||||
switch-animate="true"
|
||||
ng-change="filterAvailabilities(filter)"
|
||||
switch-animate="true"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-black" translate>{{ 'app.shared.calendar.show_unavailables' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.dispo" ng-change="filterAvailabilities(filter)">
|
||||
|
@ -115,7 +115,7 @@ class Availability < ApplicationRecord
|
||||
# check if the reservations are complete?
|
||||
# if a nb_total_places hasn't been defined, then places are unlimited
|
||||
def full?
|
||||
return false if nb_total_places.blank?
|
||||
return false if nb_total_places.blank? && available_type != 'machines'
|
||||
|
||||
if available_type == 'event'
|
||||
event.nb_free_places.zero?
|
||||
@ -124,6 +124,11 @@ class Availability < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# check availability don't have any reservation
|
||||
def empty?
|
||||
slots.map(&:empty?).reduce(:&)
|
||||
end
|
||||
|
||||
def available_places_per_slot(reservable = nil)
|
||||
case available_type
|
||||
when 'training'
|
||||
|
@ -23,6 +23,14 @@ class Slot < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def empty?(reservable = nil)
|
||||
if reservable.nil?
|
||||
slots_reservations.where(canceled_at: nil).count.zero?
|
||||
else
|
||||
slots_reservations.includes(:reservation).where(canceled_at: nil).where('reservations.reservable': reservable).count.zero?
|
||||
end
|
||||
end
|
||||
|
||||
def duration
|
||||
(end_at - start_at).seconds
|
||||
end
|
||||
|
@ -536,5 +536,6 @@ en:
|
||||
spaces: "Spaces"
|
||||
events: "Events"
|
||||
externals: "Other calendars"
|
||||
show_reserved_uniq: "Show reserved slots only"
|
||||
machine:
|
||||
machine_uncategorized: "Uncategorized machines"
|
||||
|
@ -536,5 +536,6 @@ fr:
|
||||
spaces: "Espaces"
|
||||
events: "Événements"
|
||||
externals: "Autres calendriers"
|
||||
show_reserved_uniq: "Voir les créneaux réservés uniquement"
|
||||
machine:
|
||||
machine_uncategorized: "Machines non classés"
|
||||
|
@ -15,4 +15,12 @@ class AvailabilityTest < ActiveSupport::TestCase
|
||||
assert a.invalid?
|
||||
assert a.errors.key?(:machine_ids)
|
||||
end
|
||||
|
||||
test 'return empty = true if availability dont have any reservation' do
|
||||
not_reserved = Availability.find(1)
|
||||
assert not_reserved.empty?
|
||||
|
||||
reserved = Availability.find(13)
|
||||
assert_not reserved.empty?
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user