-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add setting actions & dependencies
- Loading branch information
Showing
5 changed files
with
830 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,57 @@ AlchemySetting.constitute(function chimeraConfig() { | |
edit.addField('configuration') | ||
}); | ||
|
||
/** | ||
* Apply the given changes | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {Object} changes | ||
* @param {Conduit} permission_context | ||
*/ | ||
AlchemySetting.setMethod(async function saveChanges(changes, permission_context) { | ||
|
||
if (!changes) { | ||
return; | ||
} | ||
|
||
let setting_id, | ||
new_value, | ||
setting, | ||
doc; | ||
|
||
for (setting_id in changes) { | ||
new_value = changes[setting_id]; | ||
setting = Classes.Alchemy.Setting.SYSTEM.get(setting_id); | ||
|
||
if (!setting) { | ||
throw new Error('Unknown setting: ' + setting_id); | ||
} | ||
|
||
// We don't throw an error here: | ||
// we assume the user should not have seen this setting anyway | ||
if (!setting.canBeEditedBy(permission_context)) { | ||
continue; | ||
} | ||
|
||
doc = await this.findByValues({ | ||
setting_id: setting_id | ||
}); | ||
|
||
if (!doc) { | ||
doc = this.createDocument({ | ||
setting_id | ||
}); | ||
} | ||
|
||
doc.configuration = setting.createConfigurationObject(new_value); | ||
|
||
await doc.save(); | ||
} | ||
}); | ||
|
||
/** | ||
* Do something before saving the record | ||
* | ||
|
@@ -65,19 +116,39 @@ AlchemySetting.constitute(function chimeraConfig() { | |
* @param {Document.AlchemyTask} doc | ||
*/ | ||
AlchemySetting.setMethod(function beforeSave(doc) { | ||
|
||
return doc.applySetting(); | ||
}); | ||
|
||
/** | ||
* Update the schedules after saving | ||
* Apply this setting | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {Object} main | ||
* @param {Object} info | ||
* @param {boolean} do_actions Should the setting actions be executed | ||
*/ | ||
AlchemySetting.setMethod(function afterSave(main, info) { | ||
AlchemySetting.setDocumentMethod(function applySetting(do_actions = true) { | ||
|
||
}); | ||
if (!this.setting_id) { | ||
return; | ||
} | ||
|
||
let setting = Classes.Alchemy.Setting.SYSTEM.get(this.setting_id); | ||
|
||
if (!setting) { | ||
return; | ||
} | ||
|
||
let existing_value = alchemy.system_settings.getPath(this.setting_id); | ||
|
||
if (!existing_value) { | ||
existing_value = setting.generateValue(); | ||
} | ||
|
||
if (do_actions) { | ||
return existing_value.setValue(this.configuration.value); | ||
} else { | ||
return existing_value.setValueSilently(this.configuration.value); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -467,7 +467,7 @@ Alchemy.setMethod(function isProcessRunning(pid) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.5.0 | ||
* @version 1.3.1 | ||
* @version 1.4.0 | ||
* | ||
* @param {Object} options | ||
*/ | ||
|
@@ -527,41 +527,6 @@ Alchemy.setMethod(function startJaneway(options) { | |
|
||
this.Janeway.started = true; | ||
this.Janeway.start(options); | ||
|
||
if (this.settings.frontend.title) { | ||
let title = this.settings.frontend.title; | ||
this.Janeway.setTitle(title); | ||
} | ||
|
||
if (this.settings.sessions.janeway_menu) { | ||
|
||
let session_menu = this.Janeway.addIndicator('⌨ '); | ||
|
||
if (!session_menu.addItem) { | ||
return session_menu.remove(); | ||
} | ||
|
||
session_menu.addItem({ | ||
title : 'Current active browser sessions:', | ||
weight : Infinity, | ||
}, () => { | ||
console.log('All sessions:', this.sessions); | ||
}); | ||
|
||
this.Janeway.session_menu = session_menu; | ||
} | ||
|
||
if (this.settings.performance.janeway_lag_menu) { | ||
let lag_menu = this.Janeway.addIndicator('0 ms'); | ||
|
||
setInterval(() => { | ||
lag_menu.setIcon(this.lagInMs() + ' ms'); | ||
this.Janeway.redraw(); | ||
}, 900).unref(); | ||
|
||
this.Janeway.lag_menu = lag_menu; | ||
} | ||
|
||
}); | ||
|
||
/** | ||
|
@@ -649,13 +614,44 @@ Alchemy.setMethod(function setSetting(path, value) { | |
*/ | ||
Alchemy.setMethod(function getSetting(path) { | ||
|
||
let value = this.system_settings.getPath(path); | ||
let value = this.getSettingValueInstance(path); | ||
|
||
if (value) { | ||
return value.get(); | ||
} | ||
}); | ||
|
||
/** | ||
* Get a setting value instance | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {string} path The path of the setting (without system prefix) | ||
*/ | ||
Alchemy.setMethod(function getSettingValueInstance(path) { | ||
return this.system_settings.getPath(path); | ||
}); | ||
|
||
/** | ||
* Execute the action linked to a setting | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {string} path The path of the setting (without system prefix) | ||
*/ | ||
Alchemy.setMethod(function executeSetting(path) { | ||
|
||
let value = this.getSettingValueInstance(path); | ||
|
||
if (value) { | ||
return value.executeAction(); | ||
} | ||
}); | ||
|
||
/** | ||
* Load the initial hard-coded settings | ||
* | ||
|
@@ -683,7 +679,7 @@ Alchemy.setMethod(function loadSettings() { | |
let value = require(default_path); | ||
system.setDefaultValue(value); | ||
} catch (err) { | ||
this.setSetting('no_default_file', true); | ||
this.setSetting('no_default_file', default_path); | ||
} | ||
|
||
// Generate the path to the local settings file | ||
|
@@ -695,7 +691,7 @@ Alchemy.setMethod(function loadSettings() { | |
local = require(local_path); | ||
} catch(err) { | ||
local = {}; | ||
this.setSetting('no_local_file', true); | ||
this.setSetting('no_local_file', local_path); | ||
} | ||
|
||
// Default to the 'dev' environment | ||
|
@@ -721,13 +717,13 @@ Alchemy.setMethod(function loadSettings() { | |
// Get the config | ||
try { | ||
let value = require(env_path); | ||
system.setValue(value); | ||
system.setValueSilently(value); | ||
} catch(err) { | ||
this.setSetting('no_env_file', true); | ||
this.setSetting('no_env_file', env_path); | ||
} | ||
|
||
// And now overlay the final local settings | ||
system.setValue(local); | ||
system.setValueSilently(local); | ||
|
||
if (!settings.name) { | ||
this.setSetting('name', this.package.name); | ||
|
Oops, something went wrong.