Browse Source

Add subtitle for contests

Database migration is needed.
master
Pisces000221 7 years ago
parent
commit
8dfe055fa5
  1. 2
      models/contest.js
  2. 4
      modules/contest.js
  3. 5
      views/contest.ejs
  4. 6
      views/contest_edit.ejs
  5. 2
      views/contests.ejs

2
models/contest.js

@ -30,6 +30,7 @@ let ContestPlayer = syzoj.model('contest_player');
let model = db.define('contest', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
title: { type: Sequelize.STRING(80) },
subtitle: { type: Sequelize.TEXT },
start_time: { type: Sequelize.INTEGER },
end_time: { type: Sequelize.INTEGER },
@ -71,6 +72,7 @@ class Contest extends Model {
static async create(val) {
return Contest.fromRecord(Contest.model.build(Object.assign({
title: '',
subtitle: '',
problems: '',
information: '',
type: 'noi',

4
modules/contest.js

@ -31,7 +31,7 @@ app.get('/contests', async (req, res) => {
let paginate = syzoj.utils.paginate(await Contest.count(), req.query.page, syzoj.config.page.contest);
let contests = await Contest.query(paginate, null, [['start_time', 'desc']]);
await contests.forEachAsync(async x => x.information = await syzoj.utils.markdown(x.information));
await contests.forEachAsync(async x => x.subtitle = await syzoj.utils.markdown(x.subtitle));
res.render('contests', {
contests: contests,
@ -89,6 +89,7 @@ app.post('/contest/:id/edit', async (req, res) => {
if (!req.body.title.trim()) throw new ErrorMessage('比赛名不能为空。');
contest.title = req.body.title;
contest.subtitle = req.body.subtitle;
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems];
contest.problems = req.body.problems.join('|');
if (!['noi', 'ioi', 'acm'].includes(req.body.type)) throw new ErrorMessage('无效的赛制。');
@ -117,6 +118,7 @@ app.get('/contest/:id', async (req, res) => {
contest.allowedEdit = await contest.isAllowedEditBy(res.locals.user);
contest.running = await contest.isRunning();
contest.subtitle = await syzoj.utils.markdown(contest.subtitle);
contest.information = await syzoj.utils.markdown(contest.information);
let problems_id = await contest.getProblems();

5
views/contest.ejs

@ -8,7 +8,8 @@
</style>
<% include header %>
<div class="padding">
<h1 style="margin-bottom: 30px; "><%= contest.title %></h1>
<h1><%= contest.title %></h1>
<div style="margin-bottom: 30px;"><%- contest.subtitle %></div>
<% let unveiled = (contest.allowedEdit || syzoj.utils.getCurrentDate() >= contest.start_time); %>
<% let start = syzoj.utils.formatDate(contest.start_time), end = syzoj.utils.formatDate(contest.end_time); %>
<% if (contest.running && start.split(' ')[0] === end.split(' ')[0]) {
@ -36,7 +37,7 @@
<% } %>
<div class="row">
<div class="column">
<h4 class="ui top attached block header">描述</h4>
<h4 class="ui top attached block header">信息与公告</h4>
<div class="ui bottom attached segment font-content">
<%- contest.information %>
</div>

6
views/contest_edit.ejs

@ -6,6 +6,10 @@
<label>比赛名称</label>
<input type="text" name="title" value="<%= contest.title %>">
</div>
<div class="field">
<label>比赛描述</label>
<input type="text" name="subtitle" value="<%= contest.subtitle %>">
</div>
<div class="field">
<label>试题列表</label>
<select class="ui fluid search dropdown" multiple="" id="search_problems" name="problems">
@ -36,7 +40,7 @@
</div>
</div>
<div class="field">
<label>比赛介绍</label>
<label>比赛公告</label>
<textarea class="" rows="5" id="doc-ta-1" name="information" class="font-content"><%= contest.information %></textarea>
</div>
<div class="field">

2
views/contests.ejs

@ -37,7 +37,7 @@
<td><a href="<%= syzoj.utils.makeUrl(['contest', contest.id]) %>"><%= contest.title %> <%- tag %></a></td>
<td><%= syzoj.utils.formatDate(contest.start_time) %></td>
<td><%= syzoj.utils.formatDate(contest.end_time) %></td>
<td class="font-content"><%- contest.information %></td>
<td class="font-content"><%- contest.subtitle %></td>
</tr>
<% } %>
</tbody>

Loading…
Cancel
Save