From cb94737519da03acf701e44d5b4d8a8ebe65ddf5 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Sun, 14 Jun 2020 16:31:06 +0200 Subject: [PATCH] Fix bug where location change makes the app temporarily disappear --- src/js/client.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/js/client.js b/src/js/client.js index c29c64ab5..824629094 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1768,30 +1768,20 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout } Client.prototype._updateAppCache = function (app) { - var found = -1; - - // find by id and not by loc because the app's fqdn might have changed between invokations - for (var i = 0; i < this._installedApps.length; ++i) { - if (this._installedApps[i].id === app.id) { - found = i; - break; - } - } - var tmp = {}; angular.copy(app, tmp); - // 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 + var foundIndex = this._installedApps.findIndex(function (a) { return a.id === app.id; }); + + // we replace new data into the existing reference to keep angular bindings + if (foundIndex !== -1) { + angular.copy(tmp, this._installedApps[foundIndex]); } else { - 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 + this._installedApps.push(tmp); } - this._installedAppsById[app.id] = this._installedApps[found]; + // add reference to object map with appId keys + this._installedAppsById[app.id] = this._installedApps[foundIndex]; // TODO this not very elegant // update app tags