core: contest problem auto hide

This commit is contained in:
undefined committed 2021-11-24 01:11:11 +08:00
1 parent 20489f3f2e
commit 06a247f819
5 files changed
+48 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.1.34", "version": "3.1.35",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+26 -2
View File
@@ -14,6 +14,7 @@ import message from '../model/message';
import problem from '../model/problem'; import problem from '../model/problem';
import record from '../model/record'; import record from '../model/record';
import * as system from '../model/system'; import * as system from '../model/system';
import TaskModel from '../model/task';
import user from '../model/user'; import user from '../model/user';
import { import {
Handler, param, Route, Types, Handler, param, Route, Types,
@@ -46,6 +47,15 @@ registerResolver(
'Get a contest by ID', '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 { export class ContestListHandler extends Handler {
@param('rule', Types.Range(contest.RULES), true) @param('rule', Types.Range(contest.RULES), true)
@param('page', Types.PositiveInt, true) @param('page', Types.PositiveInt, true)
@@ -224,10 +234,12 @@ export class ContestEditHandler extends Handler {
@param('pids', Types.Content) @param('pids', Types.Content)
@param('rated', Types.Boolean) @param('rated', Types.Boolean)
@param('code', Types.String, true) @param('code', Types.String, true)
@param('autoHide', Types.String, true)
async post( async post(
domainId: string, tid: ObjectID, beginAtDate: string, beginAtTime: string, duration: number, 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 pids = _pids.replace(/,/g, ',').split(',').map((i) => +i).filter((i) => i);
const beginAtMoment = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone); const beginAtMoment = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
if (!beginAtMoment.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime'); if (!beginAtMoment.isValid()) throw new ValidationError('beginAtDate', 'beginAtTime');
@@ -246,7 +258,19 @@ export class ContestEditHandler extends Handler {
} else { } else {
tid = await contest.add(domainId, title, content, this.user._id, rule, beginAt, endAt, pids, rated); 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.body = { tid };
this.response.redirect = this.url('contest_detail', { tid }); this.response.redirect = this.url('contest_detail', { tid });
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.26.20", "version": "4.26.21",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -0,0 +1,6 @@
.page--contest_edit
.page--contest_create
label
&.checkbox
margin-top: 24px
@@ -67,13 +67,25 @@
row:false row:false
}) }} }) }}
</div> </div>
<div class="row">
{{ form.form_text({ {{ form.form_text({
columns:null, columns:9,
label:'Problems', label:'Problems',
name:'pids', name:'pids',
value: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({ {{ form.form_textarea({
columns:null, columns:null,
label:'Content', label:'Content',