-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rich text handling to service notes & update timeline when servic…
…es added or edited This change includes a number of underlying changes, the most notable of which are updating all frontend javascript packages and added support for mantine web components. We use the mantine rich text editor for service notes. This required a few changes to our webpack configuration. Other changes are: - Changed the UI/UX for case closures so that users are notified immediately if there are unfinished ongoing services & prevents closing the case rather than as a validation error when they attempt to close the case. - Fixed some parameter name mismatch typing errors.
- Loading branch information
Showing
27 changed files
with
9,901 additions
and
3,000 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div> | ||
<span>{{ intro }}</span> | ||
<table class="ui definition table small very compact"> | ||
<tbody> | ||
<tr> | ||
<td class="three wide">Type</td> | ||
<td>{{ service.get_type_display }}</td> | ||
</tr> | ||
{% if service.category == categories.discrete %} | ||
<tr> | ||
<td class="three wide">Date</td> | ||
<td>{{ service.started_at|date:'d/m/Y' }}</td> | ||
</tr> | ||
{% if service.count %} | ||
<tr> | ||
<td class="three wide">Count</td> | ||
<td>{{ service.count }}</td> | ||
</tr> | ||
{% endif %} | ||
{% else %} | ||
<tr> | ||
<td class="three wide">Start date</td> | ||
<td>{{ service.started_at|date:'d/m/Y' }}</td> | ||
</tr> | ||
{% if service.finished_at %} | ||
<tr> | ||
<td class="three wide">Finish date</td> | ||
<td>{{ service.finished_at|date:'d/m/Y' }}</td> | ||
</tr> | ||
{% endif %} | ||
{% endif %} | ||
{% if service.notes %} | ||
<tr> | ||
<td class="three wide">Notes</td> | ||
<td>{{ service.notes|safe }}</td> | ||
</tr> | ||
{% endif %} | ||
</tbody> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from accounts.models import User | ||
from core.models import Service | ||
from core.models.service_event import ServiceEvent, EventType | ||
|
||
|
||
def on_service_create(service: Service, user: User): | ||
ServiceEvent.objects.create(event_type=EventType.CREATE, service=service, user=user) | ||
|
||
|
||
def on_service_update(service: Service, user: User): | ||
ServiceEvent.objects.create(event_type=EventType.UPDATE, service=service, user=user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from accounts.models import User | ||
from django.contrib.contenttypes.fields import GenericRelation | ||
from django.core.serializers.json import DjangoJSONEncoder | ||
from django.db import models | ||
from django.template.loader import render_to_string | ||
from rest_framework import serializers | ||
|
||
from .issue_note import IssueNote | ||
from .service import Service, ServiceCategory | ||
from .timestamped import TimestampedModel | ||
|
||
|
||
class _ServiceSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Service | ||
fields = "__all__" | ||
|
||
|
||
class EventType(models.TextChoices): | ||
CREATE = "CREATE", "Service created" | ||
UPDATE = "UPDATE", "Service updated" | ||
|
||
|
||
class ServiceEvent(TimestampedModel): | ||
""" | ||
An event that occurs on a service. | ||
""" | ||
|
||
event_type = models.CharField(max_length=32, choices=EventType) | ||
service = models.ForeignKey(Service, on_delete=models.CASCADE) | ||
user = models.ForeignKey(User, on_delete=models.PROTECT, related_name="+") | ||
issue_notes = GenericRelation(IssueNote) | ||
|
||
# We need to save the details of the service at the point in time the event | ||
# occurred so we use the appropriate values when we generate the text for | ||
# this event (see get_text method) | ||
service_at_event = models.JSONField(encoder=DjangoJSONEncoder) | ||
|
||
def save(self, *args, **kwargs): | ||
self.service_at_event = _ServiceSerializer(self.service).data | ||
return super().save(*args, **kwargs) | ||
|
||
def get_text(self) -> str: | ||
name = self.user.get_full_name() | ||
match self.event_type: | ||
case EventType.CREATE: | ||
verb = "added" | ||
case EventType.UPDATE: | ||
verb = "updated" | ||
case _: | ||
raise Exception(f"Unhandled event type: {self.event_type}") | ||
|
||
serializer = _ServiceSerializer(data=self.service_at_event) | ||
serializer.is_valid(raise_exception=True) | ||
service = Service(**serializer.validated_data) | ||
|
||
category_lower = service.category.lower() | ||
indefinite_article = ( | ||
"an" if category_lower[0] in ("a", "e", "i", "o", "u") else "a" | ||
) | ||
|
||
context = { | ||
"intro": f"{name} {verb} {indefinite_article} {category_lower} service:", | ||
"service": service, | ||
"categories": { | ||
"discrete": ServiceCategory.DISCRETE, | ||
"ongoing": ServiceCategory.ONGOING, | ||
}, | ||
} | ||
return render_to_string("case/service_event.html", context) |
Oops, something went wrong.