mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(fastapi): add comment actions to /account/{username}/comments
With this change, we've decoupled some partials shared between `/pkgbase/{name}` and `/account/{username}/comments`. The comment actions template now resolves its package base via the `comment` instance instead of requiring `pkgbase`. We've also modified the existing package comment routes to support execution from any location using the `next` parameter. This allows us to reuse code from package comments for account comments actions. Moved the majority of comment editing javascript to its own .js file. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
adb6252f85
commit
691b7b9091
12 changed files with 276 additions and 182 deletions
100
templates/partials/comment_actions.html
Normal file
100
templates/partials/comment_actions.html
Normal file
|
@ -0,0 +1,100 @@
|
|||
{% set pkgbasename = comment.PackageBase.Name %}
|
||||
|
||||
{% if not comment.Deleter %}
|
||||
{% if request.user.has_credential('CRED_COMMENT_DELETE', approved=[comment.User]) %}
|
||||
<form class="delete-comment-form"
|
||||
method="post"
|
||||
action="/pkgbase/{{ pkgbasename }}/comments/{{ comment.ID }}/delete"
|
||||
>
|
||||
<fieldset style="display:inline;">
|
||||
<input type="hidden"
|
||||
name="next"
|
||||
value="{{ request.url.path }}" />
|
||||
<input type="image"
|
||||
class="delete-comment"
|
||||
src="/images/x.min.svg"
|
||||
width="11"
|
||||
height="11"
|
||||
alt="{{ 'Delete comment' | tr }}"
|
||||
title="{{ 'Delete comment' | tr }}"
|
||||
name="submit" value="1" />
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if request.user.has_credential('CRED_COMMENT_EDIT', approved=[comment.User]) %}
|
||||
<a id="comment-edit-link-{{ comment.ID }}"
|
||||
{# /pkgbase/{name}/comments/{id}/edit #}
|
||||
href="/pkgbase/{{ pkgbasename }}/comments/{{ comment.ID }}/edit?{{ {'next': request.url.path} | urlencode }}"
|
||||
class="edit-comment"
|
||||
title="{{ 'Edit comment' | tr }}"
|
||||
>
|
||||
<img src="/images/pencil.min.svg" alt="{{ 'Edit comment' | tr }}"
|
||||
width="11" height="11">
|
||||
</a>
|
||||
|
||||
{# Set the edit event listener for this link. We must do this here
|
||||
so that we can utilize Jinja2's values. #}
|
||||
<script type="text/javascript" nonce="{{ request.user.nonce }}">
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
let link = document.getElementById("comment-edit-link-{{ comment.ID }}");
|
||||
let fn = function(event) {
|
||||
return handleEditCommentClick(event, "{{ comment.PackageBase.Name }}");
|
||||
};
|
||||
link.addEventListener("click", fn);
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if request.user.has_credential("CRED_COMMENT_PIN", approved=[comment.PackageBase.Maintainer]) %}
|
||||
{% if comment.PinnedTS %}
|
||||
<form class="pin-comment-form"
|
||||
method="post"
|
||||
action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/unpin"
|
||||
>
|
||||
<fieldset style="display:inline;">
|
||||
<input type="hidden" name="next" value="{{ request.url.path }}" />
|
||||
<input type="image"
|
||||
class="pin-comment"
|
||||
src="/images/unpin.min.svg"
|
||||
alt="{{ 'Unpin comment' | tr }}"
|
||||
title="{{ 'Unpin comment' | tr }}"
|
||||
name="submit"
|
||||
value="1" width="11" height="11" />
|
||||
</fieldset>
|
||||
</form>
|
||||
{% else %}
|
||||
<form class="pin-comment-form"
|
||||
method="post"
|
||||
action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/pin"
|
||||
>
|
||||
<fieldset style="display:inline;">
|
||||
<input type="hidden" name="next" value="{{ request.url.path }}" />
|
||||
<input type="image"
|
||||
class="pin-comment"
|
||||
src="/images/pin.min.svg"
|
||||
alt="{{ 'Pin comment' | tr }}"
|
||||
title="{{ 'Pin comment' | tr }}"
|
||||
name="submit"
|
||||
value="1" width="11" height="11" />
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% elif request.user.has_credential("CRED_COMMENT_UNDELETE", approved=[comment.User]) %}
|
||||
<form class="undelete-comment-form"
|
||||
method="post"
|
||||
action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}/undelete"
|
||||
>
|
||||
<fieldset style="display:inline;">
|
||||
<input type="hidden" name="next" value="{{ request.url.path }}" />
|
||||
<input type="image"
|
||||
class="undelete-comment"
|
||||
src="/images/action-undo.min.svg"
|
||||
alt="{{ 'Undelete comment' | tr }}"
|
||||
title="{{ 'Undelete comment' | tr }}"
|
||||
name="submit" value="1" width="11" height="11" />
|
||||
</fieldset>
|
||||
</form>
|
||||
{% endif %}
|
Loading…
Add table
Add a link
Reference in a new issue