Skip to content

Commit

Permalink
✨ Add support to editable vector joins (1:1 relations) (#599)
Browse files Browse the repository at this point in the history
* Add 'hasCustomPrefix' property to vectorjoin.

* Add 'editable' property, so serialization of vector join.

* Add property `vectorjoin_id` to REST API /vector/api/config/.

* Fix test.

* Add 'prefix' and convert 'editable' to boolean type.

* Typo.

* Fix 'editable' property for fields in QGIS join.

* Set 'editable' to False if join field is a Pk.

* Fix test editing fi QGIS Join

* For documentation.

* ✨ Client:
   core: g3w-suite/g3w-client#483
   editing: g3w-suite/g3w-client-plugin-editing#52

* ✨ Client:
    client:  - g3w-suite/g3w-client#483
             - g3w-suite/g3w-client#159
    editing: - g3w-suite/g3w-client-plugin-editing#52
             - g3w-suite/g3w-client-plugin-editing#53

* ✨ Client:
    client:  - g3w-suite/g3w-client#483
             - g3w-suite/g3w-client#159
    editing: - g3w-suite/g3w-client-plugin-editing#52
             - g3w-suite/g3w-client-plugin-editing#53

* ✨ Client:
    editing: - g3w-suite/g3w-client-plugin-editing@96c9b40
    editing: - g3w-suite/g3w-client-plugin-editing@16f4c9f
    editing: - g3w-suite/g3w-client-plugin-editing@b7a6bb7

* ✨ Client:
    g3w-client: - g3w-suite/g3w-client@5b2e3fa

* ✨ Client:
    g3w-client-plugin-editing: -g3w-suite/g3w-client-plugin-editing@cd65314

* ✨ Client:
    g3w-client:g3w-suite/g3w-client@f557542
    g3w-client-plugin-editing: g3w-suite/g3w-client-plugin-editing@8aef6a4

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2023
1 parent d430836 commit 8e04f4f
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 444 deletions.
2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/css/app.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/js/app.min.js

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions g3w-admin/core/utils/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@


def editingFormField(fieldName, type=FIELD_TYPE_STRING, editable=True, required=False, validate=None,
fieldLabel=None, inputType=None, values=None, default_clause='', unique=False, expression='', pk=False, ** kwargs):
fieldLabel=None, inputType=None, values=None, default_clause='', unique=False, expression='',
pk=False, ** kwargs):
"""
Build editing form field for client.
"""
Expand Down Expand Up @@ -140,7 +141,7 @@ def editingFormField(fieldName, type=FIELD_TYPE_STRING, editable=True, required=

def mapLayerAttributes(layer, formField=False, **kwargs):
"""
Map database columns data from layer by type for client editing
Map database columns data from layer by type for client
"""

mappingData = FIELD_TYPES_MAPPING
Expand Down Expand Up @@ -222,6 +223,22 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):

pk_attributes = qgis_layer.primaryKeyAttributes()

# Get available Join's fields
join_fields = {}
for order, join in enumerate(qgis_layer.vectorJoins()):
join_id = f'{qgis_layer.id()}_vectorjoin_{order}'
joinlayer_pk_attributes = join.joinLayer().primaryKeyAttributes()
for i, f in enumerate(join.joinLayer().fields()):
editable = join.isEditable()

# Check if referencing field is PK
if i in joinlayer_pk_attributes:
editable = False
join_fields[join.prefixedFieldName(f)] = {
'editable': editable,
'join_id': join_id}


# Determine if we are using an old and bugged version of QGIS
IS_QGIS_3_10 = Qgis.QGIS_VERSION.startswith('3.10')

Expand Down Expand Up @@ -282,8 +299,6 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):
else:
is_pk = (field_index in pk_attributes)

#

toRes[field.name()] = editingFormField(
field.name(),
required=not_null,
Expand Down Expand Up @@ -342,6 +357,14 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):
toRes[field.name()]['input']['options']['default_expression']['apply_on_update'] = True \
if field.defaultValueDefinition().applyOnUpdate() else False

# Check for Join's field.
# About joins in QGIS control the join settings for editing.
try:
toRes[field.name()]['vectorjoin_id'] = join_fields[field.name()]['join_id']
toRes[field.name()]["editable"] = join_fields[field.name()]["editable"]
except:
pass

field_index += 1

return toRes
Expand Down
2 changes: 1 addition & 1 deletion g3w-admin/editing/static/editing/js/plugin.js

Large diffs are not rendered by default.

Loading

0 comments on commit 8e04f4f

Please sign in to comment.