Fix periodic fetching of apps/config/profile
All these are already fetched the first time in main.js * Fetch apps periodically only in the apps view. This is mostly for the installationState. We can optimize this a bit more later depending on if any app is in non-running state. * profile hardly changes, no need to fetch this over and over * config hardly changes, but is fetched primarily for the update flag
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/* global angular */
|
||||
/* global EventSource */
|
||||
|
||||
angular.module('Application').service('Client', ['$http', 'md5', 'Notification', function ($http, md5, Notification) {
|
||||
angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'Notification', function ($http, $interval, md5, Notification) {
|
||||
var client = null;
|
||||
|
||||
// variable available only here to avoid this._property pattern
|
||||
@@ -133,6 +133,8 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
|
||||
this.apiOrigin = '<%= oauth.apiOrigin %>' || window.location.origin;
|
||||
this.avatar = '';
|
||||
|
||||
this._refreshConfigTimer = null;
|
||||
|
||||
this.resetAvatar();
|
||||
|
||||
this.setToken(localStorage.token);
|
||||
@@ -474,8 +476,16 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
|
||||
};
|
||||
|
||||
Client.prototype.checkForUpdates = function (callback) {
|
||||
var that = this;
|
||||
|
||||
if (that._refreshConfigTimer) $interval.cancel(that._refreshConfigTimer);
|
||||
that._refreshConfigTimer = null;
|
||||
|
||||
post('/api/v1/cloudron/check_for_updates', { }).success(function(data, status) {
|
||||
if (status !== 200) return callback(new ClientError(status, data));
|
||||
|
||||
that._refreshConfigTimer = $interval(that.refreshConfig.bind(that), 5000, 20 /* 20 times */);
|
||||
|
||||
callback(null);
|
||||
}).error(defaultErrorHandler(callback));
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('Application').controller('MainController', ['$scope', '$route', '$interval', '$timeout', 'Client', 'AppStore', function ($scope, $route, $interval, $timeout, Client, AppStore) {
|
||||
angular.module('Application').controller('MainController', ['$scope', '$route', '$timeout', '$location', 'Client', 'AppStore', function ($scope, $route, $timeout, $location, Client, AppStore) {
|
||||
$scope.initialized = false;
|
||||
$scope.user = Client.getUserInfo();
|
||||
$scope.installedApps = Client.getInstalledApps();
|
||||
@@ -219,17 +219,6 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
|
||||
Client.refreshInstalledApps(function (error) {
|
||||
if (error) return $scope.error(error);
|
||||
|
||||
// kick off installed apps and config polling
|
||||
var refreshAppsTimer = $interval(Client.refreshInstalledApps.bind(Client), 5000);
|
||||
var refreshConfigTimer = $interval(Client.refreshConfig.bind(Client), 5000);
|
||||
var refreshUserInfoTimer = $interval(Client.refreshUserInfo.bind(Client), 5000);
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
$interval.cancel(refreshAppsTimer);
|
||||
$interval.cancel(refreshConfigTimer);
|
||||
$interval.cancel(refreshUserInfoTimer);
|
||||
});
|
||||
|
||||
// now mark the Client to be ready
|
||||
Client.setReady();
|
||||
|
||||
@@ -247,7 +236,6 @@ angular.module('Application').controller('MainController', ['$scope', '$route',
|
||||
});
|
||||
});
|
||||
|
||||
// wait till the view has loaded until showing a modal dialog
|
||||
Client.onConfig(function (config) {
|
||||
// check if we are actually updating
|
||||
if (config.progress.update && config.progress.update.percent !== -1) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
angular.module('Application').controller('AppsController', ['$scope', '$location', '$timeout', 'Client', 'ngTld', 'AppStore', function ($scope, $location, $timeout, Client, ngTld, AppStore) {
|
||||
angular.module('Application').controller('AppsController', ['$scope', '$location', '$timeout', '$interval', 'Client', 'ngTld', 'AppStore', function ($scope, $location, $timeout, $interval, Client, ngTld, AppStore) {
|
||||
$scope.HOST_PORT_MIN = 1024;
|
||||
$scope.HOST_PORT_MAX = 65535;
|
||||
$scope.installedApps = Client.getInstalledApps();
|
||||
@@ -506,13 +506,23 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
|
||||
}
|
||||
|
||||
Client.onReady(function () {
|
||||
if ($scope.user.admin) {
|
||||
fetchUsers();
|
||||
fetchGroups();
|
||||
getDomains();
|
||||
getMailConfig();
|
||||
getBackupConfig();
|
||||
}
|
||||
Client.refreshInstalledApps(function (error) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
if ($scope.user.admin) {
|
||||
fetchUsers();
|
||||
fetchGroups();
|
||||
getDomains();
|
||||
getMailConfig();
|
||||
getBackupConfig();
|
||||
}
|
||||
|
||||
var refreshAppsTimer = $interval(Client.refreshInstalledApps.bind(Client), 5000);
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
$interval.cancel(refreshAppsTimer);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// setup all the dialog focus handling
|
||||
|
||||
Reference in New Issue
Block a user