Files
cloudron-box/dashboard/public/views/support.js

97 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-01-22 13:01:38 -08:00
'use strict';
/* global angular:false */
/* global $:false */
/* global ISTATES */
/* global async */
2018-01-22 13:01:38 -08:00
angular.module('Application').controller('SupportController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
2022-10-04 10:24:48 +02:00
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastOwner) $location.path('/'); });
2021-10-19 15:14:52 +02:00
$scope.ready = false;
2018-01-22 13:01:38 -08:00
$scope.config = Client.getConfig();
$scope.user = Client.getUserInfo();
$scope.installedApps = Client.getInstalledApps();
2018-01-22 13:01:38 -08:00
$scope.toggleSshSupportError = '';
2018-01-22 13:01:38 -08:00
$scope.sshSupportEnabled = false;
$scope.troubleshoot = $location.search().troubleshoot;
$scope.updateAllBusy = false;
$scope.repairAllBusy = false;
$scope.troubleshootingMessage = '';
$scope.updateAll = function () {
$scope.updateAllBusy = true;
$scope.troubleshootingMessage = '';
let count = 0, unstable = 0;
Client.checkForUpdates(function (error) {
if (error) Client.error(error);
async.eachSeries(Object.keys($scope.config.update), function (appId, iteratorDone) {
if ($scope.config.update[appId].unstable) { ++unstable; return iteratorDone(); }
Client.updateApp(appId, $scope.config.update[appId].manifest, { skipBackup: false }, function (error) {
if (error) Client.error(error);
else ++count;
iteratorDone();
});
}, function () {
$scope.troubleshootingMessage = `${count} apps updated. ${unstable} apps with unstable updates skipped.`;
$scope.updateAllBusy = false;
});
});
};
$scope.repairAll = function () {
$scope.repairAllBusy = true;
$scope.troubleshootingMessage = '';
let count = 0;
Client.refreshInstalledApps(function () {
async.eachSeries($scope.installedApps, function (app, iteratorDone) {
if (app.installationState !== ISTATES.ERROR) return iteratorDone();
Client.repairApp(app.id, {}, function (error) {
if (error) Client.error(error);
else ++count;
iteratorDone();
});
}, function () {
$scope.troubleshootingMessage = `${count} apps repaired.`;
$scope.repairAllBusy = false;
});
});
};
2018-01-22 13:01:38 -08:00
$scope.toggleSshSupport = function () {
$scope.toggleSshSupportError = '';
Client.enableRemoteSupport(!$scope.sshSupportEnabled, function (error) {
if (error) {
if (error.statusCode === 412 || error.statusCode === 417) $scope.toggleSshSupportError = error.message;
else console.error(error);
return;
}
$scope.sshSupportEnabled = !$scope.sshSupportEnabled;
});
2018-01-22 13:01:38 -08:00
};
2021-10-19 15:14:52 +02:00
Client.onReady(function () {
2023-12-03 16:28:25 +01:00
Client.getRemoteSupport(function (error, enabled) {
if (error) return console.error(error);
2023-12-03 16:28:25 +01:00
$scope.sshSupportEnabled = enabled;
2024-07-12 14:25:11 +02:00
$scope.ready = true;
2018-01-22 13:01:38 -08:00
});
});
$('.modal-backdrop').remove();
}]);