2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// create main application module
|
|
|
|
|
var app = angular.module('Application', []);
|
|
|
|
|
|
|
|
|
|
app.controller('Controller', ['$scope', '$http', '$interval', function ($scope, $http, $interval) {
|
2016-06-29 23:26:47 -05:00
|
|
|
$scope.title = '';
|
2015-07-29 14:02:31 +02:00
|
|
|
$scope.percent = 0;
|
|
|
|
|
$scope.message = '';
|
|
|
|
|
$scope.error = false;
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2015-07-29 14:02:31 +02:00
|
|
|
$scope.loadWebadmin = function () {
|
2015-07-20 00:09:47 -07:00
|
|
|
window.location.href = '/';
|
2015-07-29 14:02:31 +02:00
|
|
|
};
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
function fetchProgress() {
|
2015-07-29 14:02:31 +02:00
|
|
|
$http.get('/api/v1/cloudron/progress').success(function(data, status) {
|
2015-07-20 00:09:47 -07:00
|
|
|
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(status, data);
|
2016-06-28 16:21:22 -05:00
|
|
|
if (data.update === null && data.migrate === null) return $scope.loadWebadmin();
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-06-28 16:21:22 -05:00
|
|
|
if (data.update) {
|
|
|
|
|
if (data.update.percent === -1) {
|
|
|
|
|
$scope.title = 'Update Error';
|
|
|
|
|
$scope.error = true;
|
|
|
|
|
$scope.message = data.update.message;
|
|
|
|
|
} else {
|
2016-06-29 23:26:47 -05:00
|
|
|
$scope.title = 'Update in progress...';
|
2016-06-28 16:21:22 -05:00
|
|
|
$scope.percent = data.update.percent;
|
|
|
|
|
$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 {
|
2016-06-29 23:26:47 -05:00
|
|
|
$scope.title = 'Migration in progress...';
|
2016-06-28 16:21:22 -05:00
|
|
|
$scope.percent = data.migrate.percent;
|
|
|
|
|
$scope.message = data.migrate.message;
|
|
|
|
|
}
|
2015-07-29 14:02:31 +02:00
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
}).error(function (data, status) {
|
|
|
|
|
console.error(status, data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$interval(fetchProgress, 2000);
|
|
|
|
|
|
|
|
|
|
fetchProgress();
|
|
|
|
|
}]);
|