add: group by thread

This commit is contained in:
Benoît Latinier 2016-07-16 00:53:52 +02:00
parent 1516f56cbd
commit 0b6a0e4d5f
4 changed files with 27 additions and 4 deletions

View File

@ -116,3 +116,10 @@ a {
.isso-comment-footer a { .isso-comment-footer a {
cursor: pointer; cursor: pointer;
} }
.thread-title {
margin-left: 3em;
}
.group {
float: left;
margin-left: 2em;
}

View File

@ -137,10 +137,10 @@ class Comments:
sql_args.append(parent) sql_args.append(parent)
# custom sanitization # custom sanitization
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes']: if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'tid']:
order_by = 'id' order_by = 'id'
sql.append('ORDER BY ') sql.append('ORDER BY ')
sql.append('comments.' + order_by) sql.append('comments.' + order_by + ", comments.created")
sql.append(' DESC') sql.append(' DESC')
if limit: if limit:

View File

@ -77,6 +77,9 @@ function delete_com(com_id, hash) {
</span> </span>
</a> </a>
</div> </div>
<div class="group">
Group by thread: <input type="checkbox" {% if order_by == "tid" %}checked{% endif %} onClick="javascript:window.location='?mode={{mode}}&page={{page}}&order_by={% if order_by == "tid" %}id{% else %}tid{% endif %}';" />
</div>
<div class="pagination"> <div class="pagination">
Pages: Pages:
{% if page > 0 %} {% if page > 0 %}
@ -94,7 +97,14 @@ function delete_com(com_id, hash) {
</div> </div>
</div> </div>
<main> <main>
{% set thread_id = "no_id" %}
{% for comment in comments %} {% for comment in comments %}
{% if order_by == "tid" %}
{% if thread_id != comment.tid %}
{% set thread_id = comment.tid %}
<h2 class="thread-title">{{comment.title}}</h2>
{% endif %}
{% endif %}
<div class='isso-comment' id='isso-{{comment.id}}'> <div class='isso-comment' id='isso-{{comment.id}}'>
{% if conf.avatar %} {% if conf.avatar %}
<div class='avatar'> <div class='avatar'>
@ -103,6 +113,9 @@ function delete_com(com_id, hash) {
{% endif %} {% endif %}
<div class='text-wrapper'> <div class='text-wrapper'>
<div class='isso-comment-header' role='meta'> <div class='isso-comment-header' role='meta'>
{% if order_by != "tid" %}
Thread: {{comment.title}}<br />
{% endif %}
{% if comment.author %} {% if comment.author %}
<span class='author'>{{comment.author}}</span> <span class='author'>{{comment.author}}</span>
{% else %} {% else %}

View File

@ -520,9 +520,11 @@ class API(object):
return render_template('login.html') return render_template('login.html')
page_size = 100 page_size = 100
page = req.args.get('page', 0) page = req.args.get('page', 0)
order_by = req.args.get('order_by', "id")
mode = req.args.get('mode', 2) mode = req.args.get('mode', 2)
comments = self.comments.fetchall(mode=mode, page=page, comments = self.comments.fetchall(mode=mode, page=page,
limit=page_size) limit=page_size,
order_by=order_by)
comments_enriched = [] comments_enriched = []
for comment in list(comments): for comment in list(comments):
comment['hash'] = self.isso.sign(comment['id']) comment['hash'] = self.isso.sign(comment['id'])
@ -532,4 +534,5 @@ class API(object):
return render_template('admin.html', comments=comments_enriched, return render_template('admin.html', comments=comments_enriched,
page=int(page), mode=int(mode), page=int(page), mode=int(mode),
conf=self.conf, max_page=max_page, conf=self.conf, max_page=max_page,
counts=comment_mode_count) counts=comment_mode_count,
order_by=order_by)