Rename addons view to system

We can rename the menu entry further but I wasn't sure if diagnostics
will be nicer. Diagnostics kinda overlaps with the graphs there and all
This commit is contained in:
Johannes Zellner
2018-11-26 08:59:04 +01:00
parent 07edcc5f94
commit 1ed45656e4
4 changed files with 5 additions and 5 deletions

119
src/views/system.js Normal file
View File

@@ -0,0 +1,119 @@
'use strict';
/* global angular */
angular.module('Application').controller('SystemController', ['$scope', '$location', '$interval', 'Client', function ($scope, $location, $interval, Client) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
$scope.config = Client.getConfig();
$scope.ready = false;
$scope.addons = {};
function refresh(addonName, callback) {
callback = callback || function () {};
Client.getAddon(addonName, function (error, result) {
if (error) Client.error(error);
else $scope.addons[addonName] = result;
callback();
});
}
function refreshAll() {
Object.keys($scope.addons).forEach(function (a) {
refresh(a);
});
}
$scope.restartAddon = function (addonName) {
function waitForActive(addonName) {
refresh(addonName, function () {
if ($scope.addons[addonName].status === 'active') return;
setTimeout(function () { waitForActive(addonName); }, 1000);
});
}
Client.restartAddon(addonName, function (error) {
if (error) return Client.error(error);
waitForActive(addonName);
});
};
$scope.addonConfigure = {
error: null,
busy: false,
addon: null,
// form model
memoryLimit: 0,
memoryTicks: [],
show: function (addon) {
$scope.addonConfigure.reset();
$scope.addonConfigure.addon = addon;
$scope.addonConfigure.memoryLimit = addon.config.memory;
// TODO improve those
$scope.addonConfigure.memoryTicks = [];
// create ticks starting from manifest memory limit. the memory limit here is currently split into ram+swap (and thus *2 below)
// TODO: the *2 will overallocate since 4GB is max swap that cloudron itself allocates
$scope.addonConfigure.memoryTicks = [];
var npow2 = Math.pow(2, Math.ceil(Math.log($scope.config.memory)/Math.log(2)));
for (var i = 256; i <= (npow2*2/1024/1024); i *= 2) {
$scope.addonConfigure.memoryTicks.push(i * 1024 * 1024);
}
$('#addonConfigureModal').modal('show');
},
submit: function (memoryLimit) {
$scope.addonConfigure.busy = true;
$scope.addonConfigure.error = null;
Client.configureAddon($scope.addonConfigure.addon.name, memoryLimit, function (error) {
$scope.addonConfigure.busy = false;
if (error) {
$scope.addonConfigure.error = error.message;
return;
}
refresh($scope.addonConfigure.addon.name);
$('#addonConfigureModal').modal('hide');
$scope.addonConfigure.reset();
});
},
reset: function () {
$scope.addonConfigure.busy = false;
$scope.addonConfigure.error = null;
$scope.addonConfigure.addon = null;
$scope.addonConfigure.memoryLimit = 0;
$scope.addonConfigure.memoryTicks = [];
$scope.addonConfigureForm.$setPristine();
$scope.addonConfigureForm.$setUntouched();
}
};
Client.onReady(function () {
Client.getAddons(function (error, result) {
if (error) return Client.error(error);
result.forEach(function (a) {
$scope.addons[a] = { name: a };
});
// just kick off the status fetching
refreshAll();
$scope.ready = true;
});
});
}]);