Skip to content

Commit

Permalink
[#1829] Make call-to-action url + text configurable per statustype
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Nov 14, 2023
1 parent 90870cf commit 49bb500
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ def get_context_data(self, **kwargs):
"status_indicator_text",
None,
),
"call_to_action_url": getattr(
statustype_config_mapping.get(end_statustype.url),
"call_to_action_url",
None,
),
"call_to_action_text": getattr(
statustype_config_mapping.get(end_statustype.url),
"call_to_action_text",
None,
),
}

context["case"] = {
Expand Down Expand Up @@ -203,6 +213,7 @@ def get_context_data(self, **kwargs):
)
else:
context["case"] = None

return context

def add_second_status_preview(self, statuses: list, statustypen: list) -> None:
Expand Down Expand Up @@ -295,21 +306,23 @@ def get_upload_info_context(self, case: Zaak):
),
}

def get_result_display(self, case: Zaak) -> str:
@staticmethod
def get_result_display(case: Zaak) -> str:
if case.resultaat:
result = fetch_single_result(case.resultaat)
if result:
return result.toelichting
return None

def get_initiator_display(self, case: Zaak) -> str:
@staticmethod
def get_initiator_display(case: Zaak) -> str:
roles = fetch_case_roles(case.url, RolOmschrijving.initiator)
if not roles:
return ""
return ", ".join([get_role_name_display(r) for r in roles])

@staticmethod
def get_statuses_data(
self,
statuses: List[Status],
lookup: TranslationLookup,
statustype_config_mapping: Optional[dict] = None,
Expand All @@ -330,11 +343,22 @@ def get_statuses_data(
"status_indicator_text",
None,
),
"call_to_action_url": getattr(
statustype_config_mapping.get(s.statustype.url),
"call_to_action_url",
None,
),
"call_to_action_text": getattr(
statustype_config_mapping.get(s.statustype.url),
"call_to_action_text",
None,
),
}
for s in statuses
]

def get_case_document_files(self, case: Zaak) -> List[SimpleFile]:
@staticmethod
def get_case_document_files(case: Zaak) -> List[SimpleFile]:
case_info_objects = fetch_case_information_objects(case.url)

# get the information objects for the case objects
Expand Down
3 changes: 3 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ class ZaakTypeStatusTypeConfigInline(admin.StackedInline):
"zaaktype_uuids",
"status_indicator",
"status_indicator_text",
"show_document_uploads",
"document_upload_description",
"description",
"call_to_action_url",
"call_to_action_text",
]
readonly_fields = [
"statustekst",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2.20 on 2023-10-31 11:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0027_zaaktype_resultaattype_config"),
]

operations = [
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="call_to_action_text",
field=models.CharField(
blank=True,
default="",
help_text="The text displayed on the call-to-action button",
max_length=48,
verbose_name="Call to action text",
),
),
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="call_to_action_url",
field=models.URLField(
blank=True,
default="",
help_text="The url the user will be sent to by clicking on the call-to-action button",
verbose_name="Call to action url",
),
),
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="show_document_uploads",
field=models.BooleanField(
default=True,
help_text="Wheter document uploads are to be shown",
verbose_name="Show document uploads",
),
),
]
13 changes: 13 additions & 0 deletions src/open_inwoner/openzaak/migrations/0029_merge_20231107_1355.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.20 on 2023-11-07 12:55

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0028_merge_20231101_1705"),
("openzaak", "0028_zaaktype_statustype_button"),
]

operations = []
13 changes: 13 additions & 0 deletions src/open_inwoner/openzaak/migrations/0031_merge_20231114_1400.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.20 on 2023-11-14 13:00

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0029_merge_20231107_1355"),
("openzaak", "0030_merge_20231113_1518"),
]

operations = []
20 changes: 20 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,26 @@ class ZaakTypeStatusTypeConfig(models.Model):
"Whether the user should be notfied if a case is set to this type of status"
),
)
show_document_uploads = models.BooleanField(
default=True,
verbose_name=_("Show document uploads"),
help_text=_("Wheter document uploads are to be shown"),
)
call_to_action_url = models.URLField(
blank=True,
default="",
verbose_name=_("Call to action url"),
help_text=_(
"The url the user will be sent to by clicking on the call-to-action button"
),
)
call_to_action_text = models.CharField(
max_length=48,
blank=True,
default="",
verbose_name=_("Call to action text"),
help_text=_("The text displayed on the call-to-action button"),
)

class Meta:
verbose_name = _("Zaaktype Statustype Configuration")
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ZaakTypeStatusTypeConfigFactory(factory.django.DjangoModelFactory):
zaaktype_config = factory.SubFactory(ZaakTypeConfigFactory)
statustype_url = factory.Faker("url")
omschrijving = factory.Faker("pystr", max_chars=80)
# call_to_action_url = statustype_url

class Meta:
model = ZaakTypeStatusTypeConfig
Expand Down
12 changes: 12 additions & 0 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
statustype_url=self.status_type_finish["url"],
status_indicator=StatusIndicators.success,
status_indicator_text="bar",
call_to_action_url="https://www.example.com",
call_to_action_text="Click me",
)

self._setUpMocks(m)
Expand Down Expand Up @@ -436,12 +438,16 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
"label": "Initial request",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
"call_to_action_text": "",
},
{
"date": datetime.datetime(2021, 3, 12),
"label": "Finish",
"status_indicator": "success",
"status_indicator_text": "bar",
"call_to_action_url": "https://www.example.com",
"call_to_action_text": "Click me",
},
],
# only one visible information object
Expand Down Expand Up @@ -475,6 +481,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
statustype_url=self.status_type_finish["url"],
status_indicator=StatusIndicators.success,
status_indicator_text="bar",
call_to_action_url="https://www.example.com",
call_to_action_text="Click me",
)

self._setUpMocks(m, use_eindstatus=False)
Expand All @@ -499,6 +507,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"label": "Finish",
"status_indicator": "success",
"status_indicator_text": "bar",
"call_to_action_url": "https://www.example.com",
"call_to_action_text": "Click me",
},
"description": "Coffee zaaktype",
"statuses": [
Expand All @@ -507,6 +517,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"label": "Initial request",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
"call_to_action_text": "",
},
# preview of second (upcoming) status
{
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openzaak/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def setUpTestData(cls):
status_indicator=StatusIndicators.warning,
status_indicator_text="U moet documenten toevoegen",
description="Lorem ipsum dolor sit amet",
call_to_action_url="https://example.com",
call_to_action_text="Click me",
)
# open
cls.zaak1 = generate_oas_component(
Expand Down
59 changes: 59 additions & 0 deletions src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,65 @@ <h1 class="h1" id="title">{{ case.description }}</h1>
<section id="statuses_component" class="statuses__section">
{% include 'pages/cases/statuses.html' %}
</section>
{% if case.statuses %}
<h2 class="h2" id="statuses">{% trans 'Status' %}</h2>

<aside class="status-list" aria-label="{% trans "Status lijst" %}">
<ul class="status-list__list">
{% for status in case.statuses %}

{% if forloop.last %}
{# Current active status, including final status #}
<li class="{% if case.end_statustype_data %}status--current{% endif %} status-list__list-item status-list__list-item--{{ status.status_indicator }} {% if not case.end_statustype_data %}item--completed status-list__list-item--info{% endif %}">
{% icon icon="circle" %}
<div class="status-list__notification status-list__notification--{{ status.status_indicator }}">
<h3 class="status-list__notification-h3"><a href="#" class="link link-toggle link--bold">{{ status.label }}</a>{% icon icon="expand_more" icon_position="after" outlined=True %}</h3>
<div class="status-list__notification-content">
<p class="p p-text p--compact">{{ status.status_indicator_text }}</p>
<p class="p p-date p--compact">{{ status.date|date }}</p>
<p>
{% if case.internal_upload_enabled or case.external_upload_enabled %}
{% button href="#form_upload" text=_("Scroll naar document uploaden") title=_("Ga direct naar document upload sectie.") primary=True icon="arrow_downward" icon_position="after" %}
{% endif %}
{# IF there is a CTA button in the final status, show this #}
{% with button_url=status.call_to_action_url %}
{% if button_url %}
{% translate status.call_to_action_text as button_text %}
{% button href=button_url text=button_text title=_("Open de bijlage") primary=True icon="arrow_forward" icon_position="after" %}
{% endif %}
{% endwith %}
</p>
</div>
</div>
</li>
{% else %}
{# Completed past statuses #}
<li class="status--completed status-list__list-item">
{% icon icon="task_alt" %}
<div class="status-list__notification">
<h3 class="status-list__notification-h3"><a href="#" class="link link-toggle link-success">{{ status.label }}</a>{% icon icon="expand_more" icon_position="after" outlined=True %}</h3>
<div class="status-list__notification-content">
<p class="p p-text p--compact">{{ status.status_indicator_text }}</p>
<p class="p p-date p--compact">{{ status.date|date }}</p>
</div>
</div>
</li>

{% endif %}
{% endfor %}
{% if case.end_statustype_data %}
{# Future end status #}
<li class="status--future status-list__list-item status-list__list-item--future">
{% icon icon="circle_outlined" outlined=True %}
<div class="status-list__notification status-list__notification--future">
<h3 class="status-list__notification-h3"><span class="link">{{ case.end_statustype_data.label }}</span></h3>
</div>
</li>

{% endif %}
</ul>
</aside>
{% endif %}

{# Documents. #}
{% if case.documents %}
Expand Down

0 comments on commit 49bb500

Please sign in to comment.