Browse Source

Workaround for submissions page refresh

master
Menci 7 years ago
parent
commit
4e00f43d67
  1. 16
      modules/submission.js
  2. 23
      views/submissions.ejs
  3. 17
      views/submissions_item.ejs

16
modules/submission.js

@ -87,9 +87,12 @@ app.get('/submissions', async (req, res) => {
}
});
app.get('/submissions/:id/ajax', async (req, res) => {
app.get('/submissions/:ids/ajax', async (req, res) => {
try {
let judge_state = await JudgeState.fromID(req.params.id);
let ids = req.params.ids.split(','), rendered = {};
for (let id of ids) {
let judge_state = await JudgeState.fromID(id);
if (!judge_state) throw new ErrorMessage('无此提交记录。');
await judge_state.loadRelationships();
@ -113,10 +116,17 @@ app.get('/submissions/:id/ajax', async (req, res) => {
}
}
res.render('submissions_item', {
let o = { pending: judge_state.pending, html: null, status: judge_state.status };
o.html = await require('util').promisify(app.render).bind(app)('submissions_item', {
contest: contest,
judge: judge_state
});
rendered[id] = o;
}
res.send(rendered);
} catch (e) {
syzoj.log(e);
res.render('error', {

23
views/submissions.ejs

@ -77,7 +77,9 @@
</tr>
</thead>
<tbody>
<% let ids = []; %>
<% for (let judge of judge_state) { %>
<% if (judge.pending) ids.push(judge.id); %>
<tr id="submissions_<%= judge.id %>"><% include submissions_item %></tr>
<% } %>
</tbody>
@ -93,5 +95,26 @@ $(function () {
$('#select_language').dropdown();
$('#select_status').dropdown();
});
var ids = <%= JSON.stringify(ids) %>;
function update() {
setTimeout(function () {
$.get('/submissions/' + ids.join(',') + '/ajax', function (data) {
var newIDs = [];
for (var id in data) {
if (data[id].pending) newIDs.push(id);
var e = $('#submissions_' + id);
if (e.find('span.status').text().trim() !== data[id].status) e.html(data[id].html);
}
if (newIDs.length > 0) {
ids = newIDs;
update();
}
});
}, 500);
}
update();
</script>
<% include footer %>

17
views/submissions_item.ejs

@ -33,21 +33,4 @@ textFit(e, { maxFontSize: 14 });
<% } %>
<td><a href="<%= syzoj.utils.makeUrl(['user', judge.user_id]) %>"><%= judge.user.username %></a><% if (judge.user.nameplate) { %><%- judge.user.nameplate %><% } %></td>
<td><%= syzoj.utils.formatDate(judge.submit_time) %>
<% if (isPending(judge.status)) { %>
<script>
function update_judge_<%= judge.id %>() {
setTimeout(function () {
<%
let 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 %>();
});
}, 500);
}
update_judge_<%= judge.id %>();
</script>
<% } %>
</td>

Loading…
Cancel
Save