diff --git a/models/article.js b/models/article.js index 0e2017b..41153d7 100644 --- a/models/article.js +++ b/models/article.js @@ -23,6 +23,7 @@ let Sequelize = require('sequelize'); let db = syzoj.db; let User = syzoj.model('user'); +const Problem = syzoj.model('problem'); let model = db.define('article', { id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, diff --git a/modules/discussion.js b/modules/discussion.js index b61f430..9ec6014 100644 --- a/modules/discussion.js +++ b/modules/discussion.js @@ -24,18 +24,34 @@ let Article = syzoj.model('article'); let ArticleComment = syzoj.model('article-comment'); let User = syzoj.model('user'); -app.get('/discussion', async (req, res) => { +app.get('/discussion/:type?', async (req, res) => { try { - let where = { problem_id: null }; + if (!['global', 'problems'].includes(req.params.type)) { + res.redirect(syzoj.utils.makeUrl(['discussion', 'global'])); + } + const in_problems = req.params.type === 'problems'; + + let where; + if (in_problems) { + where = { problem_id: { $not: null } }; + } else { + where = { problem_id: { $eq: null } }; + } 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']]); - for (let article of articles) await article.loadRelationships(); + for (let article of articles) { + await article.loadRelationships(); + if (in_problems) { + article.problem = await Problem.fromID(article.problem_id); + } + } res.render('discussion', { articles: articles, paginate: paginate, - problem: null + problem: null, + in_problems: in_problems }); } catch (e) { syzoj.log(e); @@ -45,7 +61,7 @@ app.get('/discussion', async (req, res) => { } }); -app.get('/problem/:pid/discussion', async (req, res) => { +app.get('/discussion/problem/:pid', async (req, res) => { try { let pid = parseInt(req.params.pid); let problem = await Problem.fromID(pid); @@ -63,7 +79,8 @@ app.get('/problem/:pid/discussion', async (req, res) => { res.render('discussion', { articles: articles, paginate: paginate, - problem: problem + problem: problem, + in_problems: false }); } catch (e) { syzoj.log(e); @@ -201,7 +218,7 @@ app.post('/article/:id/delete', async (req, res) => { await article.destroy(); - res.redirect(syzoj.utils.makeUrl(['discussion'])); + res.redirect(syzoj.utils.makeUrl(['discussion', 'global'])); } catch (e) { syzoj.log(e); res.render('error', { diff --git a/views/article.ejs b/views/article.ejs index 1d7a2ee..b40b6f4 100644 --- a/views/article.ejs +++ b/views/article.ejs @@ -10,11 +10,11 @@
讨论
<% if (problem) { %> -
题目
+
题目
- <%= problem.title %> + <%= problem.title %> <% } else { %> - 全局板块 + 全局板块 <% } %>

<%= article.title %>

diff --git a/views/discussion.ejs b/views/discussion.ejs index 52d4527..b31037f 100644 --- a/views/discussion.ejs +++ b/views/discussion.ejs @@ -8,33 +8,50 @@
讨论
<% if (problem) { %> -
题目
+
题目
<%= problem.title %>
+ <% } else if (in_problems) { %> +
题目
<% } else { %>
全局板块
<% } %>
- <% if (problem) { %> - - - 返回题目 + <% if(in_problems) { %> + + + 全局板块 + + <% } else { %> + <% if (problem) { %> + + + 返回题目 + + <% } else { %> + + + 题目板块 + + <% } %> + + + 发帖 <% } %> - - - 发帖 -
- - + + <% if (in_problems) { %> + + <% } %> + @@ -42,6 +59,9 @@ <% for (let article of articles) { %> + <% if (in_problems) { %> + + <% } %> diff --git a/views/header.ejs b/views/header.ejs index c3210be..b0d1a87 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -22,7 +22,7 @@ 比赛 评测 排名 - 讨论 + 讨论 帮助 <% if (typeof contest !== 'undefined' && contest && contest.id) { %> 返回比赛 diff --git a/views/problem.ejs b/views/problem.ejs index 4153a0e..00770e9 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -96,7 +96,7 @@ div[class*=ace_br] { <% } %> 提交记录统计 - + 讨论 <% if (discussionCount) { %>
<%= discussionCount %>
标题作者标题所属题目作者 发表时间
<%= article.title %><%= article.problem.title %><%= article.user.username %><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %> <%= syzoj.utils.formatDate(article.public_time) %>