diff --git a/src/js/client.js b/src/js/client.js index 2f71f1942..96a445c1c 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -31,22 +31,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N function defaultErrorHandler(callback) { return function (data, status) { if (status === 401) return client.login(); - if (status === 503) { - // this could indicate a update/upgrade/restore/migration - client.progress(function (error, result) { - if (error) { - client.error(error); - return callback(new ClientError(status, data)); - } - - if (result.update && result.update.percent !== -1) window.location.href = '/update.html'; - else callback(new ClientError(status, data)); - }, function (data, status) { - client.error(data); - return callback(new ClientError(status, data)); - }); - return; - } if (status >= 500) { client.error(data); return callback(new ClientError(status, data)); @@ -435,16 +419,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }).error(defaultErrorHandler(callback)); }; - Client.prototype.progress = function (callback, errorCallback) { - // this is used in the defaultErrorHandler itself, and avoids a loop - if (typeof errorCallback !== 'function') errorCallback = defaultErrorHandler(callback); - - get('/api/v1/cloudron/progress').success(function(data, status) { - if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); - callback(null, data); - }).error(errorCallback); - }; - Client.prototype.version = function (callback) { get('/api/v1/cloudron/status').success(function(data, status) { if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); diff --git a/src/js/main.js b/src/js/main.js index 8f49b4abf..bba911ad4 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -201,11 +201,6 @@ angular.module('Application').controller('MainController', ['$scope', '$route', }); Client.onConfig(function (config) { - // check if we are actually updating - // if (config.progress.update && config.progress.update.percent !== -1) { - // window.location.href = '/update.html'; - // } - if (config.cloudronName) { document.title = config.cloudronName; } diff --git a/src/js/update.js b/src/js/update.js deleted file mode 100644 index 251fccac9..000000000 --- a/src/js/update.js +++ /dev/null @@ -1,69 +0,0 @@ -'use strict'; - -// create main application module -var app = angular.module('Application', []); - -app.controller('Controller', ['$scope', '$http', '$interval', function ($scope, $http, $interval) { - $scope.title = ''; - $scope.percent = 0; - $scope.message = ''; - $scope.error = false; - - $scope.loadWebadmin = function () { - window.location.href = '/'; - }; - - function fetchProgress() { - $http.get('/api/v1/cloudron/progress').success(function(data, status) { - if (status === 404) return; // just wait until we create the progress.json on the server side - if (status !== 200 || typeof data !== 'object') return console.error('Invalid response for progress', status, data); - if (!data.update && !data.migrate) return $scope.loadWebadmin(); - - if (data.update) { - if (data.update.percent >= 100) { - return $scope.loadWebadmin(); - } else if (data.update.percent === -1) { - $scope.title = 'Update Error'; - $scope.error = true; - $scope.message = data.update.message; - } else { - if (data.backup && data.backup.percent < 100) { - $scope.title = 'Backup in progress...'; - $scope.percent = data.backup.percent < 0 ? 5 : (data.backup.percent / 100) * 50; // never show 0 as it looks like nothing happens - $scope.message = data.backup.message; - } else { - $scope.title = 'Update in progress...'; - $scope.percent = 50 + ((data.update.percent / 100) * 50); // first half is backup - $scope.message = data.update.message; - } - } - } else { // migrating - if (data.migrate.percent === -1) { - $scope.title = 'Migration Error'; - $scope.error = true; - $scope.message = data.migrate.message; - } else { - $scope.title = 'Migration in progress...'; - $scope.percent = data.migrate.percent; - $scope.message = data.migrate.message; - - if (!data.migrate.info) return; - - // check if the new domain is available via the appstore (cannot use cloudron - // directly as we might hit NXDOMAIN) - $http.get(data.apiServerOrigin + '/api/v1/boxes/' + data.migrate.info.domain + '/status').success(function(data2, status) { - if (status === 200 && data2.status === 'ready') { - window.location = 'https://my.' + data.migrate.info.domain; - } - }); - } - } - }).error(function (data, status) { - console.error('Error getting progress', status, data); - }); - } - - $interval(fetchProgress, 2000); - - fetchProgress(); -}]); diff --git a/src/update.html b/src/update.html deleted file mode 100644 index a0ceb82c8..000000000 --- a/src/update.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - Cloudron Update - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
- - - diff --git a/src/views/settings.html b/src/views/settings.html index ed8ff4c8c..2f449fb93 100644 --- a/src/views/settings.html +++ b/src/views/settings.html @@ -19,30 +19,17 @@
- - This update upgrades the base system and will cause some application downtime.
-

Changes:


{{ update.error.generic }}

-
-
-
- -
-
-
-
- Please use the CLI tool to upgrade by following the instructions here. -
@@ -185,10 +172,19 @@   - + +
+
+
+
+
{{ update.message }}
+
{{ update.errorMessage }}
+
+ - - + + + diff --git a/src/views/settings.js b/src/views/settings.js index e1df8f90e..4805ef9d0 100644 --- a/src/views/settings.js +++ b/src/views/settings.js @@ -26,16 +26,16 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca }; $scope.update = { - error: {}, + error: {}, // this is for the dialog busy: false, + percent: 0, + message: '', + errorMessage: '', // this shows inline - show: function (form) { + show: function () { $scope.update.error.generic = null; $scope.update.busy = false; - form.$setPristine(); - form.$setUntouched(); - if (!$scope.config.update.box.sourceTarballUrl) { $('#setupSubscriptionModal').modal('show'); } else { @@ -43,9 +43,52 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca } }, - submit: function () { + stopUpdate: function () { + Client.stopTask('update', function (error) { + if (error) { + if (error.statusCode === 409) { + $scope.update.errorMessage = 'No update is currently in progress'; + } else { + console.error(error); + $scope.update.errorMessage = error.message; + } + + $scope.update.busy = false; + + return; + } + }); + }, + + updateStatus: function () { + Client.getTaskProgress('update', function (error, data) { + if (error) return window.setTimeout($scope.update.updateStatus, 2000); + + if (!data.active) { + $scope.update.busy = false; + $scope.update.message = ''; + $scope.update.percent = 100; // indicates that 'result' is valid + $scope.update.errorMessage = data.errorMessage; + + if (!data.errorMessage) window.location.reload(true); // assume success + + return; + } + + $scope.update.busy = true; + $scope.update.percent = data.percent; + $scope.update.message = data.message; + + window.setTimeout($scope.update.updateStatus, 500); + }); + }, + + startUpdate: function () { $scope.update.error.generic = null; $scope.update.busy = true; + $scope.update.percent = 0; + $scope.update.message = ''; + $scope.update.errorMessage = ''; Client.update(function (error) { if (error) { @@ -59,7 +102,9 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca return; } - window.location.href = '/update.html'; + $('#updateModal').modal('hide'); + + $scope.update.updateStatus(); }); } };