fix(calendar(js)): find a free slot for a maximum of 30 days

pull/274/head
Francis Lachapelle 2020-04-16 17:11:50 -04:00
parent 84f3fd5e1c
commit 058df21ada
2 changed files with 28 additions and 4 deletions

View File

@ -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);
}
});
};

View File

@ -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: [
'<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);
});
}