Skip to content

Commit

Permalink
Editing layer visible status (#957)
Browse files Browse the repository at this point in the history
* Add 'visible' editing layer status field.

* Add visible behaviour, fix disable capability user grants.

* Add 'visible' property management.

* Typo

* Add `editing` property to /vector/api/config API response.

* Extend APIVectorLayerStructure with 'editing' property.

* New structure

* ⬆️ Client
  g3w-suite/g3w-client#674
  g3w-suite/g3w-client-plugin-editing#133

* Add visible property layer editing management to multi layer editing management.

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent df0aed4 commit 100d9ee
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 27 deletions.
2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/js/vendor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g3w-admin/client/templates/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="stylesheet" type="text/css" href="{{ css }}" />
{% endfor %}{% endif %}
</head>
<body class="{% if sidebar_collapse %} sidebar-collapse {% endif %}">
<body class="skin-{{ skin_class|default:'blue' }} {% if sidebar_collapse %} sidebar-collapse {% endif %}">
{% if SETTINGS.SENTRY_JS %}
{{ SETTINGS.SENTRY_JS | safe }}
{% endif %}
Expand Down
10 changes: 10 additions & 0 deletions g3w-admin/core/utils/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class APIVectorLayerStructure(object):
_featureLocks = None
_geometryType = None
_fields = None
_editing = None

def __init__(self, **kwargs):

Expand All @@ -402,6 +403,7 @@ def __init__(self, **kwargs):
self.featureLocks = kwargs.get('featureLocks', self._featureLocks)
self.geometryType = kwargs.get('geometryType', self._geometryType)
self.fields = kwargs.get('fields', self._fields)
self.editing = kwargs.get('editing', self._fields)

def setPkField(self, pkField):
self._pkField = pkField
Expand All @@ -415,6 +417,9 @@ def setFeatureLocks(self, featuresLock):
def setFields(self, fields):
self.fields = fields

def setEditing(self, editing):
self.editing = editing

def as_dict(self):

res = {
Expand All @@ -428,6 +433,11 @@ def as_dict(self):
'featurelocks': self.featureLocks,
}

if self.editing:
res['vector'].update({
'editing': self.editing
})

return res


Expand Down
13 changes: 11 additions & 2 deletions g3w-admin/editing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ class ActiveEditingLayerForm(ActiveEditingMixin, G3WRequestFormMixin, G3WProject

active = forms.BooleanField(label=_('Active'), required=False)
scale = forms.IntegerField(label=_('Scale'), required=False, help_text=_('Scale after that editing mode is active'))
visible = forms.BooleanField(label=_('Visible'), required=False)
viewer_users = forms.MultipleChoiceField(choices=[], label=_('Viewers'), required=False,
help_text=_('Select user with viewer role can do editing on layer'))

user_groups_viewer = forms.MultipleChoiceField(
choices=[], required=False, help_text=_('Select VIEWER groups can do editing on layer'),
label=_('User viewer groups')
Expand Down Expand Up @@ -101,7 +103,9 @@ def __init__(self, *args, **kwargs):

layout_args = [
HTML(_('Check on uncheck to active/deactive editing layer capabilities:')),
'active'
'active',
HTML(_('Check on uncheck to show layer inside the list of layers to edit:')),
'visible'
]

# Check if layer ha geometry or not
Expand Down Expand Up @@ -160,6 +164,9 @@ class ActiveEditingMultiLayerForm(ActiveEditingMixin, G3WRequestFormMixin, G3WPr
scale = forms.IntegerField(label=_('Scale'), required=False, help_text=_('Scale after that editing mode is active'))

active = forms.BooleanField(label=_('Active'), required=False)

visible = forms.BooleanField(label=_('Visible'), required=False)

viewer_users = forms.MultipleChoiceField(choices=[], label=_('Viewers'), required=False,
help_text=_('Select user with viewer role can do editing on layer'))
user_groups_viewer = forms.MultipleChoiceField(
Expand All @@ -181,7 +188,9 @@ def __init__(self, *args, **kwargs):

layout_args = [
HTML(_('Check on uncheck to attive/deactive editing layers capabilities:')),
'active'
'active',
HTML(_('Check on uncheck to show layer inside the list of layers to edit:')),
'visible'
]

layout_args += [
Expand Down
18 changes: 18 additions & 0 deletions g3w-admin/editing/migrations/0013_g3weditinglayer_visible.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-10-16 13:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('editing', '0012_auto_20230213_0921'),
]

operations = [
migrations.AddField(
model_name='g3weditinglayer',
name='visible',
field=models.BooleanField(blank=True, default=True, help_text='Show layer in layers list to edit', null=True),
),
]
1 change: 1 addition & 0 deletions g3w-admin/editing/models/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class G3WEditingLayer(models.Model):
scale = models.IntegerField(null=True, blank=True)
add_user_field = models.CharField(null=True, blank=True, max_length=255)
edit_user_field = models.CharField(null=True, blank=True, max_length=255)
visible = models.BooleanField(default=True, null=True, blank=True, help_text="Show layer in layers list to edit")

class Meta:
app_label = 'editing'
Expand Down
38 changes: 22 additions & 16 deletions g3w-admin/editing/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@
from django.dispatch import receiver
from django.contrib.auth.signals import user_logged_out
from django.template import loader
from django.core.cache import cache
from django.db.models.signals import pre_delete, post_save
from core.signals import (
load_layer_actions,
initconfig_plugin_start,
after_serialized_project_layer,
pre_save_maplayer,
post_save_maplayer,
pre_delete_maplayer,
load_js_modules,
before_return_vector_data_layer,
)
from django.db.models.signals import pre_delete
from core.signals import (
load_layer_actions,
Expand All @@ -31,15 +20,12 @@
pre_save_maplayer,
post_save_maplayer,
pre_delete_maplayer,
load_js_modules,
before_return_vector_data_layer,
load_project_layers_actions
load_project_layers_actions,
post_create_maplayerattributes
)
from core.utils.qgisapi import get_qgis_layer
from qdjango.api.projects.serializers import QGIS_LAYER_TYPE_NO_GEOM
from qdjango.vector import LayerVectorView, MODE_CONFIG
from qdjango.models import GeoConstraintRule
from qdjango.utils.structure import datasource2dict
from .models import (
G3WEditingFeatureLock,
G3WEditingLayer,
Expand Down Expand Up @@ -422,3 +408,23 @@ def invalid_prj_cache(**kwargs):
f"{layer.project}"
)

@receiver(post_create_maplayerattributes)
def set_editing_visible_status(**kwargs):
"""
Add status 'visible to layer definition in /vector/api/config'
"""

# Check for layer editing capabilities are active
try:
el = G3WEditingLayer.objects.get(
app_name="qdjango", layer_id=kwargs["layer"].pk
)

kwargs['vector_params'].update({
'editing': {
'visible': el.visible
}
})

except:
return None
2 changes: 1 addition & 1 deletion g3w-admin/editing/static/editing/js/plugin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion g3w-admin/editing/static/editing/js/plugin.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion g3w-admin/editing/static/editing/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ ga.Editing.widget = {
*/
init_active_status: function () {
$check = $("#editing_layer_form").find('#id_active');
$select = $("#editing_layer_form").find('#id_scale, select:not(#id_layers)');
$select = $("#editing_layer_form").find('#id_scale, select:not(#id_layers), #id_visible');

var check_active_status = function (event) {
$ichecks = $("#editing_layer_form").find('' +
'input[name^="user_add_capability_"],' +
'input[name^="user_change_capability_"],' +
'input[name^="user_changeattributes_capability_"],' +
'input[name^="user_delete_capability_"]');

if ($check.prop('checked')) {
$select.prop('disabled', false);
$ichecks.iCheck('enable');
} else {
$select.prop('disabled', true);
$ichecks.iCheck('disable');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@
"options": {}
},
"vectorjoin_id": "cities_54d40b01_2af8_4b17_8495_c5833485536e_vectorjoin_0"
}]
}],
"editing": {
"visible": true
}
},
"featurelocks": null,
"constraints": {},
Expand Down
19 changes: 16 additions & 3 deletions g3w-admin/editing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ def get_form_kwargs(self):
try:
self.activated = G3WEditingLayer.objects.get(app_name=self.app_name, layer_id=self.layer_id)
kwargs['initial']['active'] = True
kwargs['initial']['visible'] = self.activated.visible
kwargs['initial']['scale'] = self.activated.scale
kwargs['initial']['add_user_field'] = self.activated.add_user_field
kwargs['initial']['edit_user_field'] = self.activated.edit_user_field
except:
self.activated = None
kwargs['initial']['active'] = False
kwargs['initial']['visible'] = True

# get viewer users
with_anonymous, editor_pk, editor2_pk, kwargs['initial']['viewer_users'] = self.get_initial_viewer_users(self.layer)
Expand Down Expand Up @@ -270,15 +272,20 @@ def remove_from_atomic_permissions(self, context, u_g_id):
@transaction.atomic
def form_valid(self, form):
scale = form.cleaned_data['scale']
visible = form.cleaned_data['visible']
add_user_field = form.cleaned_data['add_user_field']
edit_user_field = form.cleaned_data['edit_user_field']

if form.cleaned_data['active']:
if not self.activated:
self.activated = G3WEditingLayer.objects.create(app_name=self.app_name, layer_id=self.layer_id,
scale=scale, add_user_field=add_user_field,
self.activated = G3WEditingLayer.objects.create(app_name=self.app_name,
layer_id=self.layer_id,
scale=scale,
visible=visible,
add_user_field=add_user_field,
edit_user_field=edit_user_field)
else:
self.activated.visible = visible
self.activated.scale = scale
self.activated.add_user_field = add_user_field
self.activated.edit_user_field = edit_user_field
Expand Down Expand Up @@ -362,6 +369,9 @@ def get_form_kwargs(self):
if 'data' in kwargs:
self.get_atomic_capabilities(kwargs['data'])

# Set visibile to True
kwargs['initial']['visible'] = True

return kwargs

def add_remove_atomic_permissions(self, layer, with_anonymous=False, editor_pk=None, editor2_pk=None):
Expand Down Expand Up @@ -415,6 +425,7 @@ def form_valid(self, form):
}

scale = form.cleaned_data['scale']
visible = form.cleaned_data['visible']

for layer_pk in layers:

Expand All @@ -428,8 +439,10 @@ def form_valid(self, form):
layer_id=layer_pk,
edit_user_field=edit_user_field,
add_user_field=add_user_field,
scale=scale)
scale=scale,
visible=visible)
else:
activated[layer_pk].visible = visible
activated[layer_pk].scale = scale
activated[layer_pk].add_user_field = add_user_field
activated[layer_pk].edit_user_field = edit_user_field
Expand Down

0 comments on commit 100d9ee

Please sign in to comment.