Salta el contingut

Widgets DatabaseLayer

In order to edit data in DatabaseLayer, the administrator allows defining the necessary widget for each field. This means we can configure how the user will enter values and what values will be accepted. The widget configuration is done from the “Fields” tab of a DatabaseLayer:

  1. Select the widget.
  2. Configure the widget options according to the chosen type.

Screenshot


Below are the available widgets in the application:

  • Automatic: The application automatically configures the most suitable widget based on the data type of the field: numeric, text, date, …
  • Linked Field: To take the value from another field. For example, in a layer, there is a code and a description, and we want to automatically update the description when modifying the code.
{
    "source": "type_id"
}
  • Foreign Key: to point to the “parent” in a 1:N relationship. For example, a table of tree incidents has a foreign key to the original tree of the incident. This allows us to obtain the geometry of the tree.
{
    "dblayer": "layername",
    "to_field": "id",
    "geom": true
}
  • Date: for entering date fields. In the options, we can specify the working format.
  • Creation Date: used to automatically save the creation date of an element in this field. Only when creating the element.
  • Modification Date: used to automatically save the modification date of an element in this field.
  • Date and Time: for entering dates and times.
  • Creation Date and Time: used to automatically save the creation date and time of an element in this field. Only when creating the element.
  • Modification Date and Time: used to automatically save the modification date and time of an element in this field.
{
    "format": "YYYY-MM-DD", //Example 1
    "format": "YYYY-MM-DD HH:mm:ss", //Example 2
    ...
}
  • Choose via SQL query: This option creates a table with the possible values for the field. The list of values is obtained from a postgresql query. In the settings, we need to specify the SQL query (query) with the fields to be used and the table from which to retrieve the values. The label (label) is what the user will see and will be saved in the database. To define the values to be displayed in the table, we will define the header (table_headers) with the name of the field we want to see and the label we will see on the form.

    For example, if we wanted to choose and assign the scientific name of a tree from a table where we have all the types, we would do the following:
{
    "query": "select genus, scientific_name, common_names from tree_types",
    "label": "{scientific_name}",
    "table_headers": [{"genus": "Genus"}, {"scientific_name": "Scientific Names"}, {"common_names": "Common Names"}] // map the fields to the columns and assign them a label
}

Upon selection, “{scientific_name}” will be saved in the database.

  • Choose: one value per line: allows directly choosing one of the values entered in the configurations. Each new line will be a value that the user can choose. In each line, we must indicate the key (value stored in the database) and the value (text that the user will see), separated by commas. For example:
key1,value1
key2,value2

VEG, Vegetació
COM, Comunicació
...
  • Image: to allow the user to add images in edit mode.
{
    "upload_root": "<auto>", // Folder where the photos are uploaded
    "base_url": "<auto>", // Base URL where the photos are served
    "thumbnail_root": "<auto>", // Folder where thumbnails are saved
    "thumbnail_base_url": "<auto>", // Base URL where the thumbnails are served
    "upload_size": 1024 // Maximum size (height or width) of the image
}

For example:

// No se especifica la URL, se pone automáticamente
{
    "upload_root": "/data/apps/giscube-admin/media/layerserver/capa/img",
    "thumbnail_root": "/data/apps/giscube-admin/media/layerserver/capa/thumbnail",
    "upload_size": 1024 
}
  • Creation user: stores the username of the user who created an element in the field.
  • Modification user: stores the username of the user who modified an element in the field.
  • Distinct values: takes the distinct (unique) values of a field, for example, provider, type, or class, and allows them to be chosen. It has an option to indicate whether we can add new values or not.
{
    "allow_add_new": true
}
  • One-to-Many Relationship: to link a parent layer with its child. For example, a table of trees with the n incidents for each tree. From the edit form, we can access the incidents of the tree.
{
    "dblayer": "layername",
    "to_field": "id",
    "dblayer_fk": "parent_id",
    "count": false
}