(fix) move refresh timeout to service classes and enabled repeating timers
This commit is contained in:
parent
85f4efab46
commit
65b8382020
|
@ -32,7 +32,7 @@
|
||||||
* @desc The factory we'll use to register with Angular
|
* @desc The factory we'll use to register with Angular
|
||||||
* @returns the AddressBook constructor
|
* @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, {
|
angular.extend(AddressBook, {
|
||||||
$q: $q,
|
$q: $q,
|
||||||
$timeout: $timeout,
|
$timeout: $timeout,
|
||||||
|
@ -40,8 +40,10 @@
|
||||||
$$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser),
|
$$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser),
|
||||||
$Card: Card,
|
$Card: Card,
|
||||||
$$Acl: Acl,
|
$$Acl: Acl,
|
||||||
|
$Preferences: Preferences,
|
||||||
activeUser: Settings.activeUser,
|
activeUser: Settings.activeUser,
|
||||||
selectedFolder: null
|
selectedFolder: null,
|
||||||
|
$refreshTimeout: null
|
||||||
});
|
});
|
||||||
|
|
||||||
return AddressBook; // return constructor
|
return AddressBook; // return constructor
|
||||||
|
@ -102,7 +104,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @memberof AddressBook
|
* @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
|
* @param {array} [data] - the metadata of the addressbooks
|
||||||
* @returns the list of addressbooks
|
* @returns the list of addressbooks
|
||||||
*/
|
*/
|
||||||
|
@ -210,6 +212,27 @@
|
||||||
return count;
|
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
|
* @function $reload
|
||||||
* @memberof AddressBook.prototype
|
* @memberof AddressBook.prototype
|
||||||
|
@ -219,6 +242,8 @@
|
||||||
AddressBook.prototype.$reload = function() {
|
AddressBook.prototype.$reload = function() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
this.$startRefreshTimeout();
|
||||||
|
|
||||||
return AddressBook.$$resource.fetch(this.id, 'view')
|
return AddressBook.$$resource.fetch(this.id, 'view')
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
var index, card,
|
var index, card,
|
||||||
|
@ -441,6 +466,9 @@
|
||||||
});
|
});
|
||||||
// Instanciate Acl object
|
// Instanciate Acl object
|
||||||
_this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id);
|
_this.$acl = new AddressBook.$$Acl('Contacts/' + _this.id);
|
||||||
|
|
||||||
|
_this.$startRefreshTimeout();
|
||||||
|
|
||||||
return _this;
|
return _this;
|
||||||
});
|
});
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
/**
|
/**
|
||||||
* @ngInject
|
* @ngInject
|
||||||
*/
|
*/
|
||||||
AddressBookController.$inject = ['$scope', '$state', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'Preferences', 'sgSettings', '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, Preferences, Settings, stateAddressbooks, stateAddressbook) {
|
function AddressBookController($scope, $state, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
AddressBook.selectedFolder = stateAddressbook;
|
AddressBook.selectedFolder = stateAddressbook;
|
||||||
|
@ -98,15 +98,6 @@
|
||||||
vm.mode.search = false;
|
vm.mode.search = false;
|
||||||
vm.selectedFolder.$filter('');
|
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
|
angular
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
$Preferences: Preferences,
|
$Preferences: Preferences,
|
||||||
$query: { sort: 'date', asc: 0 },
|
$query: { sort: 'date', asc: 0 },
|
||||||
selectedFolder: null,
|
selectedFolder: null,
|
||||||
|
$refreshTimeout: null,
|
||||||
PRELOAD: PRELOAD
|
PRELOAD: PRELOAD
|
||||||
});
|
});
|
||||||
// Initialize sort parameters from user's settings
|
// Initialize sort parameters from user's settings
|
||||||
|
@ -212,6 +213,10 @@
|
||||||
this.$isLoading = true;
|
this.$isLoading = true;
|
||||||
|
|
||||||
return Mailbox.$Preferences.ready().then(function() {
|
return Mailbox.$Preferences.ready().then(function() {
|
||||||
|
|
||||||
|
if (Mailbox.$refreshTimeout)
|
||||||
|
Mailbox.$timeout.cancel(Mailbox.$refreshTimeout);
|
||||||
|
|
||||||
if (sortingAttributes)
|
if (sortingAttributes)
|
||||||
// Sorting preferences are common to all mailboxes
|
// Sorting preferences are common to all mailboxes
|
||||||
angular.extend(Mailbox.$query, sortingAttributes);
|
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);
|
var futureMailboxData = Mailbox.$$resource.post(_this.id, 'view', options);
|
||||||
return _this.$unwrap(futureMailboxData);
|
return _this.$unwrap(futureMailboxData);
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
/**
|
/**
|
||||||
* @ngInject
|
* @ngInject
|
||||||
*/
|
*/
|
||||||
MailboxController.$inject = ['$state', '$timeout', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', '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, Preferences) {
|
function MailboxController($state, $timeout, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
Mailbox.selectedFolder = stateMailbox;
|
Mailbox.selectedFolder = stateMailbox;
|
||||||
|
@ -88,14 +88,6 @@
|
||||||
vm.selectedFolder.$filter();
|
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
|
angular
|
||||||
|
|
Loading…
Reference in a new issue