Browse Source

Sort articles by last active time

pull/6/head
Pisces000221 7 years ago
parent
commit
19e7f09341
  1. 13
      modules/discussion.js
  2. 8
      views/discussion.ejs

13
modules/discussion.js

@ -38,7 +38,7 @@ app.get('/discussion/:type?', async (req, res) => {
where = { problem_id: { $eq: null } }; where = { problem_id: { $eq: null } };
} }
let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion); let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion);
let articles = await Article.query(paginate, where, [['public_time', 'desc']]); let articles = await Article.query(paginate, where, [['sort_time', 'desc']]);
for (let article of articles) { for (let article of articles) {
await article.loadRelationships(); await article.loadRelationships();
@ -72,7 +72,7 @@ app.get('/discussion/problem/:pid', async (req, res) => {
let where = { problem_id: pid }; let where = { problem_id: pid };
let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion); let paginate = syzoj.utils.paginate(await Article.count(where), req.query.page, syzoj.config.page.discussion);
let articles = await Article.query(paginate, where, [['public_time', 'desc']]); let articles = await Article.query(paginate, where, [['sort_time', 'desc']]);
for (let article of articles) await article.loadRelationships(); for (let article of articles) await article.loadRelationships();
@ -249,6 +249,10 @@ app.post('/article/:id/comment', async (req, res) => {
await comment.save(); await comment.save();
article.sort_time = syzoj.utils.getCurrentDate();
article.comments_num += 1;
await article.save();
res.redirect(syzoj.utils.makeUrl(['article', article.id])); res.redirect(syzoj.utils.makeUrl(['article', article.id]));
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);
@ -273,6 +277,11 @@ app.post('/article/:article_id/comment/:id/delete', async (req, res) => {
await comment.destroy(); await comment.destroy();
let article = comment.article;
article.comments_num -= 1;
await article.save();
res.redirect(syzoj.utils.makeUrl(['article', comment.article_id])); res.redirect(syzoj.utils.makeUrl(['article', comment.article_id]));
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);

8
views/discussion.ejs

@ -47,12 +47,13 @@
<table class="ui very basic center aligned table"> <table class="ui very basic center aligned table">
<thead> <thead>
<tr> <tr>
<th class="left aligned" style="width: 50%; ">标题</th> <th class="left aligned" style="width: 40%; ">标题</th>
<% if (in_problems) { %> <% if (in_problems) { %>
<th style="width: 20%; ">所属题目</th> <th style="width: 20%; ">所属题目</th>
<% } %> <% } %>
<th style="width: 10%; ">作者</th> <th style="width: 10%; ">作者</th>
<th style="width: 20%; ">发表时间</th> <th style="width: 10%; ">回复数</th>
<th style="width: 20%; ">最新回复</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -63,7 +64,8 @@
<td><a href="<%= syzoj.utils.makeUrl(['discussion', 'problem', article.problem_id]) %>"><%= article.problem.title %></a></td> <td><a href="<%= syzoj.utils.makeUrl(['discussion', 'problem', article.problem_id]) %>"><%= article.problem.title %></a></td>
<% } %> <% } %>
<td><a href="<%= syzoj.utils.makeUrl(['user', article.user_id]) %>"><%= article.user.username %></a><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %></td> <td><a href="<%= syzoj.utils.makeUrl(['user', article.user_id]) %>"><%= article.user.username %></a><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %></td>
<td><%= syzoj.utils.formatDate(article.public_time) %></td> <td><%= article.comments_num %></td>
<td><%= syzoj.utils.formatDate(article.sort_time) %></td>
</tr> </tr>
<% } %> <% } %>
</tbody> </tbody>

Loading…
Cancel
Save