diff --git a/app/controllers/api/availabilities_controller.rb b/app/controllers/api/availabilities_controller.rb index 73f890e30..c059fe0dc 100644 --- a/app/controllers/api/availabilities_controller.rb +++ b/app/controllers/api/availabilities_controller.rb @@ -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 diff --git a/app/frontend/src/javascript/controllers/admin/calendar.js b/app/frontend/src/javascript/controllers/admin/calendar.js index 36565d417..cb290a790 100644 --- a/app/frontend/src/javascript/controllers/admin/calendar.js +++ b/app/frontend/src/javascript/controllers/admin/calendar.js @@ -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())}`; diff --git a/app/frontend/src/javascript/controllers/calendar.js b/app/frontend/src/javascript/controllers/calendar.js index 743da2999..78933ec11 100644 --- a/app/frontend/src/javascript/controllers/calendar.js +++ b/app/frontend/src/javascript/controllers/calendar.js @@ -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(); diff --git a/app/frontend/templates/calendar/filter.html b/app/frontend/templates/calendar/filter.html index a88ffd769..61253b790 100644 --- a/app/frontend/templates/calendar/filter.html +++ b/app/frontend/templates/calendar/filter.html @@ -1,3 +1,17 @@ +