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

This commit is contained in:
panda authored and GitHub committed 2022-08-04 08:59:55 +08:00
1 parent 7101a3096c
commit 008c30c8e0
8 files changed
+26 -5

No files matched your search

@@ -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;
+10
View File
@@ -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 -1
View File
@@ -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 %}