diff --git a/src/js/client.js b/src/js/client.js index 7bcb1cd94..c29c64ab5 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1275,6 +1275,32 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getAppWithTask = function (appId, callback) { + var that = this; + + this.getApp(appId, function (error, app) { + if (error) return callback(error); + + if (!app.taskId) return callback(null, app); + + that.getTask(app.taskId, function (error, task) { + if (error) return callback(error); + + if (task) { + app.progress = task.percent; + app.message = task.message; + app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes(); + } else { + app.progress = 0; + app.message = ''; + app.taskMinutesActive = 0; + } + + callback(null, app); + }); + }); + }; + Client.prototype.getCachedAppSync = function (appId) { var appFound = null; this._installedApps.some(function (app) { @@ -1758,9 +1784,9 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout // only replace if the app is already known if (found !== -1 && this._installedApps[found].fqdn === tmp.fqdn) { // app location has not changed angular.copy(tmp, this._installedApps[found]); + } else if (found !== -1) { + this._installedApps.splice(found, 1); // remove it } else { - if (found !== -1) this._installedApps.splice(found, 1); // remove it - var loc = binarySearch(this._installedApps, function (item) { return item.fqdn.localeCompare(app.fqdn) <= 0; }); this._installedApps.splice(loc, 0, tmp); // insert into sorted fqdn array } @@ -1779,34 +1805,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout angular.copy(tmp, this._appTags); }; - Client.prototype.refreshAppCache = function (id, callback) { - var that = this; - - this.getApp(id, function (error, app) { - if (error) return callback(error); - - var getTaskFunc = app.taskId ? that.getTask.bind(null, app.taskId) : function (next) { return next(); }; - - getTaskFunc(function (error, task) { - if (error) return callback(error); - - if (task) { - app.progress = task.percent; - app.message = task.message; - app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes(); - } else { - app.progress = 0; - app.message = ''; - app.taskMinutesActive = 0; - } - - that._updateAppCache(app); - - callback(null, app); - }); - }); - }; - Client.prototype.refreshInstalledApps = function (callback) { var that = this; @@ -1814,18 +1812,24 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout if (error) return callback(error); async.eachLimit(apps, 20, function (app, iteratorCallback) { - var canManageApp = that._userInfo.isAtLeastAdmin; + var getTaskFunc = app.taskId ? that.getTask.bind(null, app.taskId) : function (next) { return next(); }; + getTaskFunc(function (error, task) { + if (error) return iteratorCallback(error); + + if (task) { + app.progress = task.percent; + app.message = task.message; + app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes(); + } else { + app.progress = 0; + app.message = ''; + app.taskMinutesActive = 0; + } - if (!canManageApp) { that._updateAppCache(app); - return iteratorCallback(); - } - if (that._installedAppsById[app.id]) { - if (!app.taskId) return iteratorCallback(); // app has active task, get latest - } - - that.refreshAppCache(app.id, iteratorCallback); + iteratorCallback(null); + }); }, function iteratorDone(error) { if (error) return callback(error); diff --git a/src/views/app.js b/src/views/app.js index 71001a45c..e53116bd8 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -1084,7 +1084,6 @@ angular.module('Application').controller('AppController', ['$scope', '$location' Client.error(error); } else { $('#uninstallModal').modal('hide'); - Client.refreshAppCache($scope.app.id, function() {}); // reflect the new app state immediately $location.path('/apps'); } @@ -1469,7 +1468,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location' function refreshApp(appId, callback) { callback = callback || function () {}; - Client.refreshAppCache(appId, function (error, app) { + Client.getAppWithTask(appId, function (error, app) { if (error && error.statusCode === 404) return $location.path('/apps'); if (error) return callback(error);