From 058df21ada3396b19db3df5f695f0b909289f0c6 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 16 Apr 2020 17:11:50 -0400 Subject: [PATCH] fix(calendar(js)): find a free slot for a maximum of 30 days --- .../js/Scheduler/Attendees.service.js | 12 +++++++++-- .../js/Scheduler/ComponentController.js | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/UI/WebServerResources/js/Scheduler/Attendees.service.js b/UI/WebServerResources/js/Scheduler/Attendees.service.js index 426b4492e..37af22577 100644 --- a/UI/WebServerResources/js/Scheduler/Attendees.service.js +++ b/UI/WebServerResources/js/Scheduler/Attendees.service.js @@ -632,6 +632,9 @@ _this.component.end.addMinutes(_this.component.delta); _this.updateFreeBusyCoverage(); return foundDate; + }).catch(function (err) { + _this.updateFreeBusy(); + throw err; }); }; @@ -666,8 +669,13 @@ * @desc Recursively search for the next available slot, one day a the time. * @param {date) currentStart - the starting day */ - Attendees.prototype.step = function(currentStart) { + Attendees.prototype.step = function(currentStart, count) { var _this = this; + if (!parseInt(count)) { + count = 0; + } else if (count >= 30) { + return Attendees.$q.reject(l('There\'s no free slot available for all attendees in the next 30 days. Please try a different date or length.')); + } // var currentStartDay = currentStart.getDayString(); return this.mergeFreebusy(currentStart).then(function () { var foundDate = _this.findDate(currentStart); @@ -680,7 +688,7 @@ if (_this.workDaysOnly) { _this.adjustCurrentStart(currentStart); } - return _this.step(currentStart); + return _this.step(currentStart, count + 1); } }); }; diff --git a/UI/WebServerResources/js/Scheduler/ComponentController.js b/UI/WebServerResources/js/Scheduler/ComponentController.js index f44bb8662..57e9c97f7 100644 --- a/UI/WebServerResources/js/Scheduler/ComponentController.js +++ b/UI/WebServerResources/js/Scheduler/ComponentController.js @@ -205,8 +205,8 @@ /** * @ngInject */ - ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$window', '$element', '$mdDialog', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Alarm', 'Preferences', 'stateComponent']; - function ComponentEditorController($rootScope, $scope, $log, $timeout, $window, $element, $mdDialog, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Alarm, Preferences, stateComponent) { + ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$window', '$element', '$mdDialog', '$mdToast', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Alarm', 'Preferences', 'stateComponent']; + function ComponentEditorController($rootScope, $scope, $log, $timeout, $window, $element, $mdDialog, $mdToast, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Alarm, Preferences, stateComponent) { var vm = this, component, oldStartDate, oldEndDate, oldDueDate, dayStartTime, dayEndTime; this.$onInit = function () { @@ -385,6 +385,22 @@ function findSlot(direction) { vm.component.$attendees.findSlot(direction).then(function () { + }).catch(function (err) { + vm.component.start = new Date(vm.component.start.getTime() + 1); // trigger update in sgFreeBusy + $timeout(scrollToStart); + $mdToast.show({ + template: [ + '', + '
', + ' error_outline', + ' ' + err + '', + '
', + '
' + ].join(''), + hideDelay: 5000, + position: 'top right' + }); + }).finally(function () { $timeout(scrollToStart); }); }