Implement preview for comments

Adds a "Preview" button alongside "Comment". Clicking this button
renders the comment text without actually creating the comment.

https://todo.sr.ht/~sircmpwn/todo.sr.ht/195
This commit is contained in:
Ivan Habunek 2020-01-04 11:36:31 +01:00 committed by Drew DeVault
parent d894df9467
commit 45fb4cf3e4
3 changed files with 40 additions and 4 deletions

View File

@ -213,9 +213,19 @@ select.form-control {
top: -0.1rem;
}
.event > blockquote {
margin-top: 0.5rem;
border: none;
.event {
> blockquote {
margin-top: 0.5rem;
border: none;
}
&.preview {
border: 1px dashed black;
.preview-tag {
float: right;
font-size: 0.8rem;
font-style: italic;
}
}
}
}

View File

@ -6,7 +6,7 @@ from srht.database import db
from srht.oauth import current_user, loginrequired
from srht.validation import Validation
from todosrht.access import get_tracker, get_ticket
from todosrht.filters import invalidate_markup_cache
from todosrht.filters import invalidate_markup_cache, render_markup
from todosrht.search import find_usernames
from todosrht.tickets import add_comment, mark_seen, assign, unassign
from todosrht.tickets import get_participant_for_user
@ -138,6 +138,7 @@ def ticket_comment_POST(owner, name, ticket_id):
resolve = valid.optional("resolve")
resolution = valid.optional("resolution")
reopen = valid.optional("reopen")
preview = valid.optional("preview")
valid.expect(not text or 3 <= len(text) <= 16384,
"Comment must be between 3 and 16384 characters.", field="comment")
@ -159,6 +160,14 @@ def ticket_comment_POST(owner, name, ticket_id):
ctx = get_ticket_context(ticket, tracker, access)
return render_template("ticket.html", **ctx, **valid.kwargs)
if preview == "true":
ctx = get_ticket_context(ticket, tracker, access)
ctx.update({
"comment": text,
"rendered_preview": render_markup(tracker, text),
})
return render_template("ticket.html", **ctx)
participant = get_participant_for_user(current_user)
event = add_comment(participant, ticket,
text=text, resolve=resolve, resolution=resolution, reopen=reopen)

View File

@ -321,6 +321,17 @@
</div>
{% endif %}
{% endfor %}
{% if rendered_preview %}
<div class="event preview">
<span class="preview-tag">Comment preview</span>
<a href="{{ current_user|user_url }}">{{ current_user }}</a>
<blockquote>
{{ rendered_preview }}
</blockquote>
</div>
{% endif %}
{% if TicketAccess.comment in access %}
{% if current_user %}
<form
@ -370,6 +381,12 @@
{% endif %}
{% endfor %}
</select>
<button
type="submit"
name="preview"
value="true"
class="btn btn-default pull-right"
>Preview {{icon("caret-right")}}</button>
{% else %}
<button
type="submit"