Fix usage of config.memory

This commit is contained in:
Girish Ramakrishnan
2019-12-20 10:02:01 -08:00
parent 7d70060962
commit 3f3ec9ef9a
2 changed files with 28 additions and 17 deletions
+27 -2
View File
@@ -24,6 +24,7 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
$scope.validSubscription = false;
$scope.unstableApps = false;
$scope.subscription = {};
$scope.memory = null; // { memory, swap }
$scope.showView = function (view) {
// wait for dialog to be fully closed to avoid modal behavior breakage when moving to a different view already
@@ -96,7 +97,17 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
},
showForm: function (force) {
if (Client.enoughResourcesAvailable($scope.appInstall.app) || force) {
var app = $scope.appInstall.app;
var DEFAULT_MEMORY_LIMIT = 1024 * 1024 * 256;
var needed = app.manifest.memoryLimit || DEFAULT_MEMORY_LIMIT; // RAM+Swap
var used = Client.getInstalledApps().reduce(function (prev, cur) { return prev + (cur.memoryLimit || cur.manifest.memoryLimit || DEFAULT_MEMORY_LIMIT); }, 0);
var totalMemory = ($scope.memory.memory + $scope.memory.swap) * 1.5;
var available = (totalMemory || 0) - used;
var enoughResourcesAvailable = (available - needed) >= 0;
if (enoughResourcesAvailable || force) {
$scope.appInstall.state = 'installForm';
$('#collapseMediaLinksCarousel').collapse('hide');
$('#collapseResourceConstraint').collapse('hide');
@@ -551,6 +562,16 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
});
}
function getMemory(callback) {
Client.memory(function (error, memory) {
if (error) console.error(error);
$scope.memory = memory;
callback();
});
}
function init() {
$scope.ready = false;
@@ -573,7 +594,11 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
});
}
Client.onReady(init);
Client.onReady(function () {
getMemory(function () {
init();
});
});
// note: do not use hide.bs.model since it is called immediately from switchToAppsView which is already in angular scope
$('#appInstallModal').on('hidden.bs.modal', function () {