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

+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;