core: allow user to manually end contest early (#1147)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-04-28 04:26:02 +08:00
1 parent d8a5716a22
commit 125c4b2388
9 files changed
+99 -40

No files matched your search

+3
View File
@@ -195,6 +195,7 @@ Confirm deleting the selected roles?: 您确定删除所选角色吗?
Confirm deleting this comment? Its replies will be deleted as well.: 确认删除这个评论吗?回复会被同时删除。
Confirm deleting this domain? This action cannot be undone.: '确认删除此域?此操作无法撤销。'
Confirm deleting this reply?: 确认删除这个回复吗?
Confirm end contest early? You will not be able to submit after this.: 确认提前结束比赛吗?之后您将无法提交代码。
Confirm rejudge this problem?: 确定要重测这道题吗?
Confirm removing the selected users?: 您确定将所选用户移除吗?
Confirm to delete the file?: 确认删除此文件吗?
@@ -209,6 +210,7 @@ Content copied to clipboard!: 内容已复制到剪贴板!
content: 内容
Content: 内容
Contest Maintainer: 比赛管理员
Contest resumed.: 比赛已恢复。
Contest scoreboard is not visible.: 当前比赛成绩表隐藏,暂不可显示。
Contest Scoreboard: 比赛成绩表
Contest Settings: 比赛设置
@@ -376,6 +378,7 @@ Email Visibility: Email 可见性
Email: 电子邮件
Enabled: 开启
End at: 结束于
End Contest Early: 提前结束比赛
End Date: 结束日期
End Time: 结束时间
Enroll Training: 参加训练
+1 -1
View File
@@ -8,7 +8,7 @@ contestTimer.appendTo(document.body);
export default new NamedPage(['contest_detail', 'contest_problemlist', 'contest_detail_problem', 'contest_scoreboard'], () => {
const beginAt = new Date((UiContext.tdoc.duration && UiContext.tsdoc?.startAt) || UiContext.tdoc.beginAt).getTime();
const endAt = new Date((UiContext.tdoc.duration && UiContext.tsdoc?.endAt) || UiContext.tdoc.endAt).getTime();
const endAt = new Date(UiContext.tsdoc?.endAt || UiContext.tdoc.endAt).getTime();
NProgress.configure({ trickle: false, showSpinner: false, minimum: 0 });
function updateProgress() {
const now = Date.now();
+31 -27
View File
@@ -52,46 +52,50 @@ const page = new NamedPage('contest_user', () => {
return this;
};
async function handlePostRequest(params, successMessage) {
try {
const res = await request.post('', params);
if (res.url && res.url !== window.location.href) window.location.href = res.url;
else {
Notification.success(successMessage);
pjax.request({ push: false });
}
} catch (error) {
Notification.error([error.message, ...error.params].join(' '));
}
}
async function handleClickAddUser() {
const action = await addUserDialog.clear().open();
if (action !== 'ok') return;
const unrank = addUserDialog.$dom.find('[name="unrank"]').prop('checked');
const uids = userSelect.value();
try {
const res = await request.post('', {
operation: 'add_user',
uids: uids.join(','),
unrank,
});
if (res.url && res.url !== window.location.href) window.location.href = res.url;
else {
Notification.success(i18n('User added.'));
pjax.request({ push: false });
}
} catch (error) {
Notification.error([error.message, ...error.params].join(' '));
}
await handlePostRequest({
operation: 'add_user',
uids: uids.join(','),
unrank,
}, i18n('User added.'));
}
async function handleEditRank(ev) {
const uid = $(ev.target).data('uid');
try {
const res = await request.post('', {
operation: 'rank',
uid,
});
if (res.url && res.url !== window.location.href) window.location.href = res.url;
else {
Notification.success(i18n('Ranking status updated.'));
pjax.request({ push: false });
}
} catch (error) {
Notification.error([error.message, ...error.params].join(' '));
}
await handlePostRequest({
operation: 'rank',
uid,
}, i18n('Ranking status updated.'));
}
async function handleResume(ev) {
const uid = $(ev.target).data('uid');
await handlePostRequest({
operation: 'resume',
uid,
}, i18n('Contest resumed.'));
}
$('[name="add_user"]').on('click', () => handleClickAddUser());
$(document).on('click', '[name="edit_rank"]', handleEditRank);
$(document).on('click', '[name="resume_contest"]', handleResume);
});
export default page;
@@ -68,6 +68,16 @@
<li class="menu__item"><a class="menu__link" href="{{ url('contest_problemlist', tid=tdoc.docId) }}">
<span class="icon icon-unordered_list"></span> {{ _('Problem List') }}
</a></li>
{% if page_name == 'contest_detail' and tsdoc.attend and model.contest.isOngoing(tdoc, tsdoc) and tdoc.rule !== 'homework' %}
<li class="menu__item">
<form action="{{ url('contest_detail', tid=tdoc.docId) }}" method="POST" onsubmit='return confirm({{ _("Confirm end contest early? You will not be able to submit after this.")|json|safe }});'>
<input type="hidden" name="operation" value="early_end">
<button class="menu__link" type="submit">
<span class="icon icon-delete"></span> {{ _('End Contest Early') }}
</button>
</form>
</li>
{% endif %}
{% endif %}{# not attend and not done #}
{% if model.contest.canShowScoreboard.call(handler, tdoc, False) %}
<li class="menu__item"><a class="menu__link" href="{{ url('contest_scoreboard', tid=tdoc.docId) }}">
@@ -10,7 +10,10 @@
<td class="col--rank">{{ _('UnRank') if tsdoc.unrank else _('Rank') }}</td>
<td class="col--actions">
<a name="edit_rank" data-uid="{{ tsdoc.uid }}">{{ _('Rank') if tsdoc.unrank else _('UnRank') }}</a>
{% if tsdoc.endAt and tsdoc.endAt < tdoc.endAt and tdoc.endAt.getTime() > Date.now() and (not tdoc.duration or not tsdoc.startAt or tsdoc.startAt.getTime() + tdoc.duration * 3600000 > Date.now()) %}
| <a name="resume_contest" data-uid="{{ tsdoc.uid }}">{{ _('Resume') }}</a>
{% endif %}
</td>
</tr>
{%- endfor -%}
</tbody>
</tbody>