Campo List
Una tabella di righe, ognuna modificata in un sottomodulo
Un campo list mostra una tabella di righe, ognuna creata e modificata in un pannello dedicato di sottomodulo (uno schema di drilldown). Sostituisce il campo table, rimosso nella 7.0.0.
Caratteristiche principali
Il campo list offre le seguenti funzionalità:
- Ogni riga viene modificata in un sottomodulo a schermo intero, che dà accesso a tutti i tipi di campo, comprese le liste annidate.
- Il sottomodulo è un modulo a sé, di tipo
subform, e può essere riutilizzato in più campi list di moduli diversi (ad es. un unico sottomoduloAddresscondiviso da clienti, fornitori, ordini…). - Le proprietà marker (
insertMarker,updateMarker,deleteMarker) supportano schemi di playbook idempotenti. - Con
allowDelete: false, le righe preesistenti sono protette; si possono eliminare solo le righe aggiunte nella sessione corrente (quelle con l’insertMarker). - La proprietà
columnsstabilisce quali campi del sottomodulo compaiono come colonne nella tabella riepilogativa. - L’output è sempre un array di oggetti.
model,output,outputObjectevalueColumndichiarati sui campi del sottomodulo vengono rispettati quando si generano le extravars.
Dichiarazione del sottomodulo
Un sottomodulo è un modulo a sé con type: subform, in un file della cartella dei moduli come qualsiasi altro modulo. Accetta lo stesso array fields di qualsiasi altro modulo, ma non compare mai nell’elenco a riquadri dei moduli e non viene mai inviato direttamente.
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
required: true
- name: city
type: text
label: City
required: true
- name: country
type: text
label: Country
Proprietà
Le proprietà disponibili per un campo list, raggruppate per scopo:
| Attributo | Commenti |
|---|---|
| basic | |
| name string / obbligatorio / univoco | Field name
This attribute represents the name of the form field. |
| type string / obbligatorio | Field type
Other attributes might only be available for some field types. Valore: list EsempiText |
| label string | Field label
A friendly name/label for the field. Note: if not set, the field name is used as label, but not when type is html. Since 6.0.3: Supports placeholders for dynamic labels (e.g., |
| help string | Field help message
Some fields require additional help information. This help message will be shown below the field. Since 6.0.3: Supports placeholders for dynamic help text (e.g., |
| subform string / obbligatorio | Name of the subform that defines one row
For a |
| data | |
| default many | Default value
The type of the value depends on the field type.
For |
| expression string | A javascript expression.
By default this javascript is evaluated on the server side and limited to predefined functions (for security). However in combination with tip: use the alias EsempiGet a list of users from a rest api Filter and sort an array of objects Make a numbered list Use the alias `local` Use the alias `local_out` |
| runLocal boolean | Run an expression locally
When running expressions, by default they are run remotely on the server. Predefinito: false |
| dbConfig string, array or object | A database connection
When you want to query data from a database, you will need the proper connection information. Esempiget information from a mysql database (legacy example - deprecated) get information from a mysql database (new example) get information from a mysql database (array example) get information from a mongodb |
| query string | The query to select data from a database
This is typically a classic SELECT statement. Every Esempiget information from a mysql database get information from a mongodb |
| interaction | |
| dependencyFn string aggiunto nella versione 4.0.0 | The dependency logical function
This attribute represents the logical function between multiple dependencies. Scelte:
|
| dependencies list / elements=object | Show/hide this field based on the values or other fields
Each dependency element is either an object with the following 2 attributes:
Or with the following 2 attributes:
Use in combination with attribute EsempiShow a field based on a checkbox Show a field if another field is valid Show a field based on 2 fields, using the 'or' function |
| allowInsert boolean | Allow table/list insert
A table or list can be used to modify existing data. If new data is not allowed, set this property to false. Predefinito: true |
| allowDelete boolean | Allow table/list delete
A table can be used to modify existing data. If you don’t was recoreds to be deleted, set this property to false. Predefinito: true |
| showLoadButton boolean aggiunto nella versione 6.1.5 | Show load button for file import
Enables a “Load YAML” button that allows users to import data from .yml or .yaml files. For list fields, the YAML file must contain a valid array of objects. For yaml fields, the file can contain any valid YAML structure. Single objects are automatically wrapped in arrays for list fields. Predefinito: false EsempiList with YAML import YAML field with file import |
| showDownloadButton boolean aggiunto nella versione 6.1.5 | Show download button for file export
Enables a “Download” button that exports the field content as a .yml file. The filename is automatically generated from the field name. Predefinito: false |
| output | |
| output boolean aggiunto nella versione 6.2.0 | Include field value as extravar
Form fields are by default sent as extravars. Predefinito: true |
| model string or array | Extravar modelling
By default, a field is sent as a root-extravar. EsempiModel 2 fields together as a single object |
| deleteMarker string | Adds an additional deletemarker field
When you remove a record in a table, it gets removed. Since 6.4.1 the markers of a EsempiMark delete record |
| insertMarker string | Adds an additional insertmarker field
When you add a record in a table, it simply gets added. EsempiMark new record |
| updateMarker string aggiunto nella versione 5.1.0 | Adds an additional updatemarker field
In addition to the insert and delete markers, you can also add an update marker. EsempiMark updated record |
| security | |
| noLog boolean aggiunto nella versione 2.2.3 | Disable backend logging
Disables logging in the backend, to hide passwords for example. Predefinito: false Esempihide password in log |
| validation | |
| required boolean | Required field
Makes the field required. Predefinito: false |
| validIf object aggiunto nella versione 2.2.4 | An field based validation (field must be true)
Enforces a validation where a referencing (expression) field must be true. This field requires an object with 2 attributes:
EsempiIp must be pingable |
| validIfNot object aggiunto nella versione 2.2.4 | An field based validation (field must be false)
Enforces a validation where a referencing (expression) field must be false. This field requires an object with 2 attributes:
EsempiCheck if powered off |
| ignoreIncomplete boolean | Allow form submit on non-evaluated placeholders
When an expression-based field has placeholders, Predefinito: false |
| visualization | |
| group string | The field group name
With this attribute you can group fields together. |
| line string aggiunto nella versione 4.0.3 | The field line name
With this attribute you can group fields in a single line together. |
| width string aggiunto nella versione 4.0.3 | The field width
With this attribute you can set the width of a field. Scelte:
EsempiName and lastname |
| titleAdd string | Title shown in the subform pane when adding a new row
When you add a row through a |
| titleEdit string | Title shown in the subform pane when editing an existing row
When you edit a row through a |
| columns array | The list of columns visible in the dropdown/table
For an EsempiShow only wanted columns |
Esempi
Sottomodulo di indirizzo condiviso
Un unico sottomodulo Address riutilizzato da due campi list dello stesso modulo:
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
required: true
- name: city
type: text
label: City
required: true
- name: country
type: text
label: Country
- name: Create customer
type: ansible
playbook: customer.yaml
roles: [default]
fields:
- name: name
type: text
label: Customer name
required: true
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- city
- country
titleAdd: Add address
titleEdit: Edit address
allowInsert: true
allowDelete: true
Tracciamento con marker (attento all’idempotenza)
Le righe precaricate sono protette, e i marker indicano al playbook quali righe sono nuove, modificate o rimosse:
- name: people
type: list
label: People
subform: Person
allowDelete: false # preloaded rows are protected
insertMarker: added # session-added rows remain removable
updateMarker: updated
deleteMarker: removed
columns:
- name
- email
Precompilare le righe
Una lista può essere precompilata da tre sorgenti. In ogni caso, le righe risultanti devono essere oggetti le cui chiavi corrispondono ai nomi dei campi del sottomodulo a cui si fa riferimento.
default statico
Righe scritte nel modulo stesso:
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- city
- country
default:
- street: Main 1
city: Brussels
country: BE
- street: Side 22
city: Paris
country: FR
Da un’API REST (expression)
Righe caricate da un’API REST tramite un’espressione lato server:
- name: users
type: list
label: Users
subform: User
columns:
- username
- email
expression: fn.fnRestBasic('get','https://api.example.com/users','','my_api_cred','')
Da una query su database (dbConfig + query)
Righe caricate da una query su database:
- name: servers
type: list
label: Servers
subform: Server
columns:
- hostname
- role
dbConfig: CMDB_CONN
query: SELECT hostname, role FROM servers WHERE active = 1
dbConfig indica un database di Connessioni > Database (dalla 7.5.0), o altrimenti una credenziale di tipo database, come prima (vedi I database nei moduli).
Da un’espressione locale (runLocal)
Righe calcolate nel browser da un’espressione locale:
- name: ports
type: list
label: Open ports
subform: Port
columns:
- port
- protocol
runLocal: true
expression: |
[
{ port: 22, protocol: 'tcp' },
{ port: 80, protocol: 'tcp' },
{ port: 443, protocol: 'tcp' }
]
Liste annidate
Un sottomodulo può contenere un proprio campo list, per avere una lista dentro ogni riga:
- name: Address
type: subform
fields:
- name: street
type: text
label: Street
- name: city
type: text
label: City
- name: Person
type: subform
fields:
- name: name
type: text
label: Name
required: true
- name: addresses
type: list
label: Addresses
subform: Address
columns:
- street
- city
- name: My Form
type: ansible
playbook: people.yaml
roles: [default]
fields:
- name: people
type: list
label: People
subform: Person
columns:
- name
- addresses
Accedere ai dati del modulo padre tramite __parent__
Quando si apre l’editor di una riga del sottomodulo, AnsibleForms inserisce una variabile __parent__ nel sottomodulo. Contiene un’istantanea di tutti i valori dei campi del modulo padre, comprese costanti e variabili.
Fai riferimento a essa con la sintassi standard delle espressioni $(...) nelle definizioni dei campi del sottomodulo:
- name: NodeConfig
type: subform
fields:
- name: node_name
type: text
label: Node name
required: true
- name: node_type
type: enum
# only offer gpu in production environments (parent field)
expression: |
'$(__parent__.environment)' === 'production'
? ['standard', 'high-memory', 'gpu']
: ['standard', 'high-memory']
runLocal: true
default: __auto__
- name: Deploy cluster
type: ansible
playbook: deploy.yml
roles: [default]
fields:
- name: environment
type: enum
values: [dev, staging, production]
required: true
- name: nodes
type: list
subform: NodeConfig
columns: [node_name, node_type]
__parent__è un helper solo frontend. Viene rimosso dalle extravars di Ansible e non viene mai inviato al playbook.