diff --git a/src/js/client.js b/src/js/client.js index e262d911b..bf9cfe990 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -134,8 +134,6 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N this.apiOrigin = '<%= oauth.apiOrigin %>' || window.location.origin; this.avatar = ''; - this._refreshConfigTimer = null; - this.resetAvatar(); this.setToken(localStorage.token); @@ -283,9 +281,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N * Rest API wrappers */ Client.prototype.config = function (callback) { - var configRoute = this.hasScope('cloudron') ? '/api/v1/cloudron/config' : '/api/v1/user/cloudron_config'; - - get(configRoute).success(function(data, status) { + get('/api/v1/config').success(function(data, status) { if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); callback(null, data); }).error(defaultErrorHandler(callback)); @@ -497,6 +493,13 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }).error(defaultErrorHandler(callback)); }; + Client.prototype.getUpdateInfo = function (callback) { + get('/api/v1/cloudron/update').success(function(data, status) { + if (status !== 200) return callback(new ClientError(status, data)); + callback(null, data); + }).error(defaultErrorHandler(callback)); + }; + Client.prototype.checkForUpdates = function (callback) { var that = this; @@ -550,6 +553,13 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }).error(defaultErrorHandler(callback)); }; + Client.prototype.getCaasConfig = function (callback) { + get('/api/v1/caas/config').success(function(data, status) { + if (status !== 200) return callback(new ClientError(status, data)); + callback(null, data); + }).error(defaultErrorHandler(callback)); + }; + Client.prototype.addAuthorizedKey = function (key, callback) { put('/api/v1/cloudron/ssh/authorized_keys', { key: key }).success(function (data, status) { if (status !== 201) return callback(new ClientError(status, data)); @@ -971,6 +981,17 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N }).error(defaultErrorHandler(callback)); }; + Client.prototype.transferOwnership = function (oldOwnerId, newOwnerId, callback) { + var data = { + ownerId: newOwnerId + }; + + post('/api/v1/users/' + oldOwnerId + '/transfer', data).success(function (data, status) { + if (status !== 200) return callback(new ClientError(status, data)); + callback(null); + }).error(defaultErrorHandler(callback)); + }; + Client.prototype.removeUser = function (userId, password, callback) { var config = { data: { @@ -1058,9 +1079,12 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N this.config(function (error, result) { if (error) return callback(error); - that.setConfig(result); + that.getUpdateInfo(function (error, info) { // note: non-admin users may get access denied for this + if (!error) result.update = info.update; // attach update information to config object - callback(null); + that.setConfig(result); + callback(null); + }); }); }; diff --git a/src/views/settings.html b/src/views/settings.html index 5b4db186e..83018915e 100644 --- a/src/views/settings.html +++ b/src/views/settings.html @@ -168,7 +168,7 @@ Model - {{ config.size }} - {{ config.region }} + {{ caasConfig.size }} - {{ caasConfig.region }} Version diff --git a/src/views/settings.js b/src/views/settings.js index c093a7c9b..bb90e4c25 100644 --- a/src/views/settings.js +++ b/src/views/settings.js @@ -6,6 +6,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca $scope.client = Client; $scope.user = Client.getUserInfo(); $scope.config = Client.getConfig(); + $scope.caasConfig = {}; $scope.appstoreConfig = {}; $scope.installedApps = Client.getInstalledApps(); @@ -318,13 +319,13 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca result = result.filter(function (size) { // only show plans bigger than the current size if (found) return true; - found = SIZE_SLUGS.indexOf(size.slug) > SIZE_SLUGS.indexOf($scope.config.plan.slug); + found = SIZE_SLUGS.indexOf(size.slug) > SIZE_SLUGS.indexOf($scope.caasConfig.plan.slug); return found; }); angular.copy(result, $scope.availablePlans); // prepend the current plan - $scope.availablePlans.unshift($scope.config.plan); + $scope.availablePlans.unshift($scope.caasConfig.plan); $scope.planChange.requestedPlan = $scope.availablePlans[0]; // need the reference to preselect @@ -333,7 +334,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca angular.copy(result, $scope.availableRegions); - $scope.currentRegionSlug = $scope.config.region; + $scope.currentRegionSlug = $scope.caasConfig.region; }); }); } @@ -406,10 +407,16 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca getAutoupdatePattern(); if ($scope.config.provider === 'caas') { - getPlans(); + Client.getCaasConfig(function (error, caasConfig) { + if (error) return console.error(error); - $scope.currentPlan = $scope.config.plan; - $scope.currency = $scope.config.currency === 'eur' ? '€' : '$'; + $scope.caasConfig = caasConfig; + + getPlans(); + + $scope.currentPlan = caasConfig.plan; + $scope.currency = caasConfig.currency === 'eur' ? '€' : '$'; + }); } else { Client.getAppstoreConfig(function (error, appstoreConfig) { if (error) return console.error(error);