Skip to content

Commit

Permalink
✨ More settings changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jan 23, 2024
1 parent 4793c65 commit 32ebcb2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/class/conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ Conduit.setMethod(function setRouteParameters(data) {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.3.18
* @version 1.4.0
*
* @param {string} name
* @param {Mixed} value
Expand Down Expand Up @@ -2582,8 +2582,8 @@ Conduit.setMethod(function cookie(name, value, options) {
this.new_cookies[name] = value;

// If there is no domain set, see if it is required
if ((options.domain === true || options.domain == null) && alchemy.settings.cookies.domain && this.url) {
let wanted_domain = alchemy.settings.cookies.domain,
if ((options.domain === true || options.domain == null) && alchemy.settings.frontend.cookies.domain && this.url) {
let wanted_domain = alchemy.settings.frontend.cookies.domain,
actual_domain = this.url.hostname;

if (wanted_domain != actual_domain) {
Expand Down
4 changes: 0 additions & 4 deletions lib/core/alchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,6 @@ Alchemy.setMethod(function loadSettings() {

let port = this.getSetting('network.port');

// Create the settings object
this.settings = system.toObject();


if (port > 49151) {
port_error = 'Could not use port number ' + String(port).bold.red + ' because ';

Expand Down
43 changes: 42 additions & 1 deletion lib/core/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ Definition.enforceProperty(function schema(new_value, old_value) {
type = 'string';
}

if (type == 'function') {
type = 'string';
}

new_value.addField('value', type, {
description: this.description,
allowed_values: this.allowed_values,
Expand Down Expand Up @@ -917,15 +921,33 @@ GroupValue.setProperty(function is_group() {
GroupValue.setMethod(function toObject() {

let result = {},
entry,
key;

for (key in this[VALUE]) {
result[key] = this[VALUE][key].toObject();
entry = this[VALUE][key];

if (!entry) {
continue;
}

result[key] = entry.toObject();
}

return result;
});

/**
* Remove an entry
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
GroupValue.setMethod(function remove(name) {
this[VALUE][name] = undefined;
});

/**
* Get the proxy representation of this group value.
*
Expand Down Expand Up @@ -970,6 +992,17 @@ GroupValue.setMethod(function setValueSilently(value) {
this.definition.setValueSilently(this, value);
});

/**
* Inject the given group value
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
GroupValue.setMethod(function injectSubGroupValue(name, value) {
this[VALUE][name] = value;
});

/**
* Get all the setting values with executable actions in order.
*
Expand Down Expand Up @@ -1011,6 +1044,10 @@ GroupValue.setMethod(function getFlattenedValues() {
for (key in this[VALUE]) {
entry = this[VALUE][key];

if (!entry) {
continue;
}

if (entry.is_group) {
result.push(...entry.getFlattenedValues());
} else {
Expand Down Expand Up @@ -1218,6 +1255,10 @@ SettingValue.setMethod(function setDefaultValue(value) {
*/
SettingValue.setMethod(function setValueSilently(value) {

if (value instanceof Value) {
value = value[VALUE];
}

// Even though the default value and this new value might be the same,
// it is no longer considered to be the "default" value!
this.has_default_value = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/scripts/create_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ system.addSetting('name', {
description : 'The package name',
});

const extensions = system.createGroup('extensions');
SettingNs.EXTENSIONS = extensions;
const plugins = system.createGroup('plugins');
SettingNs.PLUGINS = plugins;

const network = system.createGroup('network');

Expand Down
20 changes: 17 additions & 3 deletions lib/stages/20-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ const load = settings.createStage('load', async () => {
}
});


/**
* "datasource.connect.load_settings"
* Load any possible settings in the database
* "settings.perform_actions"
* Do all the setting-associated actions.
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
Expand All @@ -51,4 +50,19 @@ const load = settings.createStage('load', async () => {
*/
const perform_actions = settings.createStage('perform_actions', async () => {
await alchemy.system_settings.performAllActions();
});

/**
* "settings.to_object"
* Convert the `alchemy.settings` property to a simple object
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @type {Alchemy.Stages.Stage}
*/
const to_object = settings.createStage('to_object', async () => {
// Create the settings object
alchemy.settings = alchemy.system_settings.toObject();
});

0 comments on commit 32ebcb2

Please sign in to comment.