Add restore and backup logic to app view

This commit is contained in:
Johannes Zellner
2019-09-13 17:07:45 +02:00
parent a1fe79c876
commit 8f8aa31304
4 changed files with 115 additions and 202 deletions

View File

@@ -35,9 +35,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
portBindingsEnabled: {},
show: function (app, backup) {
// hide restore modal if open
$('#appRestoreModal').modal('hide');
$scope.appClone.busy = false;
$scope.appClone.error = {};
$scope.appClone.app = app;
@@ -97,87 +94,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
}
};
$scope.appRestore = {
busy: false,
busyFetching: false,
error: {},
app: {},
backups: [],
copyBackupIdDone: false,
creatingBackup: false,
copyBackupId: function (backup) {
var copyText = document.getElementById('appRestoreBackupIdHelper');
copyText.value = backup.id;
copyText.select();
document.execCommand('copy');
$scope.appRestore.copyBackupIdDone = true;
// reset after 2.5sec
$timeout(function () { $scope.appRestore.copyBackupIdDone = false; }, 2500);
},
createBackup: function () {
$scope.appRestore.creatingBackup = true;
Client.backupApp($scope.appRestore.app.id, function (error) {
if (error) Client.error(error);
function waitForBackupFinish() {
if ($scope.appRestore.app.installationState === 'pending_backup') return $timeout(waitForBackupFinish, 1000);
// we are done, refresh the backup list
Client.getAppBackups($scope.appRestore.app.id, function (error, backups) {
if (error) return Client.error(error);
$scope.appRestore.backups = backups;
$scope.appRestore.creatingBackup = false;
});
}
// reflect the new app state immediately
Client.refreshAppCache($scope.appRestore.app.id, waitForBackupFinish);
});
},
show: function (app) {
$scope.reset();
$scope.appRestore.app = app;
$scope.appRestore.busyFetching = true;
$scope.appRestore.creatingBackup = $scope.appRestore.app.installationState === 'pending_backup';
$('#appRestoreModal').modal('show');
Client.getAppBackups(app.id, function (error, backups) {
if (error) {
Client.error(error);
} else {
$scope.appRestore.backups = backups;
$scope.appRestore.busyFetching = false;
}
});
return false; // prevent propagation and default
},
restore: function (backup) {
$scope.appRestore.busy = true;
Client.restoreApp($scope.appRestore.app.id, backup.id, function (error) {
if (error) {
Client.error(error);
} else {
$('#appRestoreModal').modal('hide');
}
$scope.appRestore.busy = false;
Client.refreshAppCache($scope.appRestore.app.id); // reflect the new app state immediately
});
}
};
$scope.appPostInstallConfirm = {
app: {},
@@ -256,7 +172,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.reset = function () {
// close all dialogs
$('#appErrorModal').modal('hide');
$('#appRestoreModal').modal('hide');
$('#appUpdateModal').modal('hide');
$('#appPostInstallConfirmModal').modal('hide');
@@ -265,17 +180,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.appUpdate.app = {};
$scope.appUpdate.manifest = {};
// reset restore dialog
$scope.appRestore.error = {};
$scope.appRestore.app = {};
$scope.appRestore.backups = [];
$scope.appRestore.location = '';
$scope.appRestore.domain = null;
$scope.appRestore.portBindings = {};
$scope.appRestore.portBindingsInfo = {};
$scope.appRestore.portBindingsEnabled = {};
$scope.appRestore.action = 'restore';
// post install confirmation dialog
$scope.appPostInstallConfirm.app = {};
$scope.appPostInstallConfirm.message = '';
@@ -358,7 +262,7 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
});
// setup all the dialog focus handling
['appUpdateModal', 'appRestoreModal', 'appErrorModal'].forEach(function (id) {
['appUpdateModal', 'appErrorModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
});