ui: new judge config (#533)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2023-03-15 21:15:04 +08:00
1 parent f4d8cd7a5d
commit 85cb1d6dff
26 files changed
+910 -222

No files matched your search

@@ -2,6 +2,7 @@ import { diffLines } from 'diff';
import type { ProblemConfigFile, TestCaseConfig } from 'hydrooj/src/interface';
import $ from 'jquery';
import yaml from 'js-yaml';
import { isEqual } from 'lodash';
import type { editor } from 'monaco-editor';
import React from 'react';
import { connect } from 'react-redux';
@@ -21,7 +22,7 @@ const mapDispatchToProps = (dispatch) => ({
});
interface Props {
config: object;
config: any;
handleUpdateCode: Function;
}
@@ -29,7 +30,7 @@ const configKey = [
'type', 'subType', 'target', 'score', 'time',
'memory', 'filename', 'checker_type', 'checker', 'interactor',
'validator', 'user_extra_files', 'judge_extra_files', 'detail', 'outputs',
'redirect', 'cases', 'subtasks', 'langs',
'redirect', 'cases', 'subtasks', 'langs', 'key',
];
const subtasksKey = [
@@ -99,6 +100,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
this.vjEditor = Editor.getOrConstruct($(this.containerElement), {
language: 'yaml',
model: this.model,
lineNumbers: 'off',
onChange: (value: string) => {
this.__preventUpdate = true;
if (!this.__preventFormat) this.props.handleUpdateCode(value);
@@ -109,30 +111,34 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
}
componentDidUpdate(prevProps) {
if (this.__preventUpdate || !this.model) return;
if (yaml.dump(prevProps.config) !== yaml.dump(this.props.config)) {
this.__preventFormat = true;
const curValue = this.model.getValue();
const diff = diffLines(curValue, yaml.dump(configYamlFormat(this.props.config)));
const ops = [];
let cursor = 1;
for (const line of diff) {
if (line.added) {
let range = this.model.getFullModelRange();
range = range.setStartPosition(cursor, 0);
range = range.setEndPosition(cursor, 0);
ops.push({ range, text: line.value });
} else if (line.removed) {
let range = this.model.getFullModelRange();
range = range.setStartPosition(cursor, 0);
cursor += line.count;
range = range.setEndPosition(cursor, 0);
ops.push({ range, text: '' });
} else cursor += line.count;
}
this.model.pushEditOperations([], ops, undefined);
this.__preventFormat = false;
if (this.__preventUpdate || !this.model || !this.props.config.__valid) return;
if (yaml.dump(prevProps.config) === yaml.dump(this.props.config)) return;
const curValue = this.model.getValue();
const pending = configYamlFormat(this.props.config);
try {
const curConfig = yaml.load(curValue);
if (isEqual(curConfig, pending)) return;
} catch { }
this.__preventFormat = true;
const diff = diffLines(curValue, yaml.dump(pending));
const ops = [];
let cursor = 1;
for (const line of diff) {
if (line.added) {
let range = this.model.getFullModelRange();
range = range.setStartPosition(cursor, 0);
range = range.setEndPosition(cursor, 0);
ops.push({ range, text: line.value });
} else if (line.removed) {
let range = this.model.getFullModelRange();
range = range.setStartPosition(cursor, 0);
cursor += line.count;
range = range.setEndPosition(cursor, 0);
ops.push({ range, text: '' });
} else cursor += line.count;
}
this.model.pushEditOperations([], ops, undefined);
this.__preventFormat = false;
}
componentWillUnmount() {