Adding Template Settings
In FlowForge, every project is created from a template. Templates define a set of preconfigured options for the project. This includes runtime settings - commonly, the values set in the Node-RED settings.js file.
Templates also define which options can be customized by the project.
This article explains how to add new Node-RED runtime options to the template object, so that developers can customize for individual instances and pass them to the underlying Node-RED settings.js file.
For simple types such as boolean, string, and number, they can be directly defined. For other types (objects/arrays), it becomes slightly more complex, and there are currently no good examples provided by the official documentation.
For general cases, you can follow these steps to set up the template:
- Update the frontend
- Choose a name for the setting and add it to the list of known settings and any required validation logic
- Add it to the appropriate template section
- Update the runtime
- Add it to the list of known settings and any additional validation logic
- Update the launcher
- Update the template used to generate settings.js with the new properties
Update the frontend
The frontend contains a set of views for displaying and editing templates. They are used in two different ways:
When creating/editing templates. All options are available, with a dropdown list allowing users to set policies on settings (controlling whether the project allows overriding settings)
When editing project settings. All options are displayed, but users are only allowed to modify options that the template policy allows changes to.
This reuse of views saves a lot of code duplication and introduces some complexity in implementation.
Choose a name for the setting
The name should attempt to match its corresponding property in the Node-RED settings.js file.
Edit frontend/src/pages/admin/Template/utils.js
Add the new property names to thetemplateFieldsanddefaultTemplateValuesobject. Note that these names are flat strings, with _ used as a hierarchy separator...
If the value requires any form of validation, add it to the same filetemplateValidatorsIn
, 1.2 - Add it to the appropriate template section
. Currently supported customizable configurations include:
Edit
Palette
Environment - Special cases where it is unlikely to add other options
. These all exist under their own filesfrontendfrontend/src/pages/admin/Template/sections/.
. Select the settings (i.e., check boxes or text inputs) to add that most closely match the existing settings, and copy their entries to the appropriate location.
Ensure that all references to the copied property names are updated to the new property names.
Update the runtime
. Add it to the known list
. Editforge/db/controllers/ProjectTemplate.jsAdd the new attribute to the list of known settings.
In the same file, update thevalidateSettingsfunction with any additional validation or data cleaning required.
Update the nr-launcher
in theflowforge-nr-launcherproject by editing
Editlib/runtimeSettings.jsto include the new settings in the generated settings.js file. Please note that you must handle the situation where the new setting does not exist - either use a reasonable default value or omit the value.
Leave a Reply