ui: enhance problem_files page

This commit is contained in:
undefined committed 2022-02-08 18:26:34 +08:00
1 parent 1acd2ff0bb
commit 9158550139
5 files changed
+25 -23

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.4.8",
"version": "3.4.9",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+6 -3
View File
@@ -291,11 +291,14 @@ export class ProblemDetailHandler extends ProblemHandler {
this.tdoc = await contest.get(domainId, tid);
if (!this.tdoc) throw new ContestNotFoundError(domainId, tid);
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.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)) {
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
this.model = typeof model === 'string'
? 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;
this.model.setValue(value);
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');
}
/**
* @param {string?} val
* @returns {string}
*/
value(val) {
value(val?: string) {
this.ensureValid();
if (typeof val === 'string') return (this.editor || this.vditor).setValue(val);
return (this.editor || this.vditor).getValue();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.31.4",
"version": "4.31.5",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
+15 -12
View File
@@ -115,10 +115,7 @@ const page = new NamedPage('problem_files', () => {
const selectedFiles = ensureAndGetSelectedFiles(type);
if (selectedFiles === null) return;
const action = await new ConfirmDialog({
$body: tpl`
<div class="typo">
<p>${i18n('Confirm to delete the selected files?')}</p>
</div>`,
$body: tpl.typoMsg(i18n('Confirm to delete the selected files?')),
}).open();
if (action !== 'yes') return;
try {
@@ -181,12 +178,13 @@ const page = new NamedPage('problem_files', () => {
height: `${window.innerHeight - 100}px`,
cancelByEsc: false,
}).open();
const language = {
yaml: 'yaml',
yml: 'yaml',
cc: 'cpp',
json: 'json',
}[filename.split('.').pop()] || 'plain';
const languages = [
['yaml', ['yaml', 'yml']],
['cpp', ['c', 'cc', 'cpp', 'h', 'hpp']],
['json', ['json']],
['plain', ['in', 'out', 'ans']],
];
const language = languages.filter((i) => i[1].includes(filename.split('.').pop()))[0]?.[0] || 'auto';
const editor = new Editor($('[name="fileContent"]'), {
value,
autoResize: false,
@@ -224,8 +222,13 @@ const page = new NamedPage('problem_files', () => {
return;
}
Notification.info(i18n('Loading file...'));
const res = await request.get(link);
content = await request.get(res.url, undefined, { dataType: 'text' });
try {
const res = await request.get(link);
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...'));
const val = await startEdit(filename, content);
if (typeof val !== 'string') return;