Sync port bindings handling with install/configure and move obsolete ones out of the model
This commit is contained in:
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+14
-6
@@ -94,13 +94,21 @@
|
||||
<div class="modal-body">
|
||||
<fieldset>
|
||||
<form class="form-signin" role="form" name="update_form" ng-submit="doUpdate(update_form)" autocomplete="off">
|
||||
<div ng-repeat="(env, portInfo) in appupdate.portBindings" ng-class="{ 'newPort': portInfo.isNew, 'obsoletePort': portInfo.isObsolete }">
|
||||
<div ng-repeat="(env, info) in appupdate.portBindingsInfo" ng-class="{ 'newPort': info.isNew }">
|
||||
<ng-form name="portInfo_form">
|
||||
<div class="form-group" ng-class="{ 'has-error': portInfo_form.itemName{{$index}}.$dirty && portInfo_form.itemName{{$index}}.$invalid, 'text-muted': portInfo.isObsolete }">
|
||||
<span ng-show="portInfo.isNew">New - </span>
|
||||
<span ng-show="portInfo.isObsolete">Obsolete - </span>
|
||||
<label class="control-label" for="inputPortInfo{{env}}">{{ portInfo.description }} ({{ HOST_PORT_MIN }} - {{ HOST_PORT_MAX }})</label>
|
||||
<input type="number" class="form-control" ng-model="appupdate.portBindings[env].hostPort" id="inputPortInfo{{port}}" later-name="itemName{{$index}}" min="{{HOST_PORT_MIN}}" max="{{HOST_PORT_MAX}}" ng-disabled="portInfo.isObsolete" required>
|
||||
<div class="form-group" ng-class="{ 'has-error': portInfo_form.itemName{{$index}}.$dirty && portInfo_form.itemName{{$index}}.$invalid }">
|
||||
<span ng-show="info.isNew">New - </span>
|
||||
<label class="control-label" for="inputPortInfo{{env}}">{{ info.description }} ({{ HOST_PORT_MIN }} - {{ HOST_PORT_MAX }})</label>
|
||||
<input type="number" class="form-control" ng-model="appupdate.portBindings[env]" id="inputPortInfo{{env}}" later-name="itemName{{$index}}" min="{{HOST_PORT_MIN}}" max="{{HOST_PORT_MAX}}" required>
|
||||
</div>
|
||||
</ng-form>
|
||||
</div>
|
||||
<div ng-repeat="(env, port) in appupdate.obsoletePortBindings" class="obsoletePort">
|
||||
<ng-form name="obsoletePortInfo_form">
|
||||
<div class="form-group">
|
||||
Obsolete -
|
||||
<label class="control-label">{{ env }}</label>
|
||||
<input type="number" class="form-control" ng-model="port" disabled>
|
||||
</div>
|
||||
</ng-form>
|
||||
</div>
|
||||
|
||||
@@ -94,13 +94,21 @@
|
||||
<div class="modal-body">
|
||||
<fieldset>
|
||||
<form class="form-signin" role="form" name="update_form" ng-submit="doUpdate(update_form)" autocomplete="off">
|
||||
<div ng-repeat="(env, portInfo) in appupdate.portBindings" ng-class="{ 'newPort': portInfo.isNew, 'obsoletePort': portInfo.isObsolete }">
|
||||
<div ng-repeat="(env, info) in appupdate.portBindingsInfo" ng-class="{ 'newPort': info.isNew }">
|
||||
<ng-form name="portInfo_form">
|
||||
<div class="form-group" ng-class="{ 'has-error': portInfo_form.itemName{{$index}}.$dirty && portInfo_form.itemName{{$index}}.$invalid, 'text-muted': portInfo.isObsolete }">
|
||||
<span ng-show="portInfo.isNew">New - </span>
|
||||
<span ng-show="portInfo.isObsolete">Obsolete - </span>
|
||||
<label class="control-label" for="inputPortInfo{{env}}">{{ portInfo.description }} ({{ HOST_PORT_MIN }} - {{ HOST_PORT_MAX }})</label>
|
||||
<input type="number" class="form-control" ng-model="appupdate.portBindings[env].hostPort" id="inputPortInfo{{port}}" later-name="itemName{{$index}}" min="{{HOST_PORT_MIN}}" max="{{HOST_PORT_MAX}}" ng-disabled="portInfo.isObsolete" required>
|
||||
<div class="form-group" ng-class="{ 'has-error': portInfo_form.itemName{{$index}}.$dirty && portInfo_form.itemName{{$index}}.$invalid }">
|
||||
<span ng-show="info.isNew">New - </span>
|
||||
<label class="control-label" for="inputPortInfo{{env}}">{{ info.description }} ({{ HOST_PORT_MIN }} - {{ HOST_PORT_MAX }})</label>
|
||||
<input type="number" class="form-control" ng-model="appupdate.portBindings[env]" id="inputPortInfo{{env}}" later-name="itemName{{$index}}" min="{{HOST_PORT_MIN}}" max="{{HOST_PORT_MAX}}" required>
|
||||
</div>
|
||||
</ng-form>
|
||||
</div>
|
||||
<div ng-repeat="(env, port) in appupdate.obsoletePortBindings" class="obsoletePort">
|
||||
<ng-form name="obsoletePortInfo_form">
|
||||
<div class="form-group">
|
||||
Obsolete -
|
||||
<label class="control-label">{{ env }}</label>
|
||||
<input type="number" class="form-control" ng-model="port" disabled>
|
||||
</div>
|
||||
</ng-form>
|
||||
</div>
|
||||
|
||||
+35
-24
@@ -124,32 +124,49 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
|
||||
if (error) return console.error(error);
|
||||
|
||||
// Activate below two lines for testing the UI
|
||||
// manifest.tcpPorts['TEST_HTTP'] = { port: 1337, description: 'HTTP server'};
|
||||
// app.portBindings['TEST_SSH'] = { port: 1337, description: 'SSH server'};
|
||||
// manifest.tcpPorts['TEST_HTTP'] = { defaultValue: 1337, description: 'HTTP server'};
|
||||
// app.portBindings['TEST_SSH'] = 1337;
|
||||
|
||||
$scope.appupdate.manifest = manifest;
|
||||
var portBindings = angular.copy(app.portBindings);
|
||||
var portsChanged = false;
|
||||
|
||||
// detect new portbindings
|
||||
for (var env in $scope.appupdate.manifest.tcpPorts) {
|
||||
portBindings[env] = $scope.appupdate.manifest.tcpPorts[env];
|
||||
if (!$scope.appupdate.app.portBindings[env]) {
|
||||
portBindings[env].isNew = true;
|
||||
portsChanged = true;
|
||||
var portBindingsInfo = {}; // Portbinding map only for information
|
||||
var portBindings = {}; // This is the actual model holding the env:port pair
|
||||
var obsoletePortBindings = {}; // Info map for obsolete port bindings, this is for display use only and thus not in the model
|
||||
var newPorts = false;
|
||||
|
||||
// detect new portbindings and copy all from manifest.tcpPorts
|
||||
for (var env in manifest.tcpPorts) {
|
||||
portBindingsInfo[env] = manifest.tcpPorts[env];
|
||||
if (!app.portBindings[env]) {
|
||||
portBindingsInfo[env].isNew = true;
|
||||
|
||||
// use default integer port value in model
|
||||
portBindings[env] = manifest.tcpPorts[env].defaultValue || 0;
|
||||
|
||||
newPorts = true;
|
||||
} else {
|
||||
// just copy the integer port value into model
|
||||
portBindings[env] = app.portBindings[env];
|
||||
}
|
||||
}
|
||||
|
||||
// detect obsolete portbindings
|
||||
for (env in $scope.appupdate.app.portBindings) {
|
||||
if (!$scope.appupdate.manifest.tcpPorts[env]) {
|
||||
portBindings[env].isObsolete = true;
|
||||
portsChanged = true;
|
||||
// detect obsolete portbindings (mappings in app.portBindings, but not anymore in manifest.tcpPorts)
|
||||
for (env in app.portBindings) {
|
||||
if (!manifest.tcpPorts[env]) {
|
||||
obsoletePortBindings[env] = app.portBindings[env];
|
||||
}
|
||||
}
|
||||
|
||||
if (portsChanged) $scope.appupdate.portBindings = portBindings;
|
||||
else $scope.appupdate.portBindings = {};
|
||||
// now inject the maps into the $scope, we only show those if ports have changed
|
||||
if (newPorts) {
|
||||
$scope.appupdate.portBindingsInfo = portBindingsInfo;
|
||||
$scope.appupdate.portBindings = portBindings;
|
||||
} else {
|
||||
$scope.appupdate.portBindingsInfo = {};
|
||||
$scope.appupdate.portBindings = {};
|
||||
}
|
||||
|
||||
$scope.appupdate.obsoletePortBindings = obsoletePortBindings;
|
||||
|
||||
$('#appUpdateModal').modal('show');
|
||||
});
|
||||
@@ -158,13 +175,7 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
|
||||
$scope.doUpdate = function (form) {
|
||||
$scope.appupdate.error.password = null;
|
||||
|
||||
var portBindings = {};
|
||||
for (var env in $scope.appupdate.portBindings) {
|
||||
if ($scope.appupdate.portBindings[env].isObsolete) continue;
|
||||
portBindings[env] = $scope.appupdate.portBindings[env].hostPort;
|
||||
}
|
||||
|
||||
Client.updateApp($scope.appupdate.app.id, $scope.appupdate.manifest, portBindings, $scope.appupdate.password, function (error) {
|
||||
Client.updateApp($scope.appupdate.app.id, $scope.appupdate.manifest, $scope.appupdate.portBindings, $scope.appupdate.password, function (error) {
|
||||
if (error) {
|
||||
if (error.statusCode === 403) {
|
||||
$scope.appupdate.password = '';
|
||||
|
||||
Reference in New Issue
Block a user