core&ui: show homework relate on problem_detail (#396)

pull/398/head
panda 2 years ago committed by GitHub
parent 7101a3096c
commit 008c30c8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.15.3",
"version": "3.15.4",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",

@ -408,6 +408,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
this.response.body.rdoc = await record.get(this.args.domainId, this.psdoc.rid);
}
this.response.body.ctdocs = await contest.getRelated(this.args.domainId, this.pdoc.docId);
this.response.body.htdocs = await contest.getRelated(this.args.domainId, this.pdoc.docId, 'homework');
}
}

@ -487,9 +487,9 @@ export async function get(domainId: string, tid: ObjectID): Promise<Tdoc<30>> {
return tdoc;
}
export async function getRelated(domainId: string, pid: number) {
export async function getRelated(domainId: string, pid: number, rule?: string) {
const rules = Object.keys(RULES).filter((i) => !RULES[i].hidden);
return await document.getMulti(domainId, document.TYPE_CONTEST, { pids: pid, rule: { $in: rules } }).toArray();
return await document.getMulti(domainId, document.TYPE_CONTEST, { pids: pid, rule: rule || { $in: rules } }).toArray();
}
export async function getStatus(domainId: string, tid: ObjectID, uid: number) {

@ -32,6 +32,7 @@ export default new AutoloadPage('media', async () => {
if (category === 'user' && Number.isInteger(+data) && !extra) resolve(ele, { type: 'user', id: +data });
if (category === 'p' && !extra) resolve(ele, { type: 'problem', id: data, domainId });
if (category === 'contest' && !extra) resolve(ele, { type: 'contest', id: data, domainId });
if (category === 'homework' && !extra) resolve(ele, { type: 'homework', id: data, domainId });
});
});
if (!items.length) return;

@ -184,6 +184,15 @@ class RichMediaHandler extends Handler {
return '';
}
async renderHomework(domainId, payload) {
const cur = payload.domainId ? await user.getById(payload.domainId, this.user._id) : this.user;
const tdoc = cur.hasPerm(PERM.PERM_VIEW | PERM.PERM_VIEW_HOMEWORK)
? await contest.get(payload.domainId || domainId, new ObjectID(payload.id))
: null;
if (tdoc) return await this.renderHTML('partials/homework.html', { tdoc });
return '';
}
async post({ domainId, items }) {
const res = [];
for (const item of items) {
@ -191,6 +200,7 @@ class RichMediaHandler extends Handler {
if (item.type === 'user') res.push(this.renderUser(domainId, item).catch(() => ''));
else if (item.type === 'problem') res.push(this.renderProblem(domainId, item).catch(() => ''));
else if (item.type === 'contest') res.push(this.renderContest(domainId, item).catch(() => ''));
else if (item.type === 'homework') res.push(this.renderHomework(domainId, item).catch(() => ''));
else res.push('');
}
this.response.body = await Promise.all(res);

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.38.33",
"version": "4.38.34",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

@ -0,0 +1,3 @@
<a class="discussion-node-tag media-link" href="{{ url('homework_detail', domainId=tdoc.domainId, tid=tdoc.docId) }}">
<span class="v-center icon icon-homework"></span>{{ tdoc.title }}
</a>

@ -121,7 +121,7 @@
<div id="submission-score-placeholder" style="width: 100%; height:230px"></div>
</div>
{% endif %}
{% if page_name == 'problem_detail' and (tdocs.length or ctdocs.length) %}
{% if page_name == 'problem_detail' and (tdocs.length or ctdocs.length or htdocs.length) %}
<div class="section side">
<div class="section__header">
<h1 class="section__title">{{ _('Related') }}</h1>
@ -139,6 +139,12 @@
<p><a href="{{ url('contest_detail', tid=tdoc.docId) }}">{{ tdoc.title }}</a></p>
{%- endfor -%}
{% endif %}
{% if htdocs.length %}
<p>{{ _('In following homework') }}: </p>
{%- for tdoc in htdocs -%}
<p><a href="{{ url('homework_detail', tid=tdoc.docId) }}">{{ tdoc.title }}</a></p>
{%- endfor -%}
{% endif %}
</div>
</div>
{% endif %}

Loading…
Cancel
Save