add storage section in app view

This commit is contained in:
Girish Ramakrishnan
2020-10-28 22:11:05 -07:00
parent 377c2f678e
commit 671b9f235b
2 changed files with 112 additions and 71 deletions

View File

@@ -117,6 +117,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
$scope.config = Client.getConfig();
$scope.user = Client.getUserInfo();
$scope.domains = [];
$scope.volumes = [];
$scope.groups = [];
$scope.users = [];
$scope.backupConfig = null;
@@ -460,24 +461,15 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
currentCpuShares: 0,
cpuShares: 0,
busyDataDir: false,
dataDir: null,
busyBinds: false,
binds: [],
show: function () {
console.log('i am here.............');
var app = $scope.app;
$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;
$scope.resources.dataDir = app.dataDir;
$scope.resources.binds = [];
Object.keys(app.binds).forEach(function (name) {
$scope.resources.binds.push({ name: name, hostPath: app.binds[name].hostPath, readOnly: app.binds[name].readOnly });
});
Client.memory(function (error, memory) {
if (error) return console.error(error);
@@ -534,56 +526,81 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
});
});
},
};
$scope.storage = {
error: {},
busy: false,
busyDataDir: false,
dataDir: null,
busyBinds: false,
mounts: [], // { volume, readOnly }
show: function () {
var app = $scope.app;
$scope.storage.error = {};
$scope.storage.dataDir = app.dataDir;
$scope.storage.mounts = [];
Object.keys(app.mounts).forEach(function (mount) { // { volumeId, readOnly }
var volume = $scope.volumes.find(function (v) { return v.id === mount.volumeId; });
$scope.storage.mounts.push({ volume: volume, readOnly: mount.readOnly });
});
},
submitDataDir: function () {
$scope.resources.busyDataDir = true;
$scope.resources.error = {};
$scope.storage.busyDataDir = true;
$scope.storage.error = {};
Client.configureApp($scope.app.id, 'data_dir', { dataDir: $scope.resources.dataDir || null }, function (error) {
Client.configureApp($scope.app.id, 'data_dir', { dataDir: $scope.storage.dataDir || null }, function (error) {
if (error && error.statusCode === 400) {
$scope.resources.error.dataDir = error.message;
$scope.resources.busyDataDir = false;
$scope.storage.error.dataDir = error.message;
$scope.storage.busyDataDir = false;
return;
}
if (error) return Client.error(error);
$scope.resourcesDataDirForm.$setPristine();
$scope.storageDataDirForm.$setPristine();
refreshApp($scope.app.id, function (error) {
if (error) return Client.error(error);
$timeout(function () { $scope.resources.busyDataDir = false; }, 1000);
$timeout(function () { $scope.storage.busyDataDir = false; }, 1000);
});
});
},
addBind: function (event) {
addMount: function (event) {
console.log('Will add a mount');
event.preventDefault();
$scope.resources.binds.push({
hostPath: '',
name: '',
$scope.storage.mounts.push({
volume: $scope.volumes[0],
readOnly: true
});
},
delBind: function (event, index) {
delMount: function (event, index) {
event.preventDefault();
$scope.resources.binds.splice(index, 1);
$scope.storage.mounts.splice(index, 1);
},
submitBinds: function () {
$scope.resources.busyBinds = true;
$scope.resources.error = {};
submitMounts: function () {
$scope.storage.busyMounts = true;
$scope.storage.error = {};
var binds = {};
$scope.resources.binds.forEach(function (bind) {
binds[bind.name] = { hostPath: bind.hostPath, readOnly: bind.readOnly };
var data = [];
$scope.storage.mounts.forEach(function (mount) {
data.push({ volumeId: mount.volumeId, readOnly: mount.readOnly });
});
Client.configureApp($scope.app.id, 'binds', { binds: binds }, function (error) {
Client.configureApp($scope.app.id, 'mounts', { mounts: data }, function (error) {
if (error && error.statusCode === 400) {
$scope.resources.error.binds = error.message;
$scope.resources.busyBinds = false;
$scope.storage.error.mounts = error.message;
$scope.storage.busyMounts = false;
return;
}
if (error) return Client.error(error);
@@ -591,7 +608,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
refreshApp($scope.app.id, function (error) {
if (error) return Client.error(error);
$timeout(function () { $scope.resources.busyBinds = false; }, 1000);
$timeout(function () { $scope.storage.busyMounts = false; }, 1000);
});
});
}
@@ -1471,6 +1488,16 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
});
}
function getVolumes(callback) {
Client.getVolumes(function (error, result) {
if (error) return callback(error);
$scope.volumes = result;
callback();
});
}
function getBackupConfig(callback) {
Client.getBackupConfig(function (error, backupConfig) {
if (error) return callback(error);
@@ -1583,6 +1610,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location'
fetchUsers,
fetchGroups,
getDomains,
getVolumes,
getBackupConfig
], function (error) {
if (error) return Client.error(error);