core: pass pdoc with UiContext

This commit is contained in:
undefined committed 2021-05-17 12:29:40 +08:00
1 parent ec83da1080
commit 19e14fc90f
7 files changed
+23 -26

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.26.6",
"version": "2.26.7",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+1 -4
View File
@@ -381,10 +381,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@param('additional_file', Types.Boolean)
@param('pjax', Types.Boolean)
async get(domainId: string, getTestdata = true, getAdditionalFile = true, pjax = false) {
const canReadData = this.user.own(this.pdoc)
|| this.user.hasPriv(PRIV.PRIV_READ_PROBLEM_DATA)
|| this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
this.response.body.testdata = (getTestdata && canReadData) ? sortFiles(this.pdoc.data || []) : [];
this.response.body.testdata = getTestdata ? sortFiles(this.pdoc.data || []) : [];
this.response.body.additional_file = getAdditionalFile ? sortFiles(this.pdoc.additional_file || []) : [];
if (pjax) {
const { testdata, additional_file } = this.response.body;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.8.20",
"version": "4.8.21",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
@@ -251,8 +251,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
loadSubjective();
if (pagename === 'contest_detail_problem') return;
const data = await request.get('');
data.pdoc.stats = data.pdoc.stats || {};
UiContext.pdoc.stats = UiContext.pdoc.stats || {};
const $status = document.getElementById('submission-status-placeholder');
const statusChart = echarts.init($status);
statusChart.setOption({
@@ -264,20 +263,20 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
radius: [10, 70],
roseType: 'radius',
data: [
{ value: data.pdoc.stats.TLE, name: 'TLE' },
{ value: data.pdoc.stats.AC, name: 'AC' },
{ value: data.pdoc.stats.MLE, name: 'MLE' },
{ value: data.pdoc.stats.WA, name: 'WA' },
{ value: data.pdoc.stats.RE, name: 'RE' },
{ value: data.pdoc.stats.CE, name: 'CE' },
{ value: data.pdoc.stats.SE, name: 'SE' },
{ value: data.pdoc.stats.IGN, name: 'IGN' },
{ value: UiContext.pdoc.stats.TLE, name: 'TLE' },
{ value: UiContext.pdoc.stats.AC, name: 'AC' },
{ value: UiContext.pdoc.stats.MLE, name: 'MLE' },
{ value: UiContext.pdoc.stats.WA, name: 'WA' },
{ value: UiContext.pdoc.stats.RE, name: 'RE' },
{ value: UiContext.pdoc.stats.CE, name: 'CE' },
{ value: UiContext.pdoc.stats.SE, name: 'SE' },
{ value: UiContext.pdoc.stats.IGN, name: 'IGN' },
],
},
],
});
const $score = document.getElementById('submission-score-placeholder');
const x = Array.from({ length: 101 }, (v, i) => i).filter((i) => data.pdoc.stats[`s${i}`]);
const x = Array.from({ length: 101 }, (v, i) => i).filter((i) => UiContext.pdoc.stats[`s${i}`]);
const scoreChart = echarts.init($score);
scoreChart.setOption({
tooltip: { trigger: 'item' },
@@ -285,7 +284,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
yAxis: {},
series: [{
data: x.map((i) => ({
value: data.pdoc.stats[`s${i}`],
value: UiContext.pdoc.stats[`s${i}`],
itemStyle: { color: getScoreColor(i) },
})),
type: 'bar',
@@ -27,7 +27,11 @@
</label>
</td>
<td class="col--name">
<a href="{{ url('problem_file_download', {pid: pdoc.docId, filename: file.name, query:{type:'testdata'} }) }}">{{ file.name }}</a>
{% if handler.user.own(pdoc) or handler.user.hasPriv(PRIV.PRIV_READ_PROBLEM_DATA) or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA) %}
<a href="{{ url('problem_file_download', {pid: pdoc.docId, filename: file.name, query:{type:'testdata'} }) }}">{{ file.name }}</a>
{% else %}
<p>{{ file.name }}</p>
{% endif %}
</td>
<td class="col--size">{{ size(file.size) }}</td>
</tr>
@@ -35,10 +39,6 @@
</tbody>
</table>
{% else %}
{% if handler.user.own(pdoc) or handler.user.hasPriv(PRIV.PRIV_READ_PROBLEM_DATA) or handler.user.hasPerm(perm.PERM_READ_PROBLEM_DATA) %}
{{ nothing.render('No testdata at current.') }}
{% else %}
{{ nothing.render("You don't have permission to read testdata.")}}
{% endif %}
{{ nothing.render('No testdata at current.') }}
{% endif %}
</div>
@@ -105,7 +105,7 @@
</ol>
</div>
</div>
{% if page_name != 'problem_detail' %}
{% if page_name != 'problem_detail' and page_name != 'homework_detail_problem' %}
<div class="section side">
<div class="section__header">
<h1 class="section__title">{{ _('Information') }}</h1>
@@ -9,7 +9,8 @@
postPretestUrl: url('problem_pretest', pid=pdoc.docId),
pretestConnUrl: "/conn/pretest?pid=" + pdoc.pid|default(pdoc.docId) + "&domainId=" + handler.domainId,
codeLang: handler.user.codeLang,
codeTemplate: handler.user.codeTemplate
codeTemplate: handler.user.codeTemplate,
pdoc: pdoc
}) }}
{% if tdoc %}
{{ set(UiContext, 'postSubmitUrl', url('contest_detail_problem_submit' if tdoc.docType == model.document.TYPE_CONTEST else 'homework_detail_problem_submit', pid=pdoc.docId, tid=tdoc.docId)) }}