Added expert settings mode

This commit is contained in:
Pax1601
2024-01-30 17:45:25 +01:00
parent be625fdca9
commit 21040da195
10 changed files with 341 additions and 161 deletions

View File

@@ -14,7 +14,8 @@ const { sleep } = require("./utils");
class Manager {
options = {
logLocation: path.join(__dirname, "..", "manager.log"),
configLoaded: false
configLoaded: false,
operation: 'NONE'
};
activePage = null;
@@ -27,6 +28,7 @@ class Manager {
passwordsPage = null;
resultPage = null;
instancesPage = null;
expertSettingsPage = null;
constructor() {
/* Simple framework to define callbacks to events directly in the .ejs files. When an event happens, e.g. a button is clicked, the signal function is called with the function
@@ -56,7 +58,7 @@ class Manager {
this.options.configLoaded = true;
} catch (e) {
logger.error(`An error occurred while reading the options.json file: ${e}`);
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`)
}
}
@@ -99,7 +101,7 @@ class Manager {
return instance.installed && instance.error;
})) {
/* Ask the user for confirmation */
showConfirmPopup("<div style='font-size: var(--very-large); max-width: 100%;'>One or more of your Olympus instances are not up to date! </div> If you have just updated Olympus this is normal. Press Accept and the Manager will update your instances for you. <br> Press Close to update your instances manually using the Installation Wizard", async () => {
showConfirmPopup("<div class='main-message'> One or more of your Olympus instances are not up to date! </div><div class='sub-message'> If you have just updated Olympus this is normal.<br><br> Press <b>Accept</b> and the Manager will update your instances for you. <br> Press <b>Close</b> to update your instances manually using the Installation Wizard</div>", async () => {
try {
await sleep(300);
await DCSInstance.fixInstances();
@@ -107,7 +109,7 @@ class Manager {
} catch (err) {
logger.error(err);
await sleep(300);
showErrorPopup(`An error occurred while trying to fix your installations. Please reinstall Olympus manually. <br><br> You can find more info in ${this.options.logLocation}`);
showErrorPopup(`<div class='main-message'>An error occurred while trying to fix your installations. Please reinstall Olympus manually. </div><div class='sub-message'> You can find more info in ${this.options.logLocation} </div>`);
}
})
}
@@ -130,6 +132,7 @@ class Manager {
this.passwordsPage = new WizardPage(this, "./ejs/passwords.ejs");
this.resultPage = new ManagerPage(this, "./ejs/result.ejs");
this.instancesPage = new ManagerPage(this, "./ejs/instances.ejs");
this.expertSettingsPage = new WizardPage(this, "./ejs/expertsettings.ejs");
/* Force the setting of the ports whenever the page is shown */
this.connectionsPage.options.onShow = () => {
@@ -138,6 +141,16 @@ class Manager {
this.setPort('backend', this.options.activeInstance.backendPort);
}
}
this.expertSettingsPage.options.onShow = () => {
if (this.options.activeInstance) {
this.setPort('client', this.options.activeInstance.clientPort);
this.setPort('backend', this.options.activeInstance.backendPort);
}
}
this.instancesPage.options.onShow = () => {
this.updateInstances();
}
if (this.options.mode === "basic") {
/* In basic mode no dashboard is shown */
@@ -172,7 +185,7 @@ class Manager {
location.reload();
} catch (err) {
logger.log(err);
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`)
}
}
@@ -209,7 +222,7 @@ class Manager {
*
*/
onInstallMenuClicked() {
this.options.install = true;
this.options.operation = 'INSTALL';
if (this.options.instances.length == 0) {
// TODO: show error
@@ -222,7 +235,7 @@ class Manager {
this.activePage.hide()
this.typePage.show();
} else {
showConfirmPopup("<div style='font-size: var(--large); max-width: 100%;'> Olympus is already installed in this instance! </div> <div style='font-weight: normal'>If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?</div>",
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?</div>",
() => {
this.activePage.hide()
this.typePage.show();
@@ -241,7 +254,8 @@ class Manager {
*/
onEditMenuClicked() {
this.activePage.hide()
this.options.install = false;
this.options.operation = 'EDIT';
delete this.options.activeInstance;
this.settingsPage.show();
}
@@ -268,7 +282,7 @@ class Manager {
if (this.options.activeInstance)
this.options.activeInstance.installationType = type;
else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`);
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`);
}
}
@@ -279,16 +293,16 @@ class Manager {
if (this.options.activeInstance)
this.options.activeInstance.connectionsType = type;
else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`);
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`);
}
}
/* When the next button of a wizard page is clicked */
onNextClicked() {
async onNextClicked() {
/* Choose which page to show depending on the active page */
if (this.activePage == this.folderPage) {
if (this.options.activeInstance.installed) {
showConfirmPopup("<div style='font-size: var(--large); max-width: 100%;'> Olympus is already installed in this instance! </div> <div style='font-weight: normal'>If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?</div>",
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?</div>",
() => {
this.activePage.hide()
this.typePage.show();
@@ -310,48 +324,25 @@ class Manager {
else {
this.activePage.hide();
this.connectionsPage.show();
this.connectionsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
(this.options.mode === 'basic'? this.connectionsPage: this.expertSettingsPage).getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
}
} else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`)
}
} else if (this.activePage == this.connectionsPage) {
this.options.activeInstance.checkClientPort().then(
(portFree) => {
if (portFree) {
return this.options.activeInstance.checkBackendPort();
} else {
return Promise.reject('Port not free');
}
}).then((portFree) => {
if (portFree) {
this.activePage.hide();
this.passwordsPage.show();
} else {
return Promise.reject('Port not free');
}
}).catch(() => {
showErrorPopup('Please, make sure both the client and backend ports are free!');
}
);
if (await this.checkPorts()) {
this.activePage.hide();
this.passwordsPage.show();
}
} else if (this.activePage == this.passwordsPage) {
if (this.options.activeInstance) {
if (this.options.activeInstance.installed && !this.options.activeInstance.arePasswordsEdited()) {
this.activePage.hide();
this.options.install ? this.options.activeInstance.install() : this.options.activeInstance.edit();
}
else {
if (!this.options.activeInstance.arePasswordsSet()) {
showErrorPopup('Please, make sure all passwords are set!');
} else if (!this.options.activeInstance.arePasswordsDifferent()) {
showErrorPopup('Please, set different passwords for the Game Master, Blue Commander, and Red Commander roles!');
} else {
this.activePage.hide();
this.options.install ? this.options.activeInstance.install() : this.options.activeInstance.edit();
}
}
} else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
if (await this.checkPasswords()) {
this.activePage.hide();
this.options.operation === 'INSTALL' ? this.options.activeInstance.install() : this.options.activeInstance.edit();
}
} else if (this.activePage == this.expertSettingsPage) {
if (await this.checkPorts() && await this.checkPasswords()) {
this.activePage.hide();
this.options.operation === 'INSTALL' ? this.options.activeInstance.install() : this.options.activeInstance.edit();
}
}
}
@@ -380,42 +371,24 @@ class Manager {
}
onGameMasterPasswordChanged(value) {
if (this.options.activeInstance) {
if (this.options.activeInstance)
this.options.activeInstance.setGameMasterPassword(value);
if (!this.options.activeInstance.blueCommanderPasswordEdited)
this.passwordsPage.getElement().querySelector(".blue-commander input").value = "";
if (!this.options.activeInstance.redCommanderPasswordEdited)
this.passwordsPage.getElement().querySelector(".red-commander input").value = "";
}
else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`);
}
else
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`);
}
onBlueCommanderPasswordChanged(value) {
if (this.options.activeInstance) {
if (this.options.activeInstance)
this.options.activeInstance.setBlueCommanderPassword(value);
if (!this.options.activeInstance.gameMasterPasswordEdited)
this.passwordsPage.getElement().querySelector(".game-master input").value = "";
if (!this.options.activeInstance.redCommanderPasswordEdited)
this.passwordsPage.getElement().querySelector(".red-commander input").value = "";
}
else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`);
}
else
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`);
}
onRedCommanderPasswordChanged(value) {
if (this.options.activeInstance) {
if (this.options.activeInstance)
this.options.activeInstance.setRedCommanderPassword(value);
if (!this.options.activeInstance.gameMasterPasswordEdited)
this.passwordsPage.getElement().querySelector(".game-master input").value = "";
if (!this.options.activeInstance.blueCommanderPasswordEdited)
this.passwordsPage.getElement().querySelector(".blue-commander input").value = "";
}
else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`);
}
else
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`);
}
/* When the client port input value is changed */
@@ -436,16 +409,22 @@ class Manager {
} else {
this.options.activeInstance.backendAddress = 'localhost';
}
this.connectionsPage.getElement().querySelector(".note.warning").classList.toggle("hide", this.options.activeInstance.backendAddress !== '*')
this.connectionsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
if (this.options.mode === 'basic') {
this.connectionsPage.getElement().querySelector(".note.warning").classList.toggle("hide", this.options.activeInstance.backendAddress !== '*')
this.connectionsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
} else {
this.expertSettingsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
}
} else {
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`)
}
}
/* When the "Return to manager" button is pressed */
onReturnClicked() {
location.reload();
async onReturnClicked() {
await this.reload();
this.activePage.hide();
this.menuPage.show();
}
/* When the "Close manager" button is pressed */
@@ -453,6 +432,39 @@ class Manager {
document.querySelector('.close').click();
}
async checkPorts() {
var clientPortFree = await this.options.activeInstance.checkClientPort();
var backendPortFree = await this.options.activeInstance.checkBackendPort();
if (clientPortFree && backendPortFree) {
return true;
} else {
showErrorPopup(`<div class='main-message'> Please, make sure both the client and backend ports are free!</div><div class='sub-message'>If ports are already in use, Olympus will not be able to communicated correctly.</div>`);
return false;
}
}
async checkPasswords() {
if (this.options.activeInstance) {
if (this.options.activeInstance.installed && !this.options.activeInstance.arePasswordsEdited()) {
return true;
}
else {
if (!this.options.activeInstance.arePasswordsSet()) {
showErrorPopup(`<div class='main-message'>Please, make sure all passwords are set!</div><div class='sub-message'>The role users will fulfill depends on the password they enter at login. </div>`);
return false;
} else if (!this.options.activeInstance.arePasswordsDifferent()) {
showErrorPopup(`<div class='main-message'>Please, set different passwords! </div><div class='sub-message'>The role users will fulfill depends on the password they enter at login. </div>`);
return false;
} else {
return true;
}
}
} else {
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${getManager().options.logLocation} for more info. </div>`)
return false;
}
}
async onStartServerClicked(name) {
var div = await this.getClickedInstanceDiv(name);
div.querySelector(".collapse").classList.add("loading")
@@ -480,29 +492,31 @@ class Manager {
async onEditClicked(name) {
var instance = await this.getClickedInstance(name);
if (instance.webserverOnline || instance.backendOnline) {
showErrorPopup("Error, the selected Olympus instance is currently active, please stop Olympus before editing it!")
showErrorPopup("<div class='main-message'>Error, the selected Olympus instance is currently active </div><div class='sub-message'> Please stop Olympus before editing it! </div>")
} else {
this.options.activeInstance = instance;
this.options.install = false;
this.options.operation = 'EDIT';
this.activePage.hide();
this.typePage.show();
(this.options.mode === 'basic'? this.typePage: this.expertSettingsPage).show();
}
}
async onInstallClicked(name) {
var instance = await this.getClickedInstance(name);
this.options.activeInstance = instance;
this.options.install = true;
this.options.operation = 'INSTALL';
this.options.singleInstance = false;
this.activePage.hide();
this.typePage.show();
(this.options.mode === 'basic'? this.typePage: this.expertSettingsPage).show();
}
async onUninstallClicked(name) {
var instance = await this.getClickedInstance(name);
this.options.activeInstance = instance;
this.options.operation = 'UNINSTALL';
if (instance.webserverOnline || instance.backendOnline)
showErrorPopup("Error, the selected Olympus instance is currently active, please stop Olympus before uninstalling it!")
showErrorPopup("<div class='main-message'>Error, the selected Olympus instance is currently active </div><div class='sub-message'> Please stop Olympus before removing it! </div>")
else
await instance.uninstall();
}
@@ -543,11 +557,11 @@ class Manager {
this.options.activeInstance.setBackendPort(value);
}
var successEls = this.connectionsPage.getElement().querySelector(`.${port}-port`).querySelectorAll(".success");
var successEls = (this.options.mode === 'basic'? this.connectionsPage: this.expertSettingsPage).getElement().querySelector(`.${port}-port`).querySelectorAll(".success");
for (let i = 0; i < successEls.length; i++) {
successEls[i].classList.toggle("hide", !success);
}
var errorEls = this.connectionsPage.getElement().querySelector(`.${port}-port`).querySelectorAll(".error");
var errorEls = (this.options.mode === 'basic'? this.connectionsPage: this.expertSettingsPage).getElement().querySelector(`.${port}-port`).querySelectorAll(".error");
for (let i = 0; i < errorEls.length; i++) {
errorEls[i].classList.toggle("hide", success);
}
@@ -596,8 +610,11 @@ class Manager {
}
}
reload() {
this.activePage.show();
async reload() {
await DCSInstance.reloadInstances();
this.options.installEnabled = true;
this.options.editEnabled = this.options.instances.find(instance => instance.installed);
}
setLoadingProgress(message, percent) {