Decorators
Decorators are functions applied to an expression. They can be chained into a group. Then, each subsequent decorator will perform a function on the value returned by the previous item.
Decorators can contain parameters (optional or mandatory). If the operator is entered correctly, a popup will be shown with a hint of possible parameters and format of the decorator function.
Decorators can be applied anywhere a computing context is available.
- parameters in square brackets indicate optional parameters;
- bold text with an asterisk indicates required parameters;
- each parameter has a data type and some hover tooltips;
Decorator usage format:
${calculated_context}@{decorator_name: param1 = value1}@{second_decorator}...
A contextual popup will appear to show you what is possible to do with decorators after entering @{ at the end of a variable:
${V.get_newspapers}{newspapers}@{
In the example below, we will remove the text "[volume]" from the "label" component of the array:
${V.get_newspapers}{newspapers}@{array-modify: affect=label; func=replace(' [volume]', '')}
This decorator instructs to show the number with thousands separator, as well as 2 decimals:
${V.number}@{thousands-separator: decimal=2}
- can be applied to a number or to a string;
- parameter
mask
(required): sets the mask according to which the data will be displayed (based on quasar templates). More information: https://v1.quasar.dev/vue-components/input#mask - parameter
fill-mask
(optional): specifies the character that will replace missing characters.
Formula
- ${V.num}@{format: mask = ##/###}; result: 12/3__
- ${V.num}@{format: mask = ##/##; fill-mask = -}; result: 12/3--
- name:
date-format
- parameters: only one non-named parameter, which is passed without quotes.
2023-12-15 14:15:53
Formula:
- Basic:
${V.db_date}@{date-format: [Day is] dddd}
; result =Day is Friday
- Complex:
${V.db_date}@{date-format: dddd, MMMM Do YYYY, h:mm:ss a}
; result =Friday, December 15th 2023, 2:15:53 pm
To get today's date/time and convert it to a format you need, use something like this:
${E.timestamp}@{date-format: YYYY-MM-DD}
As decorator:
- name: date-add
- parameters: qty - number of intervals to add; interval - interval type (days, months, seconds, etc.)
- can be applied: to valid date/time format, UTC milliseconds, ${E.timestamp}, etc.
- result: Moment.js instance, which can be displayed in the desired format using the “date-format” decorator
${E.timestamp}@{date-add: qty = 1; interval = days}{date-format: LLLL
}
Function subtract, doc: https://momentjs.com/docs/#/manipulating/subtract/
As decorator:
- name: date-sub
- same as the decorator “add”...
Get current timestamp, subtract 30 days, and display in the format YYYY-MM-DD:
${E.timestamp}@{date-sub: qty = 30; interval = d}{date-format: YYYY-MM-DD}
As decorator:
- name: date-to-utc
- no parameters
- can be applied: same as “date-add”
- result: same as “date-add”
${E.timestamp}@{date-sub: qty = 1; interval = d}{date-to-utc}{date-format: LLLL}
Function local, doc: https://momentjs.com/docs/#/manipulating/local/
As decorator:
- name: date-to-local
- no parameters
- can be applied: same as “date-add”
- result: same as “date-add”
The following converts time to local time, subtracts one day, and shows it in the desired format: ${V.db_time}@{date-to-local}{date-sub: qty = 1; interval = d}{date-format: LLLL}
Decoration array-to-list:
- [type: String]: bulleted|numbered|custom;
- [shape: String]: any available shape for ou/ul html lists;
- [max: Number]: maximum number of items;
- [path: String]: data path for array of objects;
- [template: String]: custom element template;
Parameters:
type
- default: numbered (HTML tag <ol>
- bulleted (HTML tag <ul>)
- custom (the list will not be built as an HTML template/tag. It is convenient to use if you need to display elements in a simple list, or store them in a variable as text, or send them to the API in a certain format)
- shape
- used together with type
- numbered:
- bulleted:
- custom:
- user specifies any character (or string) that will be used as a separator between elements.
- default: “, ” (comma with space).
- max
- Allows to specify the maximum number of elements to form a list.
- Default: the length of the array (maximum items).
- Any positive number is allowed. If the value is a string or a number “<= 0”, the default value will be automatically set.
- path
- Allows to specify the path to data inside the array. Useful if the array is not one-dimensional.
- Default: null (this means that the array element will be taken as a whole)
A single path or multiple paths can be specified, separated by commas.
Let's say we have a response from the server containing an array of data:
[ { id: 1, userInfo: { firstName: 'John', email: 'john@qreli.com', } }, { id: 2, userInfo: { firstName: 'Mary', email: 'mary@qreli.com', } }, // … ]
path = userInfo.firstName
But if we want to output multiple data values in each list element, then we will specify multiple paths, for example:
path = id, userInfo.firstName, userInfo.email
When we define this parameter, then the data in the template will be available using the $N specifiers, where N is the data path number starting from 1.
Example:
@{ array-to-list: type = custom; path = id, userInfo.firstName; template = Hello $2! Your ID is equal to $1. }
—> "Hello, John! Your ID is equal to 1"
template
- Allows to change the display template of a list item.
- By default, a list of "<li>" tags will be generated.
- You can use the special data specifier $N (see above) inside a template.
Decorator array-modify:
[ { label: '', value: '', }, // … ]
It can only be applied to arrays.
Parameters:
func
- Required —> String
- A function can be applied to a variable of type String from this list: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
- toLowerCase()
- toUpperCase()
- trim()
- trimEnd()
- trimStart()
- slice()
- replace()
- replaceAll()
- substring()
- affect
- String
- Can only be label or value
- Default: label
@{ array-modify: func = substring(0, 2) }
This means taking only the first 2 characters of the labels (for vector elements).
You can learn more about certain variables and functions you could be using the Environment and Text/Math Libraries below.