mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: enhance problem_files page
This commit is contained in:
1 parent
1acd2ff0bb
commit
9158550139
5 files changed
+23
-21
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.4.8",
|
"version": "3.4.9",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -291,11 +291,14 @@ export class ProblemDetailHandler extends ProblemHandler {
|
|||||||
this.tdoc = await contest.get(domainId, tid);
|
this.tdoc = await contest.get(domainId, tid);
|
||||||
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
|
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
|
||||||
this.tsdoc = await contest.getStatus(domainId, tid, this.user._id);
|
this.tsdoc = await contest.getStatus(domainId, tid, this.user._id);
|
||||||
this.pdoc.tag.length = 0;
|
|
||||||
const showAccept = contest.canShowScoreboard.call(this, this.tdoc, true);
|
|
||||||
if (!showAccept) this.pdoc.nAccept = 0;
|
|
||||||
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid);
|
if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid);
|
||||||
if (!contest.isDone(this.tdoc) && !this.tsdoc?.attend) throw new ContestNotAttendedError(tid);
|
if (!contest.isDone(this.tdoc) && !this.tsdoc?.attend) throw new ContestNotAttendedError(tid);
|
||||||
|
this.pdoc.tag.length = 0;
|
||||||
|
if (!contest.canShowScoreboard(this.tdoc) || !contest.isLocked(this.tdoc)) {
|
||||||
|
delete this.pdoc.nAccept;
|
||||||
|
delete this.pdoc.nSubmit;
|
||||||
|
delete this.pdoc.stats;
|
||||||
|
}
|
||||||
} else if (!problem.canViewBy(this.pdoc, this.user)) {
|
} else if (!problem.canViewBy(this.pdoc, this.user)) {
|
||||||
throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
this.model = typeof model === 'string'
|
this.model = typeof model === 'string'
|
||||||
? monaco.editor.getModel(monaco.Uri.parse(model))
|
? monaco.editor.getModel(monaco.Uri.parse(model))
|
||||||
|| monaco.editor.createModel(value, language, monaco.Uri.parse(model))
|
|| monaco.editor.createModel(value, language === 'auto' ? undefined : language, monaco.Uri.parse(model))
|
||||||
: model;
|
: model;
|
||||||
this.model.setValue(value);
|
this.model.setValue(value);
|
||||||
const cfg: import('../monaco').default.editor.IStandaloneEditorConstructionOptions = {
|
const cfg: import('../monaco').default.editor.IStandaloneEditorConstructionOptions = {
|
||||||
@@ -195,11 +195,7 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
if (!this.isValid) throw new Error('Editor is not loaded');
|
if (!this.isValid) throw new Error('Editor is not loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
value(val?: string) {
|
||||||
* @param {string?} val
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
value(val) {
|
|
||||||
this.ensureValid();
|
this.ensureValid();
|
||||||
if (typeof val === 'string') return (this.editor || this.vditor).setValue(val);
|
if (typeof val === 'string') return (this.editor || this.vditor).setValue(val);
|
||||||
return (this.editor || this.vditor).getValue();
|
return (this.editor || this.vditor).getValue();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.31.4",
|
"version": "4.31.5",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -115,10 +115,7 @@ const page = new NamedPage('problem_files', () => {
|
|||||||
const selectedFiles = ensureAndGetSelectedFiles(type);
|
const selectedFiles = ensureAndGetSelectedFiles(type);
|
||||||
if (selectedFiles === null) return;
|
if (selectedFiles === null) return;
|
||||||
const action = await new ConfirmDialog({
|
const action = await new ConfirmDialog({
|
||||||
$body: tpl`
|
$body: tpl.typoMsg(i18n('Confirm to delete the selected files?')),
|
||||||
<div class="typo">
|
|
||||||
<p>${i18n('Confirm to delete the selected files?')}</p>
|
|
||||||
</div>`,
|
|
||||||
}).open();
|
}).open();
|
||||||
if (action !== 'yes') return;
|
if (action !== 'yes') return;
|
||||||
try {
|
try {
|
||||||
@@ -181,12 +178,13 @@ const page = new NamedPage('problem_files', () => {
|
|||||||
height: `${window.innerHeight - 100}px`,
|
height: `${window.innerHeight - 100}px`,
|
||||||
cancelByEsc: false,
|
cancelByEsc: false,
|
||||||
}).open();
|
}).open();
|
||||||
const language = {
|
const languages = [
|
||||||
yaml: 'yaml',
|
['yaml', ['yaml', 'yml']],
|
||||||
yml: 'yaml',
|
['cpp', ['c', 'cc', 'cpp', 'h', 'hpp']],
|
||||||
cc: 'cpp',
|
['json', ['json']],
|
||||||
json: 'json',
|
['plain', ['in', 'out', 'ans']],
|
||||||
}[filename.split('.').pop()] || 'plain';
|
];
|
||||||
|
const language = languages.filter((i) => i[1].includes(filename.split('.').pop()))[0]?.[0] || 'auto';
|
||||||
const editor = new Editor($('[name="fileContent"]'), {
|
const editor = new Editor($('[name="fileContent"]'), {
|
||||||
value,
|
value,
|
||||||
autoResize: false,
|
autoResize: false,
|
||||||
@@ -224,8 +222,13 @@ const page = new NamedPage('problem_files', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Notification.info(i18n('Loading file...'));
|
Notification.info(i18n('Loading file...'));
|
||||||
|
try {
|
||||||
const res = await request.get(link);
|
const res = await request.get(link);
|
||||||
content = await request.get(res.url, undefined, { dataType: 'text' });
|
content = await request.get(res.url, undefined, { dataType: 'text' });
|
||||||
|
} catch (e) {
|
||||||
|
Notification.error(i18n('Failed to load file: {0}', e.message));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
} else Notification.info(i18n('Loading editor...'));
|
} else Notification.info(i18n('Loading editor...'));
|
||||||
const val = await startEdit(filename, content);
|
const val = await startEdit(filename, content);
|
||||||
if (typeof val !== 'string') return;
|
if (typeof val !== 'string') return;
|
||||||
|
|||||||
Reference in new issue
Block a user