dashboard: use native slider element for app memory and cpu

This commit is contained in:
Johannes Zellner
2024-03-11 19:20:38 +01:00
parent 63b395982c
commit 1892c0cd80
2 changed files with 29 additions and 24 deletions

View File

@@ -543,17 +543,15 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
memoryLimit: 0,
memoryTicks: [],
busyCpuShares: false,
currentCpuShares: 0,
cpuShares: 0,
show: function () {
var app = $scope.app;
$scope.resources.busy = true;
$scope.resources.error = {};
$scope.resources.currentMemoryLimit = app.memoryLimit || app.manifest.memoryLimit || (256 * 1024 * 1024);
$scope.resources.memoryLimit = $scope.resources.currentMemoryLimit;
$scope.resources.currentCpuShares = $scope.resources.cpuShares = app.cpuShares;
Client.getAppLimits(app.id, function (error, limits) {
if (error) return console.error(error);
@@ -569,14 +567,23 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.resources.memoryTicks.unshift(app.manifest.memoryLimit);
}
});
// for firefox widget update
$timeout(function() {
$scope.resources.currentCpuShares = $scope.resources.cpuShares = app.cpuShares;
$scope.resources.memoryLimit = $scope.resources.currentMemoryLimit;
$scope.resources.busy = false;
}, 500);
},
submitMemoryLimit: function () {
$scope.resources.busy = true;
$scope.resources.error = {};
var memoryLimit = $scope.resources.memoryLimit === $scope.resources.memoryTicks[0] ? 0 : $scope.resources.memoryLimit;
Client.configureApp($scope.app.id, 'memory_limit', { memoryLimit: memoryLimit }, function (error) {
const tmp = parseInt($scope.resources.memoryLimit);
const memoryLimit = tmp === $scope.resources.memoryTicks[0] ? 0 : tmp;
Client.configureApp($scope.app.id, 'memory_limit', { memoryLimit }, function (error) {
if (error && error.statusCode === 400) {
$scope.resources.busy = false;
$scope.resources.error.memoryLimit = true;
@@ -595,10 +602,10 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
},
submitCpuShares: function () {
$scope.resources.busyCpuShares = true;
$scope.resources.busy = true;
$scope.resources.error = {};
Client.configureApp($scope.app.id, 'cpu_shares', { cpuShares: $scope.resources.cpuShares }, function (error) {
Client.configureApp($scope.app.id, 'cpu_shares', { cpuShares: parseInt($scope.resources.cpuShares) }, function (error) {
if (error) return Client.error(error);
$scope.resources.currentCpuShares = $scope.resources.cpuShares;
@@ -606,7 +613,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
refreshApp($scope.app.id, function (error) {
if (error) return Client.error(error);
$timeout(function () { $scope.resources.busyCpuShares = false; }, 1000);
$timeout(function () { $scope.resources.busy = false; }, 1000);
});
});
},