Add clone UI

part of #248
This commit is contained in:
Girish Ramakrishnan
2018-05-28 00:47:53 -07:00
parent 8da07a16b9
commit 1d88a935a5
3 changed files with 128 additions and 0 deletions

View File

@@ -190,6 +190,13 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
backups: [ ],
selectedBackup: null,
// from clone
location: '',
domain: null,
portBindings: {},
portBindingsInfo: {},
portBindingsEnabled: {},
selectBackup: function (backup) {
$scope.appRestore.selectedBackup = backup;
},
@@ -206,12 +213,47 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
});
},
clone: function () {
var data = {
location: $scope.appRestore.location,
domain: $scope.appRestore.domain.domain,
portBindings: $scope.appRestore.portBindings,
backupId: $scope.appRestore.selectedBackup.id
};
Client.cloneApp($scope.appRestore.app.id, data, function (error) {
if (error) {
if (error.statusCode === 409 && (error.message.indexOf('is reserved') !== -1 || error.message.indexOf('is already in use') !== -1)) {
$scope.appRestore.error.port = error.message;
} else if (error.statusCode === 409) {
$scope.appRestore.error.location = 'This name is already taken.';
$scope.appCloneForm.location.$setPristine();
$('#appRestoreLocationInput').focus();
} else {
Client.error(error);
}
} else {
$('#appRestoreModal').modal('hide');
}
Client.refreshInstalledApps(); // reflect the new app state immediately
});
},
show: function (app) {
$scope.reset();
$scope.appRestore.app = app;
$scope.appRestore.busyFetching = true;
$scope.appRestore.domain = $scope.domains.find(function (d) { return app.domain === d.domain; }); // pre-select the app's domain
$scope.appRestore.portBindingsInfo = $scope.appRestore.app.manifest.tcpPorts || {}; // Portbinding map only for information
// set default ports
for (var env in $scope.appRestore.app.manifest.tcpPorts) {
$scope.appRestore.portBindings[env] = $scope.appRestore.app.manifest.tcpPorts[env].defaultValue || 0;
$scope.appRestore.portBindingsEnabled[env] = true;
}
$('#appRestoreModal').modal('show');
Client.getAppBackups(app.id, function (error, backups) {
@@ -319,6 +361,11 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.appRestore.password = '';
$scope.appRestore.selectedBackup = null;
$scope.appRestore.backups = [];
$scope.appRestore.location = '';
$scope.appRestore.domain = null;
$scope.appRestore.portBindings = {};
$scope.appRestore.portBindingsInfo = {};
$scope.appRestore.portBindingsEnabled = {};
$scope.appRestoreForm.$setPristine();
$scope.appRestoreForm.$setUntouched();