Skip to content

Commit

Permalink
fix(calendar(js)): find a free slot for a maximum of 30 days
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Apr 16, 2020
1 parent 84f3fd5 commit 058df21
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 10 additions & 2 deletions UI/WebServerResources/js/Scheduler/Attendees.service.js
Expand Up @@ -632,6 +632,9 @@
_this.component.end.addMinutes(_this.component.delta);
_this.updateFreeBusyCoverage();
return foundDate;
}).catch(function (err) {
_this.updateFreeBusy();
throw err;
});
};

Expand Down Expand Up @@ -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);
Expand All @@ -680,7 +688,7 @@
if (_this.workDaysOnly) {
_this.adjustCurrentStart(currentStart);
}
return _this.step(currentStart);
return _this.step(currentStart, count + 1);
}
});
};
Expand Down
20 changes: 18 additions & 2 deletions UI/WebServerResources/js/Scheduler/ComponentController.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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: [
'<md-toast>',
' <div class="md-toast-content">',
' <md-icon class="md-warn md-hue-1">error_outline</md-icon>',
' <span flex>' + err + '</span>',
' </div>',
'</md-toast>'
].join(''),
hideDelay: 5000,
position: 'top right'
});
}).finally(function () {
$timeout(scrollToStart);
});
}
Expand Down

0 comments on commit 058df21

Please sign in to comment.