Skip to content

Commit

Permalink
Adding Prolog environment to config structures and environment edit f…
Browse files Browse the repository at this point in the history
…orm.
  • Loading branch information
Martin Krulis committed Mar 24, 2019
1 parent 1fdf1d7 commit a652c2c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CheckboxField } from '../Fields';
import SubmitButton from '../SubmitButton';
import Button from '../../widgets/FlatButton';
import { RefreshIcon } from '../../icons';
import { STANDALONE_ENVIRONMENTS } from '../../../helpers/exercise/environments';

class EditEnvironmentSimpleForm extends Component {
render() {
Expand Down Expand Up @@ -97,24 +98,32 @@ EditEnvironmentSimpleForm.propTypes = {
intl: intlShape.isRequired,
};

const validate = formData => {
const validate = (formData, { runtimeEnvironments }) => {
const errors = {};
const allowedEnvrionmentsCount = Object.values(formData).filter(value => value === true || value === 'true').length;

if (allowedEnvrionmentsCount === 0) {
errors['_error'] = (
errors._error = (
<FormattedMessage
id="app.editEnvironmentSimpleForm.validation.environments"
defaultMessage="Please add at least one runtime environment."
/>
);
} else if (formData['data-linux'] && allowedEnvrionmentsCount > 1) {
errors['_error'] = (
<FormattedMessage
id="app.editEnvironmentSimpleForm.validation.dataOnlyCollision"
defaultMessage="Data-Only environment cannot be combined with any other environment."
/>
);
} else if (allowedEnvrionmentsCount > 1) {
const standaloneEnvs = STANDALONE_ENVIRONMENTS.filter(envId => formData[envId]).map(envId => {
const env = runtimeEnvironments.find(({ id }) => id === envId);
return env && env.name;
});

if (standaloneEnvs.length > 0) {
errors._error = (
<FormattedMessage
id="app.editEnvironmentSimpleForm.validation.standaloneEnvironmentsCollisions"
defaultMessage="Some of the selected environments ({envs}) cannot be combined with any other environment. You need to deselect these environment(s) or make sure only one environment is selected."
values={{ envs: standaloneEnvs.join(', ') }}
/>
);
}
}
return errors;
};
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/exercise/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ const SIMPLE_FORM_ENVIRONMENTS = [
'node-linux',
'php-linux',
'python3',
'prolog',
];

/**
* List of environments that must stand alone
* (exercise must be configured solely for this environment).
*/
export const STANDALONE_ENVIRONMENTS = ['data-linux', 'prolog'];

const SIMPLE_FORM_ENVIRONMENTS_INDEX = createIndex(SIMPLE_FORM_ENVIRONMENTS);

export const onlySimpleEnvironments = defaultMemoize(environments =>
Expand Down
2 changes: 1 addition & 1 deletion src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
"app.editEnvironmentSimpleForm.submit": "Uložit prostředí",
"app.editEnvironmentSimpleForm.submitting": "Ukládám...",
"app.editEnvironmentSimpleForm.success": "Konfigurace byla změněna.",
"app.editEnvironmentSimpleForm.validation.dataOnlyCollision": "Běhové prostředí data-only (pouze data) není možné kombinovat s libovolným jiným běhovým prostředím.",
"app.editEnvironmentSimpleForm.validation.environments": "Přidejte prosím alespoň jedno běhové prostředí.",
"app.editEnvironmentSimpleForm.validation.standaloneEnvironmentsCollisions": "Některá vybraná běhová prostředí ({envs}) nemohou být kombinovaná s jinými. Odeberte tato běhová prostředí, nebo zajistěte, že bude vybrané právě jedno z nich.",
"app.editExercise.deleteExercise": "Smazat úlohu",
"app.editExercise.deleteExerciseWarning": "Smazání úlohy odstraní všechna studentská řešení a všechna zadání této úlohy.",
"app.editExercise.description": "Změna nastavení úlohy",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
"app.editEnvironmentSimpleForm.submit": "Save Environments",
"app.editEnvironmentSimpleForm.submitting": "Saving Environments...",
"app.editEnvironmentSimpleForm.success": "Environments Saved.",
"app.editEnvironmentSimpleForm.validation.dataOnlyCollision": "Data-Only environment cannot be combined with any other environment.",
"app.editEnvironmentSimpleForm.validation.environments": "Please add at least one runtime environment.",
"app.editEnvironmentSimpleForm.validation.standaloneEnvironmentsCollisions": "Some of the selected environments ({envs}) cannot be combined with any other environment. You need to deselect these environment(s) or make sure only one environment is selected.",
"app.editExercise.deleteExercise": "Delete the exercise",
"app.editExercise.deleteExerciseWarning": "Deleting an exercise will remove all the students submissions and all assignments.",
"app.editExercise.description": "Change exercise settings",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/whitelist_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
"app.editEnvironmentSimpleForm.submit",
"app.editEnvironmentSimpleForm.submitting",
"app.editEnvironmentSimpleForm.success",
"app.editEnvironmentSimpleForm.validation.dataOnlyCollision",
"app.editEnvironmentSimpleForm.validation.environments",
"app.editEnvironmentSimpleForm.validation.standaloneEnvironmentsCollisions",
"app.editExercise.deleteExercise",
"app.editExercise.deleteExerciseWarning",
"app.editExercise.description",
Expand Down

0 comments on commit a652c2c

Please sign in to comment.