2022-01-23 18:21:23 -07:00
|
|
|
--- Template for module writers.
|
|
|
|
|
-- Short description goes here.
|
2021-12-19 16:42:34 -07:00
|
|
|
-- @module module_template
|
2021-12-16 14:03:42 -05:00
|
|
|
|
2022-01-09 22:15:54 -07:00
|
|
|
--- (Required): Data table containing name and description of the module
|
2021-12-19 23:23:23 -07:00
|
|
|
-- @field name "Human-readable name (parens OK, no brackets)"
|
2021-12-18 13:35:18 -07:00
|
|
|
-- @field slug "Same as module class name"
|
2021-12-16 14:07:58 -07:00
|
|
|
-- @field desc "Description of the module"
|
2022-01-09 22:15:54 -07:00
|
|
|
-- @field hide Whether this is a hidden utility module
|
2021-12-19 16:42:34 -07:00
|
|
|
local module_template = {
|
2021-12-16 14:07:58 -07:00
|
|
|
name = "Module Human-Readable Name",
|
2021-12-20 20:34:11 -07:00
|
|
|
slug = "module_template",
|
2021-12-19 16:00:26 -07:00
|
|
|
desc = "Description of the module",
|
|
|
|
|
hide = false;
|
2021-12-16 14:03:42 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-18 13:35:18 -07:00
|
|
|
--- (Required) Data for module
|
2022-01-09 22:15:54 -07:00
|
|
|
-- Variables that module uses during the course of a process.
|
2021-12-18 13:35:18 -07:00
|
|
|
-- Can be blank
|
2021-12-19 16:42:34 -07:00
|
|
|
module_template.data = {
|
2021-12-18 13:35:18 -07:00
|
|
|
}
|
|
|
|
|
|
2022-01-09 22:15:54 -07:00
|
|
|
--- (Required): Config for module
|
2021-12-16 14:07:58 -07:00
|
|
|
-- Defines the input parameters to the module initiate function.
|
2021-12-18 13:35:18 -07:00
|
|
|
-- Can be blank
|
2021-12-16 14:07:58 -07:00
|
|
|
-- When calling a module from within another module,
|
|
|
|
|
-- variables not defined in config will be ignored.
|
|
|
|
|
-- Default values set in config can be overridden
|
2022-08-09 17:00:24 -06:00
|
|
|
-- @field approval_module names a module that must pass before approval; defaults to false
|
2021-12-16 14:07:58 -07:00
|
|
|
-- @field field_1 ex: votes_required, default = 5
|
|
|
|
|
-- @field field_2 ex: voting_type, default = "majority"
|
2021-12-19 16:42:34 -07:00
|
|
|
module_template.config = {
|
2022-08-09 17:00:24 -06:00
|
|
|
approval_module = false -- visible but empty
|
|
|
|
|
hidden_config = nil -- not visible to users unless used
|
2021-12-16 14:07:58 -07:00
|
|
|
field_1 = 5
|
|
|
|
|
field_2 = "majority"
|
2021-12-16 14:03:42 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-09 22:15:54 -07:00
|
|
|
--- (Required): Initiate function
|
2021-12-16 14:07:58 -07:00
|
|
|
-- Modules have access to the following instance variables:
|
|
|
|
|
-- <li><code>self.org</code> (the org the module was called in),</li>
|
|
|
|
|
-- <li><code>self.initiator</code> (the user that callced the module),</li>
|
|
|
|
|
-- <li><code>self.id</code> (the process id of the module instance)</li>
|
2022-01-20 11:04:44 -07:00
|
|
|
-- @function module_template:initiate
|
2022-01-23 18:21:23 -07:00
|
|
|
-- @param result (optional) Callback if this module is embedded in other modules
|
2021-12-19 16:42:34 -07:00
|
|
|
function module_template:initiate(result)
|
2021-12-19 16:00:26 -07:00
|
|
|
-- call interaction functions here!
|
2021-12-16 14:03:42 -05:00
|
|
|
|
2021-12-19 16:00:26 -07:00
|
|
|
-- concluding functions:
|
2021-12-29 22:07:53 -07:00
|
|
|
-- first, where appropriate, return users to dashboards.
|
|
|
|
|
-- second, result:
|
2021-12-19 16:00:26 -07:00
|
|
|
-- may need to put result in self.data.result
|
2021-12-22 22:22:17 -07:00
|
|
|
-- call this when module is successful (not for abort):
|
2021-12-19 16:00:26 -07:00
|
|
|
if result then result() end
|
2021-12-29 22:07:53 -07:00
|
|
|
-- third, delete the process
|
2021-12-22 22:22:17 -07:00
|
|
|
-- call this wherever process might end:
|
2021-12-19 16:00:26 -07:00
|
|
|
self.org:delete_process(self.id)
|
2021-12-16 14:07:58 -07:00
|
|
|
end
|
2021-12-18 13:35:18 -07:00
|
|
|
|
|
|
|
|
--- (Required) Add to module table
|
2021-12-19 16:42:34 -07:00
|
|
|
modpol.modules.module_template = module_template
|