(fix) move refresh timeout to service classes and enabled repeating timers

pull/91/merge
Ludovic Marcotte 2015-07-30 19:47:53 -04:00
parent 85f4efab46
commit 65b8382020
4 changed files with 47 additions and 24 deletions

View File

@ -32,7 +32,7 @@
* @desc The factory we'll use to register with Angular
* @returns the AddressBook constructor
*/
AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Card', 'Acl', function($q, $timeout, $log, Settings, Resource, Card, Acl) {
AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Card', 'Acl', 'Preferences', function($q, $timeout, $log, Settings, Resource, Card, Acl, Preferences) {
angular.extend(AddressBook, {
$q: $q,
$timeout: $timeout,
@ -40,8 +40,10 @@
$$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser),
$Card: Card,
$$Acl: Acl,
$Preferences: Preferences,
activeUser: Settings.activeUser,
selectedFolder: null
selectedFolder: null,
$refreshTimeout: null
});
return AddressBook; // return constructor
@ -102,7 +104,7 @@
/**
* @memberof AddressBook
* @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item.
* @desc Set or get the list of addressbooks. Will instantiate a new AddressBook object for each item.
* @param {array} [data] - the metadata of the addressbooks
* @returns the list of addressbooks
*/
@ -210,6 +212,27 @@
return count;
};
/**
* @function $startRefreshTimeout
* @memberof AddressBook.prototype
* @desc Starts the refresh timeout for the current selected address book
* /
AddressBook.prototype.$startRefreshTimeout = function() {
var _this = this;
if (AddressBook.$refreshTimeout)
AddressBook.$timeout.cancel(AddressBook.$refreshTimeout);
AddressBook.$Preferences.ready().then(function() {
// Restart the refresh timer, if needed
var refreshViewCheck = AddressBook.$Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(_this, AddressBook.prototype.$reload);
AddressBook.$refreshTimeout = AddressBook.$timeout(f, refreshViewCheck.timeInterval()*1000);
}
});
};
/**
* @function $reload
* @memberof AddressBook.prototype
@ -219,6 +242,8 @@
AddressBook.prototype.$reload = function() {
var _this = this;
this.$startRefreshTimeout();
return AddressBook.$$resource.fetch(this.id, 'view')
.then(function(response) {
var index, card,
@ -441,6 +466,9 @@
});
// Instanciate Acl object
_this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id);
_this.$startRefreshTimeout();
return _this;
});
}, function(data) {

View File

@ -6,8 +6,8 @@
/**
* @ngInject
*/
AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'Preferences', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Preferences, Settings, stateAddressbooks, stateAddressbook) {
AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var vm = this;
AddressBook.selectedFolder = stateAddressbook;
@ -98,15 +98,6 @@
vm.mode.search = false;
vm.selectedFolder.$filter('');
}
// Start the address book refresh timer based on user's preferences
Preferences.ready().then(function() {
var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(vm.selectedFolder, AddressBook.prototype.$reload);
$timeout(f, refreshViewCheck.timeInterval()*1000);
}
});
}
angular

View File

@ -42,6 +42,7 @@
$Preferences: Preferences,
$query: { sort: 'date', asc: 0 },
selectedFolder: null,
$refreshTimeout: null,
PRELOAD: PRELOAD
});
// Initialize sort parameters from user's settings
@ -212,6 +213,10 @@
this.$isLoading = true;
return Mailbox.$Preferences.ready().then(function() {
if (Mailbox.$refreshTimeout)
Mailbox.$timeout.cancel(Mailbox.$refreshTimeout);
if (sortingAttributes)
// Sorting preferences are common to all mailboxes
angular.extend(Mailbox.$query, sortingAttributes);
@ -234,6 +239,13 @@
});
}
// Restart the refresh timer, if needed
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(_this, Mailbox.prototype.$filter);
Mailbox.$refreshTimeout = Mailbox.$timeout(f, refreshViewCheck.timeInterval()*1000);
}
var futureMailboxData = Mailbox.$$resource.post(_this.id, 'view', options);
return _this.$unwrap(futureMailboxData);
});

View File

@ -6,8 +6,8 @@
/**
* @ngInject
*/
MailboxController.$inject = ['$state', '$timeout', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox', 'Preferences'];
function MailboxController($state, $timeout, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox, Preferences) {
MailboxController.$inject = ['$state', '$timeout', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
function MailboxController($state, $timeout, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) {
var vm = this;
Mailbox.selectedFolder = stateMailbox;
@ -88,14 +88,6 @@
vm.selectedFolder.$filter();
}
// Start the mailbox refresh timer based on user's preferences
Preferences.ready().then(function() {
var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(vm.selectedFolder, Mailbox.prototype.$filter);
$timeout(f, refreshViewCheck.timeInterval()*1000);
}
});
}
angular