mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: allow user to manually end contest early (#1147)
This commit is contained in:
1 parent
d8a5716a22
commit
125c4b2388
9 files changed
+99
-40
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user