Browse Source

Separate normal submissions and contest submissions

pull/6/head
Menci 8 years ago
parent
commit
ac5273daf2
  1. 45
      modules/contest.js
  2. 22
      modules/submission.js
  3. 9
      views/contest.ejs
  4. 41
      views/contest_submissions.ejs
  5. 3
      views/problem.ejs
  6. 8
      views/submission_content.ejs
  7. 14
      views/submissions_item.ejs

45
modules/contest.js

@ -202,6 +202,50 @@ app.get('/contest/:id/ranklist', async (req, res) => {
}
});
app.get('/contest/:id/submissions', async (req, res) => {
try {
let contest_id = parseInt(req.params.id);
let contest = await Contest.fromID(contest_id);
if (!contest) throw 'No such contest.';
let problems_id = await contest.getProblems();
let user = await User.fromName(req.query.submitter || '');
let where = {};
if (user) where.user_id = user.id;
if (req.query.problem_id) where.problem_id = problems_id[parseInt(req.query.problem_id) - 1];
where.type = 1;
where.type_info = contest_id;
let paginate = syzoj.utils.paginate(await JudgeState.count(where), req.query.page, syzoj.config.page.judge_state);
let judge_state = await JudgeState.query(paginate, where, [['submit_time', 'desc']]);
await judge_state.forEachAsync(async obj => obj.hidden = !(await obj.isAllowedSeeResultBy(res.locals.user)));
await judge_state.forEachAsync(async obj => obj.allowedSeeCode = await obj.isAllowedSeeCodeBy(res.locals.user));
await judge_state.forEachAsync(async obj => {
await obj.loadRelationships();
obj.problem_id = problems_id.indexOf(obj.problem_id) + 1;
obj.problem.title = syzoj.utils.removeTitleTag(obj.problem.title);
});
res.render('contest_submissions', {
contest: contest,
judge_state: judge_state,
paginate: paginate,
form: {
submitter: req.query.submitter || '',
problem_id: req.query.problem_id || ''
}
});
} 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);
@ -221,6 +265,7 @@ app.get('/contest/:id/:pid', async (req, res) => {
let state = await problem.getJudgeState(res.locals.user, false);
res.render('problem', {
pid: pid,
contest: contest,
problem: problem,
state: state

22
modules/submission.js

@ -21,6 +21,7 @@
let JudgeState = syzoj.model('judge_state');
let User = syzoj.model('user');
let Contest = syzoj.model('contest');
app.get('/submissions', async (req, res) => {
try {
@ -28,6 +29,7 @@ app.get('/submissions', async (req, res) => {
let where = {};
if (user) where.user_id = user.id;
if (req.query.problem_id) where.problem_id = parseInt(req.query.problem_id);
where.type = { $ne: 1 };
let paginate = syzoj.utils.paginate(await JudgeState.count(where), req.query.page, syzoj.config.page.judge_state);
let judge_state = await JudgeState.query(paginate, where, [['submit_time', 'desc']]);
@ -78,6 +80,9 @@ app.get('/submission/:id', async (req, res) => {
let id = parseInt(req.params.id);
let judge = await JudgeState.fromID(id);
let contest;
if (judge.type === 1) contest = await Contest.fromID(judge.type_info);
await judge.loadRelationships();
judge.codeLength = judge.code.length;
@ -87,7 +92,14 @@ app.get('/submission/:id', async (req, res) => {
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
if (contest) {
let problems_id = await contest.getProblems();
judge.problem_id = problems_id.indexOf(judge.problem_id) + 1;
judge.problem.title = syzoj.utils.removeTitleTag(judge.problem.title);
}
res.render('submission', {
contest: contest,
judge: judge
});
} catch (e) {
@ -103,6 +115,9 @@ app.get('/submission/:id/ajax', async (req, res) => {
let id = parseInt(req.params.id);
let judge = await JudgeState.fromID(id);
let contest;
if (judge.type === 1) contest = await Contest.fromID(judge.type_info);
await judge.loadRelationships();
judge.codeLength = judge.code.length;
@ -112,7 +127,14 @@ app.get('/submission/:id/ajax', async (req, res) => {
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
if (contest) {
let problems_id = await contest.getProblems();
judge.problem_id = problems_id.indexOf(judge.problem_id) + 1;
judge.problem.title = syzoj.utils.removeTitleTag(judge.problem.title);
}
res.render('submission_content', {
contest: contest,
judge: judge
});
} catch (e) {

9
views/contest.ejs

@ -24,10 +24,11 @@
<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>
<% } %>
<a class="ui small blue button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'ranklist']) %>">排行榜</a>
<a class="ui small positive button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'submissions']) %>">提交记录</a>
<% if (contest.allowedEdit) { %>
<a class="ui small button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'edit']) %>">编辑比赛</a>
<% } %>
</div>
</div>
</div>

41
views/contest_submissions.ejs

@ -0,0 +1,41 @@
<% this.title = '提交记录 - ' + contest.title %>
<% include header %>
<div class="padding">
<div class="ui two column grid">
<div class="twelve wide column">
<form action="<%= syzoj.utils.makeUrl(['contest', contest.id, 'submissions']) %>" class="ui mini form" method="get" role="form">
<div class="inline field">
<input name="submitter" placeholder="提交者" style="margin: 0px;" type="text" value="<%= form.submitter %>"> <input name="problem_id" placeholder="题目编号" type="text" value="<%= form.problem_id %>"> <button class="ui mini button" type="submit">搜索</button>
</div>
</form>
</div>
<% if (user) { %>
<div class="four wide column padding">
<a class="ui mini button right floated" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'submissions'], { submitter: user.username }) %>">我的提交</a>
</div>
<% } %>
</div><br>
<table class="ui very basic center aligned table" style="white-space: nowrap; ">
<thead>
<tr>
<th>编号</th>
<th>题目</th>
<th>状态</th>
<th>分数</th>
<th>总时间</th>
<th>内存</th>
<th>代码</th>
<th>提交者</th>
<th>提交时间</th>
</tr>
</thead>
<tbody>
<% for (let judge of judge_state) { %>
<tr id="submissions_<%= judge.id %>"><% include submissions_item %></tr>
<% } %>
</tbody>
</table>
<br>
<% include page %>
</div>
<% include footer %>

3
views/problem.ejs

@ -47,7 +47,8 @@ if (contest) {
<div class="ui buttons">
<a class="small ui primary button" href="#submit_code">提交</a>
<% if (contest) { %>
<a href="<%= syzoj.utils.makeUrl(['contest', contest.id]) %>" class="ui positive button">返回比赛</a>
<a class="small ui positive button" href="<%= syzoj.utils.makeUrl(['contest', contest.id, 'submissions'], { problem_id: pid }) %>">提交记录</a>
<a href="<%= syzoj.utils.makeUrl(['contest', contest.id]) %>" class="ui orange button">返回比赛</a>
<% } else { %>
<a class="small ui positive button" href="<%= syzoj.utils.makeUrl(['submissions'], { problem_id: problem.id }) %>">提交记录</a>
<a class="small ui orange button" href="<%= syzoj.utils.makeUrl(['problem', problem.id, 'statistics', 'fastest']) %>">统计</a>

8
views/submission_content.ejs

@ -22,6 +22,12 @@ for (let s of judge.result.subtasks) {
}
%>
<%
let problemUrl;
if (typeof contest !== 'undefined') problemUrl = syzoj.utils.makeUrl(['contest', contest.id, judge.problem_id]);
else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
%>
<div class="padding">
<table class="ui very basic center aligned table" id="status_table">
<thead>
@ -40,7 +46,7 @@ for (let s of judge.result.subtasks) {
<tbody>
<tr>
<td>#<%= judge.id %></td>
<td><a href="<%= syzoj.utils.makeUrl(['problem', judge.problem_id]) %>">#<%= judge.problem_id %>. <%= judge.problem.title %></a></td>
<td><a href="<%= problemUrl %>">#<%= judge.problem_id %>. <%= judge.problem.title %></a></td>
<% if (judge.allowedSeeResult) { %>
<td class="status <%= getStatusMeta(judge.result.status).toLowerCase().split(' ').join('_') %>">
<i class="<%= icon[getStatusMeta(judge.status)] || 'remove' %> icon"></i>

14
views/submissions_item.ejs

@ -1,6 +1,11 @@
<% include util %>
<%
let problemUrl;
if (typeof contest !== 'undefined' && contest) problemUrl = syzoj.utils.makeUrl(['contest', contest.id, judge.problem_id]);
else problemUrl = syzoj.utils.makeUrl(['problem', judge.problem_id]);
%>
<td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>">#<%= judge.id %></a></td>
<td><a href="<%= syzoj.utils.makeUrl(['problem', judge.problem_id]) %>">#<%= judge.problem_id %>. <%= judge.problem.title %></a></td>
<td><a href="<%= problemUrl %>">#<%= judge.problem_id %>. <%= judge.problem.title %></a></td>
<% if (!judge.hidden) { %>
<td><a href="<%= syzoj.utils.makeUrl(['submission', judge.id]) %>">
<span class="status <%= getStatusMeta(judge.status).toLowerCase().split(' ').join('_') %>">
@ -25,7 +30,12 @@
<script>
function update_judge_<%= judge.id %>() {
setTimeout(function () {
$.get('/submissions/<%= judge.id %>/ajax', function (data) {
<%
let url;
if (typeof contest !== 'undefined' && contest) url = syzoj.utils.makeUrl(['contest', contest.id, 'submissions', judge.id, 'ajax']);
else url = syzoj.utils.makeUrl(['submissions', judge.id, 'ajax']);
%>
$.get('<%= url %>', function (data) {
var e = $('#submissions_<%= judge.id %>');
if (e.html() != data) e.html(data);
else update_judge_<%= judge.id %>();

Loading…
Cancel
Save