Expose user's settings and defaults inline

This improves performance by removing two AJAX calls and a lot of
JavaScript promises.
This commit is contained in:
Francis Lachapelle
2017-06-01 13:48:45 -04:00
parent 1fa056bb25
commit 89bfa0c536
22 changed files with 441 additions and 484 deletions
@@ -136,31 +136,29 @@
_this.$expanded = false;
// Set expanded folders from user's settings
Account.$Preferences.ready().then(function() {
var expandedFolders,
_visit = function(mailboxes) {
_.forEach(mailboxes, function(o) {
o.$expanded = (expandedFolders.indexOf('/' + o.id) >= 0);
if (o.children && o.children.length > 0) {
_visit(o.children);
}
});
};
if (Account.$Preferences.settings.Mail.ExpandedFolders) {
if (angular.isString(Account.$Preferences.settings.Mail.ExpandedFolders))
// Backward compatibility support
expandedFolders = angular.fromJson(Account.$Preferences.settings.Mail.ExpandedFolders);
else
expandedFolders = Account.$Preferences.settings.Mail.ExpandedFolders;
_this.$expanded = (expandedFolders.indexOf('/' + _this.id) >= 0);
if (expandedFolders.length > 0) {
_visit(_this.$mailboxes);
}
var expandedFolders,
_visit = function(mailboxes) {
_.forEach(mailboxes, function(o) {
o.$expanded = (expandedFolders.indexOf('/' + o.id) >= 0);
if (o.children && o.children.length > 0) {
_visit(o.children);
}
});
};
if (Account.$Preferences.settings.Mail.ExpandedFolders) {
if (angular.isString(Account.$Preferences.settings.Mail.ExpandedFolders))
// Backward compatibility support
expandedFolders = angular.fromJson(Account.$Preferences.settings.Mail.ExpandedFolders);
else
expandedFolders = Account.$Preferences.settings.Mail.ExpandedFolders;
_this.$expanded = (expandedFolders.indexOf('/' + _this.id) >= 0);
if (expandedFolders.length > 0) {
_visit(_this.$mailboxes);
}
if (Account.$accounts)
_this.$expanded |= (Account.$accounts.length == 1); // Always expand single account
_this.$flattenMailboxes({reload: true});
});
}
if (Account.$accounts)
_this.$expanded |= (Account.$accounts.length == 1); // Always expand single account
_this.$flattenMailboxes({reload: true});
return _this.$mailboxes;
});
@@ -48,12 +48,10 @@
PRELOAD: PRELOAD
});
// Initialize sort parameters from user's settings
Preferences.ready().then(function() {
if (Preferences.settings.Mail.SortingState) {
Mailbox.$query.sort = Preferences.settings.Mail.SortingState[0];
Mailbox.$query.asc = parseInt(Preferences.settings.Mail.SortingState[1]);
}
});
if (Preferences.settings.Mail.SortingState) {
Mailbox.$query.sort = Preferences.settings.Mail.SortingState[0];
Mailbox.$query.asc = parseInt(Preferences.settings.Mail.SortingState[1]);
}
return Mailbox; // return constructor
}];
@@ -343,46 +341,43 @@
_this.$isLoading = true;
});
return Mailbox.$Preferences.ready().then(function() {
if (Mailbox.$refreshTimeout)
Mailbox.$timeout.cancel(Mailbox.$refreshTimeout);
if (Mailbox.$refreshTimeout)
Mailbox.$timeout.cancel(Mailbox.$refreshTimeout);
if (sortingAttributes)
// Sorting preferences are common to all mailboxes
angular.extend(Mailbox.$query, sortingAttributes);
if (sortingAttributes)
// Sorting preferences are common to all mailboxes
angular.extend(Mailbox.$query, sortingAttributes);
angular.extend(options, { sortingAttributes: Mailbox.$query });
if (angular.isDefined(filters)) {
options.filters = _.reject(filters, function(filter) {
return !filter.searchInput || filter.searchInput.length === 0;
});
// Decompose filters that match two fields
_.forEach(options.filters, function(filter) {
var secondFilter,
match = filter.searchBy.match(/(\w+)_or_(\w+)/);
if (match) {
options.sortingAttributes.match = 'OR';
filter.searchBy = match[1];
secondFilter = angular.copy(filter);
secondFilter.searchBy = match[2];
options.filters.push(secondFilter);
}
});
}
// Restart the refresh timer, if needed
if (!Mailbox.$virtualMode) {
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(_this, Mailbox.prototype.$filter, null, filters);
Mailbox.$refreshTimeout = Mailbox.$timeout(f, refreshViewCheck.timeInterval()*1000);
angular.extend(options, { sortingAttributes: Mailbox.$query });
if (angular.isDefined(filters)) {
options.filters = _.reject(filters, function(filter) {
return !filter.searchInput || filter.searchInput.length === 0;
});
// Decompose filters that match two fields
_.forEach(options.filters, function(filter) {
var secondFilter,
match = filter.searchBy.match(/(\w+)_or_(\w+)/);
if (match) {
options.sortingAttributes.match = 'OR';
filter.searchBy = match[1];
secondFilter = angular.copy(filter);
secondFilter.searchBy = match[2];
options.filters.push(secondFilter);
}
}
});
}
var futureMailboxData = Mailbox.$$resource.post(_this.id, 'view', options);
return _this.$unwrap(futureMailboxData);
});
// Restart the refresh timer, if needed
if (!Mailbox.$virtualMode) {
var refreshViewCheck = Mailbox.$Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually') {
var f = angular.bind(this, Mailbox.prototype.$filter, null, filters);
Mailbox.$refreshTimeout = Mailbox.$timeout(f, refreshViewCheck.timeInterval()*1000);
}
}
var futureMailboxData = Mailbox.$$resource.post(this.id, 'view', options);
return this.$unwrap(futureMailboxData);
};
/**
@@ -32,9 +32,7 @@
params: []
};
Preferences.ready().then(function() {
vm.showSubscribedOnly = Preferences.defaults.SOGoMailShowSubscribedFoldersOnly;
});
this.showSubscribedOnly = Preferences.defaults.SOGoMailShowSubscribedFoldersOnly;
this.refreshUnseenCount();
@@ -258,7 +256,7 @@
}; // delegate
this.refreshUnseenCount = function() {
var unseenCountFolders = $window.unseenCountFolders;
var unseenCountFolders = $window.unseenCountFolders, refreshViewCheck;
_.forEach(vm.accounts, function(account) {
@@ -282,11 +280,9 @@
});
});
Preferences.ready().then(function() {
var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually')
$timeout(vm.refreshUnseenCount, refreshViewCheck.timeInterval()*1000);
});
refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
if (refreshViewCheck && refreshViewCheck != 'manually')
$timeout(vm.refreshUnseenCount, refreshViewCheck.timeInterval()*1000);
};
this.isDroppableFolder = function(srcFolder, dstFolder) {
@@ -48,16 +48,15 @@
$$resource: new Resource(Settings.activeUser('folderURL') + 'Mail', Settings.activeUser()),
$avatar: angular.bind(Preferences, Preferences.avatar)
});
// Initialize tags form user's defaults
Preferences.ready().then(function() {
if (Preferences.defaults.SOGoMailLabelsColors) {
Message.$tags = Preferences.defaults.SOGoMailLabelsColors;
}
if (Preferences.defaults.SOGoMailDisplayRemoteInlineImages &&
Preferences.defaults.SOGoMailDisplayRemoteInlineImages == 'always') {
Message.$displayRemoteInlineImages = true;
}
});
if (Preferences.defaults.SOGoMailLabelsColors) {
Message.$tags = Preferences.defaults.SOGoMailLabelsColors;
}
if (Preferences.defaults.SOGoMailDisplayRemoteInlineImages &&
Preferences.defaults.SOGoMailDisplayRemoteInlineImages == 'always') {
Message.$displayRemoteInlineImages = true;
}
return Message; // return constructor
}];
@@ -65,6 +65,13 @@
}
});
// Read user's defaults
if (Preferences.defaults.SOGoMailAutoSave)
// Enable auto-save of draft
vm.autosave = $timeout(vm.autosaveDrafts, Preferences.defaults.SOGoMailAutoSave*1000*60);
// Set the locale of CKEditor
vm.localeCode = Preferences.defaults.LocaleCode;
// Destroy file uploader when the controller is being deactivated
$scope.$on('$destroy', function() { vm.uploader.destroy(); });
@@ -297,14 +304,6 @@
vm.autosave = $timeout(vm.autosaveDrafts, Preferences.defaults.SOGoMailAutoSave*1000*60);
}
// Read user's defaults
Preferences.ready().then(function() {
if (Preferences.defaults.SOGoMailAutoSave)
// Enable auto-save of draft
vm.autosave = $timeout(vm.autosaveDrafts, Preferences.defaults.SOGoMailAutoSave*1000*60);
// Set the locale of CKEditor
vm.localeCode = Preferences.defaults.LocaleCode;
});
}
SendMessageToastController.$inject = ['$scope', '$mdToast'];