Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support to editable vector joins (1:1 relations) #599

Merged
merged 20 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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