diff --git a/webadmin/src/views/apps.html b/webadmin/src/views/apps.html index aeb3819a1..37cb386b6 100644 --- a/webadmin/src/views/apps.html +++ b/webadmin/src/views/apps.html @@ -445,7 +445,7 @@
- +
diff --git a/webadmin/src/views/apps.js b/webadmin/src/views/apps.js index dfc74a28b..067dd2683 100644 --- a/webadmin/src/views/apps.js +++ b/webadmin/src/views/apps.js @@ -392,7 +392,7 @@ angular.module('Application').controller('AppsController', ['$scope', '$location }); }; - $scope.showUpdate = function (app) { + $scope.showUpdate = function (app, updateManifest) { if ($scope.$parent.currentSubscription.plan && $scope.$parent.currentSubscription.plan.id === 'free') { $('#setupSubscriptionModal').modal('show'); return; @@ -401,75 +401,70 @@ angular.module('Application').controller('AppsController', ['$scope', '$location $scope.reset(); $scope.appUpdate.app = app; + $scope.appUpdate.manifest = angular.copy(updateManifest); - AppStore.getManifest(app.appStoreId, function (error, manifest) { - if (error) return console.error(error); + // ensure we always operate on objects here + app.portBindings = app.portBindings || {}; + app.manifest.tcpPorts = app.manifest.tcpPorts || {}; + updateManifest.tcpPorts = updateManifest.tcpPorts || {}; - $scope.appUpdate.manifest = angular.copy(manifest); + // Activate below two lines for testing the UI + // updateManifest.tcpPorts['TEST_HTTP'] = { defaultValue: 1337, description: 'HTTP server'}; + // app.manifest.tcpPorts['TEST_FOOBAR'] = { defaultValue: 1338, description: 'FOOBAR server'}; + // app.portBindings['TEST_SSH'] = 1339; - // ensure we always operate on objects here - app.portBindings = app.portBindings || {}; - app.manifest.tcpPorts = app.manifest.tcpPorts || {}; - manifest.tcpPorts = manifest.tcpPorts || {}; + var portBindingsInfo = {}; // Portbinding map only for information + var portBindings = {}; // This is the actual model holding the env:port pair + var portBindingsEnabled = {}; // This is the actual model holding the enabled/disabled flag + var obsoletePortBindings = {}; // Info map for obsolete port bindings, this is for display use only and thus not in the model + var portsChanged = false; + var env; - // Activate below two lines for testing the UI - // manifest.tcpPorts['TEST_HTTP'] = { defaultValue: 1337, description: 'HTTP server'}; - // app.manifest.tcpPorts['TEST_FOOBAR'] = { defaultValue: 1338, description: 'FOOBAR server'}; - // app.portBindings['TEST_SSH'] = 1339; + // detect new portbindings and copy all from manifest.tcpPorts + for (env in updateManifest.tcpPorts) { + portBindingsInfo[env] = updateManifest.tcpPorts[env]; + if (!app.manifest.tcpPorts[env]) { + portBindingsInfo[env].isNew = true; + portBindingsEnabled[env] = true; - var portBindingsInfo = {}; // Portbinding map only for information - var portBindings = {}; // This is the actual model holding the env:port pair - var portBindingsEnabled = {}; // This is the actual model holding the enabled/disabled flag - var obsoletePortBindings = {}; // Info map for obsolete port bindings, this is for display use only and thus not in the model - var portsChanged = false; - var env; + // use default integer port value in model + portBindings[env] = updateManifest.tcpPorts[env].defaultValue || 0; - // detect new portbindings and copy all from manifest.tcpPorts - for (env in manifest.tcpPorts) { - portBindingsInfo[env] = manifest.tcpPorts[env]; - if (!app.manifest.tcpPorts[env]) { - portBindingsInfo[env].isNew = true; - portBindingsEnabled[env] = true; - - // use default integer port value in model - portBindings[env] = manifest.tcpPorts[env].defaultValue || 0; - - portsChanged = true; - } else { - // detect if the port binding was enabled - if (app.portBindings[env]) { - portBindings[env] = app.portBindings[env]; - portBindingsEnabled[env] = true; - } else { - portBindings[env] = manifest.tcpPorts[env].defaultValue || 0; - portBindingsEnabled[env] = false; - } - } - } - - // detect obsolete portbindings (mappings in app.portBindings, but not anymore in manifest.tcpPorts) - for (env in app.manifest.tcpPorts) { - // only list the port if it is not in the new manifest and was enabled previously - if (!manifest.tcpPorts[env] && app.portBindings[env]) { - obsoletePortBindings[env] = app.portBindings[env]; - portsChanged = true; - } - } - - // now inject the maps into the $scope, we only show those if ports have changed - $scope.appUpdate.portBindings = portBindings; // always inject the model, so it gets used in the actual update call - $scope.appUpdate.portBindingsEnabled = portBindingsEnabled; // always inject the model, so it gets used in the actual update call - - if (portsChanged) { - $scope.appUpdate.portBindingsInfo = portBindingsInfo; - $scope.appUpdate.obsoletePortBindings = obsoletePortBindings; + portsChanged = true; } else { - $scope.appUpdate.portBindingsInfo = {}; - $scope.appUpdate.obsoletePortBindings = {}; + // detect if the port binding was enabled + if (app.portBindings[env]) { + portBindings[env] = app.portBindings[env]; + portBindingsEnabled[env] = true; + } else { + portBindings[env] = updateManifest.tcpPorts[env].defaultValue || 0; + portBindingsEnabled[env] = false; + } } + } - $('#appUpdateModal').modal('show'); - }); + // detect obsolete portbindings (mappings in app.portBindings, but not anymore in updateManifest.tcpPorts) + for (env in app.manifest.tcpPorts) { + // only list the port if it is not in the new manifest and was enabled previously + if (!updateManifest.tcpPorts[env] && app.portBindings[env]) { + obsoletePortBindings[env] = app.portBindings[env]; + portsChanged = true; + } + } + + // now inject the maps into the $scope, we only show those if ports have changed + $scope.appUpdate.portBindings = portBindings; // always inject the model, so it gets used in the actual update call + $scope.appUpdate.portBindingsEnabled = portBindingsEnabled; // always inject the model, so it gets used in the actual update call + + if (portsChanged) { + $scope.appUpdate.portBindingsInfo = portBindingsInfo; + $scope.appUpdate.obsoletePortBindings = obsoletePortBindings; + } else { + $scope.appUpdate.portBindingsInfo = {}; + $scope.appUpdate.obsoletePortBindings = {}; + } + + $('#appUpdateModal').modal('show'); }; $scope.doUpdate = function (form) {