Add addon configure dialog

This commit is contained in:
Johannes Zellner
2018-11-20 16:53:42 +01:00
parent d01c46bfee
commit 6e46240fd7
3 changed files with 100 additions and 0 deletions
+62
View File
@@ -5,6 +5,7 @@
angular.module('Application').controller('AddonsController', ['$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 = {};
@@ -38,6 +39,67 @@ angular.module('Application').controller('AddonsController', ['$scope', '$locati
});
};
$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) {
if (i >= (addon.config.memory/1024/1024 || 0)) $scope.addonConfigure.memoryTicks.push(i * 1024 * 1024);
}
$('#addonConfigureModal').modal('show');
},
submit: function () {
$scope.addonConfigure.busy = true;
$scope.addonConfigure.error = null;
Client.configureAddon($scope.addonConfigure.addon.name, $scope.addonConfigure.memoryLimit, function (error) {
$scope.addonConfigure.busy = false;
if (error) {
$scope.addonConfigure.error = error.message;
return;
}
$('#addonConfigureModal').modal('hide');
$scope.addonConfigure.reset();
// reload the addon
refresh($scope.addonConfigure.addon.name);
});
},
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);