ui: contest_problemlist

This commit is contained in:
undefined committed 2022-10-15 18:56:58 +08:00
1 parent add93f5783
commit f1cbe155c7
11 files changed
+127 -31

No files matched your search

+8 -3
View File
@@ -127,7 +127,12 @@ export class ContestDetailBaseHandler extends Handler {
},
{
name: 'record_main',
args: { tid, prefix: 'record_main', query: contest.canShowRecord.call(this, this.tdoc, true) ? {} : { uidOrName: this.user._id } },
args: {
prefix: 'record',
query: contest.canShowRecord.call(this, this.tdoc, true)
? { tid }
: { tid, uidOrName: this.user._id },
},
checker: () => contest.canShowSelfRecord.call(this, this.tdoc, true),
},
{
@@ -163,14 +168,14 @@ export class ContestDetailHandler extends ContestDetailBaseHandler {
&& !this.user.hasPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD)
) return;
const pdict = await problem.getList(domainId, this.tdoc.pids, true, undefined, undefined, problem.PROJECTION_CONTEST_LIST);
const psdict = {};
let psdict = {};
let rdict = {};
if (this.tsdoc) {
if (this.tsdoc.attend && !this.tsdoc.startAt && contest.isOngoing(this.tdoc)) {
await contest.setStatus(domainId, tid, this.user._id, { startAt: new Date() });
this.tsdoc.startAt = new Date();
}
for (const pdetail of this.tsdoc.journal || []) psdict[pdetail.pid] = pdetail;
psdict = this.tsdoc.detail || {};
if (contest.canShowSelfRecord.call(this, this.tdoc)) {
rdict = await record.getList(domainId, Object.values(psdict).map((i: any) => i.rid));
} else {
+5 -1
View File
@@ -377,8 +377,12 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
solutionCount: scnt,
discussionCount: dcnt,
tdoc: this.tdoc,
tsdoc: pick(this.tsdoc, ['attend', 'startAt']),
};
if (this.tdoc && this.tsdoc) {
const fields = ['attend', 'startAt'];
if (contest.canShowSelfRecord.call(this, this.tdoc, true)) fields.push('detail');
this.response.body.tsdoc = pick(this.tsdoc, fields);
}
this.response.template = 'problem_detail.html';
this.UiContext.extraTitleContent = this.pdoc.title;
}
+17 -13
View File
@@ -15,13 +15,14 @@ import * as system from '../model/system';
import TaskModel from '../model/task';
import user from '../model/user';
import * as bus from '../service/bus';
import {
ConnectionHandler, Handler, param, Types,
} from '../service/server';
import { ConnectionHandler, param, Types } from '../service/server';
import { buildProjection } from '../utils';
import { ContestDetailBaseHandler } from './contest';
import { postJudge } from './judge';
class RecordListHandler extends Handler {
class RecordListHandler extends ContestDetailBaseHandler {
tdoc?: Tdoc<30>;
@param('page', Types.PositiveInt, true)
@param('pid', Types.Name, true)
@param('tid', Types.ObjectID, true)
@@ -42,6 +43,7 @@ class RecordListHandler extends Handler {
if (full) uidOrName = this.user._id.toString();
if (tid) {
tdoc = await contest.get(domainId, tid);
this.tdoc = tdoc;
if (!tdoc) throw new ContestNotFoundError(domainId, pid);
if (!contest.canShowScoreboard.call(this, tdoc, true)) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
if (!this.user.own(tdoc) && !(await contest.getStatus(domainId, tid, this.user._id))?.attend) {
@@ -106,8 +108,10 @@ class RecordListHandler extends Handler {
}
}
class RecordDetailHandler extends Handler {
class RecordDetailHandler extends ContestDetailBaseHandler {
rdoc: RecordDoc;
tdoc?: Tdoc<30>;
@param('rid', Types.ObjectID)
async prepare(domainId: string, rid: ObjectID) {
this.rdoc = await record.get(domainId, rid);
@@ -133,15 +137,15 @@ class RecordDetailHandler extends Handler {
// eslint-disable-next-line consistent-return
async get(domainId: string, rid: ObjectID, download = false) {
const rdoc = this.rdoc;
let tdoc: Tdoc<30>;
if (rdoc.contest?.toString() === '000000000000000000000000') {
if (rdoc.uid !== this.user._id) throw new PermissionError(PERM.PERM_READ_RECORD_CODE);
} else if (rdoc.contest) {
tdoc = await contest.get(domainId, rdoc.contest);
let canView = this.user.own(tdoc);
canView ||= contest.canShowRecord.call(this, tdoc);
canView ||= contest.canShowSelfRecord.call(this, tdoc, true) && rdoc.uid === this.user._id;
this.tdoc = await contest.get(domainId, rdoc.contest);
let canView = this.user.own(this.tdoc);
canView ||= contest.canShowRecord.call(this, this.tdoc);
canView ||= contest.canShowSelfRecord.call(this, this.tdoc, true) && rdoc.uid === this.user._id;
if (!canView) throw new PermissionError(rid);
this.args.tid = this.tdoc.docId;
}
// eslint-disable-next-line prefer-const
@@ -155,8 +159,8 @@ class RecordDetailHandler extends Handler {
canViewCode ||= this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE);
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE);
canViewCode ||= this.user.hasPerm(PERM.PERM_READ_RECORD_CODE_ACCEPT) && self?.status === STATUS.STATUS_ACCEPTED;
if (tdoc && tdoc.allowViewCode && contest.isDone(tdoc)) {
const tsdoc = await contest.getStatus(domainId, tdoc.docId, this.user._id);
if (this.tdoc && this.tdoc.allowViewCode && contest.isDone(this.tdoc)) {
const tsdoc = await contest.getStatus(domainId, this.tdoc.docId, this.user._id);
canViewCode ||= tsdoc?.attend;
}
if (!canViewCode) {
@@ -170,7 +174,7 @@ class RecordDetailHandler extends Handler {
this.response.template = 'record_detail.html';
this.response.body = {
udoc, rdoc, pdoc, tdoc,
udoc, rdoc, pdoc, tdoc: this.tdoc,
};
}