From 28ced177bd211d66331c547cb3fa4a6bb42d8a58 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Sat, 19 Sep 2020 09:57:16 +0200 Subject: [PATCH] generate JSON-file --- src/actions/tutorialBuilderActions.js | 7 ++++--- src/components/Tutorial/Assessment.js | 3 +-- src/components/Tutorial/Builder/Builder.js | 22 +++++++++++++++++++++- src/components/Tutorial/Instruction.js | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/actions/tutorialBuilderActions.js b/src/actions/tutorialBuilderActions.js index 2ccca5b..4cfee80 100644 --- a/src/actions/tutorialBuilderActions.js +++ b/src/actions/tutorialBuilderActions.js @@ -154,6 +154,7 @@ export const setSubmitError = () => (dispatch, getState) => { dispatch(setError(undefined, 'title')); } for(var i = 0; i < builder.steps.length; i++){ + builder.steps[i].id = i+1; if(i === 0 && builder.steps[i].hardware.length < 1){ dispatch(setError(i, 'hardware')); } @@ -170,12 +171,12 @@ export const checkError = () => (dispatch, getState) => { dispatch(setSubmitError()); var error = getState().builder.error; if(error.id || error.title){ - return false; + return true; } for(var i = 0; i < error.steps.length; i++){ if(Object.keys(error.steps[i]).length > 0){ - return false + return true } } - return true; + return false; } diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index da5e7f1..bfce041 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -4,7 +4,6 @@ import { connect } from 'react-redux'; import { workspaceName } from '../../actions/workspaceActions'; import BlocklyWindow from '../Blockly/BlocklyWindow'; -import SolutionCheck from './SolutionCheck'; import CodeViewer from '../CodeViewer'; import WorkspaceFunc from '../WorkspaceFunc'; @@ -45,7 +44,7 @@ class Assessment extends Component { Arbeitsauftrag - {currentTask.text1} + {currentTask.text}
diff --git a/src/components/Tutorial/Builder/Builder.js b/src/components/Tutorial/Builder/Builder.js index aaea9c3..2789fd3 100644 --- a/src/components/Tutorial/Builder/Builder.js +++ b/src/components/Tutorial/Builder/Builder.js @@ -3,6 +3,10 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { checkError } from '../../../actions/tutorialBuilderActions'; +import { saveAs } from 'file-saver'; + +import { detectWhitespacesAndReturnReadableResult } from '../../../helpers/whitespace'; + import Breadcrumbs from '../../Breadcrumbs'; import Id from './Id'; import Title from './Textfield'; @@ -12,6 +16,22 @@ import Button from '@material-ui/core/Button'; class Builder extends Component { + submit = () => { + var isError = this.props.checkError(); + if(isError){ + alert('Error'); + } + else{ + var tutorial = { + id: this.props.id, + title: this.props.title, + steps: this.props.steps + } + var blob = new Blob([JSON.stringify(tutorial)], { type: 'text/json' }); + saveAs(blob, `${detectWhitespacesAndReturnReadableResult(tutorial.title)}.json`); + } + } + render() { return ( @@ -29,7 +49,7 @@ class Builder extends Component { )} - +
diff --git a/src/components/Tutorial/Instruction.js b/src/components/Tutorial/Instruction.js index ee5c82a..73ddc0d 100644 --- a/src/components/Tutorial/Instruction.js +++ b/src/components/Tutorial/Instruction.js @@ -18,7 +18,7 @@ class Instruction extends Component { return (
{step.headline} - {step.text1} + {step.text} {isHardware ? : null} {areRequirements > 0 ?