Move app clone into app view
This commit is contained in:
@@ -515,6 +515,76 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
|
||||
}
|
||||
};
|
||||
|
||||
$scope.clone = {
|
||||
busy: true,
|
||||
error: {},
|
||||
|
||||
backup: null,
|
||||
location: '',
|
||||
domain: null,
|
||||
portBindings: {},
|
||||
portBindingsInfo: {},
|
||||
portBindingsEnabled: {},
|
||||
|
||||
show: function (backup) {
|
||||
var app = $scope.app;
|
||||
|
||||
$scope.clone.backup = backup;
|
||||
$scope.clone.domain = $scope.domains.find(function (d) { return app.domain === d.domain; }); // pre-select the app's domain
|
||||
$scope.clone.portBindingsInfo = angular.extend({}, app.manifest.tcpPorts, app.manifest.udpPorts); // Portbinding map only for information
|
||||
// set default ports
|
||||
for (var env in $scope.clone.portBindingsInfo) {
|
||||
$scope.clone.portBindings[env] = $scope.clone.portBindingsInfo[env].defaultValue || 0;
|
||||
$scope.clone.portBindingsEnabled[env] = true;
|
||||
}
|
||||
|
||||
$('#cloneModal').modal('show');
|
||||
},
|
||||
|
||||
submit: function () {
|
||||
$scope.clone.busy = true;
|
||||
|
||||
// only use enabled ports from portBindings
|
||||
var finalPortBindings = {};
|
||||
for (var env in $scope.clone.portBindings) {
|
||||
if ($scope.clone.portBindingsEnabled[env]) {
|
||||
finalPortBindings[env] = $scope.clone.portBindings[env];
|
||||
}
|
||||
}
|
||||
|
||||
var data = {
|
||||
location: $scope.clone.location,
|
||||
domain: $scope.clone.domain.domain,
|
||||
portBindings: finalPortBindings,
|
||||
backupId: $scope.clone.backup.id
|
||||
};
|
||||
|
||||
Client.cloneApp($scope.app.id, data, function (error, clonedApp) {
|
||||
$scope.clone.busy = false;
|
||||
|
||||
if (error) {
|
||||
if (error.statusCode === 409) {
|
||||
if (error.portName) {
|
||||
$scope.clone.error.port = error.message;
|
||||
} else if (error.domain) {
|
||||
$scope.clone.error.location = 'This location is already taken.';
|
||||
$('#cloneLocationInput').focus();
|
||||
} else {
|
||||
Client.error(error);
|
||||
}
|
||||
} else {
|
||||
Client.error(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$('#cloneModal').modal('hide');
|
||||
|
||||
$location.path('/apps');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function fetchUsers(callback) {
|
||||
Client.getUsers(function (error, users) {
|
||||
if (error) return callback(error);
|
||||
|
||||
Reference in New Issue
Block a user