Fix some bugs for new comment

This commit is contained in:
cuom1999 2023-05-22 23:11:40 +07:00
parent b5816bbcd6
commit 57ded6ff5e
8 changed files with 267 additions and 403 deletions

View file

@ -28,6 +28,9 @@ from judge.widgets import HeavyPreviewPageDownWidget
from judge.jinja2.reference import get_user_from_text
DEFAULT_OFFSET = 10
def add_mention_notifications(comment):
user_referred = get_user_from_text(comment.body).exclude(id=comment.author.id)
for user in user_referred:
@ -152,44 +155,37 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
return self.render_to_response(context)
def get(self, request, *args, **kwargs):
pre_query = None
target_comment = None
if "comment-id" in request.GET:
comment_id = int(request.GET["comment-id"])
try:
comment_obj = Comment.objects.get(pk=comment_id)
comment_obj = Comment.objects.get(id=comment_id)
except Comment.DoesNotExist:
raise Http404
pre_query = comment_obj
while comment_obj is not None:
pre_query = comment_obj
comment_obj = comment_obj.parent
target_comment = comment_obj.get_root()
self.object = self.get_object()
return self.render_to_response(
self.get_context_data(
object=self.object,
pre_query=pre_query,
target_comment=target_comment,
comment_form=CommentForm(request, initial={"parent": None}),
)
)
def get_context_data(self, pre_query=None, **kwargs):
context = super(CommentedDetailView, self).get_context_data(**kwargs)
queryset = self.object.comments
queryset = queryset.filter(parent=None, hidden=False)
queryset_all = None
comment_count = len(queryset)
context["comment_remove"] = -1
if (pre_query != None):
comment_remove = pre_query.id
queryset_all = pre_query.get_descendants(include_self=True)
queryset_all = (
queryset_all.select_related("author__user")
def _get_queryset(self, target_comment):
if target_comment != None:
queryset = target_comment.get_descendants(include_self=True)
queryset = (
queryset.select_related("author__user")
.filter(hidden=False)
.defer("author__about")
.annotate(revisions=Count("versions", distinct=True))
.annotate(
revisions=Count("versions", distinct=True)
)
)
context["comment_remove"] = comment_remove
else:
queryset = self.object.comments
queryset = queryset.filter(parent=None, hidden=False)
queryset = (
queryset.select_related("author__user")
.defer("author__about")
@ -197,24 +193,28 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
.annotate(
count_replies=Count("replies", distinct=True),
revisions=Count("versions", distinct=True),
)[:10]
)[:DEFAULT_OFFSET]
)
if self.request.user.is_authenticated:
profile = self.request.profile
if (pre_query != None):
queryset_all = queryset_all.annotate(
my_vote=FilteredRelation(
"votes", condition=Q(votes__voter_id=profile.id)
),
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
else:
queryset = queryset.annotate(
my_vote=FilteredRelation(
"votes", condition=Q(votes__voter_id=profile.id)
),
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
return queryset
def get_context_data(self, target_comment=None, **kwargs):
context = super(CommentedDetailView, self).get_context_data(**kwargs)
queryset = self._get_queryset(target_comment)
comment_count = self.object.comments.filter(parent=None, hidden=False).count()
context["target_comment"] = -1
if (target_comment != None):
context["target_comment"] = target_comment.id
if self.request.user.is_authenticated:
context["is_new_user"] = (
not self.request.user.is_staff
and not profile.submission_set.filter(
@ -225,19 +225,20 @@ class CommentedDetailView(TemplateResponseMixin, SingleObjectMixin, View):
context["has_comments"] = queryset.exists()
context["comment_lock"] = self.is_comment_locked()
context["comment_list"] = queryset
context["comment_all_list"] = queryset_all
context["vote_hide_threshold"] = settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD
if queryset.exists():
context["comment_root_id"] = queryset[0].id
else:
context["comment_root_id"] = 0
context["comment_parrent_none"] = 1
if (pre_query != None):
context["offset"] = 1
context["comment_parent_none"] = 1
if target_comment != None:
context["offset"] = 0
context["comment_more"] = comment_count - 1
else:
context["offset"] = 10
context["offset"] = DEFAULT_OFFSET
context["comment_more"] = comment_count - DEFAULT_OFFSET
context["limit"] = 10
context["limit"] = DEFAULT_OFFSET
context["comment_count"] = comment_count
return context

View file

@ -110,35 +110,41 @@ def vote_comment(request, delta):
def upvote_comment(request):
return vote_comment(request, 1)
def downvote_comment(request):
return vote_comment(request, -1)
def get_comments(request, limit=10):
try:
comment_id = int(request.GET["id"])
parrent_none = int(request.GET["parrent_none"])
parent_none = int(request.GET["parent_none"])
except ValueError:
return HttpResponseBadRequest()
else:
if comment_id and not Comment.objects.filter(id=comment_id).exists():
raise Http404()
offset = 0
if "offset" in request.GET:
offset = int(request.GET["offset"])
comment_remove = -1
if "comment_remove" in request.GET:
comment_remove = int(request.GET["comment_remove"])
target_comment = -1
if "target_comment" in request.GET:
target_comment = int(request.GET["target_comment"])
comment_root_id = 0
if (comment_id):
if comment_id:
comment_obj = Comment.objects.get(pk=comment_id)
comment_root_id = comment_obj.id
else:
comment_obj = None
queryset = comment_obj.linked_object.comments
if parrent_none:
if parent_none:
queryset = queryset.filter(parent=None, hidden=False)
if (comment_remove != -1):
queryset.get(pk=comment_remove).delete()
queryset = queryset.exclude(pk=target_comment)
else:
queryset = queryset.filter(parent=comment_obj, hidden=False)
comment_count = len(queryset)
@ -158,6 +164,8 @@ def get_comments(request, limit=10):
),
).annotate(vote_score=Coalesce(F("my_vote__score"), Value(0)))
new_offset = offset + min(len(queryset), limit)
comment_html = loader.render_to_string(
"comments/content-list.html",
{
@ -166,22 +174,26 @@ def get_comments(request, limit=10):
"comment_list": queryset,
"vote_hide_threshold" : settings.DMOJ_COMMENT_VOTE_HIDE_THRESHOLD,
"perms": PermWrapper(request.user),
"offset": offset + min(len(queryset), limit),
"offset": new_offset,
"limit": limit,
"comment_count": comment_count,
"comment_parrent_none": parrent_none,
"comment_remove": comment_remove,
"comment_parent_none": parent_none,
"target_comment": target_comment,
"comment_more": comment_count - new_offset
}
)
return HttpResponse(comment_html)
def get_show_more(request):
return get_comments(request)
def get_replies(request):
return get_comments(request)
class CommentMixin(object):
model = Comment
pk_url_kwarg = "id"

View file

@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lqdoj2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-16 16:17+0700\n"
"POT-Creation-Date: 2023-05-22 23:06+0700\n"
"PO-Revision-Date: 2021-07-20 03:44\n"
"Last-Translator: Icyene\n"
"Language-Team: Vietnamese\n"
@ -41,19 +41,19 @@ msgstr "xem lần cuối"
msgid "LQDOJ Chat"
msgstr ""
#: dmoj/settings.py:365
#: dmoj/settings.py:363
msgid "Vietnamese"
msgstr "Tiếng Việt"
#: dmoj/settings.py:366
#: dmoj/settings.py:364
msgid "English"
msgstr ""
#: dmoj/urls.py:136
#: dmoj/urls.py:135
msgid "Login"
msgstr "Đăng nhập"
#: dmoj/urls.py:214 templates/base.html:209
#: dmoj/urls.py:212 templates/base.html:209
#: templates/organization/org-left-sidebar.html:2
msgid "Home"
msgstr "Trang chủ"
@ -426,20 +426,20 @@ msgstr "Dạng"
msgid "Online Judge"
msgstr ""
#: judge/comments.py:61
#: judge/comments.py:64
msgid "Comment body"
msgstr "Nội dung bình luận"
#: judge/comments.py:67 judge/views/ticket.py:78
#: judge/comments.py:70 judge/views/ticket.py:78
msgid "Your part is silent, little toad."
msgstr "Bạn không được phép bình luận."
#: judge/comments.py:76 templates/comments/list.html:17
#: judge/comments.py:79 templates/comments/list.html:17
msgid ""
"You need to have solved at least one problem before your voice can be heard."
msgstr "Bạn phải giải ít nhất một bài trước khi được phép bình luận."
#: judge/comments.py:125
#: judge/comments.py:128
msgid "Posted comment"
msgstr "Bình luận đã đăng"
@ -533,7 +533,7 @@ msgid "N j, Y, g:i a"
msgstr "g:i a j b, Y"
#: judge/jinja2/datetime.py:26 templates/chat/message.html:13
#: templates/comments/content-list.html:35 templates/comments/list.html:77
#: templates/comments/content-list.html:36
#, python-brace-format
msgid "{time}"
msgstr "{time}"
@ -2514,11 +2514,11 @@ msgstr "Tính lại điểm kỳ thi"
msgid "Running MOSS"
msgstr "Đang chạy MOSS"
#: judge/tasks/submission.py:47
#: judge/tasks/submission.py:49
msgid "Modifying submissions"
msgstr "Chỉnh sửa bài nộp"
#: judge/tasks/submission.py:67
#: judge/tasks/submission.py:69
msgid "Recalculating user points"
msgstr "Tính lại điểm người dùng"
@ -2658,12 +2658,12 @@ msgstr "Bạn phải giải ít nhất 1 bài trước khi được vote."
msgid "You already voted."
msgstr "Bạn đã vote."
#: judge/views/comment.py:243 judge/views/organization.py:817
#: judge/views/comment.py:255 judge/views/organization.py:817
#: judge/views/organization.py:963 judge/views/organization.py:1128
msgid "Edited from site"
msgstr "Chỉnh sửa từ web"
#: judge/views/comment.py:264
#: judge/views/comment.py:276
msgid "Editing comment"
msgstr "Chỉnh sửa bình luận"
@ -3288,8 +3288,8 @@ msgstr "Phải qua một kỳ thi"
#: judge/views/submission.py:903
#, python-brace-format
msgid ""
"<a href=\"{1}\">{0}</a>'s submissions for <a href=\"{3}\">{2}</a> in <a "
"href=\"{5}\">{4}</a>"
"<a href=\"{1}\">{0}</a>'s submissions for <a href=\"{3}\">{2}</a> in <a href="
"\"{5}\">{4}</a>"
msgstr ""
"Các bài nộp của <a href=\"{1}\">{0}</a> cho <a href=\"{3}\">{2}</a> trong <a "
"href=\"{5}\">{4}</a>"
@ -3502,7 +3502,7 @@ msgid "Profile"
msgstr "Trang cá nhân"
#: templates/base.html:276 templates/chat/chat.html:21
#: templates/comments/content-list.html:80 templates/comments/list.html:126
#: templates/comments/content-list.html:81
#: templates/contest/contest-list-tabs.html:4
#: templates/contest/ranking-table.html:47 templates/internal/problem.html:57
#: templates/organization/org-left-sidebar.html:12
@ -3559,12 +3559,12 @@ msgstr ""
msgid " posted on %(time)s"
msgstr "đã đăng vào %(time)s"
#: templates/blog/blog.html:31 templates/comments/content-list.html:61
#: templates/comments/content-list.html:75 templates/comments/list.html:105
#: templates/comments/list.html:120 templates/contest/contest-tabs.html:35
#: templates/contest/list.html:124 templates/contest/tag-title.html:9
#: templates/flatpages/admin_link.html:3 templates/license.html:10
#: templates/problem/editorial.html:15 templates/problem/feed/problems.html:50
#: templates/blog/blog.html:31 templates/comments/content-list.html:62
#: templates/comments/content-list.html:76
#: templates/contest/contest-tabs.html:35 templates/contest/list.html:124
#: templates/contest/tag-title.html:9 templates/flatpages/admin_link.html:3
#: templates/license.html:10 templates/problem/editorial.html:15
#: templates/problem/feed/problems.html:50
msgid "Edit"
msgstr "Chỉnh sửa"
@ -3699,66 +3699,54 @@ msgstr "Tắt thông báo"
msgid "users are online"
msgstr "người đang trực tuyến"
#: templates/comments/content-list.html:13
#: templates/comments/content-list.html:14
#: templates/comments/content-list.html:22
#: templates/comments/content-list.html:23 templates/comments/list.html:55
#: templates/comments/list.html:64
#: templates/comments/content-list.html:15
#: templates/comments/content-list.html:23
#: templates/comments/content-list.html:24
msgid "Please login to vote"
msgstr "Đăng nhập để vote"
#: templates/comments/content-list.html:43 templates/comments/list.html:86
#: templates/comments/content-list.html:44
#, python-format
msgid "edit %(edits)s"
msgstr "chỉnh sửa %(edits)s"
#: templates/comments/content-list.html:45 templates/comments/list.html:88
#: templates/comments/media-js.html:96
#: templates/comments/content-list.html:46 templates/comments/media-js.html:96
msgid "edited"
msgstr "đã chỉnh sửa"
#: templates/comments/content-list.html:54 templates/comments/list.html:97
#: templates/notification/list.html:14
#: templates/comments/content-list.html:55 templates/notification/list.html:14
msgid "Link"
msgstr "Link"
#: templates/comments/content-list.html:65
#: templates/comments/content-list.html:71 templates/comments/list.html:110
#: templates/comments/list.html:117
#: templates/comments/content-list.html:66
#: templates/comments/content-list.html:72
msgid "Reply"
msgstr "Phản hồi"
#: templates/comments/content-list.html:78 templates/comments/list.html:123
#: templates/comments/content-list.html:79
msgid "Hide"
msgstr "Ẩn"
#: templates/comments/content-list.html:92
#: templates/comments/content-list.html:94
#, fuzzy, python-format
#| msgid ""
#| "This comment is hidden due to too much negative feedback. Click <a "
#| "href=\"javascript:comment_show_content(%(id)s)\">here</a> to view it."
#| "This comment is hidden due to too much negative feedback. Click <a href="
#| "\"javascript:comment_show_content(%(id)s)\">here</a> to view it."
msgid ""
"This comment is hidden due to too much negative feedback. Click <a\n"
" href=\"javascript:"
"comment_show_content(%(id)s)\">here</a> to view it."
" href=\"javascript:comment_show_content(%(id)s)\">here</a> to "
"view it."
msgstr ""
"Bình luận bị ẩn vì nhiều phản hồi tiêu cực. Nhấp vào <a href=\"javascript:"
"comment_show_content(%(id)s)\">đây</a> để mở."
#: templates/comments/content-list.html:107
#: templates/comments/content-list.html:109
msgid "replies"
msgstr "phản hồi"
#: templates/comments/content-list.html:114
msgid "reply"
msgstr "phản hồi"
#: templates/comments/content-list.html:130 templates/comments/list.html:160
msgid "comment more"
msgstr "bình luận nữa"
#: templates/comments/content-list.html:137 templates/comments/list.html:168
msgid "comments more"
#: templates/comments/content-list.html:129
msgid "more comments"
msgstr "bình luận nữa"
#: templates/comments/list.html:6
@ -3777,20 +3765,11 @@ msgstr "Nội dung không hợp lệ."
msgid "Post!"
msgstr "Đăng!"
#: templates/comments/list.html:138
#, python-format
msgid ""
"This comment is hidden due to too much negative feedback. Click <a "
"href=\"javascript:comment_show_content(%(id)s)\">here</a> to view it."
msgstr ""
"Bình luận bị ẩn vì nhiều phản hồi tiêu cực. Nhấp vào <a href=\"javascript:"
"comment_show_content(%(id)s)\">đây</a> để mở."
#: templates/comments/list.html:177
#: templates/comments/list.html:44
msgid "There are no comments at the moment."
msgstr "Không có bình luận nào."
#: templates/comments/list.html:182
#: templates/comments/list.html:49
msgid "Comments are disabled on this page."
msgstr "Bình luận bị tắt trong trang này."
@ -3918,8 +3897,8 @@ msgstr "G:i T, j F, Y"
#: templates/contest/contest-datetime.html:39
#, python-format
msgid ""
"<b>%(time_limit)s</b> window between <b>%(start_time)s</b> and "
"<b>%(end_time)s</b>"
"<b>%(time_limit)s</b> window between <b>%(start_time)s</b> and <b>"
"%(end_time)s</b>"
msgstr ""
"Kéo dài <b>%(time_limit)s</b> từ <b>%(start_time)s</b> đến <b>%(end_time)s</"
"b>"
@ -5752,6 +5731,22 @@ msgstr "Thông tin"
msgid "Check all"
msgstr "Chọn tất cả"
#~ msgid "reply"
#~ msgstr "phản hồi"
#~ msgid "comment more"
#~ msgstr "bình luận nữa"
#~ msgid "comments more"
#~ msgstr "bình luận nữa"
#~ msgid ""
#~ "This comment is hidden due to too much negative feedback. Click <a href="
#~ "\"javascript:comment_show_content(%(id)s)\">here</a> to view it."
#~ msgstr ""
#~ "Bình luận bị ẩn vì nhiều phản hồi tiêu cực. Nhấp vào <a href=\"javascript:"
#~ "comment_show_content(%(id)s)\">đây</a> để mở."
#, fuzzy
#~| msgid "short name"
#~ msgid "first name"
@ -5804,7 +5799,6 @@ msgstr "Chọn tất cả"
#~ msgid "Django administration"
#~ msgstr "Quản trị viên Django"
#, python-format
#~ msgid ""
#~ "Please enter the correct %(username)s and password for an admin account. "
#~ "Note that both fields may be case-sensitive."
@ -5812,7 +5806,6 @@ msgstr "Chọn tất cả"
#~ "Hãy nhập %(username)s và mật khẩu hợp lệ cho tài khoản quản trị. Chú ý cả "
#~ "hai trường có phân biệt chữ Hoa-thường."
#, python-format
#~ msgid ""
#~ "Please enter the correct %(username)s and password for an user account. "
#~ "Note that both fields may be case-sensitive."

View file

@ -33,6 +33,9 @@ msgstr "Đề xuất bài tập"
msgid "TanKhoa"
msgstr "Tân Khoa"
msgid "Name"
msgstr "Đăng ký tên"
msgid "Report"
msgstr "Báo cáo"
@ -342,9 +345,6 @@ msgstr ""
msgid "ltt"
msgstr ""
msgid "Luyện tập"
msgstr ""
msgid "manacher"
msgstr ""
@ -593,6 +593,3 @@ msgstr ""
msgid "z-function"
msgstr ""
#~ msgid "Name"
#~ msgstr "Đăng ký tên"

View file

@ -306,6 +306,10 @@ a {
}
}
.show_more_comment {
margin-left: -20px;
}
@media (max-width: 799px) {
.hide_texts_on_mobile .actionbar-text {
display: none;

View file

@ -1,5 +1,6 @@
{% set logged_in = request.user.is_authenticated %}
{% set profile = request.profile if logged_in else None %}
{% for node in mptt_tree(comment_list) recursive %}
<li id="comment-{{ node.id }}" data-revision="{{ node.revisions - 1 }}" data-max-revision="{{ node.revisions - 1 }}"
data-revision-ajax="{{ url('comment_revision_ajax', node.id) }}" class="comment">
@ -51,7 +52,7 @@
{% else %}
<span class="comment-edits"></span>
{% endif %}
<a href="#comment-{{ node.id }}" title="{{ _('Link') }}" class="comment-link">
<a href="?comment-id={{node.id}}#comment-{{ node.id }}" title="{{ _('Link') }}" class="comment-link">
<i class="fa fa-link fa-fw"></i>
</a>
{% if logged_in and not comment_lock %}
@ -87,7 +88,8 @@
<div class="comment-body" {% if node.score <=vote_hide_threshold %} style="display:none" {% endif %}>
{{ node.body|markdown(lazy_load=True)|reference|str|safe }}
</div>
{% if node.score <= vote_hide_threshold %} <div class="comment-body bad-comment-body">
{% if node.score <= vote_hide_threshold %}
<div class="comment-body bad-comment-body">
<p>
{% trans id=node.id %}This comment is hidden due to too much negative feedback. Click <a
href="javascript:comment_show_content({{ id }})">here</a> to view it.{% endtrans %}
@ -98,42 +100,32 @@
</div>
</div>
{% if node.count_replies > 1 %}
{% if node.count_replies %}
<a href="javascript:comment_get_replies({{ node.id }}, 0)" class="show_more_reply">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrow-forward" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M15 11l4 4l-4 4m4 -4h-11a4 4 0 0 1 0 -8h1"></path>
</svg>
{{ node.count_replies }} {{ _('replies') }} </a>
{% elif node.count_replies %}
<a href="javascript:comment_get_replies({{ node.id }}, 0)" class="show_more_reply">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrow-forward" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M15 11l4 4l-4 4m4 -4h-11a4 4 0 0 1 0 -8h1"></path>
</svg>
{{ node.count_replies }} {{ _('reply') }} </a>
{{ node.count_replies }} {{ _('replies') if node.count_replies > 1 else _('reply') }}
</a>
{% endif %}
</li>
<ul id="comment-{{ node.id }}-reply" class="reply-comment" hidden></ul>
<ul id="comment-{{ node.id }}-children" class="comments"> </ul>
{% with children=node.get_children() %}
{% if children %}
<ul id="comment-{{ node.id }}-children" class="comments">{{ loop(children) }}</ul>
{% else %}
<ul id="comment-{{ node.id }}-children" class="comments"></ul>
{% endif %}
{% endwith %}
{% endfor %}
{% set comment_more = comment_count - offset %}
{% if comment_more == 1 %}
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ comment_parrent_none }}, {{ offset }}, {{ comment_remove }})" class="show_more_comment">
{% if comment_more > 0 %}
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ comment_parent_none }}, {{ offset }}, {{ target_comment }})" class="show_more_comment">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 9l6 6l6 -6"></path>
</svg>
{{ comment_count - offset }} {{ _('comment more') }}</a>
{% elif comment_more > 1 %}
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ comment_parrent_none }}, {{ offset }}, {{ comment_remove }})" class="show_more_comment">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 9l6 6l6 -6"></path>
</svg>
{{ comment_count - offset }} {{ _('comments more') }}</a>
{{ comment_more }} {{ _('more comments') if comment_more > 1 else _('more comment') }}
</a>
{% endif %}

View file

@ -36,142 +36,9 @@
{% endif %}
</div>
{% endif %}
{% if has_comments or comment_all_list %}
{% if has_comments %}
<ul class="comments top-level-comments new-comments" id="comment-0">
{% set logged_in = request.user.is_authenticated %}
{% set profile = request.profile if logged_in else None %}
{% if comment_all_list %}
{% for node in mptt_tree(comment_all_list) recursive %}
<li id="comment-{{ node.id }}" data-revision="{{ node.revisions - 1 }}"
data-max-revision="{{ node.revisions - 1 }}"
data-revision-ajax="{{ url('comment_revision_ajax', node.id) }}" class="comment">
<div class="comment-display{% if node.score <= vote_hide_threshold %} bad-comment{% endif %}">
<div class="info">
<div class="vote">
{% if logged_in %}
<a href="javascript:comment_upvote({{ node.id }})"
class="upvote-link fa fa-chevron-up fa-fw{% if node.vote_score == 1 %} voted{% endif %}"></a>
{% else %}
<a href="javascript:alert('{{ _('Please login to vote')|escapejs }}')" title="{{ _('Please login to vote') }}"
class="upvote-link fa fa-chevron-up fa-fw"></a>
{% endif %}
<br>
<div class="comment-score">{{ node.score }}</div>
{% if logged_in %}
<a href="javascript:comment_downvote({{ node.id }})"
class="downvote-link fa fa-chevron-down fa-fw{% if node.vote_score == -1 %} voted{% endif %}"></a>
{% else %}
<a href="javascript:alert('{{ _('Please login to vote')|escapejs }}')" title="{{ _('Please login to vote') }}"
class="downvote-link fa fa-chevron-down fa-fw"></a>
{% endif %}
</div>
</div>
<div class="detail">
<div class="header">
{% with author=node.author, user=node.author.user %}
<a href="{{ url('user_page', user.username) }}" class="user comment-img">
<img src="{{ gravatar(author, 135) }}" class="gravatar">
</a>
{% endwith %}
{{ link_user(node.author) }},&nbsp;
{{ relative_time(node.time, abs=_('{time}'), rel=_('{time}')) }}
<span class="comment-spacer"></span>
<span class="comment-operation">
{% if node.revisions > 1 %}
<span class="comment-edits">
<a href="javascript:show_revision({{ node.id }}, -1)"
class="previous-revision">&larr;</a>
<span class="comment-edit-text">
{% if node.revisions > 2 %}
{% trans edits=node.revisions - 1 %}edit {{ edits }}{% endtrans %}
{% else %}
{{ _('edited') }}
{% endif %}
</span>
<a href="javascript:show_revision({{ node.id }}, 1)" style="visibility: hidden"
class="next-revision">&rarr;</a>
</span>
{% else %}
<span class="comment-edits"></span>
{% endif %}
<a href="#comment-{{ node.id }}" title="{{ _('Link') }}" class="comment-link">
<i class="fa fa-link fa-fw"></i>
</a>
{% if logged_in and not comment_lock %}
{% set can_edit = node.author.id == profile.id and not profile.mute %}
{% if can_edit %}
<a data-featherlight="{{ url('comment_edit_ajax', node.id) }}"
href="{{ url('comment_edit', node.id) }}"
title="{{ _('Edit') }}" class="edit-link">
<i class="fa fa-pencil fa-fw"></i>
</a>
{% else %}
<a href="javascript:reply_comment({{ node.id }})"
title="{{ _('Reply') }}">
<i class="fa fa-reply fa-fw"></i>
</a>
{% endif %}
{% if perms.judge.change_comment %}
{% if can_edit %}
<a href="javascript:reply_comment({{ node.id }})"
title="{{ _('Reply') }}"><i class="fa fa-reply fa-fw"></i></a>
{% else %}
<a data-featherlight="{{ url('comment_edit_ajax', node.id) }}"
href="{{ url('comment_edit', node.id) }}" title="{{ _('Edit') }}"
class="edit-link"><i class="fa fa-pencil fa-fw"></i></a>
{% endif %}
<a href="javascript:" title="{{ _('Hide') }}" data-id="{{ node.id }}"
class="hide-comment"><i class="fa fa-trash fa-fw"></i></a>
<a href="{{ url('admin:judge_comment_change', node.id) }}"
title="{{ _('Admin') }}"><i class="fa fa-cog fa-fw"></i></a>
{% endif %}
{% endif %}
</span>
</div>
<div class="content content-description">
<div class="comment-body"{% if node.score <= vote_hide_threshold %} style="display:none"{% endif %}>
{{ node.body|markdown(lazy_load=True)|reference|str|safe }}
</div>
{% if node.score <= vote_hide_threshold %}
<div class="comment-body bad-comment-body">
<p>
{% trans id=node.id %}This comment is hidden due to too much negative feedback. Click <a href="javascript:comment_show_content({{ id }})">here</a> to view it.{% endtrans %}
</p>
</div>
{% endif %}
</div>
</div>
</div>
</li>
<ul id="comment-{{ node.id }}-reply" class="reply-comment" hidden></ul>
{% with children=node.get_children() %}
{% if children %}
<ul id="comment-{{ node.id }}-children" class="comments">{{ loop(children) }}</ul>
{% endif %}
{% endwith %}
{% endfor %}
{% set comment_more = comment_count - offset %}
{% if comment_more == 1 %}
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ comment_parrent_none }}, {{ offset }}, {{ comment_remove }})" class="show_more_comment">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 9l6 6l6 -6"></path>
</svg>
{{ comment_count - offset }} {{ _('comment more') }}
</a>
{% elif comment_more > 1 %}
<a href="javascript:comment_show_more({{ comment_root_id }}, {{ comment_parrent_none }}, {{ offset }}, {{ comment_remove }})" class="show_more_comment">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-down" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M6 9l6 6l6 -6"></path>
</svg>
{{ comment_count - offset }} {{ _('comments more') }}
</a>
{% endif %}
{% else %}
{% include "comments/content-list.html" %}
{% endif %}
</ul>
{% elif not comment_lock %}
<p class="no-comments-message">{{ _('There are no comments at the moment.') }}</p>

View file

@ -121,24 +121,23 @@
}
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const comment_remove = urlParams.get('comment-id');
console.log(comment_remove);
const target_comment = urlParams.get('comment-id');
window.comment_get_replies = function (id, parrent_none) {
window.comment_get_replies = function (id, parent_none) {
var $comment_show_btn = $("#comment-" + id + " .show_more_reply");
$comment_show_btn.hide();
var $comment = $("#comment-" + id + "-children");
$comment.append("<p class='loading'> Loading... </p>");
ajax_get_reply('{{ url('comment_get_replies') }}', id, parrent_none);
ajax_get_reply('{{ url('comment_get_replies') }}', id, parent_none);
}
function ajax_get_reply(url, id, parrent_none) {
function ajax_get_reply(url, id, parent_none) {
return $.ajax({
url: url,
type: 'GET',
data: {
id: id,
parrent_none: parrent_none,
parent_none: parent_none,
},
success: function(data) {
var $comment_loading = $("#comment-" + id + "-children .loading");
@ -149,9 +148,8 @@
})
}
window.comment_show_more = function (id, parrent_none, offset, comment_remove) {
console.log(parrent_none)
if (parrent_none == 1) {
window.comment_show_more = function (id, parent_none, offset, target_comment) {
if (parent_none == 1) {
var $comment_show_btn = $("#comment-0" + " .show_more_comment");
$comment_show_btn.hide();
var $comment = $("#comment-0");
@ -162,21 +160,21 @@
var $comment = $("#comment-" + id + "-children");
$comment.append("<p class='loading'> Loading... </p>");
}
ajax_comment_show_more('{{ url('comment_show_more') }}', id, parrent_none, offset, comment_remove);
ajax_comment_show_more('{{ url('comment_show_more') }}', id, parent_none, offset, target_comment);
}
function ajax_comment_show_more(url, id, parrent_none, offset, comment_remove) {
function ajax_comment_show_more(url, id, parent_none, offset, target_comment) {
return $.ajax({
url: url,
type: 'GET',
data: {
id: id,
parrent_none: parrent_none,
parent_none: parent_none,
offset: offset,
comment_remove: comment_remove,
target_comment: target_comment,
},
success: function(data) {
if (parrent_none == 1) {
if (parent_none == 1) {
var $comment_loading = $("#comment-0" + " .loading");
$comment_loading.hide();
var $comment = $("#comment-0");