Pole List
Tabela wierszy, z których każdy edytuje się w podformularzu
Pole list wyświetla tabelę wierszy, z których każdy tworzy się i edytuje w osobnym panelu podformularza (wzorzec drilldown). Zastępuje pole table, usunięte w wersji 7.0.0.
Najważniejsze funkcje
Pole list oferuje następujące możliwości:
- Każdy wiersz edytuje się w pełnoekranowym podformularzu, który daje dostęp do wszystkich typów pól, łącznie z zagnieżdżonymi listami.
- Podformularz to osobny formularz typu
subformi można go używać ponownie w wielu polach list w różnych formularzach (np. jeden podformularzAddresswspólny dla klientów, dostawców, zamówień…). - Właściwości znaczników (
insertMarker,updateMarker,deleteMarker) wspierają idempotentne wzorce playbooków. - Przy
allowDelete: falseistniejące wcześniej wiersze są chronione; usunąć można tylko wiersze dodane w bieżącej sesji (oznaczoneinsertMarker). - Właściwość
columnsokreśla, które pola podformularza pojawiają się jako kolumny w tabeli podsumowania. - Wynikiem jest zawsze tablica obiektów. Właściwości
model,output,outputObjectivalueColumnzadeklarowane w polach podformularza są respektowane przy generowaniu extravars.
Deklaracja podformularza
Podformularz to osobny formularz z type: subform, zapisany w pliku folderu formularzy jak każdy inny formularz. Przyjmuje tę samą tablicę fields co każdy inny formularz, ale nigdy nie pojawia się na liście kafelków formularzy i nigdy nie jest wysyłany bezpośrednio.
- 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
Właściwości
Właściwości dostępne dla pola list, pogrupowane według przeznaczenia:
| Atrybut | Komentarze |
|---|---|
| basic | |
| name string / wymagane / unikalne | Field name
This attribute represents the name of the form field. |
| type string / wymagane | Field type
Other attributes might only be available for some field types. Wartość: list PrzykładyText |
| 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 / wymagane | 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 PrzykładyGet 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. Domyślnie: 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. Przykładyget 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 Przykładyget information from a mysql database get information from a mongodb |
| interaction | |
| dependencyFn string dodano w wersji 4.0.0 | The dependency logical function
This attribute represents the logical function between multiple dependencies. Opcje:
|
| 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 PrzykładyShow 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. Domyślnie: 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. Domyślnie: true |
| showLoadButton boolean dodano w wersji 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. Domyślnie: false PrzykładyList with YAML import YAML field with file import |
| showDownloadButton boolean dodano w wersji 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. Domyślnie: false |
| output | |
| output boolean dodano w wersji 6.2.0 | Include field value as extravar
Form fields are by default sent as extravars. Domyślnie: true |
| model string or array | Extravar modelling
By default, a field is sent as a root-extravar. PrzykładyModel 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 PrzykładyMark delete record |
| insertMarker string | Adds an additional insertmarker field
When you add a record in a table, it simply gets added. PrzykładyMark new record |
| updateMarker string dodano w wersji 5.1.0 | Adds an additional updatemarker field
In addition to the insert and delete markers, you can also add an update marker. PrzykładyMark updated record |
| security | |
| noLog boolean dodano w wersji 2.2.3 | Disable backend logging
Disables logging in the backend, to hide passwords for example. Domyślnie: false Przykładyhide password in log |
| validation | |
| required boolean | Required field
Makes the field required. Domyślnie: false |
| validIf object dodano w wersji 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:
PrzykładyIp must be pingable |
| validIfNot object dodano w wersji 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:
PrzykładyCheck if powered off |
| ignoreIncomplete boolean | Allow form submit on non-evaluated placeholders
When an expression-based field has placeholders, Domyślnie: false |
| visualization | |
| group string | The field group name
With this attribute you can group fields together. |
| line string dodano w wersji 4.0.3 | The field line name
With this attribute you can group fields in a single line together. |
| width string dodano w wersji 4.0.3 | The field width
With this attribute you can set the width of a field. Opcje:
PrzykładyName 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 PrzykładyShow only wanted columns |
Przykłady
Wspólny podformularz adresu
Jeden podformularz Address używany przez dwa pola list tego samego formularza:
- 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
Śledzenie znacznikami (z myślą o idempotencji)
Wstępnie załadowane wiersze są chronione, a znaczniki mówią playbookowi, które wiersze są nowe, zmienione lub usunięte:
- 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
Wstępne wypełnianie wierszy
Listę można wstępnie wypełnić z trzech źródeł. W każdym przypadku wynikowe wiersze muszą być obiektami, których klucze odpowiadają nazwom pól wskazanego podformularza.
Statyczny default
Wiersze zapisane w samym formularzu:
- 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
Z REST API (expression)
Wiersze ładowane z REST API przez wyrażenie po stronie serwera:
- name: users
type: list
label: Users
subform: User
columns:
- username
- email
expression: fn.fnRestBasic('get','https://api.example.com/users','','my_api_cred','')
Z zapytania do bazy danych (dbConfig + query)
Wiersze ładowane z zapytania do bazy danych:
- name: servers
type: list
label: Servers
subform: Server
columns:
- hostname
- role
dbConfig: CMDB_CONN
query: SELECT hostname, role FROM servers WHERE active = 1
dbConfig wskazuje bazę danych z Połączenia > Bazy danych (od wersji 7.5.0), a w przeciwnym razie poświadczenie typu baza danych, jak dotąd (zobacz Bazy danych w formularzach).
Z wyrażenia lokalnego (runLocal)
Wiersze obliczane w przeglądarce przez wyrażenie lokalne:
- 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' }
]
Zagnieżdżone listy
Podformularz może mieć własne pole list, aby w każdym wierszu była lista:
- 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
Dostęp do danych formularza nadrzędnego przez __parent__
Gdy otwiera się edytor wiersza podformularza, AnsibleForms wstrzykuje do podformularza zmienną __parent__. Zawiera ona migawkę wszystkich wartości pól formularza nadrzędnego, łącznie ze stałymi i vars.
Odwołuj się do niej standardową składnią wyrażeń $(...) w definicjach pól podformularza:
- 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__to pomocnik działający wyłącznie we frontendzie. Jest usuwany z extravars Ansible i nigdy nie trafia do playbooka.