core&ui: contest: better navbar

This commit is contained in:
undefined committed 2022-10-14 17:41:07 +08:00
1 parent e8b6459e01
commit f52be39803
6 files changed
+49 -16

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "4.0.15",
"version": "4.0.16",
"bin": "bin/hydrooj.js",
"main": "src/plugin-api",
"module": "src/plugin-api",
+30
View File
@@ -106,6 +106,36 @@ export class ContestDetailBaseHandler extends Handler {
this.tsdoc.endAt = moment(this.tsdoc.startAt).add(this.tdoc.duration, 'hours').toDate();
}
}
@param('tid', Types.ObjectID, true)
async after(domainId: string, tid: ObjectID) {
if (!tid || this.request.json || !this.response.template || !contest.isOngoing(this.tdoc, this.tsdoc)) return;
const pdoc = 'pdoc' in this ? (this as any).pdoc : {};
this.response.body.overrideNav = [
{ name: 'homepage', args: { prefix: 'homepage' }, checker: () => true },
{
name: 'contest_detail',
displayName: this.tdoc.title,
args: { tid, prefix: 'contest_detail' },
checker: () => true,
},
{
name: 'contest_scoreboard',
args: { tid, prefix: 'contest_scoreboard' },
checker: () => contest.canShowScoreboard.call(this, this.tdoc, true),
},
{
name: 'record_main',
args: { tid, prefix: 'record_main', query: contest.canShowRecord.call(this, this.tdoc, true) ? {} : { uidOrName: this.user._id } },
checker: () => contest.canShowSelfRecord.call(this, this.tdoc, true),
},
{
displayName: `${String.fromCharCode(65 + this.tdoc.pids.indexOf(pdoc.docId))}. ${pdoc.title}`,
args: { query: { tid }, pid: pdoc.docId, prefix: 'contest_detail_problem' },
checker: () => 'pdoc' in this,
},
];
}
}
export class ContestDetailHandler extends ContestDetailBaseHandler {
@@ -35,17 +35,20 @@ export default (router, logger) => async (ctx: KoaContext, next) => {
response.body = await ctx.renderHTML(name, args);
response.type = 'text/html';
};
ctx.getUrl = (name: string, kwargs: any = {}) => {
ctx.getUrl = (name: string, ...kwargsList: Record<string, any>[]) => {
if (name === '#') return '#';
let res = '#';
const args: any = {};
const query: any = {};
for (const key in kwargs) {
if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString();
else args[key] = kwargs[key].toString().replace(/\//g, '%2F');
}
for (const key in kwargs.query || {}) {
if (query[key] instanceof ObjectID) query[key] = kwargs.query[key].toHexString();
else query[key] = kwargs.query[key].toString();
for (const kwargs of kwargsList) {
for (const key in kwargs) {
if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString();
else args[key] = kwargs[key].toString().replace(/\//g, '%2F');
}
for (const key in kwargs.query || {}) {
if (query[key] instanceof ObjectID) query[key] = kwargs.query[key].toHexString();
else query[key] = kwargs.query[key].toString();
}
}
try {
const { anchor } = args;
+1 -1
View File
@@ -252,7 +252,7 @@ async function handle(ctx: KoaContext, HandlerClass, checker) {
...operation ? [
`handler/before-operation/${name}`, 'handler/before-operation',
`post${operation}`, 'log/__operationDone',
] : [],
] : [], 'after',
`handler/after/${name}`, 'handler/after', 'cleanup',
`handler/finish/${name}`, 'handler/finish',
];