From 6b23b03a822c47e8424c076935e012bb6f944dd2 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Mon, 15 Apr 2024 13:44:14 +0200 Subject: [PATCH] History: edit (and fixes) --- issues/forms.py | 11 ++++++++ issues/templates/issues/history.html | 38 ++++++++++++++++++---------- issues/urls.py | 2 +- issues/views.py | 30 ++++++++++------------ static/js/issue_history.js | 7 +++++ theme/static/css/dist/styles.css | 25 ++++++++++++++++++ 6 files changed, 82 insertions(+), 31 deletions(-) create mode 100644 issues/forms.py create mode 100644 static/js/issue_history.js diff --git a/issues/forms.py b/issues/forms.py new file mode 100644 index 0000000..2eca153 --- /dev/null +++ b/issues/forms.py @@ -0,0 +1,11 @@ +from django.forms import ModelForm + +from .models import TurningPoint + + +class CommentForm(ModelForm): + # note that we use about 5% of ModelForm functionality here... but "if it ain't broke don't fix it" :-) + + class Meta: + model = TurningPoint + fields = ['comment'] diff --git a/issues/templates/issues/history.html b/issues/templates/issues/history.html index e5cf724..fb2e21e 100644 --- a/issues/templates/issues/history.html +++ b/issues/templates/issues/history.html @@ -28,14 +28,14 @@
{# 'body' part of the balloon (separated by a line) #} -
{% csrf_token %}
- -
+ + +
+
{# 'body' part of the balloon #} - @@ -52,7 +52,7 @@ -
+
{{ turningpoint.get_kind_display }} by @@ -61,7 +61,7 @@
{% if turningpoint.user == request.user %} -
+
@@ -74,17 +74,23 @@
- {% if turningpoint.comment or turningpoint.parsed_metadata or turningpoint.triggering_event %} + {% if turningpoint.parsed_metadata or turningpoint.triggering_event or turningpoint.comment or turningpoint.user == request.user %} {# the last clause means: editable, hence space must be reserved #}
{# 'body' part of the balloon (separated by a line) #} - {% if turningpoint.comment %}
- {{ turningpoint.comment|linebreaksbr }} - {% comment %} - - - {% endcomment %} +
+ {{ turningpoint.comment|linebreaksbr }} +
+ + {% if turningpoint.user == request.user %} + + {% endif %}
- {% endif %} {% if turningpoint.parsed_metadata %}
@@ -143,3 +149,7 @@ {% endblock %} + +{% block extra_js %} + +{% endblock %} diff --git a/issues/urls.py b/issues/urls.py index d3c25d3..8294f8d 100644 --- a/issues/urls.py +++ b/issues/urls.py @@ -28,5 +28,5 @@ urlpatterns = [ path('event//', event_by_internal_id, name="event_by_internal_id"), path('issue//history/comment/', history_comment_new, name="history_comment_new"), - path('event//history/comment//', history_comment_edit, name="history_comment_edit"), + path('issue//history/comment//', history_comment_edit, name="history_comment_edit"), ] diff --git a/issues/views.py b/issues/views.py index 5ff0cba..5195088 100644 --- a/issues/views.py +++ b/issues/views.py @@ -415,31 +415,29 @@ def issue_event_list(request, issue): @issue_membership_required def history_comment_new(request, issue): - # TODO something with auth if request.method == "POST": form = CommentForm(request.POST) - if form.is_valid(): - TurningPoint.objects.create( - issue=issue, kind=TurningPointKind.MANUAL_ANNOTATION, user=request.user, - comment=form.cleaned_data["comment"], - timestamp=timezone.now()) + assert form.is_valid() # we have only a textfield with no validation properties; also: no html-side handling + + TurningPoint.objects.create( + issue=issue, kind=TurningPointKind.MANUAL_ANNOTATION, user=request.user, + comment=form.cleaned_data["comment"], + timestamp=timezone.now()) + return redirect(issue_history, issue_pk=issue.pk) raise HttpResponseNotAllowed() -def history_comment_edit(request, issue_pk): - # TODO something with auth +@issue_membership_required +def history_comment_edit(request, issue, comment_pk): + comment = get_object_or_404(TurningPoint, pk=comment_pk, issue_id=issue.pk) - event = get_object_or_404(Event, id=event_pk) if request.method == "POST": - form = CommentForm(request.POST) - if form.is_valid(): - TurningPoint.objects.create( - issue=event.issue, kind=TurningPointKind.COMMENT, user=request.user, - comment=form.cleaned_data["comment"], - timestamp=timezone.now()) - return redirect(issue_event_stacktrace, issue_pk=event.issue.pk) + form = CommentForm(request.POST, instance=comment) + assert form.is_valid() + form.save() + return redirect(issue_history, issue_pk=issue.pk) raise HttpResponseNotAllowed() diff --git a/static/js/issue_history.js b/static/js/issue_history.js new file mode 100644 index 0000000..6a96b91 --- /dev/null +++ b/static/js/issue_history.js @@ -0,0 +1,7 @@ +"use strict"; + +function makeCommentEditable(element) { + const balloon = element.closest(".js-balloon"); + balloon.querySelector(".js-comment-editable").classList.remove("hidden"); + balloon.querySelector(".js-comment-plain").classList.add("hidden"); +} diff --git a/theme/static/css/dist/styles.css b/theme/static/css/dist/styles.css index 6d23f47..aced45e 100644 --- a/theme/static/css/dist/styles.css +++ b/theme/static/css/dist/styles.css @@ -938,6 +938,31 @@ select { height: 1rem; } +.h-16 { + height: 4rem; +} + +.h-24 { + height: 6rem; +} + +.h-fit { + height: -moz-fit-content; + height: fit-content; +} + +.h-32 { + height: 8rem; +} + +.h-64 { + height: 16rem; +} + +.h-48 { + height: 12rem; +} + .w-1\/4 { width: 25%; }