Browse Source

Add rejudge to submission page

pull/6/head
Menci 8 years ago
parent
commit
b6a4429657
  1. 34
      models/judge_state.js
  2. 32
      modules/submission.js
  3. 15
      views/submission_content.ejs

34
models/judge_state.js

@ -171,6 +171,40 @@ class JudgeState extends Model {
}
}
async rejudge() {
await this.loadRelationships();
let oldStatus = this.status;
this.status = 'Waiting';
this.score = 0;
this.total_time = 0;
this.max_memory = 0;
this.pending = true;
this.result = { status: "Waiting", total_time: 0, max_memory: 0, score: 0, case_num: 0, compiler_output: "", pending: true };
await this.save();
let WaitingJudge = syzoj.model('waiting_judge');
let waiting_judge = await WaitingJudge.create({
judge_id: this.id
});
await waiting_judge.save();
if (this.type === 0) {
if (oldStatus === 'Accepted') {
this.problem.ac_num--;
await this.user.refreshSubmitInfo();
await this.user.save();
}
await this.problem.save();
} else if (this.type === 1) {
let contest = await Contest.fromID(this.type_info);
await contest.newSubmission(this);
}
}
getModel() { return model; }
}

32
modules/submission.js

@ -32,6 +32,7 @@ app.get('/submissions', async (req, res) => {
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.loadRelationships());
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));
@ -56,6 +57,8 @@ app.get('/submissions/:id/ajax', async (req, res) => {
let judge_state = await JudgeState.fromID(req.params.id);
if (!judge_state) throw 'No such judge state';
await judge_state.loadRelationships();
judge_state.hidden = !(await judge_state.isAllowedSeeResultBy(res.locals.user));
judge_state.allowedSeeCode = await judge_state.isAllowedSeeCodeBy(res.locals.user);
@ -75,11 +78,14 @@ app.get('/submission/:id', async (req, res) => {
let id = parseInt(req.params.id);
let judge = await JudgeState.fromID(id);
await judge.loadRelationships();
judge.codeLength = judge.code.length;
judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
if (judge.result.compiler_output) judge.result.compiler_output = syzoj.utils.ansiToHTML(judge.result.compiler_output);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
res.render('submission', {
judge: judge
@ -97,11 +103,14 @@ app.get('/submission/:id/ajax', async (req, res) => {
let id = parseInt(req.params.id);
let judge = await JudgeState.fromID(id);
await judge.loadRelationships();
judge.codeLength = judge.code.length;
judge.code = await syzoj.utils.highlight(judge.code, syzoj.config.languages[judge.language].highlight);
if (judge.result.compiler_output) judge.result.compiler_output = syzoj.utils.ansiToHTML(judge.result.compiler_output);
judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user);
judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user);
judge.allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
res.render('submission_content', {
judge: judge
@ -113,3 +122,26 @@ app.get('/submission/:id/ajax', async (req, res) => {
});
}
});
app.get('/submission/:id/rejudge', async (req, res) => {
try {
let id = parseInt(req.params.id);
let judge = await JudgeState.fromID(id);
if (judge.pending) throw 'Can\'t rejudge a pending submission';
await judge.loadRelationships();
let allowedRejudge = await judge.problem.isAllowedEditBy(res.locals.user);
if (!allowedRejudge) throw 'Permission denied';
await judge.rejudge();
res.redirect(syzoj.utils.makeUrl(['submission', id]));
} catch (e) {
syzoj.log(e);
res.render('error', {
err: e
});
}
});

15
views/submission_content.ejs

@ -63,7 +63,12 @@ for (let s of judge.result.subtasks) {
</tbody>
</table>
<% if (judge.allowedSeeCode) { %>
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code id="code"><%- judge.code %></code></pre></div>
<div class="ui existing segment" style="position: relative; ">
<% if (judge.allowedRejudge) { %>
<a id="rejudge-button" href="<%= syzoj.utils.makeUrl(['submission', judge.id, 'rejudge']) %>" class="ui button" style="position: absolute; right: 10px; <% if (judge.pending) { %>display: none; <% } %>">重新评测</a>
<% } %>
<pre style="margin-top: 0; margin-bottom: 0; "><code id="code"><%- judge.code %></code></pre>
</div>
<script>
document.addEventListener('keydown', function (event) {
if ((event.ctrlKey || event.metaKey) && event.key === 'a') {
@ -150,7 +155,7 @@ $(function() {
});
</script>
<% if (!isPending(judge.status)) { %><div><div id="stop_ajax"></div></div><% } %>
<% if (!isPending(judge.status)) { %><div><div id="stop_ajax"></div><div id="show_rejudge"></div></div><% } %>
<script>
<% if (isPending(judge.status) && judge.allowedSeeResult) { %>
document.addEventListener('mousedown', function (event) {
@ -163,6 +168,12 @@ function update_submission() {
setTimeout(function () {
$.get('/submission/<%= judge.id %>/ajax', function (data) {
var e = $('#submission_content'), x = $($.parseHTML(data));
if (x.find('#show_rejudge').length) {
try {
document.getElementById('rejudge-button').style.display = '';
} catch (e) {}
}
if (e.find('td.status').text().trim() != x.find('td.status').text().trim()) {
var a = e.find('div.auto_update');
if (!a.length) {

Loading…
Cancel
Save