A Module Definition describes business objects (and sometimes complex business processes) for your application.
driver
"string, default module_name
Which driver implements the main logic. If no one is given, then the module name is tried as the driver.
Regularly this will be “objects” or “files”.
collection
"string, default module_name
Which collection in the key value store is used. If no one is given, then the module name is tried as the collection.
needs_person
"string, default true
Normally all objects in the system do have a connection to the originally creating user. If this is not wanted or not needed simply set this to false.
parent
"object, optional
Sets the parent object for a new created object in this module.
ref | string | The collection the parent is stored in. | |
ref_id | string | If given, the ID of the parent. | |
ref_lookup | string | If given, the field name whose value is used to lookup the parent ID. | |
self | bool | false | If set it becomes a direct connection between current object and parent. |
{
"parent": {
"ref": "devices",
"ref_lookup": "serial_no",
"self": true
}
}
default_object
"object, optional
Sets the default data for a new created object in this module.
Within the “default_object
” setting all fields could be set to static values. Additionally using the prefix “?
” field values out of a current form could be set into the “default_object
”.
{
"default_object": {
"data": {
"field1": "This is Field 1",
"field2": "?field2"
}
}
}
default_mode
"string, enum ("front", “cards”, “list”), default “cards”
The default mode to view the index of this module in. This not only changes the called view template but also the way the retrieved data is given to the appropriate view.
default_access
"object[], optional
Sets the default access for a new created object in this module.
^user_id | string | Gets replaced with the current user's ID. | |
^group | string | Gets replaced with the current user's primary group. |
{
"default_access": [
{
"scope" : [
"*"
],
"allow" : [
{
"user":"^user_id"
}
]
}
]
}
See concept “Authorization”.
default_sharing
"string[], optional
Sets the default sharing for a new created object in this module.
^ | string | Gets replaced with the current “Site Tag”. |
{
"default_sharing": ["site1", "^"]
}
See concept “Sharing”.
details_action
"string, optional
Normally clicking an object in the index of this module would navigate to details action. With this setting you could change that behavior e.g. having a click in the index directly go into edit action.
disable_add
"string, default false
Normally the system offers the add action where applicable (and permitted). With this setting this behavior could be disabled.
disable_edit
"string, default false
Normally the system offers the edit action where applicable (and permitted). With this setting this behavior could be disabled.
disable_map
"string, default false
Normally the system offers the map action where applicable (and permitted). With this setting this behavior could be disabled.
disable_tools
"string, default false
Normally the system offers the defined tools where applicable (and permitted). With this setting this behavior could be disabled.
links
"map(string => object), optional
Link Definitions describe which object( collection)s this object( collection) is linked to and how. First the current request's "Action" and "Mode" are used to find the correct Link Definition.
“Action”_ "Mode" | index-cards | For current “Action” and “Mode” |
“Action” | index | For current “Action” |
_ | _ | The default |
Additionally the "args
" section could be used to adapt the found Link Definition.
A Link Definition is an array of strings each describing a link to a different object( collection) and has the following syntax:
[~] | ~ | The Link is a direct Link | |
[~] | ~ | The Link should return the data directly | |
[<]"Collection"[."Link Field"] | organizations | The collection to link to. If given use the “Link Field” instead of current class name. | |
[;+"Select Field"]… | ;+phone | Add the “Select Field” to the returned data. If used all needed fields must be given. | |
[;-"Unselect Field"]… | ;-description | Do not add the “Unselect Field” to the returned data. | |
[;"Field""Operator""Value"]… | ;country=CA | The Link should only return data with “Field” compared using “Operator” to “Value” evaluates to true. | |
[^[+-]"Sort Field"] | +city | The Link should sort the returned data using “Sort Field”. | |
[:"Limit"] | :10 | The Link should only return the first “Limit” records. |
{
"links": {
"_": [
"projects",
"~~organizations;-description;country=CA^city:10"
]
}
}
lookup
"string[], optional
A Lookup is used for so called translation tables (e.g. list boxes in forms) where a list of human readable strings in relation to their appropriate ID are given to the user for selection.
The collections “categories” and “entities” are formed as a tree while all others are linear lists.
["Field"<] | ~ | The field containing the ID of the lookup | |
[=] | ~ | Set if it is a direct link | |
"Collection"[."Link Field"] | organizations | The collection to lookup from. If given use the “Link Field” instead of “title”. |
{
"lookup": [
"projects",
"customer<organizations.title"
]
}
args
"map(string => object), optional
The arguments are used to inject query string variables or form fields into Links and Queries. First the current request's "Action" and "Mode" are used to find the correct Arguments Definition.
“Action”_ "Mode" | index-cards | For current “Action” and “Mode” |
“Action” | index | For current “Action” |
_ | _ | The default |
A Arguments Definition is an array of strings each describing an argument and has the following syntax:
[.] | . | If set the field is a system field | |
[(timestamprange)] | (timestamprange) | The argument contains 2 values seperated by ‘..’ evaluating to a timestamp range | |
[(timestamp)] | (timestamp) | The argument is evaluating to a timestamp | |
“Field Name” | serial_no | The field name | |
[!] | ! | Normally arguments will only taken into account if an appropriate field exists within the current request. Setting this means that even empty values should be included. |
Of course all resulting relations between query string or form field relations and Links and Queries are always ment to be “equal” operator based.
{
"args": [
"index": [
"serial_no!",
".(timestamp)created_at"
]
]
}
filter
"object, optional
The Filter Definition object defines special filter and sorting operations to be performed on every data query. This filter is applied directly onto the appropriate query, so working with the data fields require the prefix “data.”.
“Filter Field” | any | “data.city”: “Vancouver” | Return only data where “Filter Field” is set to the given value. |
+ | string[] | “+”: ["data.city", “data.country”] | Add the fields to the returned data. If used all needed fields must be given. |
- | string[] | “-”: ["data.description"] | Do not add the fields to the returned data. |
^"Sort Field" | integer (-1, 1) | “^data.city”: 1 | The Link should sort the returned data using “Sort Field”. |
: | integer | “:”: 10 | The Link should only return the first “Limit” records. |
Using the special operator “||” as a prefix for a field name makes that condition into the “OR” path of that whole Filter Definition. Additionally the following special rules apply.
user_id | string | “user_id”: “^” | If “Filter Field” is set to “user_id” and value is set to “^” it is replaced with the user ID of the current authenticated user. |
“Filter Field” | array | “data.city”: {"like": “vancouver”} | If the value of the filter is an object, then the key of an element is taken to be an operator while the value becomes the filter value for that operator. |
Remember, the Filter Definition is applied to all data queries within the appropriate Module Definition.
{
"filter": [
"^created": 1,
"^user_id": "^",
"data.city": "Vancouver",
"||data.city": {"like": "vancouver"},
"-": "data.description",
":": 10
]
}
actions
"map(string => object), optional
Actions are used to implement additional methods within modules.
method | string | The method the custom action is based on. This must be one of the following: 'index', 'details', 'add', 'edit', 'connect', 'process'. | |
title | string, optional | The title of the action. If none is given, the name is used. | |
query | object, optional | A fully formed Mongo DB query which then will be used instead of the built query out of Links, Parent, Filter. | |
hint | string, optional | If Mongo DB uses the wrong index on the query, here the right index to use could be given. | |
data | object[], optional | An array of additional data sources to provide the action with additional data. See the following table. | |
args | object, optional | An object containing field names and values to for injection into the query and data queries. Within the appropriate Mongo DB query you could use “$args.” followed by the argument name to have that replaced with a query string in the request. | |
alternative_navigation | bool, default false | Switch to alternate navigation for this action if the template offers one. | |
alternative_user_navigation | bool, default false | Switch to alternate navigation for this action if the template offers one and there is an authenticated user. |
The following table shows the properties of an item of the data array in an Action Definition.
collection | string | The collection to use for that data entry. If none is given, then the collection of the module is taken. | |
alias | string, optional | Normally the results are stored in the result sets using the name of the collection. Using alias a different name could be given. | |
query | object, optional | A fully formed Mongo DB query which then will be used instead of the built query out of Links, Parent, Filter. If no query is given, then a lookup table is generated based on the collection. | |
hint | string, optional | If Mongo DB uses the wrong index on the query, here the right index to use could be given. | |
select | string, optional | If in lookup table mode, the field to build the human readable column of the lookup table is speciefied here. If none is given the field title is used. | |
is_ref | bool, default false | If in lookup table mode, this field sets if the lookup table searches only for entries where the appropriate class is equal to the collection. |
Remember that you must pay attention to the used template if injecting additional data having the template use the right names.
{
"actions": [
"locations": {
"method": "index",
"title": "Locations"
}
]
}
See "Action Definition".
tools
"map(string => object), optional
The tools are used for the context based toolbar in a view of an action. First the current request's "Action" and "Mode" are used to find the correct tools.
“Action”_ "Mode" | index-cards | For current “Action” and “Mode” |
“Action” | index | For current “Action” |
_ | _ | The default |
...
title | string, optional | The title of the tool. If none is given, then a string is built from “Tool” and the index of the tool. | |
icon | string, optional | The Awesome Font icon string to use for this tool. | |
link | string, optional | An URL to navigate to if the tool is clicked. If given, the following 4 are not taken into account. | |
module | string, optional | The module to build a link for. If none is given, the current is used. | |
action | string, optional | The action to build a link for. If none is given, the current is used. | |
id | string, optional | The ID to build a link for. If none is given, then current is used. | |
params | string[], optional | Additional parameters to build a link for. | |
menu | object[], optional | If this is given all link based properties for this item are ignored. An array of tool items to use to build a sub menu within that tool. |
{
"tools": {
"index": [
"orders": {
"title": "Orders",
"module": "orders",
"action": "index"
}
}
]
}
hooks
"map(string => string), optional
Hooks could be used to implement additional functionality into the system e.g. to do things in other backends or services. Hooks are implemented with PHP. First the current request's "Action" and "Mode" are used to find the correct hook.
“Action”_ "Mode" | index-cards | For current “Action” and “Mode” |
“Action” | index | For current “Action” |
_ | _ | The default |
A found hook always is given is a filename only which then is loaded out of the main config path with added file extension “.php”.
Each hook is run within a special closed function having the following PHP variables available:
(… args …) | Depending on the method called there are various arguments given. | ||
$context | (assoc_)array | Representing the context of the current request. | |
$__BASE | object | Providing an interface to the key value store. | |
$__DEBUG | object | Providing an interface to the current DEBUG object. |
...
{
"hooks": [
"index": "module_index_hook"
]
}
...
// module_index_hook.php
//
// $context = [
// 'def' => $def, // The current Module Definition
// 'driver' => $driver, // The current driver
// 'module' => $module, // The current Module Name
// 'method' => $method, // The current Method Name
// 'params' => $params // The current parameters
// ];
//
foreach ($page_items as $temp_i => $page_item) {
$page_items[$temp_i]['added_column'] = 'This is from a hook.';
}
//
views
"map(string => object), optional
The views are used to select the appropriate sub template for the current request's "Action" and “Mode”.
“Action”_ "Mode" | index-cards | For current “Action” and “Mode” |
“Action” | index | For current “Action” |
_ | _ | The default |
Remember that the display of the views depends on the site template used. This system only connects queried or processed data with the appropriate template files.
“View Name” | The view to load within a standard container. | ||
["View Name", “Container Name”] | The view to load within the given container. | ||
["", { … }] | An object describing view and container for template which supports generic standard templates (e.g. for tables). | ||
If nothing is given then a standard view is selected within a standard container. |
{
"views": {
"_": "general_index",
"details": "my_module_details"
}
}
forms
"map(string => object), optional
The arguments are used to inject query string variables or form fields into Links and Queries. First the current request's "Action" and "Mode" are used to find the correct Arguments Definition.
“Action” | index | For current “Action” |
_ | _ | The default |
...
["Field"<] | ~ | The field containing the ID of the lookup | |
[=] | ~ | Set if it is a direct link | |
"Collection"[."Link Field"] | organizations | The collection to lookup from. If given use the “Link Field” instead of “title”. |
{
"lookup": [
"projects",
"customer<organizations.title"
]
}
pagination
"integer, optional
The amount of items per page if pagination should be used. No pagination will be used if this value is not given.
hide_action
"bool, default false
Setting this to true results in not having the current action shown in the bread crumbs.
rest_mode
"string, enum ("default", “virtual”, “post_process”, “non”), default “default”
With rest_mode the automatic provides REST API for the current module could be changed in its behavior.
default | The default REST behaviour of the system | ||
virtual | Path segments are used as method name so incoming requests are mapped to actions. | ||
post_process | Normally the HTTP verb “POST” is translated to system's action “add”. With this mode the used system's action is “process”. | ||
none | REST for this module is disabled. |
alternative_navigation
"string, optional
Switch to alternate navigation for this action if the template offers one.
alternative_user_navigation
"string, optional
Switch to alternate navigation for this action if the template offers one and there is an authenticated user.