Browse Source

Merge branch 'master' of github.com:syzoj/syzoj

pull/6/head
t123yh 7 years ago
parent
commit
4da76158f3
  1. 13
      models/article.js
  2. 5
      modules/admin.js
  3. 3
      views/admin_other.ejs
  4. 4
      views/discussion.ejs

13
models/article.js

@ -91,6 +91,19 @@ class Article extends Model {
return user && (this.allow_comment || user.is_admin || this.user_id === user.id);
}
async resetReplyCountAndTime() {
let ArticleComment = syzoj.model('article-comment');
await syzoj.utils.lock(['Article::resetReplyCountAndTime', this.id], async () => {
this.comments_num = await ArticleComment.count({ article_id: this.id });
if (this.comments_num === 0) {
this.sort_time = this.public_time;
} else {
this.sort_time = await ArticleComment.model.max('public_time', { where: { article_id: this.id } });
}
await this.save();
});
}
getModel() { return model; }
};

5
modules/admin.js

@ -320,6 +320,11 @@ app.post('/admin/other', async (req, res) => {
for (const p of problems) {
await p.resetSubmissionCount();
}
} else if (req.body.type === 'reset_discussion') {
const articles = await Article.query();
for (const a of articles) {
await a.resetReplyCountAndTime();
}
} else {
throw new ErrorMessage("操作类型不正确");
}

3
views/admin_other.ejs

@ -1,7 +1,8 @@
<% this.adminPage = 'other'; %>
<% include admin_header %>
<form method="post" class="ui form">
<button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button>
<p><button class="ui blue button" name="type" value="reset_count" type="submit">重新计算提交及 AC 数</button></p>
<p><button class="ui blue button" name="type" value="reset_discussion" type="submit">重新计算讨论版回复数和回复时间</button></p>
<!-- <button name="type" value="reset_size" type="submit">重新计算代码大小</button> -->
</form>
<% include admin_footer %>

4
views/discussion.ejs

@ -47,13 +47,13 @@
<table class="ui very basic center aligned table">
<thead>
<tr>
<th class="left aligned" style="width: 40%; ">标题</th>
<th class="left aligned" style="width: 45%; ">标题</th>
<% if (in_problems) { %>
<th style="width: 20%; ">所属题目</th>
<% } %>
<th style="width: 10%; ">作者</th>
<th style="width: 10%; ">回复数</th>
<th style="width: 20%; ">最新回复</th>
<th style="width: 15%; ">最新回复</th>
</tr>
</thead>
<tbody>

Loading…
Cancel
Save