Skip to content

Commit

Permalink
Exercise config loaded into simple form ... uff
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Nov 25, 2017
1 parent 24fa8d3 commit 36c1653
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class EditExerciseSimpleConfigForm extends Component {
hasSucceeded = false,
invalid,
formValues,
supplementaryFiles
supplementaryFiles,
exerciseTests
} = this.props;
return (
<div>
Expand All @@ -40,6 +41,7 @@ class EditExerciseSimpleConfigForm extends Component {
formValues={formValues}
supplementaryFiles={files}
prefix="config"
exerciseTests={exerciseTests}
/>}
</ResourceRenderer>

Expand Down Expand Up @@ -92,7 +94,8 @@ EditExerciseSimpleConfigForm.propTypes = {
id: PropTypes.string.isRequired
}),
formValues: PropTypes.object,
supplementaryFiles: ImmutablePropTypes.map
supplementaryFiles: ImmutablePropTypes.map,
exerciseTests: PropTypes.array
};

const validate = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
} from '../Fields';

const EditExerciseSimpleConfigTest = ({
fields,
prefix,
supplementaryFiles,
formValues,
exerciseTests,
intl
}) => {
const supplementaryFilesOptions = [{ key: '', name: '...' }].concat(
Expand All @@ -29,145 +31,193 @@ const EditExerciseSimpleConfigTest = ({
);
return (
<div>
<Row>
<Col lg={12}>
<h3>Test 1</h3>
</Col>
</Row>
<Row>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputTitle"
defaultMessage="input"
/>
</h4>
<Field
name={`${prefix}.inputFiles`}
component={ExpandingInputFilesField}
options={supplementaryFilesOptions}
leftLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputFilesActual"
defaultMessage="Input file:"
{fields.map((test, i) =>
<div key={i}>
<Row>
<Col lg={12}>
<h3>
{exerciseTests[i].name}
</h3>
</Col>
</Row>
<Row>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputTitle"
defaultMessage="Input"
/>
</h4>
<Field
name={`${test}.inputFiles`}
component={ExpandingInputFilesField}
options={supplementaryFilesOptions}
leftLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputFilesActual"
defaultMessage="Input file:"
/>
}
rightLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputFilesRename"
defaultMessage="Renamed file name:"
/>
}
/>
}
rightLabel={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputFilesRename"
defaultMessage="Renamed file name:"
<Field
name={`${test}.inputStdin`}
component={SelectField}
options={supplementaryFilesOptions}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputStdin"
defaultMessage="Stdin:"
/>
}
/>
}
/>
<Field
name={`${prefix}.inputStdin`}
component={SelectField}
options={supplementaryFilesOptions}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.inputStdin"
defaultMessage="Stdin:"
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.executionTitle"
defaultMessage="Execution"
/>
</h4>
<Field
name={`${test}.runArgs`}
component={ExpandingTextField}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.executionArguments"
defaultMessage="Execution arguments:"
/>
}
/>
}
/>
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.executionTitle"
defaultMessage="Execution"
/>
</h4>
<Field
name={`${prefix}.execArgs`}
component={ExpandingTextField}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.executionArguments"
defaultMessage="Execution arguments:"
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.outputTitle"
defaultMessage="Output"
/>
</h4>
<Field
name={`${test}.useOutFile`}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.useOutfile"
defaultMessage="Use output file instead of stdout"
/>
}
/>
}
/>
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.outputTitle"
defaultMessage="Output"
/>
</h4>
<Field
name={`${prefix}.useStdout`}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.useOutfile"
defaultMessage="Use output file instead of stdout"
{formValues &&
formValues.config &&
formValues.config[i] &&
(formValues.config[i].useOutFile === true ||
formValues.config[i].useOutFile === 'true') &&
<Field
name={`${test}.outputFile`}
component={TextField}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.outputFile"
defaultMessage="Output file:"
/>
}
/>}
<Field
name={`${test}.expectedOutput`}
component={SelectField}
options={supplementaryFilesOptions}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.expectedOutput"
defaultMessage="Expected output:"
/>
}
/>
}
/>
{formValues &&
formValues.useStdout !== 'true' &&
<Field
name={`${prefix}.output`}
component={TextField}
label={
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.outputFile"
defaultMessage="Output file:"
id="app.editExerciseSimpleConfigTests.judgeTitle"
defaultMessage="Judge"
/>
}
/>}
<Field
name={`${prefix}.outputSpecimen`}
component={SelectField}
options={supplementaryFilesOptions}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.outputSpecimen"
defaultMessage="Output specimen:"
/>
}
/>
</Col>
<Col lg={3}>
<h4>
<FormattedMessage
id="app.editExerciseSimpleConfigTests.judgeTitle"
defaultMessage="Judge"
/>
</h4>
<Field
name={`${prefix}.judgeType`}
component={SelectField}
options={[{ key: '', name: '...' }]}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.judgeType"
defaultMessage="Judge type:"
</h4>
<Field
name={`${test}.useCustomJudge`}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.useCustomJudge"
defaultMessage="Use custom judge binary"
/>
}
/>
}
/>
<Field
name={`${prefix}.judgeArgs`}
component={TextField}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.judgeArgs"
defaultMessage="Judge arguments:"
{formValues &&
formValues.config &&
formValues.config[i] &&
(formValues.config[i].useCustomJudge === true ||
formValues.config[i].useCustomJudge === 'true')
? <Field
name={`${test}.customJudgeBinary`}
component={SelectField}
options={supplementaryFilesOptions}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.customJudgeBinary"
defaultMessage="Custom judge binary:"
/>
}
/>
: <Field
name={`${test}.judgeBinary`}
component={SelectField}
options={[
{ key: '', name: '...' },
{
key: 'recodex-judge-normal',
name: 'recodex-judge-normal'
},
{
key: 'recodex-judge-shuffle',
name: 'recodex-judge-shuffle'
}
]}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.judgeBinary"
defaultMessage="Judge binary:"
/>
}
/>}
<Field
name={`${test}.judgeArgs`}
component={TextField}
label={
<FormattedMessage
id="app.editExerciseSimpleConfigTests.judgeArgs"
defaultMessage="Judge arguments:"
/>
}
/>
}
/>
</Col>
</Row>
</Col>
</Row>
</div>
)}
</div>
);
};

EditExerciseSimpleConfigTest.propTypes = {
fields: PropTypes.object.isRequired,
prefix: PropTypes.string.isRequired,
supplementaryFiles: PropTypes.array.isRequired,
exerciseTests: PropTypes.array,
formValues: PropTypes.object,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};
Expand Down
7 changes: 3 additions & 4 deletions src/components/forms/Fields/ExpandingInputFilesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ class ExpandingInputFilesField extends Component {

componentDidMount() {
const { input: { value } } = this.props;
const initialValue =
Array.isArray(value) && value.first && value.second
? value.concat([EMPTY_VALUE])
: [EMPTY_VALUE];
const initialValue = Array.isArray(value)
? value.concat([EMPTY_VALUE])
: [EMPTY_VALUE];
this.setState({ texts: initialValue });
}

Expand Down
Loading

0 comments on commit 36c1653

Please sign in to comment.