diff --git a/src/views/apps.html b/src/views/apps.html
index 438dd666d..4aabd8dc9 100644
--- a/src/views/apps.html
+++ b/src/views/apps.html
@@ -257,107 +257,115 @@
-
-
-
-
-
Fetching backups
+
+
+
+
+
Fetching backups
+
This app has no backups yet.
-
+
+
-
-
-
-
- This app has no backups to restore or clone from yet.
-
-
Restoring the app will lose all it's data since the backup.
-
-
-
-
-
-
-
-
-
-
+
+
+
+ | |
+ Created |
+ Version |
+ Actions |
+
+
+
+
+
|
+ {{ backup.creationTime | prettyDate }} |
+ v{{ backup.version }} |
+
+
+
+
+
+ |
+
+
+
+
+
-
-
-
- This app has no backups to restore or clone from yet.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
Using backup from {{ appClone.backup.creationTime | prettyDate }} and version v{{ appClone.backup.version }}
+
+
+
+
+
+
diff --git a/src/views/apps.js b/src/views/apps.js
index d7306f370..aafc8fd57 100644
--- a/src/views/apps.js
+++ b/src/views/apps.js
@@ -281,27 +281,89 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
app: {}
};
- $scope.appRestore = {
+ $scope.appClone = {
busy: false,
- busyFetching: false,
error: {},
app: {},
- backups: [ ],
- selectedBackup: null,
+ backup: {},
- // from clone
+ // form
location: '',
domain: null,
portBindings: {},
portBindingsInfo: {},
portBindingsEnabled: {},
- action: 'restore',
+ show: function (app, backup) {
+ // hide restore modal if open
+ $('#appRestoreModal').modal('hide');
+ $scope.appClone.busy = false;
+ $scope.appClone.error = {};
+ $scope.appClone.app = app;
+ $scope.appClone.backup = backup;
+ $scope.appClone.location = '';
+ $scope.appClone.domain = $scope.domains.find(function (d) { return app.domain === d.domain; }); // pre-select the app's domain
+ $scope.appClone.portBindingsInfo = angular.extend({}, $scope.appClone.app.manifest.tcpPorts, $scope.appClone.app.manifest.udpPorts); // Portbinding map only for information
+ // set default ports
+ for (var env in $scope.appClone.portBindingsInfo) {
+ $scope.appClone.portBindings[env] = $scope.appClone.portBindingsInfo[env].defaultValue || 0;
+ $scope.appClone.portBindingsEnabled[env] = true;
+ }
+
+ $('#appCloneModal').modal('show');
+ },
+
+ submit: function () {
+ $scope.appClone.busy = true;
+
+ // only use enabled ports from portBindings
+ var finalPortBindings = {};
+ for (var env in $scope.appClone.portBindings) {
+ if ($scope.appClone.portBindingsEnabled[env]) {
+ finalPortBindings[env] = $scope.appClone.portBindings[env];
+ }
+ }
+
+ var data = {
+ location: $scope.appClone.location,
+ domain: $scope.appClone.domain.domain,
+ portBindings: finalPortBindings,
+ backupId: $scope.appClone.backup.id
+ };
+
+ Client.cloneApp($scope.appClone.app.id, data, function (error, clonedApp) {
+ $scope.appClone.busy = false;
+
+ if (error) {
+ if (error.statusCode === 409 && (error.message.indexOf('is reserved') !== -1 || error.message.indexOf('is already in use') !== -1)) {
+ $scope.appClone.error.port = error.message;
+ } else if (error.statusCode === 409) {
+ $scope.appClone.error.location = 'This location is already taken.';
+ $('#appCloneLocationInput').focus();
+ } else {
+ Client.error(error);
+ }
+ return;
+ }
+ $('#appCloneModal').modal('hide');
+
+ Client.refreshAppCache(clonedApp.id); // reflect the new app state immediately
+ });
+ }
+ }
+
+ $scope.appRestore = {
+ busy: false,
+ busyFetching: false,
+ error: {},
+ app: {},
+ backups: [],
copyBackupIdDone: false,
- copyBackupId: function () {
- var copyText = document.getElementById('appRestoreSelectedBackupId');
+ copyBackupId: function (backup) {
+ var copyText = document.getElementById('appRestoreBackupIdHelper');
+ copyText.value = backup.id;
copyText.select();
document.execCommand('copy');
@@ -311,10 +373,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$timeout(function () { $scope.appRestore.copyBackupIdDone = false; }, 2500);
},
- selectBackup: function (backup) {
- $scope.appRestore.selectedBackup = backup;
- },
-
createBackup: function () {
Client.backupApp($scope.appRestore.app.id, function (error) {
if (error) Client.error(error);
@@ -327,7 +385,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
if (error) return Client.error(error);
$scope.appRestore.backups = backups;
- if (backups.length) $scope.appRestore.selectedBackup = backups[0]; // pre-select first backup
});
}
@@ -336,60 +393,12 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
});
},
- clone: function () {
- $scope.appRestore.busy = true;
-
- // only use enabled ports from portBindings
- var finalPortBindings = {};
- for (var env in $scope.appRestore.portBindings) {
- if ($scope.appRestore.portBindingsEnabled[env]) {
- finalPortBindings[env] = $scope.appRestore.portBindings[env];
- }
- }
-
- var data = {
- location: $scope.appRestore.location,
- domain: $scope.appRestore.domain.domain,
- portBindings: finalPortBindings,
- backupId: $scope.appRestore.selectedBackup.id
- };
-
- Client.cloneApp($scope.appRestore.app.id, data, function (error, clonedApp) {
- $scope.appRestore.busy = false;
-
- 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.';
- $('#appRestoreLocationInput').focus();
- } else {
- Client.error(error);
- }
- return;
- }
- $('#appRestoreModal').modal('hide');
-
- Client.refreshAppCache(clonedApp.id); // 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 = angular.extend({}, $scope.appRestore.app.manifest.tcpPorts, $scope.appRestore.app.manifest.udpPorts); // Portbinding map only for information
- // set default ports
- for (var env in $scope.appRestore.portBindingsInfo) {
- $scope.appRestore.portBindings[env] = $scope.appRestore.portBindingsInfo[env].defaultValue || 0;
- $scope.appRestore.portBindingsEnabled[env] = true;
- }
-
- $scope.appRestore.action = 'restore';
-
$('#appRestoreModal').modal('show');
Client.getAppBackups(app.id, function (error, backups) {
@@ -397,7 +406,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
Client.error(error);
} else {
$scope.appRestore.backups = backups;
- if (backups.length) $scope.appRestore.selectedBackup = backups[0]; // pre-select first backup
$scope.appRestore.busyFetching = false;
}
});
@@ -405,10 +413,10 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
return false; // prevent propagation and default
},
- restore: function () {
+ restore: function (backup) {
$scope.appRestore.busy = true;
- Client.restoreApp($scope.appRestore.app.id, $scope.appRestore.selectedBackup.id, function (error) {
+ Client.restoreApp($scope.appRestore.app.id, backup.id, function (error) {
if (error) {
Client.error(error);
} else {
@@ -512,7 +520,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
// reset restore dialog
$scope.appRestore.error = {};
$scope.appRestore.app = {};
- $scope.appRestore.selectedBackup = null;
$scope.appRestore.backups = [];
$scope.appRestore.location = '';
$scope.appRestore.domain = null;