Skip to content

Commit

Permalink
[#1798] Updated document list element
Browse files Browse the repository at this point in the history
  - Added date
  - Added 'new' indicator to documents created no more than 24h in the
    past
  • Loading branch information
pi-sigma committed Nov 21, 2023
1 parent 5cb8198 commit b199501
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 55 deletions.
14 changes: 13 additions & 1 deletion src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import dataclasses
import datetime as dt
import logging
from collections import defaultdict
from datetime import datetime
from typing import List, Optional

from django.conf import settings
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.http import Http404, StreamingHttpResponse
Expand Down Expand Up @@ -50,6 +53,7 @@
ZaakTypeStatusTypeConfig,
)
from open_inwoner.openzaak.utils import get_role_name_display, is_info_object_visible
from open_inwoner.utils.time import has_new_elements
from open_inwoner.utils.translate import TranslationLookup
from open_inwoner.utils.views import CommonPageMixin, LogMixin

Expand All @@ -64,6 +68,7 @@ class SimpleFile:
name: str
size: int
url: str
created: Optional[datetime] = None


class OuterCaseDetailView(
Expand Down Expand Up @@ -201,6 +206,11 @@ def get_context_data(self, **kwargs):
"end_statustype_data": end_statustype_data,
"documents": documents,
"allowed_file_extensions": sorted(config.allowed_file_extensions),
"new_docs": has_new_elements(
documents,
"created",
dt.timedelta(days=settings.DOCUMENT_RECENT_DAYS),
),
}
context["case"].update(self.get_upload_info_context(self.case))
context["anchors"] = self.get_anchors(statuses, documents)
Expand Down Expand Up @@ -285,7 +295,7 @@ def get_upload_info_context(self, case: Zaak):
zt_statustype_config = ztc.zaaktypestatustypeconfig_set.get(
statustype_url=case.status.statustype.url
)
# case has no status, or status type not found
# case has no status, or statustype config not found
except (AttributeError, ObjectDoesNotExist):
pass
else:
Expand Down Expand Up @@ -395,8 +405,10 @@ def get_case_document_files(case: Zaak) -> List[SimpleFile]:
"info_id": info_obj.uuid,
},
),
created=case_info_obj.registratiedatum,
)
)

return documents

def get_form_kwargs(self):
Expand Down
93 changes: 51 additions & 42 deletions src/open_inwoner/components/templates/components/File/File.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
{% load i18n link_tags utils icon_tags form_tags dropdown_tags button_tags string_tags %}
{% load i18n l10n link_tags utils icon_tags form_tags dropdown_tags button_tags string_tags %}

<aside class="file" aria-label="{% trans "Bestand" %} {{ name }}">
<div class="file__file">
{% if is_image %}
{% icon icon="image" outlined=True %}
{% else %}
{% icon icon="description" outlined=True %}
{% endif %}
<p class="p">
{{ name }}
{% if extension and size %}
({{extension}}, {{size|readable_size}})
{% elif extension %}
({{extension}})
{% elif size %}
({{size|readable_size}})
{% endif %}
</p>
{% if allow_delete %}
{% dropdown icon="more_horiz" %}
<div class="dropdown__item">
{% url 'inbox:start' as inbox_url %}
{% with inbox_url|addstr:"?file="|addstr:uuid as share_url %}
{% button icon="send" text=_("Deel") href=share_url icon_outlined=True transparent=True %}
{% endwith %}
</div>
{% if show_download %}
<div class="dropdown__item">
{% button icon="file_download" text=_("Download") href=url icon_outlined=True transparent=True %}
</div>
<div class="file__container {% if recently_added %}file__container--recent{% endif %}">
<div class="file__file">
<p class="file__symbol">
{% if is_image %}
{% icon icon="image" outlined=True %}
{% else %}
{% icon icon="insert_drive_file" outlined=True %}
{% endif %}
</p>

<p class="p file__data">
{% if recently_added %}
<span class="file__file--recent">{% icon icon="fiber_manual_record" outlined=False extra_classes="file__file--recent" %}{% trans "Nieuw" %}</span>
{% endif %}
{{ name }}
{% if extension and size %}
({{extension}}, {{size|readable_size}})
{% elif extension %}
({{extension}})
{% elif size %}
({{size|readable_size}})
{% endif %}
<span class="file__date">{{ created|date:'d.m.Y' }}</span>
</p>
{% if allow_delete %}
{% dropdown icon="more_horiz" %}
<div class="dropdown__item">
{% url 'inbox:start' as inbox_url %}
{% with inbox_url|addstr:"?file="|addstr:uuid as share_url %}
{% button icon="send" text=_("Deel") href=share_url icon_outlined=True transparent=True %}
{% endwith %}
</div>
{% if show_download %}
<div class="dropdown__item">
{% button icon="file_download" text=_("Download") href=url icon_outlined=True transparent=True %}
</div>
{% endif %}
<div class="dropdown__item">
{% url 'profile:documents_delete' uuid=uuid as delete_url %}
{% render_form form=None form_action=delete_url method="POST" spaceless=True id="deactivate-form" extra_classes="confirm" data_confirm_title=_("Weet je het zeker dat je dit bestand wilt verwijderen?") data_confirm_cancel=_("Nee") data_confirm_default=_("Ja") %}
{% csrf_token %}
{% button icon="delete" text=_("Verwijderen") transparent=True %}
{% endrender_form %}
</div>
{% enddropdown %}
{% elif show_download %}
{% trans "Download" as download %}
{% link href=url text=download secondary=True download=True icon="file_download" icon_position="before" %}
{% endif %}
<div class="dropdown__item">
{% url 'profile:documents_delete' uuid=uuid as delete_url %}
{% render_form form=None form_action=delete_url method="POST" spaceless=True id="deactivate-form" extra_classes="confirm" data_confirm_title=_("Weet je het zeker dat je dit bestand wilt verwijderen?") data_confirm_cancel=_("Nee") data_confirm_default=_("Ja") %}
{% csrf_token %}
{% button icon="delete" text=_("Verwijderen") transparent=True %}
{% endrender_form %}
</div>
{% enddropdown %}
{% elif show_download %}
{% trans "Download" as download %}
{% link href=url text=download secondary=True download=True icon="file_download" icon_position="before" %}
{% endif %}
{% if description %}<p class="p p--small">{{ description }}</p>{% endif %}
</div>
</div>
{% if description %}<p class="p p--small">{{ description }}</p>{% endif %}
</aside>

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 class="h3" id="files">{{ title }}</h3>
{% for file in files %}
{% url download_view uuid=file.uuid as download_url %}
<li class="file-list__list-item">
{% file file=file.file name=file.name uuid=file.uuid allow_delete=allow_delete download_url=download_url show_download=show_download %}
{% file file=file.file created=created name=file.name uuid=file.uuid allow_delete=allow_delete download_url=download_url show_download=show_download %}
</li>
{% empty %}
<li><p class="p">{% trans "Er zijn nog geen bestanden geupload" %}</p></li>
Expand Down
13 changes: 11 additions & 2 deletions src/open_inwoner/components/templatetags/file_tags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import datetime
import pathlib

from django import template
from django.conf import settings

from filer.models.filemodels import File

from open_inwoner.openzaak.api_models import ZaakInformatieObject
from open_inwoner.cms.cases.views.status import SimpleFile
from open_inwoner.utils.time import is_new

register = template.Library()

Expand Down Expand Up @@ -46,7 +49,7 @@ def file_list(files, **kwargs):


@register.inclusion_tag("components/File/FileList.html")
def case_document_list(documents: list[ZaakInformatieObject], **kwargs) -> dict:
def case_document_list(documents: list[SimpleFile], **kwargs) -> dict:
"""
Shows multiple case documents in a file_list.
Expand Down Expand Up @@ -141,6 +144,12 @@ def file(file, **kwargs):
if kwargs.get("download_url"):
kwargs["url"] = kwargs["download_url"]

created = getattr(file, "created", None)
kwargs["created"] = created

if is_new(file, "created", datetime.timedelta(days=settings.DOCUMENT_RECENT_DAYS)):
kwargs["recently_added"] = True

if "show_download" not in kwargs:
kwargs["show_download"] = True

Expand Down
7 changes: 4 additions & 3 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,7 @@
#
LOG_OUTGOING_REQUESTS_DB_SAVE = config("LOG_OUTGOING_REQUESTS_DB_SAVE", default=True)
LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER = None # reset config after $ minutes
LOG_OUTGOING_REQUESTS_MAX_AGE = config(
"LOG_OUTGOING_REQUESTS_MAX_AGE", default=30
) # clean logs after 30 days


#
# AUTH settings - user accounts, passwords, backends...
Expand Down Expand Up @@ -806,6 +804,9 @@
"ZGW_LIMIT_NOTIFICATIONS_FREQUENCY", default=60 * 15
)

# recent documents: created/added no longer than n days in the past
DOCUMENT_RECENT_DAYS = config("DOCUMENT_RECENT_DAYS", default=1)

#
# Maykin fork of DJANGO-TWO-FACTOR-AUTH
#
Expand Down
13 changes: 12 additions & 1 deletion src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import requests_mock
from django_webtest import WebTest
from freezegun import freeze_time
from timeline_logger.models import TimelineLog
from webtest import Upload
from webtest.forms import Hidden
Expand Down Expand Up @@ -312,6 +313,7 @@ def setUpTestData(cls):
"info_id": cls.informatie_object["uuid"],
},
),
created=datetime.datetime(2021, 1, 12, 0, 0, 0),
)

def _setUpOASMocks(self, m):
Expand Down Expand Up @@ -384,7 +386,6 @@ def _setUpMocks(self, m, use_eindstatus=True):
f"{DOCUMENTEN_ROOT}enkelvoudiginformatieobjecten/014c38fe-b010-4412-881c-3000032fb812/download",
text="document content",
)
# TODO
m.get(
f"{CATALOGI_ROOT}statustypen?zaaktype={self.zaaktype['url']}",
json=paginated_response(
Expand Down Expand Up @@ -461,6 +462,7 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
"external_upload_url": "",
"allowed_file_extensions": sorted(self.config.allowed_file_extensions),
"contact_form_enabled": False,
"new_docs": False,
},
)

Expand Down Expand Up @@ -541,9 +543,18 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"external_upload_url": "",
"allowed_file_extensions": sorted(self.config.allowed_file_extensions),
"contact_form_enabled": False,
"new_docs": False,
},
)

@freeze_time("2021-01-12 17:00:00")
def test_new_docs(self, m):
self._setUpMocks(m)

response = self.app.get(self.case_detail_url, user=self.user)

self.assertEqual(response.context.get("case")["new_docs"], True)

def test_page_displays_expected_data(self, m):
self._setUpMocks(m)

Expand Down
39 changes: 35 additions & 4 deletions src/open_inwoner/scss/components/File/File.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.file {
&__container {
&--recent {
border-left: var(--border-width-thin) solid var(--color-red);
}
}

&__file {
align-items: center;
border: var(--border-width-thin) solid var(--color-gray);
Expand All @@ -7,11 +13,25 @@
display: flex;
}

&__file > *[class*='icon']:first-child,
&__file > *[class*='Icon']:first-child {
background-color: var(--color-gray-light);
padding: var(--spacing-large);
&__symbol {
display: flex;
align-items: center;
background-color: var(--color-gray-lightest);
padding: var(--spacing-large) 0;
margin: 0;
box-sizing: content-box;

align-self: stretch;

*[class*='icon'],
*[class*='Icon'] {
padding: var(--spacing-large);
}
}

&__data {
display: flex;
flex-direction: column;
}

&__file .link,
Expand All @@ -25,6 +45,7 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: var(--spacing-extra-large);
}

&__file .link__text {
Expand All @@ -46,4 +67,14 @@
&__file + .p {
margin-top: var(--spacing-small);
}

&__file--recent {
color: var(--color-red);
font-size: var(--font-size-body-extra-small);
vertical-align: middle;
}

&__date {
font-size: var(--font-size-body-extra-small);
}
}
3 changes: 3 additions & 0 deletions src/open_inwoner/scss/components/Status/_Status.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#documents {
justify-content: left;
}
1 change: 1 addition & 0 deletions src/open_inwoner/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
@import './Social/Social.scss';
@import './Spinner/Spinner.scss';
@import './Status/StatusList.scss';
@import './Status/Status.scss';
@import './Step/StepIndicator.scss';
@import './Sticky/Sticky.scss';
@import './Table/Table.scss';
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/scss/views/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
--font-size-body: 16px;
--font-line-height-body: 21px;

--font-size-body-extra-small: 12px;
--font-size-body-small: 14px;
--font-size-body-large: 20px;
--font-line-height-body-small: 20px;
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h3 class="status-list__notification-h3"><span class="link">{{ case.end_statusty

{# Documents. #}
{% if case.documents %}
<h2 class="h2" id="documents">{% trans 'Documenten' %}</h2>
<h2 class="h2" id="documents">{% trans 'Documenten' %}{% if case.new_docs %}{% icon icon="fiber_manual_record" outlined=False extra_classes="file__file--recent" %}{% endif %}</h2>
{% case_document_list case.documents %}
{% endif %}

Expand Down
Loading

0 comments on commit b199501

Please sign in to comment.