Skip to content

Commit

Permalink
Merge pull request #31 from Amsterdam/feature/131685-variables-in-bpm…
Browse files Browse the repository at this point in the history
…n-field

make it possible to add vars to questions in bpmn forms
  • Loading branch information
NvdLaan authored Dec 12, 2024
2 parents 068b702 + bd84606 commit 6535a85
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ Containers should be running to run tests via docker.
docker compose -f docker-compose.local.yml -f docker-compose.override.yml up -d
docker compose exec -T zwd-backend python manage.py test /app/apps
```

## Dynamic values in BPMN field labels
The embedded form in the camunda task does not support dynamic values by default.
In the workflow model is a "method _evaluate_form_field_label" that will parse a form label with the following structure {{workflow.prop}}
``
<camunda:formData>
<camunda:formField id="form_controle_bouwjaar" label="This is a sentence for case {{workflow.case.id}}" type="enum">
</camunda:formField>
``
The above label will be parsed to "This is a sentence for case 123"
Currently all properties and related objects of the workflow model are supported
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
<bpmn:userTask id="task_controle_bouwjaar" name="Controle bouwjaar">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="form_controle_bouwjaar" label="Het bouwjaar en het type advies voldoen niet aan de vereisten. Wil je doorgaan met de aanvraag?" type="enum">
<camunda:formField id="form_controle_bouwjaar" label="Het bouwjaar {{workflow.case.homeowner_association.build_year}} en de aanvraag voor een {{workflow.case.advice_type} voldoen niet aan de vereisten. Wil je doorgaan met de aanvraag?" type="enum">
<camunda:value id="yes" name="Ja" />
<camunda:value id="no" name="Nee" />
</camunda:formField>
Expand Down
43 changes: 41 additions & 2 deletions app/apps/workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
task_script_wait,
task_start_subworkflow,
)
from .utils import get_initial_data_from_config, parse_task_spec_form
from .utils import get_initial_data_from_config


class CaseWorkflow(models.Model):
Expand Down Expand Up @@ -161,7 +161,7 @@ def _create_user_tasks(self, wf):
task_name=task.task_spec.name,
name=task.task_spec.bpmn_name,
roles=[r.strip() for r in task.task_spec.lane.split(",")],
form=parse_task_spec_form(task.task_spec.form),
form=self._parse_task_spec_form(task.task_spec.form),
due_date=datetime.datetime.today(),
case=self.case,
workflow=self,
Expand All @@ -175,6 +175,45 @@ def _create_user_tasks(self, wf):
task_instances = CaseUserTask.objects.bulk_create(task_data)
return task_instances

def _evaluate_form_field_label(self, label):
expression = label.replace("{{", "{").replace("}}", "}")
return expression.format(workflow=self)

def _parse_task_spec_form(self, form):
trans_types = {
"enum": "select",
"boolean": "checkbox",
"string": "text",
"long": "number",
"expression": "expression",
}
fields = [
{
"label": self._evaluate_form_field_label(f.label),
"options": [
{
"value": o.id,
"label": o.name,
}
for o in f.__dict__.get("options", [])
],
"name": f.id,
"type": (
"multiselect"
if bool([v.name for v in f.validation if v.name == "multiple"])
else trans_types.get(f.type, "text")
),
"required": not bool(
[v.name for v in f.validation if v.name == "optional"]
),
"tooltip": next(
iter([v.value for v in f.properties if v.id == "tooltip"]), None
),
}
for f in form.fields
]
return fields

def _set_obsolete_tasks_to_completed(self, wf):
ready_tasks_ids = [t.id for t in wf.get_tasks(state=TaskState.READY)]
task_instances = self.tasks.all().exclude(
Expand Down
35 changes: 0 additions & 35 deletions app/apps/workflow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,41 +172,6 @@ def validate_workflow_spec(workflow_spec_config):
return serializer.data


def parse_task_spec_form(form):
trans_types = {
"enum": "select",
"boolean": "checkbox",
"string": "text",
"long": "number",
}
fields = [
{
"label": f.label,
"options": [
{
"value": o.id,
"label": o.name,
}
for o in f.__dict__.get("options", [])
],
"name": f.id,
"type": (
"multiselect"
if bool([v.name for v in f.validation if v.name == "multiple"])
else trans_types.get(f.type, "text")
),
"required": not bool(
[v.name for v in f.validation if v.name == "optional"]
),
"tooltip": next(
iter([v.value for v in f.properties if v.id == "tooltip"]), None
),
}
for f in form.fields
]
return fields


def get_latest_version_from_config(workflow_type):
validated_workflow_spec_config = validate_workflow_spec(
settings.WORKFLOW_SPEC_CONFIG
Expand Down
1 change: 0 additions & 1 deletion app/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
"https://login.microsoftonline.com/72fca1b1-2c2e-4376-a445-294d80196804/discovery/v2.0/keys",
)
OIDC_RP_CLIENT_SECRET = os.environ.get("OIDC_RP_CLIENT_SECRET", None)

ROOT_URLCONF = "config.urls"

TEMPLATES = [
Expand Down

0 comments on commit 6535a85

Please sign in to comment.