mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: contest problem auto hide
This commit is contained in:
1 parent
20489f3f2e
commit
06a247f819
5 files changed
+48
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.1.34",
|
||||
"version": "3.1.35",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -14,6 +14,7 @@ import message from '../model/message';
|
||||
import problem from '../model/problem';
|
||||
import record from '../model/record';
|
||||
import * as system from '../model/system';
|
||||
import TaskModel from '../model/task';
|
||||
import user from '../model/user';
|
||||
import {
|
||||
Handler, param, Route, Types,
|
||||
@@ -46,6 +47,15 @@ registerResolver(
|
||||
'Get a contest by ID',
|
||||
);
|
||||
|
||||
TaskModel.Worker.addHandler('contest.problemHide', async (doc) => {
|
||||
const tdoc = await contest.get(doc.domainId, doc.tid);
|
||||
if (!tdoc) return;
|
||||
for (const pid of tdoc.pids) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await problem.edit(doc.domainId, pid, { hidden: false });
|
||||
}
|
||||
});
|
||||
|
||||
export class ContestListHandler extends Handler {
|
||||
@param('rule', Types.Range(contest.RULES), true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@@ -224,10 +234,12 @@ export class ContestEditHandler extends Handler {
|
||||
@param('pids', Types.Content)
|
||||
@param('rated', Types.Boolean)
|
||||
@param('code', Types.String, true)
|
||||
@param('autoHide', Types.String, true)
|
||||
async post(
|
||||
domainId: string, tid: ObjectID, beginAtDate: string, beginAtTime: string, duration: number,
|
||||
title: string, content: string, rule: string, _pids: string, rated = false, _code = '',
|
||||
title: string, content: string, rule: string, _pids: string, rated = false, _code = '', autoHide = false,
|
||||
) {
|
||||
if (autoHide) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
const pids = _pids.replace(/,/g, ',').split(',').map((i) => +i).filter((i) => i);
|
||||
const beginAtMoment = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
|
||||
if (!beginAtMoment.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
@@ -246,7 +258,19 @@ export class ContestEditHandler extends Handler {
|
||||
} else {
|
||||
tid = await contest.add(domainId, title, content, this.user._id, rule, beginAt, endAt, pids, rated);
|
||||
}
|
||||
await contest.edit(domainId, tid, { _code });
|
||||
const task = {
|
||||
type: 'schedule', subType: 'contest.problemHide', domainId, tid,
|
||||
};
|
||||
await TaskModel.deleteMany(task);
|
||||
if (Date.now() <= endAt.getTime() && autoHide) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const pid of pids) await problem.edit(domainId, pid, { hidden: true });
|
||||
await TaskModel.add({
|
||||
...task,
|
||||
executeAfter: endAt,
|
||||
});
|
||||
}
|
||||
await contest.edit(domainId, tid, { _code, autoHide });
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = this.url('contest_detail', { tid });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.26.20",
|
||||
"version": "4.26.21",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
.page--contest_edit
|
||||
.page--contest_create
|
||||
label
|
||||
&.checkbox
|
||||
margin-top: 24px
|
||||
|
||||
@@ -67,13 +67,25 @@
|
||||
row:false
|
||||
}) }}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{ form.form_text({
|
||||
columns:null,
|
||||
columns:9,
|
||||
label:'Problems',
|
||||
name:'pids',
|
||||
value:pids,
|
||||
placeholder:_("Seperated with ','")
|
||||
placeholder:_("Seperated with ','"),
|
||||
row:false
|
||||
}) }}
|
||||
{{ form.form_checkbox({
|
||||
columns:3,
|
||||
label:'Auto hide-and show',
|
||||
name:'autoHide',
|
||||
placeholder:'',
|
||||
value:handler.user.hasPerm(perm.PERM_EDIT_PROBLEM) and (tdoc.autoHide|default(true)),
|
||||
disabled:not handler.user.hasPerm(perm.PERM_EDIT_PROBLEM),
|
||||
row:false
|
||||
}) }}
|
||||
</div>
|
||||
{{ form.form_textarea({
|
||||
columns:null,
|
||||
label:'Content',
|
||||
|
||||
Reference in new issue
Block a user