Skip to content

Commit

Permalink
Extra files in Simple Edit Form (#177)
Browse files Browse the repository at this point in the history
* Adding extra files edit boxes to simple edit form.

* Implementing Smart Fill function for extra files.

* Fixing bug with non-loaded Supplementary and Attached files.

* Fixing bug in Smart fill procedure.

* Finalization of extra files inputs in simple config form.

* One last cleanup.

* Fixing the issue of reloading exercise when config or tests changed on simple edit page.
  • Loading branch information
Martin Kruliš committed Feb 15, 2018
1 parent 40049d8 commit fc0e87d
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 363 deletions.
4 changes: 2 additions & 2 deletions src/components/Exercises/FilesTable/FilesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const FilesTable = ({
</Button>
</p>}

<ResourceRenderer resource={attachments.toArray()}>
{(...attachments) =>
<ResourceRenderer resource={attachments.toArray()} returnAsArray={true}>
{attachments =>
<div>
{attachments.length > 0 &&
<Table responsive>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
.configRow {
padding-left: 15px;
padding-right: 15px;
border-bottom: 2px solid #ddd;
}

.configRow:nth-child(1) {
background-color: #f4fcf4!important;
}

.configRow:nth-child(odd) {
background-color: #F9F9F9;
}


.compilation {
overflow: auto;
}

.compilation > table {
width: 100%;
margin-bottom: 10px;
}

.compilation > table > tbody > tr > td {
padding-right: 10px;
padding-left: 10px;
border-right: 1px solid #ddd;
min-width: 250px;
}

.compilation > table > tbody > tr > td:first-of-type {
padding-left: 0;
}

.compilation > table > tbody > tr > td:last-of-type {
border-right-width: 0;
padding-right: 0;
}

.compilation-open {
cursor: pointer;
font-size: 85%;
}

.compilation-close {
cursor: pointer;
margin-top: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import { encodeTestId } from '../../../redux/modules/simpleLimits';
import { smartFillExerciseConfigForm } from '../../../redux/modules/exerciseConfigs';
import { exerciseConfigFormErrors } from '../../../redux/selectors/exerciseConfigs';

const hasCompilationExtraFiles = testData =>
testData &&
testData.compilation &&
Object.keys(testData.compilation).reduce(
(res, envId) =>
res || testData.compilation[envId]['extra-files'].length > 0,
false
);

class EditExerciseSimpleConfigForm extends Component {
render() {
const {
Expand All @@ -31,6 +40,7 @@ class EditExerciseSimpleConfigForm extends Component {
formValues,
formErrors,
supplementaryFiles,
exercise,
exerciseTests,
smartFill,
intl: { locale }
Expand Down Expand Up @@ -116,20 +126,34 @@ class EditExerciseSimpleConfigForm extends Component {
<div>
{exerciseTests
.sort((a, b) => a.name.localeCompare(b.name, locale))
.map((test, idx) =>
<EditExerciseSimpleConfigTest
key={idx}
formValues={formValues}
supplementaryFiles={files}
testName={test.name}
test={'config.' + encodeTestId(test.id)}
testId={test.id}
testKey={encodeTestId(test.id)}
testIndex={idx}
testErrors={formErrors && formErrors[encodeTestId(test.id)]}
smartFill={smartFill(test.id, exerciseTests, files)}
/>
)}
.map((test, idx) => {
const testData =
formValues &&
formValues.config &&
formValues.config[encodeTestId(test.id)];
return (
<EditExerciseSimpleConfigTest
key={idx}
exercise={exercise}
hasCompilationExtraFiles={hasCompilationExtraFiles(
testData
)}
useOutFile={testData && testData.useOutFile}
useCustomJudge={testData && testData.useCustomJudge}
supplementaryFiles={files}
testName={test.name}
test={'config.' + encodeTestId(test.id)}
testErrors={
formErrors && formErrors[encodeTestId(test.id)]
}
smartFill={
idx === 0
? smartFill(test.id, exerciseTests, files)
: undefined
}
/>
);
})}
</div>}
</ResourceRenderer>
</FormBox>
Expand All @@ -151,6 +175,7 @@ EditExerciseSimpleConfigForm.propTypes = {
formValues: PropTypes.object,
formErrors: PropTypes.object,
supplementaryFiles: ImmutablePropTypes.map,
exercise: PropTypes.object,
exerciseTests: PropTypes.array,
smartFill: PropTypes.func.isRequired,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
Expand Down Expand Up @@ -205,7 +230,7 @@ const validate = formData => {
};

export default connect(
(state, { exercise }) => {
(state, { exercise, exerciseTests }) => {
return {
supplementaryFiles: getSupplementaryFilesForExercise(exercise.id)(state),
formValues: getFormValues(FORM_NAME)(state),
Expand Down
Loading

0 comments on commit fc0e87d

Please sign in to comment.