2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2019-01-22 10:54:03 +01:00
|
|
|
/* global angular:false */
|
|
|
|
|
/* global $:false */
|
|
|
|
|
|
2019-05-04 21:57:42 -07:00
|
|
|
angular.module('Application').controller('SettingsController', ['$scope', '$location', '$rootScope', '$timeout', 'Client', function ($scope, $location, $rootScope, $timeout, Client) {
|
2020-02-24 12:56:13 +01:00
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.client = Client;
|
|
|
|
|
$scope.user = Client.getUserInfo();
|
|
|
|
|
$scope.config = Client.getConfig();
|
2018-03-30 15:12:34 +02:00
|
|
|
$scope.installedApps = Client.getInstalledApps();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-03-28 12:29:37 +02:00
|
|
|
$scope.subscription = null;
|
2019-05-06 11:39:45 +02:00
|
|
|
$scope.subscriptionBusy = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2020-06-18 12:29:25 +02:00
|
|
|
$scope.openSubscriptionSetup = function () {
|
|
|
|
|
Client.openSubscriptionSetup($scope.subscription || {});
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-09 00:32:34 -08:00
|
|
|
$scope.prettyProviderName = function (provider) {
|
|
|
|
|
switch (provider) {
|
2018-09-05 14:37:54 -07:00
|
|
|
case 'caas': return 'Managed Cloudron';
|
|
|
|
|
default: return provider;
|
2018-03-09 00:32:34 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-30 15:12:34 +02:00
|
|
|
$scope.update = {
|
2018-11-30 16:06:37 -08:00
|
|
|
error: {}, // this is for the dialog
|
2018-03-30 15:12:34 +02:00
|
|
|
busy: false,
|
2020-03-18 21:31:51 -07:00
|
|
|
checking: false,
|
2018-11-30 16:06:37 -08:00
|
|
|
percent: 0,
|
2018-12-10 16:50:40 +01:00
|
|
|
message: 'Downloading',
|
2018-11-30 16:06:37 -08:00
|
|
|
errorMessage: '', // this shows inline
|
2018-12-09 10:45:01 -08:00
|
|
|
taskId: '',
|
2019-05-12 13:08:40 -07:00
|
|
|
skipBackup: false,
|
2018-03-30 15:12:34 +02:00
|
|
|
|
2020-03-18 21:31:51 -07:00
|
|
|
checkNow: function () {
|
|
|
|
|
$scope.update.checking = true;
|
|
|
|
|
|
|
|
|
|
Client.checkForUpdates(function (error) {
|
|
|
|
|
if (error) Client.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.update.checking = false;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2018-11-30 16:06:37 -08:00
|
|
|
show: function () {
|
2018-03-30 15:12:34 +02:00
|
|
|
$scope.update.error.generic = null;
|
|
|
|
|
$scope.update.busy = false;
|
|
|
|
|
|
2020-02-14 14:16:04 +01:00
|
|
|
$('#updateModal').modal('show');
|
2018-03-30 15:12:34 +02:00
|
|
|
},
|
|
|
|
|
|
2018-11-30 16:06:37 -08:00
|
|
|
stopUpdate: function () {
|
2019-01-24 15:55:21 -08:00
|
|
|
Client.stopTask($scope.update.taskId, function (error) {
|
2018-11-30 16:06:37 -08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2018-12-08 20:21:11 -08:00
|
|
|
checkStatus: function () {
|
2018-12-09 10:45:01 -08:00
|
|
|
Client.getLatestTaskByType('update', function (error, task) {
|
2018-12-08 20:21:11 -08:00
|
|
|
if (error) return console.error(error);
|
2019-01-06 14:52:36 -08:00
|
|
|
if (!task) return;
|
2018-12-08 20:21:11 -08:00
|
|
|
|
2018-12-09 10:45:01 -08:00
|
|
|
$scope.update.taskId = task.id;
|
|
|
|
|
$scope.update.updateStatus();
|
2018-12-08 20:21:11 -08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2018-12-09 10:45:01 -08:00
|
|
|
reloadIfNeeded: function () {
|
|
|
|
|
Client.getStatus(function (error, status) {
|
|
|
|
|
if (error) return $scope.error(error);
|
|
|
|
|
|
|
|
|
|
if (window.localStorage.version !== status.version) window.location.reload(true);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updateStatus: function () {
|
|
|
|
|
Client.getTask($scope.update.taskId, function (error, data) {
|
|
|
|
|
if (error) return window.setTimeout($scope.update.updateStatus, 5000);
|
2018-11-30 16:06:37 -08:00
|
|
|
|
|
|
|
|
if (!data.active) {
|
|
|
|
|
$scope.update.busy = false;
|
|
|
|
|
$scope.update.message = '';
|
|
|
|
|
$scope.update.percent = 100; // indicates that 'result' is valid
|
2019-08-30 14:24:59 -07:00
|
|
|
$scope.update.errorMessage = data.success ? '' : data.error.message;
|
2018-11-30 16:06:37 -08:00
|
|
|
|
2018-12-09 10:45:01 -08:00
|
|
|
if (!data.errorMessage) $scope.update.reloadIfNeeded(); // assume success
|
2018-11-30 16:06:37 -08:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.update.busy = true;
|
|
|
|
|
$scope.update.percent = data.percent;
|
|
|
|
|
$scope.update.message = data.message;
|
|
|
|
|
|
2018-12-09 10:45:01 -08:00
|
|
|
window.setTimeout($scope.update.updateStatus, 500);
|
2018-11-30 16:06:37 -08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
startUpdate: function () {
|
2018-03-30 15:12:34 +02:00
|
|
|
$scope.update.error.generic = null;
|
|
|
|
|
$scope.update.busy = true;
|
2018-11-30 16:06:37 -08:00
|
|
|
$scope.update.percent = 0;
|
|
|
|
|
$scope.update.message = '';
|
|
|
|
|
$scope.update.errorMessage = '';
|
2018-03-30 15:12:34 +02:00
|
|
|
|
2019-05-12 13:08:40 -07:00
|
|
|
Client.update({ skipBackup: $scope.update.skipBackup }, function (error, taskId) {
|
2018-03-30 15:12:34 +02:00
|
|
|
if (error) {
|
2018-12-04 14:12:35 -08:00
|
|
|
$scope.update.error.generic = error.message;
|
2018-03-30 15:12:34 +02:00
|
|
|
$scope.update.busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-30 16:06:37 -08:00
|
|
|
$('#updateModal').modal('hide');
|
|
|
|
|
|
2018-12-09 10:45:01 -08:00
|
|
|
$scope.update.taskId = taskId;
|
|
|
|
|
$scope.update.updateStatus();
|
2018-03-30 15:12:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-07 21:41:45 +01:00
|
|
|
$scope.timeZone = {
|
|
|
|
|
busy: false,
|
|
|
|
|
success: false,
|
|
|
|
|
error: '',
|
|
|
|
|
timeZone: '',
|
|
|
|
|
currentTimeZone: '',
|
2020-01-08 13:01:31 +01:00
|
|
|
availableTimeZones: window.timezones,
|
2020-01-07 21:41:45 +01:00
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
if ($scope.timeZone.timeZone === $scope.timeZone.currentTimeZone) return;
|
|
|
|
|
|
|
|
|
|
$scope.timeZone.error = '';
|
|
|
|
|
$scope.timeZone.busy = true;
|
|
|
|
|
$scope.timeZone.success = false;
|
|
|
|
|
|
2020-01-08 13:01:31 +01:00
|
|
|
Client.setTimeZone($scope.timeZone.timeZone.id, function (error) {
|
2020-01-07 21:41:45 +01:00
|
|
|
if (error) $scope.timeZone.error = error.message;
|
|
|
|
|
else $scope.timeZone.currentTimeZone = $scope.timeZone.timeZone;
|
|
|
|
|
|
|
|
|
|
$scope.timeZone.busy = false;
|
|
|
|
|
$scope.timeZone.success = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-18 21:31:51 -07:00
|
|
|
};
|
2020-01-07 21:41:45 +01:00
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.autoUpdate = {
|
|
|
|
|
busy: false,
|
|
|
|
|
pattern: '',
|
|
|
|
|
currentPattern: '',
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
if ($scope.autoUpdate.pattern === $scope.autoUpdate.currentPattern) return;
|
|
|
|
|
|
|
|
|
|
$scope.autoUpdate.busy = true;
|
|
|
|
|
|
2018-02-06 19:23:52 +01:00
|
|
|
Client.setAppAutoupdatePattern($scope.autoUpdate.pattern, function (error) {
|
2020-03-18 21:31:51 -07:00
|
|
|
if (error) Client.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
else $scope.autoUpdate.currentPattern = $scope.autoUpdate.pattern;
|
|
|
|
|
|
2020-03-18 21:31:51 -07:00
|
|
|
$timeout(function () {
|
|
|
|
|
$scope.autoUpdate.busy = false;
|
|
|
|
|
}, 3000);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-07 21:41:45 +01:00
|
|
|
function getTimeZone() {
|
|
|
|
|
Client.getTimeZone(function (error, timeZone) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2020-01-08 13:01:31 +01:00
|
|
|
$scope.timeZone.currentTimeZone = window.timezones.find(function (t) { return t.id === timeZone; });
|
|
|
|
|
$scope.timeZone.timeZone = $scope.timeZone.currentTimeZone;
|
2020-01-07 21:41:45 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
function getAutoupdatePattern() {
|
2018-02-06 19:23:52 +01:00
|
|
|
Client.getAppAutoupdatePattern(function (error, result) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.autoUpdate.currentPattern = result.pattern;
|
|
|
|
|
$scope.autoUpdate.pattern = result.pattern;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 22:31:38 -07:00
|
|
|
function getRegistryConfig() {
|
|
|
|
|
Client.getRegistryConfig(function (error, result) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2019-11-07 23:04:02 -08:00
|
|
|
$scope.registryConfig.currentConfig.serverAddress = result.serverAddress;
|
|
|
|
|
$scope.registryConfig.currentConfig.username = result.username || '';
|
|
|
|
|
$scope.registryConfig.currentConfig.email = result.email || '';
|
|
|
|
|
$scope.registryConfig.currentConfig.password = result.password;
|
2019-10-22 22:31:38 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
function getSubscription() {
|
2019-05-06 11:39:45 +02:00
|
|
|
$scope.subscriptionBusy = true;
|
|
|
|
|
|
2019-05-04 21:26:50 -07:00
|
|
|
Client.getSubscription(function (error, result) {
|
2019-05-06 11:39:45 +02:00
|
|
|
$scope.subscriptionBusy = false;
|
|
|
|
|
|
2019-05-13 16:39:52 -07:00
|
|
|
if (error && error.statusCode === 412) return; // not yet registered
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.subscription = result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 22:31:38 -07:00
|
|
|
$scope.registryConfig = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: null,
|
|
|
|
|
serverAddress: '',
|
|
|
|
|
username: '',
|
|
|
|
|
password: '',
|
2019-10-23 06:11:27 -07:00
|
|
|
email: '',
|
2019-11-07 23:04:02 -08:00
|
|
|
currentConfig: {},
|
2019-10-22 22:31:38 -07:00
|
|
|
|
|
|
|
|
reset: function () {
|
2020-04-03 09:56:38 -07:00
|
|
|
$scope.registryConfig.busy = false;
|
2019-10-22 22:31:38 -07:00
|
|
|
$scope.registryConfig.error = null;
|
|
|
|
|
|
2019-11-07 23:04:02 -08:00
|
|
|
$scope.registryConfig.serverAddress = $scope.registryConfig.currentConfig.serverAddress;
|
|
|
|
|
$scope.registryConfig.username = $scope.registryConfig.currentConfig.username;
|
|
|
|
|
$scope.registryConfig.email = $scope.registryConfig.currentConfig.email;
|
|
|
|
|
$scope.registryConfig.password = $scope.registryConfig.currentConfig.password;
|
|
|
|
|
|
2019-10-22 22:31:38 -07:00
|
|
|
$scope.registryConfigForm.$setUntouched();
|
|
|
|
|
$scope.registryConfigForm.$setPristine();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.registryConfig.reset();
|
|
|
|
|
$('#registryConfigModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.registryConfig.busy = true;
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
serverAddress: $scope.registryConfig.serverAddress,
|
2019-10-23 06:11:27 -07:00
|
|
|
username: $scope.registryConfig.username || '',
|
|
|
|
|
password: $scope.registryConfig.password,
|
|
|
|
|
email: $scope.registryConfig.email || '',
|
2019-10-22 22:31:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.setRegistryConfig(data, function (error) {
|
|
|
|
|
$scope.registryConfig.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2019-10-23 06:11:27 -07:00
|
|
|
$scope.registryConfig.error = error.message;
|
2019-10-22 22:31:38 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#registryConfigModal').modal('hide');
|
|
|
|
|
|
|
|
|
|
getRegistryConfig();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
Client.onReady(function () {
|
|
|
|
|
getAutoupdatePattern();
|
2019-10-22 22:31:38 -07:00
|
|
|
getRegistryConfig();
|
2020-01-07 21:41:45 +01:00
|
|
|
getTimeZone();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-12-08 20:21:11 -08:00
|
|
|
$scope.update.checkStatus();
|
2018-12-04 14:05:55 -08:00
|
|
|
|
2020-03-06 11:42:27 -08:00
|
|
|
if ($scope.user.isAtLeastOwner) getSubscription();
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// setup all the dialog focus handling
|
2020-03-18 21:31:51 -07:00
|
|
|
['planChangeModal', 'appstoreLoginModal'].forEach(function (id) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
|
|
|
$(this).find("[autofocus]:first").focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|