From 18789c231dd6bc4b18c24642d660ef197c9c4ac0 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Tue, 10 May 2022 15:07:21 +0200 Subject: [PATCH 1/4] Visual enhancement for custom JS tree widget * adds proper css behaviour for collapsed icon * adds minor js comments --- konova/static/css/konova.css | 11 ++++++++++- .../konova/widgets/checkbox-tree-select-content.html | 6 ++++-- .../konova/widgets/checkbox-tree-select.html | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/konova/static/css/konova.css b/konova/static/css/konova.css index 7e7f3fd..ed79704 100644 --- a/konova/static/css/konova.css +++ b/konova/static/css/konova.css @@ -262,4 +262,13 @@ Similar to bootstraps 'shadow-lg' padding-left: 2em; } - */ \ No newline at end of file + */ +.collapse-icn > i{ + transition: all 0.3s ease; +} +.collapsed .collapse-icn > i{ + transform: rotate(-90deg); +} +.tree-label.badge{ + font-size: 90%; +} \ No newline at end of file diff --git a/konova/templates/konova/widgets/checkbox-tree-select-content.html b/konova/templates/konova/widgets/checkbox-tree-select-content.html index 9bf5725..31599ef 100644 --- a/konova/templates/konova/widgets/checkbox-tree-select-content.html +++ b/konova/templates/konova/widgets/checkbox-tree-select-content.html @@ -2,11 +2,13 @@ {% for code in codes %}
- {% if not code.is_leaf %}
{% with code.children as codes %} - {% include 'konova/widgets/checkbox-tree-select-content.html' %} + {% include 'konova/widgets/tree/checkbox/checkbox-tree-select-content.html' %} {% endwith %}
{% endif %} diff --git a/konova/templates/konova/widgets/checkbox-tree-select.html b/konova/templates/konova/widgets/tree/checkbox/checkbox-tree-select.html similarity index 96% rename from konova/templates/konova/widgets/checkbox-tree-select.html rename to konova/templates/konova/widgets/tree/checkbox/checkbox-tree-select.html index 68e4321..9626945 100644 --- a/konova/templates/konova/widgets/checkbox-tree-select.html +++ b/konova/templates/konova/widgets/tree/checkbox/checkbox-tree-select.html @@ -5,7 +5,7 @@
- {% include 'konova/widgets/checkbox-tree-select-content.html' %} + {% include 'konova/widgets/tree/checkbox/checkbox-tree-select-content.html' %}
\ No newline at end of file -- 2.38.5 From 5fe27e02ecaf3d866652e4baae61171159f0bbba Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 11 May 2022 08:41:37 +0200 Subject: [PATCH 3/4] WIP: JS Tree * simplifies js for single-select radio tree --- .../widgets/tree/radio/radio-tree-select.html | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/konova/templates/konova/widgets/tree/radio/radio-tree-select.html b/konova/templates/konova/widgets/tree/radio/radio-tree-select.html index 87df9f2..0c919c3 100644 --- a/konova/templates/konova/widgets/tree/radio/radio-tree-select.html +++ b/konova/templates/konova/widgets/tree/radio/radio-tree-select.html @@ -12,24 +12,16 @@ element = $(element); var cssClass = "badge rlp-r" - var directParent = element.closest(".tree-element-children") - var root = element.parents(".tree-element-children") + // Find all already tagged input elements and reset them to be untagged + var allTaggedInputs = $("#tree-root").find(".badge.rlp-r") + allTaggedInputs.removeClass(cssClass) - var otherCheckedInputsOfParent = directParent.find('.tree-input:checked'); - var otherCheckedInputsOfRoot = root.find('.tree-input:checked'); - - if(otherCheckedInputsOfParent.length == 0){ - var parentLabel = directParent.siblings(".tree-label"); - parentLabel.removeClass(cssClass) - if(otherCheckedInputsOfRoot.length == 0){ - var rootLabel = root.siblings(".tree-label") - rootLabel.removeClass(cssClass) - } - }else{ - var rootAndParentLabel = root.siblings(".tree-label"); - rootAndParentLabel.addClass(cssClass); - } + // Find all parents of selected element + var parentElements = element.parents(".tree-element-children") + // Tag parents of element + var parentLabels = parentElements.siblings(".tree-label"); + parentLabels.addClass(cssClass); } function changeHandler(event){ -- 2.38.5 From eb763a94fbc71952fb76b588d43811b218340ce4 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 11 May 2022 10:16:34 +0200 Subject: [PATCH 4/4] JS Tree enhancement * extends compensation state forms to match the new logic * adds minor changes for tests --- compensation/forms/modalForms.py | 18 +++++++++++++++--- compensation/models/compensation.py | 6 +++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index d129459..581a7b3 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -157,7 +157,7 @@ class NewStateModalForm(BaseModalForm): What has been on this area before changes/compensations have been applied and what will be the result ('after')? """ - biotope_type = forms.MultipleChoiceField( + biotope_type = forms.ChoiceField( label=_("Biotope Type"), label_suffix="", required=True, @@ -200,6 +200,16 @@ class NewStateModalForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("New state") self.form_caption = _("Insert data for the new state") + choices = KonovaCode.objects.filter( + code_lists__in=[CODELIST_BIOTOPES_ID], + is_archived=False, + is_leaf=True, + ).values_list("id", flat=True) + choices = [ + (choice, choice) + for choice in choices + ] + self.fields["biotope_type"].choices = choices def save(self, is_before_state: bool = False): state = self.instance.add_state(self, is_before_state) @@ -262,8 +272,9 @@ class EditCompensationStateModalForm(NewStateModalForm): self.state = kwargs.pop("state", None) super().__init__(*args, **kwargs) self.form_title = _("Edit state") + biotope_type_id = self.state.biotope_type.id if self.state.biotope_type else None form_data = { - "biotope_type": self.state.biotope_type.id, + "biotope_type": biotope_type_id, "biotope_extra": self.state.biotope_type_details.all(), "surface": self.state.surface, } @@ -271,7 +282,8 @@ class EditCompensationStateModalForm(NewStateModalForm): def save(self, is_before_state: bool = False): state = self.state - state.biotope_type = self.cleaned_data.get("biotope_type", None) + biotope_type_id = self.cleaned_data.get("biotope_type", None) + state.biotope_type = KonovaCode.objects.get(id=biotope_type_id) state.biotope_type_details.set(self.cleaned_data.get("biotope_extra", [])) state.surface = self.cleaned_data.get("surface", None) state.save() diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index 3deff50..3727e0c 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -8,6 +8,8 @@ Created on: 16.11.21 import shutil from django.contrib import messages + +from codelist.models import KonovaCode from user.models import User, Team from django.db import models, transaction from django.db.models import QuerySet, Sum @@ -142,8 +144,10 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin): """ form_data = form.cleaned_data with transaction.atomic(): + biotope_type_id = form_data["biotope_type"] + code = KonovaCode.objects.get(id=biotope_type_id) state = CompensationState.objects.create( - biotope_type=form_data["biotope_type"], + biotope_type=code, surface=form_data["surface"], ) state_additional_types = form_data["biotope_extra"] -- 2.38.5