Browse Source

Merge pull request #65 from syzoj/latest_update

Show latest updated problems in main page
pull/6/head
Menci 6 years ago committed by GitHub
parent
commit
84b9e2d7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      libs/timeago/index.js
  2. 53
      libs/timeago/long.json
  3. 53
      libs/timeago/narrow.json
  4. 53
      libs/timeago/short.json
  5. 7
      models/problem.js
  6. 17
      modules/index.js
  7. 3
      modules/problem.js
  8. 1
      package.json
  9. 21
      views/index.ejs

7
libs/timeago/index.js

@ -0,0 +1,7 @@
module.exports =
{
locale: 'zh',
long: require('./long.json'),
short: require('./short.json'),
narrow: require('./narrow.json')
}

53
libs/timeago/long.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒钟前",
"future": "{0} 秒钟后"
},
"now": "现在"
}

53
libs/timeago/narrow.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒前",
"future": "{0} 秒后"
},
"now": "现在"
}

53
libs/timeago/short.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒前",
"future": "{0} 秒后"
},
"now": "现在"
}

7
models/problem.js

@ -244,6 +244,8 @@ let model = db.define('problem', {
file_io_input_name: { type: Sequelize.TEXT },
file_io_output_name: { type: Sequelize.TEXT },
publicize_time: { type: Sequelize.DATE },
type: {
type: Sequelize.ENUM,
values: ['traditional', 'submit-answer', 'interaction']
@ -257,7 +259,10 @@ let model = db.define('problem', {
},
{
fields: ['user_id'],
}
},
{
fields: ['publicize_time'],
},
]
});

17
modules/index.js

@ -22,7 +22,12 @@
let User = syzoj.model('user');
let Article = syzoj.model('article');
let Contest = syzoj.model('contest');
let Problem = syzoj.model('problem');
let Divine = require('syzoj-divine');
let TimeAgo = require('javascript-time-ago');
let zh = require('../libs/timeago');
TimeAgo.locale(zh);
const timeAgo = new TimeAgo('zh-CN');
app.get('/', async (req, res) => {
try {
@ -40,16 +45,20 @@ app.get('/', async (req, res) => {
fortune = Divine(res.locals.user.username, res.locals.user.sex);
}
let where;
if (res.locals.user && await res.locals.user.is_admin) where = {}
else where = { is_public: true };
let contests = await Contest.query([1, 5], where, [['start_time', 'desc']]);
let contests = await Contest.query([1, 5], { is_public: true }, [['start_time', 'desc']]);
let problems = (await Problem.query([1, 5], { is_public: true }, [['publicize_time', 'desc']])).map(problem => ({
id: problem.id,
title: problem.title,
time: timeAgo.format(new Date(problem.publicize_time)),
}));
res.render('index', {
ranklist: ranklist,
notices: notices,
fortune: fortune,
contests: contests,
problems: problems,
links: syzoj.config.links
});
} catch (e) {

3
modules/problem.js

@ -35,7 +35,7 @@ app.get('/problems', async (req, res) => {
try {
const sort = req.query.sort || syzoj.config.sorting.problem.field;
const order = req.query.order || syzoj.config.sorting.problem.order;
if (!['id', 'title', 'rating', 'ac_num', 'submit_num', 'ac_rate'].includes(sort) || !['asc', 'desc'].includes(order)) {
if (!['id', 'title', 'rating', 'ac_num', 'submit_num', 'ac_rate', 'publicize_time'].includes(sort) || !['asc', 'desc'].includes(order)) {
throw new ErrorMessage('错误的排序参数。');
}
@ -581,6 +581,7 @@ async function setPublic(req, res, is_public) {
problem.is_public = is_public;
problem.publicizer_id = res.locals.user.id;
problem.publicize_time = new Date();
await problem.save();
JudgeState.model.update(

1
package.json

@ -38,6 +38,7 @@
"file-size": "^1.0.0",
"fs-extra": "^7.0.0",
"gravatar": "^1.5.2",
"javascript-time-ago": "^1.0.30",
"js-yaml": "^3.9.0",
"jsdom": "^13.0.0",
"jsondiffpatch": "0.3.11",

21
views/index.ejs

@ -92,6 +92,27 @@
<div style="font-size: 1em; line-height: 1.5em; display: none; " id="hitokoto-content"></div>
<div style="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; display: none; " id="hitokoto-from"></div>
</div>
<h4 class="ui top attached block header">最近更新</h4>
<div class="ui bottom attached segment">
<table class="ui very basic center aligned table">
<thead>
<tr>
<th>题目</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
<%
for (let problem of problems) {
%>
<tr>
<td><a href="<%= syzoj.utils.makeUrl(['problem', problem.id]) %>"><%= problem.title %></a></td>
<td><%= problem.time %></td>
</tr>
<% } %>
</tbody>
</table>
</div>
<%
if (fortune) {
let color;

Loading…
Cancel
Save