Remove all configure bits from the app grid page

This commit is contained in:
Johannes Zellner
2019-09-13 11:29:19 +02:00
parent 7a2a5d3846
commit 3d5cdd659b
4 changed files with 62 additions and 587 deletions

View File

@@ -21,271 +21,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.backupsEnabled = true;
$scope.disableIndexingTemplate = '# Disable search engine indexing\n\nUser-agent: *\nDisallow: /';
$scope.appConfigure = {
busy: false,
error: {},
app: {},
domain: null,
location: '',
advancedVisible: false,
portBindings: {},
portBindingsEnabled: {},
portBindingsInfo: {},
robotsTxt: '',
certificateFile: null,
certificateFileName: '',
keyFile: null,
keyFileName: '',
mailboxName: '',
accessRestrictionOption: 'any',
accessRestriction: { users: [], groups: [] },
alternateDomains: [],
mailboxNameEnabled: false,
memoryLimit: 0,
memoryTicks: [],
dataDir: null,
dataDirEnabled: false,
ssoAuth: false,
ftp: false,
tags: '',
label: '',
icon: { data: null },
action: 'location',
iconUrl: function () {
if ($scope.appConfigure.icon.data === '__original__') { // user clicked reset
return $scope.appConfigure.app.iconUrl + '&original=true';
} else if ($scope.appConfigure.icon.data) { // user uploaded icon
return $scope.appConfigure.icon.data;
} else { // current icon
return $scope.appConfigure.app.iconUrl;
}
},
isAccessRestrictionValid: function () {
var tmp = $scope.appConfigure.accessRestriction;
return !!(tmp.users.length || tmp.groups.length);
},
addAlternateDomain: function (event) {
event.preventDefault();
$scope.appConfigure.alternateDomains.push({
domain: $scope.domains[0],
subdomain: ''
});
},
delAlternateDomain: function (event, index) {
event.preventDefault();
$scope.appConfigure.alternateDomains.splice(index, 1);
},
show: function (app) {
$scope.reset();
// fill relevant info from the app
$scope.appConfigure.app = app;
$scope.appConfigure.location = app.location;
$scope.appConfigure.domain = $scope.domains.filter(function (d) { return d.domain === app.domain; })[0];
$scope.appConfigure.portBindingsInfo = angular.extend({}, app.manifest.tcpPorts, app.manifest.udpPorts); // Portbinding map only for information
$scope.appConfigure.memoryLimit = app.memoryLimit || app.manifest.memoryLimit || (256 * 1024 * 1024);
$scope.appConfigure.dataDirEnabled = !!app.dataDir;
$scope.appConfigure.dataDir = app.dataDir;
$scope.appConfigure.alternateDomains = app.alternateDomains.map(function (a) { return { subdomain: a.subdomain, domain: $scope.domains.filter(function (d) { return d.domain === a.domain; })[0] };});
$scope.appConfigure.robotsTxt = app.robotsTxt;
$scope.appConfigure.enableBackup = app.enableBackup;
$scope.appConfigure.enableAutomaticUpdate = app.enableAutomaticUpdate;
$scope.appConfigure.mailboxNameEnabled = app.mailboxName && (app.mailboxName.match(/\.app$/) === null);
$scope.appConfigure.mailboxName = app.mailboxName || '';
$scope.appConfigure.label = app.label || '';
$scope.appConfigure.ftp = app.manifest.addons.localstorage && app.manifest.addons.localstorage.ftp;
// 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.appConfigure.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 >= (app.manifest.memoryLimit/1024/1024 || 0)) $scope.appConfigure.memoryTicks.push(i * 1024 * 1024);
}
if (app.manifest.memoryLimit && $scope.appConfigure.memoryTicks[0] !== app.manifest.memoryLimit) {
$scope.appConfigure.memoryTicks.unshift(app.manifest.memoryLimit);
}
$scope.appConfigure.ssoAuth = (app.manifest.addons['ldap'] || app.manifest.addons['oauth']) && app.sso;
$scope.appConfigure.accessRestrictionOption = app.accessRestriction ? 'groups' : 'any';
$scope.appConfigure.accessRestriction = { users: [], groups: [] };
if (app.accessRestriction) {
var userSet = { };
app.accessRestriction.users.forEach(function (uid) { userSet[uid] = true; });
$scope.users.forEach(function (u) { if (userSet[u.id] === true) $scope.appConfigure.accessRestriction.users.push(u); });
var groupSet = { };
app.accessRestriction.groups.forEach(function (gid) { groupSet[gid] = true; });
$scope.groups.forEach(function (g) { if (groupSet[g.id] === true) $scope.appConfigure.accessRestriction.groups.push(g); });
}
// fill the portBinding structures. There might be holes in the app.portBindings, which signalizes a disabled port
for (var env in $scope.appConfigure.portBindingsInfo) {
if (app.portBindings && app.portBindings[env]) {
$scope.appConfigure.portBindings[env] = app.portBindings[env];
$scope.appConfigure.portBindingsEnabled[env] = true;
} else {
$scope.appConfigure.portBindings[env] = $scope.appConfigure.portBindingsInfo[env].defaultValue || 0;
$scope.appConfigure.portBindingsEnabled[env] = false;
}
}
// translate for tag-input
$scope.appConfigure.tags = app.tags ? app.tags.join(',') : '';
$scope.appConfigure.icon = { data: null };
$('#iconFileInput').get(0).onchange = function (event) {
var fr = new FileReader();
fr.onload = function () {
$scope.$apply(function () {
// var file = event.target.files[0];
$scope.appConfigure.icon.data = fr.result;
});
};
fr.readAsDataURL(event.target.files[0]);
};
$('#appConfigureModal').modal('show');
},
submit: function () {
$scope.appConfigure.busy = true;
$scope.appConfigure.error.other = null;
$scope.appConfigure.error.location = null;
$scope.appConfigure.error.label = null;
$scope.appConfigure.error.dataDir = null;
$scope.appConfigure.error.alternateDomains = null;
$scope.appConfigure.error.mailboxName = null;
// only use enabled ports from portBindings
var finalPortBindings = {};
for (var env in $scope.appConfigure.portBindings) {
if ($scope.appConfigure.portBindingsEnabled[env]) {
finalPortBindings[env] = $scope.appConfigure.portBindings[env];
}
}
var finalAccessRestriction = null;
if ($scope.appConfigure.accessRestrictionOption === 'groups') {
finalAccessRestriction = { users: [], groups: [] };
finalAccessRestriction.users = $scope.appConfigure.accessRestriction.users.map(function (u) { return u.id; });
finalAccessRestriction.groups = $scope.appConfigure.accessRestriction.groups.map(function (g) { return g.id; });
}
var data = {
location: $scope.appConfigure.location,
domain: $scope.appConfigure.domain.domain,
portBindings: finalPortBindings,
accessRestriction: finalAccessRestriction,
cert: $scope.appConfigure.certificateFile,
key: $scope.appConfigure.keyFile,
memoryLimit: $scope.appConfigure.memoryLimit === $scope.appConfigure.memoryTicks[0] ? 0 : $scope.appConfigure.memoryLimit,
robotsTxt: $scope.appConfigure.robotsTxt,
enableBackup: $scope.appConfigure.enableBackup,
enableAutomaticUpdate: $scope.appConfigure.enableAutomaticUpdate,
alternateDomains: $scope.appConfigure.alternateDomains.map(function (a) { return { subdomain: a.subdomain, domain: a.domain.domain };}),
label: $scope.appConfigure.label,
tags: $scope.appConfigure.tags.split(',').map(function (t) { return t.trim(); }).filter(function (t) { return !!t; }),
dataDir: $scope.appConfigure.dataDirEnabled ? $scope.appConfigure.dataDir : ''
};
if ($scope.appConfigure.mailboxNameEnabled) {
data.mailboxName = $scope.appConfigure.mailboxName;
// add mailbox automatically for convenience
if ($scope.appConfigure.app.manifest.addons.recvmail) {
Client.addMailbox(data.domain, data.mailboxName, $scope.user.id, function (error) {
if (error && error.statusCode !== 409) console.error(error); // it's fine if it already exists
});
}
} else { // setting to empty will reset to .app name
data.mailboxName = '';
}
if ($scope.appConfigure.icon.data === '__original__') { // user reset the icon
data.icon = '';
} else if ($scope.appConfigure.icon.data) { // user loaded custom icon
data.icon = $scope.appConfigure.icon.data.replace(/^data:image\/[a-z]+;base64,/, '');
}
Client.configureApp($scope.appConfigure.app.id, data, function (error) {
let tab = 'advanced'; // the tab to switch to
if (error) {
if (error.statusCode === 409) {
if (error.portName) {
$scope.appConfigure.error.port = error.message;
tab = 'location';
} else if (error.domain && error.domain === $scope.config.adminDomin) {
$scope.appConfigure.error.location = error.message;
$scope.appConfigureForm.location.$setPristine();
tab = 'location';
$('#appConfigureLocationInput').focus();
} else if (error.domain && error.domain !== $scope.config.adminDomin) {
$scope.appConfigure.error.alternateDomains = error.message;
tab = 'location';
} else {
$scope.appConfigure.error.other = error.message;
tab = 'location';
}
} else if (error.statusCode === 400) {
if (error.field === 'mailboxName') {
$scope.appConfigure.error.mailboxName = error.message;
$scope.appConfigureForm.mailboxName.$setPristine();
tab = 'email';
$('#appConfigureMailboxNameInput').focus();
} else if (error.field === 'cert') {
$scope.appConfigure.error.cert = error.message;
$scope.appConfigure.certificateFileName = '';
$scope.appConfigure.certificateFile = null;
$scope.appConfigure.keyFileName = '';
$scope.appConfigure.keyFile = null;
} else if (error.field === 'dataDir') {
$scope.appConfigure.error.dataDir = error.message;
$scope.appConfigureForm.dataDir.$setPristine();
$('#appConfigureDataDirInput').focus();
} else {
$scope.appConfigure.error.other = error.message;
tab = 'location';
}
} else {
$scope.appConfigure.error.other = error.message;
tab = 'location';
}
$scope.appConfigure.action = tab;
$scope.appConfigure.busy = false;
return;
}
$scope.appConfigure.busy = false;
Client.refreshAppCache($scope.appConfigure.app.id); // reflect the new app state immediately
$('#appConfigureModal').modal('hide');
$scope.reset();
});
},
resetCustomIcon: function () {
$scope.appConfigure.icon.data = '__original__';
},
showCustomIconSelector: function () {
$('#iconFileInput').click();
}
};
$scope.appClone = {
busy: false,
error: {},
@@ -556,37 +291,11 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.reset = function () {
// close all dialogs
$('#appErrorModal').modal('hide');
$('#appConfigureModal').modal('hide');
$('#appRestoreModal').modal('hide');
$('#appUpdateModal').modal('hide');
$('#appInfoModal').modal('hide');
$('#appPostInstallConfirmModal').modal('hide');
// reset configure dialog
$scope.appConfigure.error = {};
$scope.appConfigure.app = {};
$scope.appConfigure.domain = null;
$scope.appConfigure.location = '';
$scope.appConfigure.advancedVisible = false;
$scope.appConfigure.portBindings = {}; // This is the actual model holding the env:port pair
$scope.appConfigure.portBindingsEnabled = {}; // This is the actual model holding the enabled/disabled flag
$scope.appConfigure.certificateFile = null;
$scope.appConfigure.certificateFileName = '';
$scope.appConfigure.keyFile = null;
$scope.appConfigure.keyFileName = '';
$scope.appConfigure.memoryLimit = 0;
$scope.appConfigure.memoryTicks = [];
$scope.appConfigure.accessRestrictionOption = 'any';
$scope.appConfigure.accessRestriction = { users: [], groups: [] };
$scope.appConfigure.ssoAuth = false;
$scope.appConfigure.ftp = false;
$scope.appConfigure.robotsTxt = '';
$scope.appConfigure.enableBackup = true;
$scope.appConfigure.enableAutomaticUpdate = true;
$scope.appConfigureForm.$setPristine();
$scope.appConfigureForm.$setUntouched();
// reset update dialog
$scope.appUpdate.error = {};
$scope.appUpdate.app = {};
@@ -609,33 +318,6 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
$scope.appPostInstallConfirm.confirmed = false;
};
$scope.readCertificate = function (event) {
$scope.$apply(function () {
$scope.appConfigure.certificateFile = null;
$scope.appConfigure.certificateFileName = event.target.files[0].name;
var reader = new FileReader();
reader.onload = function (result) {
if (!result.target || !result.target.result) return console.error('Unable to read local file');
$scope.appConfigure.certificateFile = result.target.result;
};
reader.readAsText(event.target.files[0]);
});
};
$scope.readKey = function (event) {
$scope.$apply(function () {
$scope.appConfigure.keyFile = null;
$scope.appConfigure.keyFileName = event.target.files[0].name;
var reader = new FileReader();
reader.onload = function (result) {
if (!result.target || !result.target.result) return console.error('Unable to read local file');
$scope.appConfigure.keyFile = result.target.result;
};
reader.readAsText(event.target.files[0]);
});
};
$scope.showInformation = function (app) {
$scope.reset();
@@ -728,7 +410,7 @@ angular.module('Application').controller('AppsController', ['$scope', '$location
});
// setup all the dialog focus handling
['appConfigureModal', 'appUpdateModal', 'appRestoreModal', 'appInfoModal', 'appErrorModal'].forEach(function (id) {
['appUpdateModal', 'appRestoreModal', 'appInfoModal', 'appErrorModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
});