Allow days/hours to be selected for auto update schedule
This commit is contained in:
@@ -14,6 +14,26 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
|
||||
$scope.subscription = null;
|
||||
$scope.subscriptionBusy = true;
|
||||
|
||||
// values correspond to cron days
|
||||
$scope.cronDays = [
|
||||
{ name: 'Sunday', value: 0 },
|
||||
{ name: 'Monday', value: 1 },
|
||||
{ name: 'Tuesday', value: 2 },
|
||||
{ name: 'Wednesday', value: 3 },
|
||||
{ name: 'Thursday', value: 4 },
|
||||
{ name: 'Friday', value: 5 },
|
||||
{ name: 'Saturday', value: 6 },
|
||||
];
|
||||
|
||||
$scope.cronHours = [
|
||||
{ name: 'Midnight', value: 0 }, { name: '1 AM', value: 1 }, { name: '2 AM', value: 2 }, { name: '3 AM', value: 3 },
|
||||
{ name: '4 AM', value: 4 }, { name: '5 AM', value: 5 }, { name: '6 AM', value: 6 }, { name: '7 AM', value: 7 },
|
||||
{ name: '8 AM', value: 8 }, { name: '9 AM', value: 9 }, { name: '10 AM', value: 10 }, { name: '11 AM', value: 11 },
|
||||
{ name: 'Noon', value: 12 }, { name: '1 PM', value: 13 }, { name: '2 PM', value: 14 }, { name: '3 PM', value: 15 },
|
||||
{ name: '4 PM', value: 16 }, { name: '5 PM', value: 17 }, { name: '6 PM', value: 18 }, { name: '7 PM', value: 19 },
|
||||
{ name: '8 PM', value: 20 }, { name: '9 PM', value: 21 }, { name: '10 PM', value: 22 }, { name: '11 PM', value: 23 }
|
||||
];
|
||||
|
||||
$scope.openSubscriptionSetup = function () {
|
||||
Client.openSubscriptionSetup($scope.subscription || {});
|
||||
};
|
||||
@@ -25,6 +45,22 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
|
||||
}
|
||||
};
|
||||
|
||||
$scope.prettyAutoUpdateSchedule = function (pattern) {
|
||||
if (!pattern) return '';
|
||||
var tmp = pattern.split(' ');
|
||||
var hours = tmp[2].split(','), days = tmp[5].split(',');
|
||||
var prettyDay;
|
||||
if (days.length === 7 || days[0] === '*') {
|
||||
prettyDay = 'Everyday';
|
||||
} else {
|
||||
prettyDay = days.map(function (day) { return $scope.cronDays[parseInt(day, 10)].name.substr(0, 3); }).join(',');
|
||||
}
|
||||
|
||||
var prettyHour = hours.map(function (hour) { return $scope.cronHours[parseInt(hour, 10)].name; }).join(',');
|
||||
|
||||
return prettyDay + ' at ' + prettyHour;
|
||||
};
|
||||
|
||||
$scope.update = {
|
||||
error: {}, // this is for the dialog
|
||||
busy: false,
|
||||
@@ -157,22 +193,47 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
|
||||
}
|
||||
};
|
||||
|
||||
$scope.autoUpdate = {
|
||||
$scope.updateSchedule = {
|
||||
busy: false,
|
||||
pattern: '',
|
||||
currentPattern: '',
|
||||
days: [],
|
||||
hours: [],
|
||||
|
||||
show: function () {
|
||||
$scope.updateSchedule.busy = false;
|
||||
|
||||
var tmp = $scope.updateSchedule.currentPattern.split(' ');
|
||||
var hours = tmp[2].split(','), days = tmp[5].split(',');
|
||||
if (days[0] === '*') {
|
||||
$scope.updateSchedule.days = angular.copy($scope.cronDays, []);
|
||||
} else {
|
||||
$scope.updateSchedule.days = days.map(function (day) { return $scope.cronDays[parseInt(day, 10)]; });
|
||||
}
|
||||
$scope.updateSchedule.hours = hours.map(function (hour) { return $scope.cronHours[parseInt(hour, 10)]; });
|
||||
|
||||
$('#updateScheduleModal').modal('show');
|
||||
},
|
||||
|
||||
submit: function () {
|
||||
if ($scope.autoUpdate.pattern === $scope.autoUpdate.currentPattern) return;
|
||||
var daysPattern;
|
||||
if ($scope.updateSchedule.days.length === 7) daysPattern = '*';
|
||||
else daysPattern = $scope.updateSchedule.days.map(function (d) { return d.value; });
|
||||
|
||||
$scope.autoUpdate.busy = true;
|
||||
var hoursPattern;
|
||||
if ($scope.updateSchedule.hours.length === 24) hoursPattern = '*';
|
||||
else hoursPattern = $scope.updateSchedule.hours.map(function (d) { return d.value; });
|
||||
|
||||
Client.setAppAutoupdatePattern($scope.autoUpdate.pattern, function (error) {
|
||||
var pattern ='00 00 ' + hoursPattern + ' * * ' + daysPattern;
|
||||
|
||||
$scope.updateSchedule.busy = true;
|
||||
|
||||
Client.setAppAutoupdatePattern(pattern, function (error) {
|
||||
if (error) Client.error(error);
|
||||
else $scope.autoUpdate.currentPattern = $scope.autoUpdate.pattern;
|
||||
|
||||
$timeout(function () {
|
||||
$scope.autoUpdate.busy = false;
|
||||
$scope.updateSchedule.busy = false;
|
||||
if (!error) $scope.updateSchedule.currentPattern = pattern;
|
||||
$('#updateScheduleModal').modal('hide');
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
@@ -194,8 +255,8 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
|
||||
// just keep the UI sane by supporting previous default pattern
|
||||
if (result.pattern === '00 30 1,3,5,23 * * *') result.pattern = '00 15 1,3,5,23 * * *';
|
||||
|
||||
$scope.autoUpdate.currentPattern = result.pattern;
|
||||
$scope.autoUpdate.pattern = result.pattern;
|
||||
$scope.updateSchedule.currentPattern = result.pattern;
|
||||
$scope.updateSchedule.pattern = result.pattern;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user