Menci
8 years ago
27 changed files with 1032 additions and 97 deletions
@ -0,0 +1,140 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Sequelize = require('sequelize'); |
||||
let db = syzoj.db; |
||||
|
||||
let User = syzoj.model('user'); |
||||
let Problem = syzoj.model('problem'); |
||||
let ContestRanklist = syzoj.model('contest_ranklist'); |
||||
let ContestPlayer = syzoj.model('contest_player'); |
||||
|
||||
let model = db.define('contest', { |
||||
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, |
||||
title: { type: Sequelize.STRING(80) }, |
||||
start_time: { type: Sequelize.INTEGER }, |
||||
end_time: { type: Sequelize.INTEGER }, |
||||
|
||||
holder_id: { |
||||
type: Sequelize.INTEGER, |
||||
references: { |
||||
model: 'user', |
||||
key: 'id' |
||||
} |
||||
}, |
||||
|
||||
information: { type: Sequelize.TEXT }, |
||||
problems: { type: Sequelize.TEXT }, |
||||
|
||||
ranklist_id: { |
||||
type: Sequelize.INTEGER, |
||||
references: { |
||||
model: 'contest_ranklist', |
||||
key: 'id' |
||||
} |
||||
} |
||||
}, { |
||||
timestamps: false, |
||||
tableName: 'contest', |
||||
indexes: [ |
||||
{ |
||||
fields: ['holder_id'], |
||||
}, |
||||
{ |
||||
fields: ['ranklist_id'], |
||||
} |
||||
] |
||||
}); |
||||
|
||||
let Model = require('./common'); |
||||
class Contest extends Model { |
||||
static async create(val) { |
||||
return Contest.fromRecord(Contest.model.build(Object.assign({ |
||||
title: '', |
||||
start_time: 0, |
||||
end_time: 0, |
||||
holder: 0, |
||||
ranklist_id: 0 |
||||
}, val))); |
||||
} |
||||
|
||||
async loadRelationships() { |
||||
this.holder = await User.fromID(this.holder_id); |
||||
this.ranklist = await ContestRanklist.fromID(this.ranklist_id); |
||||
} |
||||
|
||||
async isAllowedEditBy(user) { |
||||
return user && (user.is_admin || this.holder_id === user.id); |
||||
} |
||||
|
||||
async isAllowedSeeResultBy(user) { |
||||
return (user && (user.is_admin || this.holder_id === user.id)) || !(await this.isRunning()); |
||||
} |
||||
|
||||
async getProblems() { |
||||
return this.problems.split('|').map(x => parseInt(x)); |
||||
} |
||||
|
||||
async setProblems(s) { |
||||
let a = []; |
||||
await s.split('|').forEachAsync(async x => { |
||||
let problem = await Problem.fromID(x); |
||||
if (!problem) return; |
||||
a.push(x); |
||||
}); |
||||
this.problems = a.join('|'); |
||||
} |
||||
|
||||
async newSubmission(judge_state) { |
||||
let problems = await this.getProblems(); |
||||
if (!problems.includes(judge_state.problem_id)) throw 'No such problem in contest.'; |
||||
|
||||
let player = await ContestPlayer.findInContest({ |
||||
contest_id: this.id, |
||||
user_id: judge_state.user_id |
||||
}); |
||||
|
||||
if (!player) { |
||||
player = await ContestPlayer.create({ |
||||
contest_id: this.id, |
||||
user_id: judge_state.user_id |
||||
}); |
||||
} |
||||
|
||||
await player.updateScore(judge_state); |
||||
await player.save(); |
||||
|
||||
await this.loadRelationships(); |
||||
await this.ranklist.updatePlayer(player); |
||||
await this.ranklist.save(); |
||||
} |
||||
|
||||
async isRunning(now) { |
||||
if (!now) now = syzoj.utils.getCurrentTime(); |
||||
return now >= this.start_time && now < this.end_time; |
||||
} |
||||
|
||||
getModel() { return model; } |
||||
} |
||||
|
||||
Contest.model = model; |
||||
|
||||
module.exports = Contest; |
@ -0,0 +1,99 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Sequelize = require('sequelize'); |
||||
let db = syzoj.db; |
||||
|
||||
let User = syzoj.model('user'); |
||||
let Problem = syzoj.model('problem'); |
||||
let Contest = syzoj.model('contest'); |
||||
|
||||
let model = db.define('contest_player', { |
||||
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, |
||||
contest_id: { |
||||
type: Sequelize.INTEGER, |
||||
references: { |
||||
model: 'contest', |
||||
key: 'id' |
||||
} |
||||
}, |
||||
user_id: { |
||||
type: Sequelize.INTEGER, |
||||
references: { |
||||
model: 'user', |
||||
key: 'id' |
||||
} |
||||
}, |
||||
|
||||
score: { type: Sequelize.INTEGER }, |
||||
score_details: { type: Sequelize.TEXT, json: true }, |
||||
time_spent: { type: Sequelize.INTEGER } |
||||
}, { |
||||
timestamps: false, |
||||
tableName: 'contest_player', |
||||
indexes: [ |
||||
{ |
||||
fields: ['contest_id'], |
||||
}, |
||||
{ |
||||
fields: ['user_id'], |
||||
} |
||||
] |
||||
}); |
||||
|
||||
let Model = require('./common'); |
||||
class ContestPlayer extends Model { |
||||
static async create(val) { |
||||
return ContestPlayer.fromRecord(ContestPlayer.model.build(Object.assign({ |
||||
contest_id: 0, |
||||
user_id: 0, |
||||
score: 0, |
||||
score_details: '{}', |
||||
time_spent: 0 |
||||
}, val))); |
||||
} |
||||
|
||||
static async findInContest(where) { |
||||
return ContestPlayer.findOne({ where: where }); |
||||
} |
||||
|
||||
async loadRelationships() { |
||||
this.user = await User.fromID(this.user_id); |
||||
this.contest = await Contest.fromID(this.contest_id); |
||||
} |
||||
|
||||
async updateScore(judge_state) { |
||||
this.score_details[judge_state.problem_id] = { |
||||
score: judge_state.score, |
||||
judge_id: judge_state.id |
||||
}; |
||||
this.score = 0; |
||||
for (let x in this.score_details) { |
||||
this.score += this.score_details[x].score; |
||||
} |
||||
} |
||||
|
||||
getModel() { return model; } |
||||
} |
||||
|
||||
ContestPlayer.model = model; |
||||
|
||||
module.exports = ContestPlayer; |
@ -0,0 +1,77 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Sequelize = require('sequelize'); |
||||
let db = syzoj.db; |
||||
|
||||
let User = syzoj.model('user'); |
||||
let Problem = syzoj.model('problem'); |
||||
let ContestPlayer = syzoj.model('contest_player'); |
||||
|
||||
let model = db.define('contest_ranklist', { |
||||
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, |
||||
ranklist: { type: Sequelize.TEXT, json: true } |
||||
}, { |
||||
timestamps: false, |
||||
tableName: 'contest_ranklist' |
||||
}); |
||||
|
||||
let Model = require('./common'); |
||||
class ContestRanklist extends Model { |
||||
static async create(val) { |
||||
return ContestRanklist.fromRecord(ContestRanklist.model.build(Object.assign({ |
||||
ranklist: '{}' |
||||
}, val))); |
||||
} |
||||
|
||||
async getPlayers() { |
||||
let a = []; |
||||
for (let i = 1; i <= this.ranklist.player_num; i++) { |
||||
a.push(await ContestPlayer.fromID(this.ranklist[i])); |
||||
} |
||||
return a; |
||||
} |
||||
|
||||
async updatePlayer(player) { |
||||
let players = await this.getPlayers(), newPlayer = true; |
||||
for (let x of players) { |
||||
if (x.user_id === player.user_id) { |
||||
newPlayer = false; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (newPlayer) { |
||||
players.push(player); |
||||
} |
||||
|
||||
players.sort((a, b) => b.score - a.score); |
||||
|
||||
this.ranklist = { player_num: players.length }; |
||||
for (let i = 0; i < players.length; i++) this.ranklist[i + 1] = players[i].id; |
||||
} |
||||
|
||||
getModel() { return model; } |
||||
} |
||||
|
||||
ContestRanklist.model = model; |
||||
|
||||
module.exports = ContestRanklist; |
@ -0,0 +1,52 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Problem = syzoj.model('problem'); |
||||
|
||||
app.get('/api/v2/search/problem/:keyword*?', async (req, res) => { |
||||
try { |
||||
let keyword = req.params.keyword || ''; |
||||
let problems = await Problem.query(null, { |
||||
title: { like: `%${req.params.keyword}%` } |
||||
}, [['id', 'asc']]); |
||||
|
||||
let result = []; |
||||
|
||||
let id = parseInt(keyword); |
||||
if (id) { |
||||
let problemById = await Problem.fromID(parseInt(keyword)); |
||||
if (problemById && await problemById.isAllowedUseBy(res.locals.user)) { |
||||
result.push(problemById); |
||||
} |
||||
} |
||||
await problems.forEachAsync(async problem => { |
||||
if (await problem.isAllowedUseBy(res.locals.user) && result.length < syzoj.config.page.edit_contest_problem_list && problem.id !== id) { |
||||
result.push(problem); |
||||
} |
||||
}); |
||||
|
||||
result = result.map(x => ({ name: `#${x.id}. ${x.title}`, value: x.id })); |
||||
res.send({ success: true, results: result }); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.send({ success: false }); |
||||
} |
||||
}); |
@ -0,0 +1,226 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Contest = syzoj.model('contest'); |
||||
let ContestRanklist = syzoj.model('contest_ranklist'); |
||||
let ContestPlayer = syzoj.model('contest_player'); |
||||
let Problem = syzoj.model('problem'); |
||||
let JudgeState = syzoj.model('judge_state'); |
||||
let User = syzoj.model('user'); |
||||
|
||||
app.get('/contest', async (req, res) => { |
||||
try { |
||||
let paginate = syzoj.utils.paginate(Contest.count(), req.query.page, syzoj.config.page.contest); |
||||
let contests = await Contest.query(paginate); |
||||
|
||||
await contests.forEachAsync(async x => x.information = await syzoj.utils.markdown(x.information)); |
||||
|
||||
res.render('contest_list', { |
||||
contests: contests, |
||||
paginate: paginate |
||||
}) |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
app.get('/contest/:id/edit', async (req, res) => { |
||||
try { |
||||
if (!res.locals.user || !res.locals.user.is_admin) throw 'Permission denied.'; |
||||
|
||||
let contest_id = parseInt(req.params.id); |
||||
let contest = await Contest.fromID(contest_id); |
||||
if (!contest) { |
||||
contest = await Contest.create(); |
||||
} |
||||
|
||||
let problems = await contest.problems.split('|').mapAsync(async id => await Problem.fromID(id)); |
||||
|
||||
res.render('edit_contest', { |
||||
contest: contest, |
||||
problems: problems |
||||
}); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
app.post('/contest/:id/edit', async (req, res) => { |
||||
try { |
||||
if (!res.locals.user || !res.locals.user.is_admin) throw 'Permission denied.'; |
||||
|
||||
let contest_id = parseInt(req.params.id); |
||||
let contest = await Contest.fromID(contest_id); |
||||
if (!contest) { |
||||
contest = await Contest.create(); |
||||
|
||||
contest.holder_id = res.locals.user.id; |
||||
|
||||
let ranklist = await ContestRanklist.create(); |
||||
await ranklist.save(); |
||||
contest.ranklist_id = ranklist.id; |
||||
} |
||||
|
||||
contest.title = req.body.title; |
||||
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems]; |
||||
contest.problems = req.body.problems.join('|'); |
||||
contest.information = req.body.information; |
||||
contest.start_time = syzoj.utils.parseTime(req.body.start_time); |
||||
contest.end_time = syzoj.utils.parseTime(req.body.end_time); |
||||
|
||||
await contest.save(); |
||||
|
||||
res.redirect(syzoj.utils.makeUrl(['contest', contest.id])); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
app.get('/contest/:id', async (req, res) => { |
||||
try { |
||||
let contest_id = parseInt(req.params.id); |
||||
|
||||
let contest = await Contest.fromID(contest_id); |
||||
if (!contest) throw 'No such contest.'; |
||||
|
||||
contest.allowedEdit = await contest.isAllowedEditBy(res.locals.user); |
||||
contest.running = await contest.isRunning(); |
||||
contest.information = await syzoj.utils.markdown(contest.information); |
||||
|
||||
let problems_id = await contest.getProblems(); |
||||
let problems = await problems_id.mapAsync(async id => await Problem.fromID(id)); |
||||
|
||||
let player = null; |
||||
|
||||
if (res.locals.user) { |
||||
player = await ContestPlayer.findInContest({ |
||||
contest_id: contest.id, |
||||
user_id: res.locals.user.id |
||||
}); |
||||
} |
||||
|
||||
problems = problems.map(x => ({ problem: x, status: null, judge_id: null })); |
||||
if (player) { |
||||
for (let problem of problems) { |
||||
if (player.score_details[problem.problem.id]) { |
||||
if (await contest.isRunning()) { |
||||
problem.status = true; |
||||
} else { |
||||
let judge_state = await JudgeState.fromID(player.score_details[problem.problem.id].judge_id); |
||||
problem.status = judge_state.status; |
||||
} |
||||
problem.judge_id = player.score_details[problem.problem.id].judge_id; |
||||
} else { |
||||
if (contest.isRunning()) { |
||||
problem.status = false; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
res.render('contest', { |
||||
contest: contest, |
||||
problems: problems |
||||
}); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
app.get('/contest/:id/ranklist', async (req, res) => { |
||||
try { |
||||
let contest_id = parseInt(req.params.id); |
||||
let contest = await Contest.fromID(contest_id); |
||||
if (!contest) throw 'No such contest.'; |
||||
|
||||
if (!await contest.isAllowedSeeResultBy(res.locals.user)) throw 'Permission denied'; |
||||
|
||||
await contest.loadRelationships(); |
||||
|
||||
let players_id = []; |
||||
for (let i = 1; i <= contest.ranklist.ranklist.player_num; i++) players_id.push(contest.ranklist.ranklist[i]); |
||||
|
||||
let ranklist = await players_id.mapAsync(async player_id => { |
||||
let player = await ContestPlayer.fromID(player_id); |
||||
|
||||
let user = await User.fromID(player.user_id); |
||||
|
||||
return { |
||||
user: user, |
||||
player: player |
||||
}; |
||||
}); |
||||
|
||||
let problems_id = await contest.getProblems(); |
||||
let problems = await problems_id.mapAsync(async id => await Problem.fromID(id)); |
||||
|
||||
res.render('contest_ranklist', { |
||||
contest: contest, |
||||
ranklist: ranklist, |
||||
problems: problems |
||||
}); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
app.get('/contest/:id/:pid', async (req, res) => { |
||||
try { |
||||
let contest_id = parseInt(req.params.id); |
||||
let contest = await Contest.fromID(contest_id); |
||||
if (!await contest.isRunning()) throw 'The contest has ended.' |
||||
|
||||
let problems_id = await contest.getProblems(); |
||||
|
||||
let pid = parseInt(req.params.pid); |
||||
if (!pid || pid < 1 || pid > problems_id.length) throw 'No such problem.'; |
||||
|
||||
let problem_id = problems_id[pid - 1]; |
||||
let problem = await Problem.fromID(problem_id); |
||||
|
||||
await syzoj.utils.markdown(problem, [ 'description', 'input_format', 'output_format', 'example', 'limit_and_hint' ]); |
||||
|
||||
res.render('contest_problem', { |
||||
contest: contest, |
||||
problem: problem |
||||
}); |
||||
} catch (e) { |
||||
syzoj.log(e); |
||||
res.render('error', { |
||||
err: e |
||||
}); |
||||
} |
||||
}); |
@ -0,0 +1,69 @@
|
||||
<% this.title = contest.title + ' - 比赛' %> |
||||
<% include header %> |
||||
<div class="padding"> |
||||
<h1 style="margin-bottom: 30px; "><%= contest.title %></h1> |
||||
<div class="ui grid"> |
||||
<% if (contest.allowedEdit || !contest.running) { %> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<div class="ui buttons"> |
||||
<a class="ui small positive button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'ranklist']) %>">排行榜</a> |
||||
<% if (contest.allowedEdit) { %> |
||||
<a class="ui small button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'edit']) %>">编辑比赛</a> |
||||
<% } %> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<% } %> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">描述</h4> |
||||
<div class="ui bottom attached segment"> |
||||
<%- contest.information %> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<table class="ui selectable celled table"> |
||||
<thead> |
||||
<tr> |
||||
<th class="one wide" style="text-align: center">状态</th> |
||||
<th class="fourteen wide">题目</th> |
||||
<th class="one wide" style="text-align: center">代码</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<% |
||||
let i = 0; |
||||
for (let problem of problems) { |
||||
i++; |
||||
%> |
||||
<tr> |
||||
<td class="center aligned" style="white-space: nowrap; "> |
||||
<% if (problem.judge_id) { %> |
||||
<a href="<%= syzoj.utils.makeUrl(['judge_detail', problem.judge_id]) %>"> |
||||
<% if (problem.status === true) { %> |
||||
<i class="black checkmark icon"></i> |
||||
<% } else if (problem.status !== false) { %> |
||||
<span class="status <%= problem.status.toLowerCase().split(' ').join('_') %>"> |
||||
<%= problem.status %> |
||||
</span> |
||||
<% } %> |
||||
<% } %> |
||||
</td> |
||||
<td><a href="<%= syzoj.utils.makeUrl(['contest', contest.id, i]) %>"><%= syzoj.utils.removeTitleTag(problem.problem.title) %></a></td> |
||||
<td class="center aligned"> |
||||
<% if (problem.judge_id) { %> |
||||
<a href="<%= syzoj.utils.makeUrl(['judge_detail', problem.judge_id]) %>"><i style="color: #000;" class="code icon"></i></a> |
||||
<% } %> |
||||
</td> |
||||
</tr> |
||||
<% } %> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<% include footer %> |
@ -0,0 +1,48 @@
|
||||
<% this.title = '比赛' %> |
||||
<% include header %> |
||||
<div class="padding"> |
||||
<% if (user && user.is_admin) { %> |
||||
<div class="ui grid"> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<a href="<%= syzoj.utils.makeUrl(['contest', 0, 'edit']) %>" class="ui mini right floated button">添加比赛</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<% } %> |
||||
<table class="ui very basic center aligned table"> |
||||
<thead> |
||||
<tr> |
||||
<th>比赛名称</th> |
||||
<th>开始时间</th> |
||||
<th>结束时间</th> |
||||
<th>描述</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<% |
||||
for (let contest of contests) { |
||||
let now = syzoj.utils.getCurrentTime(); |
||||
let tag = ''; |
||||
%> |
||||
<tr> |
||||
<% if (now < contest.start_time) { %> |
||||
<% tag = '<span class="ui header"><div class="ui mini grey label">未开始</div></span>' %> |
||||
<% } else if (now >= contest.start_time && now < contest.end_time) { %> |
||||
<% tag = '<span class="ui header"><div class="ui mini green label">进行中</div></span>' %> |
||||
<% } else { %> |
||||
<% tag = '<span class="ui header"><div class="ui mini red label">已结束</div></span>' %> |
||||
<% } %> |
||||
|
||||
<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><%- contest.information %></td> |
||||
</tr> |
||||
<% } %> |
||||
</tbody> |
||||
</table> |
||||
<br> |
||||
<% include page %> |
||||
</div> |
||||
<% include footer %> |
@ -0,0 +1,81 @@
|
||||
<% this.title = syzoj.utils.removeTitleTag(problem.title) + ' - ' + contest.title + ' - 比赛' %> |
||||
<% include header %> |
||||
<div class="ui center aligned grid"> |
||||
<div class="row"> |
||||
<h1><%= syzoj.utils.removeTitleTag(problem.title) %></h1> |
||||
</div> |
||||
<div class="row" style="margin-top: -15px"> |
||||
<span class="ui label">内存限制: <%= problem.memory_limit %> MiB</span> |
||||
<span class="ui label">时间限制: <%= problem.time_limit %> ms</span> |
||||
</div> |
||||
<div class="row" style="margin-top: -23px"> |
||||
<% if (problem.file_io) { %> |
||||
<span class="ui label">输入文件: <%= problem.file_io_input_name %></span> |
||||
<span class="ui label">输出文件: <%= problem.file_io_output_name %></span> |
||||
<% } else { %> |
||||
<span class="ui label">标准输入输出</span> |
||||
<% } %> |
||||
</div> |
||||
</div> |
||||
<div class="ui grid"> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<div class="ui buttons"> |
||||
<a href="#submit_form" class="ui primary button">提交</a> |
||||
<a href="<%= syzoj.utils.makeUrl(['contest', contest.id]) %>" class="ui positive button">返回比赛</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">题目描述</h4> |
||||
<div class="ui bottom attached segment" id="description"><%- problem.description %></div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">输入格式</h4> |
||||
<div class="ui bottom attached segment" id="input"><%- problem.input_format %></div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">输出格式</h4> |
||||
<div class="ui bottom attached segment" id="output"><%- problem.output_format %></div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">测试样例</h4> |
||||
<div class="ui bottom attached segment" id="example"><%- problem.example %></div> |
||||
</div> |
||||
</div> |
||||
<div class="row"> |
||||
<div class="column"> |
||||
<h4 class="ui top attached block header">数据范围与提示</h4> |
||||
<div class="ui bottom attached segment" id="hint"><%- problem.limit_and_hint %></div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<h2 class="ui header">提交代码</h2> |
||||
<form id="submit_form" class="ui form" action="<%= syzoj.utils.makeUrl(['submit', problem.id], { contest_id: contest.id }) %>" method="post"> |
||||
<div class="field"> |
||||
<label for="doc-select-1">选择语言</label> |
||||
<select class="ui fluid dropdown" name="language" id="doc-select-1"> |
||||
<% for (lang of syzoj.config.languages) { %> |
||||
<option value="<%= lang %>"><%= lang %></option> |
||||
<% } %> |
||||
</select> |
||||
</div> |
||||
<div class="field"> |
||||
<textarea rows="15" name="code" style="font-family: 'Roboto Mono', 'Bitstream Vera Sans Mono', 'Menlo', 'Consolas', 'Lucida Console', monospace; "></textarea> |
||||
</div> |
||||
<button type="submit" class="ui button">提交</button> |
||||
</form> |
||||
<script> |
||||
$(function () { |
||||
$('.ui.dropdown').dropdown(); |
||||
}); |
||||
</script> |
||||
<% include footer %> |
@ -0,0 +1,63 @@
|
||||
<%= this.title = '排名 - ' + contest.title %> |
||||
<% include header %> |
||||
<div class="padding"> |
||||
<table class="ui very basic center aligned table"> |
||||
<thead> |
||||
<tr> |
||||
<th>#</th> |
||||
<th>用户名</th> |
||||
<% for (let problem of problems) { %> |
||||
<th><a href="<%= syzoj.utils.makeUrl(['problem', problem.id]) %>"> |
||||
<%= syzoj.utils.removeTitleTag(problem.title) %> |
||||
</a></th> |
||||
<% } %> |
||||
<th>总分</th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<% |
||||
let i = 0; |
||||
for (let item of ranklist) { |
||||
i++ |
||||
%> |
||||
<tr> |
||||
<td> |
||||
<% if (i == 1) { %> |
||||
<div class="ui yellow ribbon label"> |
||||
<% } else if (i == 2) { %> |
||||
<div class="ui ribbon label"> |
||||
<% } else if (i == 3) { %> |
||||
<div class="ui brown ribbon label" style="background-color: #C47222 !important;"> |
||||
<% } else { %> |
||||
<div> |
||||
<% } %> |
||||
<%= i %> |
||||
</div> |
||||
</td> |
||||
<td><a href="<%= syzoj.utils.makeUrl(['user', item.user.id]) %>"><%= item.user.username %></a> |
||||
<% if (item.user.nameplate) { %> |
||||
<%= item.user.nameplate %> |
||||
<% } %> |
||||
</td> |
||||
<% for (let problem of problems) { %> |
||||
<% if (item.player.score_details[problem.id]) { %> |
||||
<td><a href="<%= syzoj.utils.makeUrl(['judge_detail', item.player.score_details[problem.id].judge_id]) %>"> |
||||
<span class="score score_<%= parseInt((item.player.score_details[problem.id].score / 10) || 0) %>"> |
||||
<%= item.player.score_details[problem.id].score %> |
||||
</span> |
||||
</a></td> |
||||
<% } else { %> |
||||
<td></td> |
||||
<% } %> |
||||
<% } %> |
||||
<td> |
||||
<span class="score score_<%= parseInt((item.player.score / ranklist[0].player.score * 10) || 0) %>"> |
||||
<%= item.player.score %> |
||||
</span> |
||||
</td> |
||||
</tr> |
||||
<% } %> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
<% include footer %> |
@ -0,0 +1,50 @@
|
||||
<% this.title = contest.id ? '编辑比赛' : '新建比赛' %> |
||||
<% include header %> |
||||
<div class="padding"> |
||||
<form class="ui form" action="<%= syzoj.utils.makeUrl(['contest', contest.id, 'edit']) %>" method="post"> |
||||
<div class="field"> |
||||
<label>比赛名称</label> |
||||
<input type="text" name="title" value="<%= contest.title %>"> |
||||
</div> |
||||
<div class="field"> |
||||
<label>试题列表</label> |
||||
<select class="ui fluid search dropdown" multiple="" id="search_problems" name="problems"> |
||||
<% for (let problem of problems) { %> |
||||
<option value="<%= problem.id %>" selected>#<%= problem.id %>. <%= problem.title %></option> |
||||
<% } %> |
||||
</select> |
||||
</div> |
||||
<div class="field"> |
||||
<label>比赛介绍</label> |
||||
<textarea class="" rows="5" id="doc-ta-1" name="information"><%= contest.information %></textarea> |
||||
</div> |
||||
<div class="field"> |
||||
<label>开始时间</label> |
||||
<input type="text" name="start_time" value="<%= syzoj.utils.formatDate(contest.start_time || syzoj.utils.getCurrentTime()) %>"> |
||||
</div> |
||||
<div class="field"> |
||||
<label>结束时间</label> |
||||
<input type="text" name="end_time" value="<%= syzoj.utils.formatDate(contest.end_time || syzoj.utils.getCurrentTime()) %>"> |
||||
</div> |
||||
<button type="submit" class="ui button">提交</button> |
||||
</form> |
||||
<script> |
||||
$(function () { |
||||
$('#search_problems') |
||||
.dropdown({ |
||||
debug: true, |
||||
apiSettings: { |
||||
url: '/api/v2/search/problem/{query}', |
||||
onResponse: function (response) { |
||||
var a = $('#search_problems').val().map(x => parseInt(x)); |
||||
if (response.results) { |
||||
response.results = response.results.filter(x => !a.includes(parseInt(x.value))); |
||||
} |
||||
return response; |
||||
}, |
||||
cache: false |
||||
} |
||||
}); |
||||
}); |
||||
</script> |
||||
<% include footer %> |
Loading…
Reference in new issue