Skip to content

Commit

Permalink
✨ Implement new settings system
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jan 13, 2024
1 parent 697a5d7 commit 3774e19
Show file tree
Hide file tree
Showing 28 changed files with 1,717 additions and 477 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.4.0 (WIP)

* Implement new settings system

## 1.3.22 (2023-12-21)

* Allow ending a non-file-serve `Conduit` response with a stream
Expand Down
2 changes: 1 addition & 1 deletion lib/app/conduit/electron_conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var ElectronConduit = Function.inherits('Alchemy.Conduit', function Electron(req
request.conduit = this;

// Allow use of the log in the views
if (alchemy.settings.debug) {
if (alchemy.settings.debugging.debug) {
this.internal('debuglog', {_placeholder_: 'debuglog'});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/app/conduit/http_conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ HttpConduit.enforceProperty(function fingerprint() {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.3.3
* @version 1.3.1
* @version 1.4.0
*
* @param {IncomingMessage} req
* @param {ServerResponse} res
Expand All @@ -133,7 +133,7 @@ HttpConduit.setMethod(async function initHttp(req, res, router) {
return;
}

if (alchemy.settings.debug || alchemy.settings.environment != 'live') {
if (alchemy.settings.debugging.debug || alchemy.settings.environment != 'live') {
this.setHeader('X-Robots-Tag', 'none');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/app/conduit/socket_conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ SocketConduit.setMethod(function parseRequest() {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.1.0
* @version 1.4.0
*
* @param {Object} data
*/
Expand All @@ -182,7 +182,7 @@ SocketConduit.setMethod(function parseAnnouncement() {
// Tell the client we're ready
this.websocket.emit('ready');

if (alchemy.settings.debug) {
if (alchemy.settings.debugging.debug) {
log.info('Established websocket connection to', this.ip, 'using', this.useragent.family, this.useragent.major);
}
});
Expand Down
8 changes: 4 additions & 4 deletions lib/app/controller/alchemy_info_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ Info.setMethod(function setInfoVariables() {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.0.0
* @version 1.4.0
*/
Info.setAction(function info(conduit, name) {

// Don't show the page if info_page is false
if (!alchemy.settings.info_page) {
if (!alchemy.settings.debugging.info_page) {
return conduit.notFound();
}

Expand All @@ -110,11 +110,11 @@ Info.setAction(function info(conduit, name) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.7
* @version 1.0.7
* @version 1.4.0
*/
Info.setAction(async function appcache(conduit) {

if (!alchemy.settings.offline_clients) {
if (!alchemy.settings.frontend.appcache) {
return conduit.notFound();
}

Expand Down
10 changes: 5 additions & 5 deletions lib/app/helper/router_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Router.setProperty(function current_route() {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.3.0
* @version 1.3.0
* @version 1.4.0
*
* @param {String|RURL} url
*
Expand All @@ -89,9 +89,9 @@ Router.setMethod(function isLocalUrl(url) {
return true;
}

if (Blast.isNode && alchemy.settings.url) {
if (Blast.isNode && alchemy.settings.network.main_url) {
// @TODO: Would be nice to not have to parse this every time
let server_url = RURL.parse(alchemy.settings.url);
let server_url = RURL.parse(alchemy.settings.network.main_url);

if (server_url.hostname == url.hostname) {
return true;
Expand Down Expand Up @@ -375,7 +375,7 @@ Router.setMethod(function routeConfig(name, socket_route) {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.3.10
* @version 1.4.0
*
* @param {String} name
* @param {Object} parameters
Expand Down Expand Up @@ -528,7 +528,7 @@ Router.setMethod(function routeUrl(name, parameters, options) {
if (Blast.isBrowser) {
base_url = RURL.parse(window.location);
} else {
base_url = RURL.parse(alchemy.settings.url);
base_url = RURL.parse(alchemy.settings.network.main_url);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/app/helper_controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Controller.setMethod(function end(message) {
*
* @author Jelle De Loecker <[email protected]>
* @since 0.2.0
* @version 1.3.0
* @version 1.4.0
*
* @param {String} name The name of the action to execute
* @param {Array} args Arguments to apply to the action
Expand Down Expand Up @@ -362,8 +362,8 @@ Controller.setMethod(async function doAction(name, args) {
// @TODO: Add support for objects with language keys
let title = route.options.title;

if (alchemy.settings && alchemy.settings.title_suffix) {
title += alchemy.settings.title_suffix;
if (alchemy.settings && alchemy.settings.frontend.title_suffix) {
title += alchemy.settings.frontend.title_suffix;
}

this.setTitle(title);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/helper_model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ Model.setMethod(function addAssociatedDataToRecord(criteria, item, callback) {
};
});

pledge = Function.parallel(alchemy.settings.model_assoc_parallel_limit || 4, aliases, function gotAssociatedList(err, list) {
pledge = Function.parallel(alchemy.settings.data_management.model_assoc_parallel_limit || 4, aliases, function gotAssociatedList(err, list) {

if (err != null) {
console.log('ERROR: ' + err, err);
Expand Down
83 changes: 83 additions & 0 deletions lib/app/model/alchemy_setting_model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* The Alchemy Setting model:
* Contains all the system settings of Alchemy.
*
* @constructor
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
const AlchemySetting = Function.inherits('Alchemy.Model.App', 'AlchemySetting');

/**
* Constitute the class wide schema
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
AlchemySetting.constitute(function addTaskFields() {

this.addField('setting_id', 'Enum', {
description: 'The setting id',
values : Classes.Alchemy.Setting.SYSTEM.createEnumMap(),
});

this.addField('configuration', 'Schema', {
description: 'The actual configuration of the setting',
schema : 'setting_id',
});
});

/**
* Configure the default chimera fieldsets
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
AlchemySetting.constitute(function chimeraConfig() {

if (!this.chimera) {
return;
}

// Get the list group
let list = this.chimera.getActionFields('list');

list.addField('setting_id');

// Get the edit group
let edit = this.chimera.getActionFields('edit');

edit.addField('setting_id');
edit.addField('configuration')
});

/**
* Do something before saving the record
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @param {Document.AlchemyTask} doc
*/
AlchemySetting.setMethod(function beforeSave(doc) {

});

/**
* Update the schedules after saving
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*
* @param {Object} main
* @param {Object} info
*/
AlchemySetting.setMethod(function afterSave(main, info) {

});
60 changes: 29 additions & 31 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var libpath = require('path'),
starting;
const libpath = require('path');
let starting;

/**
* Calling dynamic `import()` from certain places in the codebase actually
Expand Down Expand Up @@ -29,6 +29,26 @@ require('protoblast')();
*/
require('./init/constants');

/**
* Alchemy's Base class (from which all other classes inherit)
*/
require('./core/base');

/**
* Alchemy's Client Base class
*/
require('./core/client_base');

/**
* Load the setting class
*/
require(libpath.resolve(PATH_CORE, 'core', 'setting.js'));

/**
* Load the actual settings
*/
require(libpath.resolve(PATH_CORE, 'init', 'settings.js'));

/**
* Define alchemy class and instance
*/
Expand Down Expand Up @@ -59,30 +79,8 @@ require('./init/requirements');
*/
require('./init/devwatch');

/**
* Alchemy's Base class
*
* @author Jelle De Loecker <[email protected]>
* @since 0.3.0
* @version 0.3.0
*/
require('./core/base');

/**
* Alchemy's Client Base class
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.0.0
*/
require('./core/client_base');

/**
* The migration class
*
* @author Jelle De Loecker <[email protected]>
* @since 1.2.0
* @version 1.2.0
*/
require('./class/migration');

Expand Down Expand Up @@ -276,7 +274,7 @@ Alchemy.setMethod(function start(options, callback) {

// If silent is true, don't output anything
if (options.silent == true) {
this.settings.silent = true;
this.setSetting('debugging.silent', true);
}

if (starting) {
Expand All @@ -288,18 +286,18 @@ Alchemy.setMethod(function start(options, callback) {
}

if (options.client_mode) {
this.settings.client_mode = true;
this.setSetting('client_mode', true);
} else {
if (this.settings.no_default_file) {
log.warn('Could not find default settings file at "' + this.settings.no_default_file + '.js"');
if (alchemy.settings.no_default_file) {
log.warn('Could not find default settings file at "' + alchemy.settings.no_default_file + '.js"');
}

if (this.settings.no_local_file) {
if (alchemy.settings.no_local_file) {
log.warn('Could not find local settings file');
}

if (this.settings.no_env_file) {
log.warn('Could not find environment settings file at "' + this.settings.no_env_file + '.js"');
if (alchemy.settings.no_env_file) {
log.warn('Could not find environment settings file at "' + alchemy.settings.no_env_file + '.js"');
}
}

Expand Down
Loading

0 comments on commit 3774e19

Please sign in to comment.