config_form_fields - Giswater/giswater_dbmodel GitHub Wiki


Goals:

Show the capabilities and uses related to manipulating the config_form_fields table with the intention of customizing the forms displayed in QGIS for network elements (node, connec, gully, arc). You can translate the labels and tooltips of all the widgets, as well as move or hide them in case you are interested.

Introduction:

Since incorrect manipulation can cause significant damage to the configuration table, there is a backup function of any table in the database that can be very useful for this process. Its use consists of:

BACKUP CREATION:

SELECT gw_fct_admin_manage_backup ($${"data":{"action":"CREATE","backupName":"test6", "table":"config_form_fields"}}$$)

BACKUP RECOVERY:

SELECT gw_fct_admin_manage_backup ($${"data":{"action":"RESTORE", "backupName":"test6","newBackupName":"test5", "table":"config_form_fields"}}$$)

BACKUP DELETE:

SELECT gw_fct_admin_manage_backup ($${"data":{"action":"DELETE","backupName":"test4","table":"config_form_fields" }}$$)

COMMENTS: The creation process stores all the information in the temp_table table with fprocesscat_id = 111

To avoid possible bad manipulations, a double factor of safety strategy is used. In this sense:

  • It is mandatory to always put the two keys (backupName and table)
  • Before restoring the backup, a backup of the existing data in the table is saved with the name of newBackupName.

Description:

Notes to keep in mind. The primary key of the tables is: formname & formtype & tabname & columnname

The only rows that must be manipulated to customize the forms of the elements are those that in the formname column have the prefix:

ve_node_*

ve_arc_*

ve_connec_*

ve_gully_*

Normally there should be records for all the fields of the elements that we find in the cat_feature table (they must also match with the child views that we have created in our schema).

So, in the config_form_fields table, we will have for each child view a number of rows that match all the fields that this view has, in order to configure them one by one.

Of the many columns there is in config_form_fields, the user should only consider a few at the configuration level:

Fields:

Column name Data type Description Example Domain values
formname varchar (50) Name of form to configure cat_arc
formtype varchar (50) Type of form, defined on config_typevalue as formtype_typevalue form_feature [form_feature, form_print, form_visit, form_catalog, form_list_footer, form_lot, form_list_header]
tabname varchar (50) Name of a dynamic form tab in which the widget is placed data [data, main]
columnname varchar (30) Name of the column in DB arctype_id
layoutname varchar (16) Field position respect the different groups of fields in the form, defined on config_typevalue as layout_name_typevalue. For more detailes check out the image below lyt_data_1 [lyt_top_1, lyt_data_1, lyt_data_2, lyt_data_3, lyt_bot_1, lyt_bot_2]
layoutorder integer Field order within its corresponding layout. They will be sorted in ascending order using the value they have in this field. If two fields with the same layoutname and layout_order values are found, they will obviously overlap within the form. 13
datatype varchar (30) Field data type, defined on config_typevalue as datatype_typevalue. Doesn't apply for combo widget types string [string, double, date, bytea, boolean, text, integer]
widgettype varchar (30) Type of widget displayed on form, defined on config_typevalue as widgettype_typevalue. For more detailes check out (*) additional information combo [datetime, label, nowidget, text, image, typeahead, button, spinbox, check, combo, hyperlink, divider]
label text Label of the field in the form and the attribute table. Fully personalized. arctype_id
tooltip text Text that is displayed if you hover over the field label. Fully personalized. It's recommended to put an english name at the begining of a tooltip in order to identify it easly in case of a translation Date used as complementary date
hidden boolean If true, widget is hidden from the form and attribute table. FALSE
placeholder text Sample value to display when the field is empty. Ex.:annotation
iseditable boolean If true, field can be edited in info form and attribute table. TRUE
ismandatory boolean If true, field is mandatory and must have a value FALSE
isparent boolean If true, widget is a parent of another widget. it allows to reload combos of the children that have this widget identified as their parent (dv_parent_id) FALSE
isautoupdate boolean If true, field is automatically updated, without necessity of saving the entire form. Valid for fields that need to recalculate things like depths or others: This option is not available for typeahead type widgets. FALSE
isfilter If true, a widget with type list, can be filtered by this field if both are located in the same tab. Filter conditions may be specified on widgetcontrols field using keys ‘vdefault’ and ‘listFilterSign’. TRUE
dv_querytext text Query that fills in combobox and typeahead widgets in the form. The fields must have alias id and idval. In case of typeahead id and idval must be the same field SELECT expl_id as id, name AS idval FROM exploitation WHERE expl_id IS NOT NULL
dv_orderby_id boolean If true, data will be ordered by id TRUE
dv_isnullvalue boolean If true, empty value is allowed FALSE
dv_parent_id text Parent field name, set in case when values depend one on another expl_id
dv_querytext_filterc text Name of form to configure AND dma.expl_id
stylesheet json Json type field that allows graphical customization of the label. For more details check out (*) additional information {"label":"color:red; font-weight:bold"}
widgetcontrols json Allows an advanced control of the form with different options. For more details check out (*) additional information {"setQgisMultiline":true}
widgetfunction text Function related to the widget, defined on config_typevalue as widgetfunction_typevalue. As it is a python function it has to be defined in the file core/utils/tools_backend_calls.py. Function may take additional parameters {"functionName":"add_document", "parameters":{"sourcewidget", "targetwidget"}} [get_lot, set_visit, get_visit, set_visit_manager_end, set_visit_manager_start, set_print, get_visit_manager, set_previous_form_back, set_visit_manager, set_open_url, get_info_node]
linkedobject text Object name related to the field. For more details check out (*) additional information action_link [NULL, action_workcat, action_catalog, action_link]
web_layoutorder integer Web widget order on a form

Additional information

layoutname

_datatype_ combo & typeahead - Filled in using the [VALUE DOMAIN MANAGEMENT] with some limitation for the typeahead. The combo can also use the enableWhenParent key to be activated only for the certain values of parent. list - Widet uses the list defined in the linkedobject field in the config_form_list table. spinbox - Widget for double values, number of decimals may be defined aa key ‘spinboxDecimals’ de widgetcontrols {"spinboxDecimals":2}. image - Shows image defined on linkedobject field, definedon the table sys_image. button - Button that executes a front-end function defined on field widgetfunction. link - Widget that acts as a link. Needs a definition of a front-end function ('open_url') on field widgetfuncion.

widgetcontrols

autoupdateReloadFields – instantly reloads other fields in case one is modified UPDATE config_form_fields SET widgettype = ‘combo’ , isreload=true, widgetcontrols = gw_fct_json_object_set_key(widgetcontrols,'autoupdateReloadFields','["cat_matcat_id","cat_dnom", "cat_pnom"]'::json) WHERE column_id IN ('arccat_id', 'nodecat_id', 'connecat_id')

enableWhenParent – enables a combo only in case the parent field has certain values UPDATE config_form_fields SET widgetcontrols = gw_fct_json_object_set_key (widgetcontrols,'enableWhenParent','[1, 2]'::json) WHERE column_id IN ('state_type')

regexpControl UPDATE config_form_fields SET hidden=false, datatype ='text', widgetcontrols = gw_fct_json_object_set_key(widgetcontrols,'regexpControl','[\d]+:[0-5][0-9]:[0-5][0-9]'::text) WHERE column_id = 'observ' Additional note: Since the character ' \ ' is reserved by system for PostgreSQL, the update must be done with a ' \ ' so that in the row appears two, so that the syntax stored and to work with will be [\d]+:[0-5][0-9]:[0-5][0-9]

maxMinValues – sets a maximum value for numeric fields UPDATE config_form_fields SET widgetcontrols = gw_fct_json_object_set_key(widgetcontrols,'maxMinValues','{"min":0.001, "max":100}'::json) WHERE column_id = 'descript'

setMultiline - Allows multiline fields for writing with enter

spinboxDecimals – set number of decimals for widget spinbox (two by default) UPDATE config_form_fields SET widgetcontrols = gw_fct_json_object_set_key(widgetcontrols,'spinboxDecimals','3’) WHERE column_id = 'descript'

widgetdim – Sets the dimensions of a widget

vdefault - Default value of the widget. Useful for those widgets that do not belong to the data of a feature, since the default values are defined in those that the user already has set in config_param_user. Of special interest to filter widgets

listFilterSign - Sign (LIKE, ILIKE, =,>, <) for filter type fields. In case of omission, ILIKE will be used for tableview type lists and = for tab type lists

skipSaveValue – If this value is set to true, the changes made in the corresponding widget will not be saved. By default it is not necessary to put anything because true is understood

minLength / maxLength – sets a minimum or maximum length for a field UPDATE config_form_fields SET widgetcontrols= gw_fct_json_object_set_key(widgetcontrols,'maxLength','16'::json WHERE column_id = 'descript'

Also if the widgettype=''typeahead'' id & idval for querytext they should be the same field except for streetname.

linkedobject

For widgettype list - Name of the list located in the config_form_list table linked to the widget. In this table you configure the query (querytext) and the client with which it will be called. There are two fields in the table that do not have an associated code at the moment, such as listtype, which reffers to the way list is showed: tab (vertical list for a narrow tab) or attributetable (elements in a table view for bigger tabs). It is recommended that lists has prefix list_. For widgettype image - Name of the image defined in sys_image table. It is recommended that lists has prefix img_. For widgettype text / check / combo / typeahead - Name of action (optional) linked to the widget (getcatalog e.g.) that is available in the dialog, configured in config_form_tabs. Action names are defined on config_typevalue as linkedaction_typevalue. It is recommended that the actions have the name action_. For widgettype button - Name of an icon (option) to set on the button with the image associated folder located in the icons/backend/20x20 plugin folder. It is recommended that the names of the icons were simple numbers.png.


FAQS:

Any useful queries for making massive replacements? Replace for all the element types the label of a specific field. In this case, the label of the presszonecat_id field is replaced to Pressure zone for all elements, be they node, connec, gully or arc. UPDATE config_form_fields SET label='Pressure zone' WHERE column_id = 'presszonecat_id' AND formtype='feature' AND formname LIKE 've_%'; Hide for all element types a specific field. In this case the verified field is hidden for all elements. UPDATE config_form_fields SET isenabled=FALSE WHERE column_id = 'verified' AND formtype='feature' AND formname LIKE 've_%'; Hide a specific field only for node type elements. In this case, the code field is hidden for node type elements. UPDATE config_form_fields SET isenabled=FALSE WHERE column_id = 'code' AND formtype='feature' AND formname LIKE 've_node_%'; Hide a specific field only for some specific element type. In this case the parent_id field is hidden for the node types: pump, reduction and tank. UPDATE config_form_fields SET isenabled=FALSE WHERE column_id = 'parent_id' AND formtype='feature' AND formname IN ('ve_node_pump', ‘ve_node_reduction’, ‘ve_node_tank’);

Is it possible to add a field that I want in the form? Yes, you can add the field you want ALWAYS AND WHEN YOU ARE ONLY INQUIRY and it is not an additional field (addfield). For this you must: Modify the ve_node_ / ve_arc_ / ve_connec_ / ve_gully_ adding all those fields that you want to see (only query. Editing is not allowed since the trigger will not work). Modification can be made with DROP or CREATE OR REPLACE, we recommend the latter method. While for DROP you have to keep the trigger and redo it, if we do it with CREATE OR REPLACE we must MANDATORILY add the new fields at the end of the view, they cannot be intermediate. Add in the config_form_fields a new row referring to the created field. EXAMPLE: I want to add the descriptor of the material in the form of ve_arc_ownpipes, since in the form and in the corresponding view there is only the id: I modify the ve_arc_ownpipe by doing a JOIN to cat_mat and adding the cat_mat.descript field. Add in the config_form_fields a new row referring to the created field, in this case descript. If I have used an alias for the name I will have to put the alias.

This is a complex environment. Can I manage backups? See the INTRODUCTION of the protocol.

Which values can I put in the stylesheet field to modify the colors of the label? Put color and bold in a field.

  • Value in stylesheet - {"label":"color:blue; font-weight:bold"}
  • Result