From 567f94135b46849f2febd78ea5407d7c65a31dae Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 10:29:53 +0200 Subject: [PATCH 01/16] reorganize media files --- public/media/{ => blockly}/1x1.gif | Bin public/media/{ => blockly}/click.mp3 | Bin public/media/{ => blockly}/click.ogg | Bin public/media/{ => blockly}/click.wav | Bin public/media/{ => blockly}/delete.mp3 | Bin public/media/{ => blockly}/delete.ogg | Bin public/media/{ => blockly}/delete.wav | Bin public/media/{ => blockly}/disconnect.mp3 | Bin public/media/{ => blockly}/disconnect.ogg | Bin public/media/{ => blockly}/disconnect.wav | Bin public/media/{ => blockly}/dropdown-arrow.svg | 0 public/media/{ => blockly}/handclosed.cur | Bin public/media/{ => blockly}/handdelete.cur | Bin public/media/{ => blockly}/handopen.cur | Bin public/media/{ => blockly}/pilcrow.png | Bin public/media/{ => blockly}/quote0.png | Bin public/media/{ => blockly}/quote1.png | Bin public/media/{ => blockly}/sprites.png | Bin public/media/{ => blockly}/sprites.svg | 0 src/components/Blockly/BlocklyWindow.js | 2 +- 20 files changed, 1 insertion(+), 1 deletion(-) rename public/media/{ => blockly}/1x1.gif (100%) rename public/media/{ => blockly}/click.mp3 (100%) rename public/media/{ => blockly}/click.ogg (100%) rename public/media/{ => blockly}/click.wav (100%) rename public/media/{ => blockly}/delete.mp3 (100%) rename public/media/{ => blockly}/delete.ogg (100%) rename public/media/{ => blockly}/delete.wav (100%) rename public/media/{ => blockly}/disconnect.mp3 (100%) rename public/media/{ => blockly}/disconnect.ogg (100%) rename public/media/{ => blockly}/disconnect.wav (100%) rename public/media/{ => blockly}/dropdown-arrow.svg (100%) rename public/media/{ => blockly}/handclosed.cur (100%) rename public/media/{ => blockly}/handdelete.cur (100%) rename public/media/{ => blockly}/handopen.cur (100%) rename public/media/{ => blockly}/pilcrow.png (100%) rename public/media/{ => blockly}/quote0.png (100%) rename public/media/{ => blockly}/quote1.png (100%) rename public/media/{ => blockly}/sprites.png (100%) rename public/media/{ => blockly}/sprites.svg (100%) diff --git a/public/media/1x1.gif b/public/media/blockly/1x1.gif similarity index 100% rename from public/media/1x1.gif rename to public/media/blockly/1x1.gif diff --git a/public/media/click.mp3 b/public/media/blockly/click.mp3 similarity index 100% rename from public/media/click.mp3 rename to public/media/blockly/click.mp3 diff --git a/public/media/click.ogg b/public/media/blockly/click.ogg similarity index 100% rename from public/media/click.ogg rename to public/media/blockly/click.ogg diff --git a/public/media/click.wav b/public/media/blockly/click.wav similarity index 100% rename from public/media/click.wav rename to public/media/blockly/click.wav diff --git a/public/media/delete.mp3 b/public/media/blockly/delete.mp3 similarity index 100% rename from public/media/delete.mp3 rename to public/media/blockly/delete.mp3 diff --git a/public/media/delete.ogg b/public/media/blockly/delete.ogg similarity index 100% rename from public/media/delete.ogg rename to public/media/blockly/delete.ogg diff --git a/public/media/delete.wav b/public/media/blockly/delete.wav similarity index 100% rename from public/media/delete.wav rename to public/media/blockly/delete.wav diff --git a/public/media/disconnect.mp3 b/public/media/blockly/disconnect.mp3 similarity index 100% rename from public/media/disconnect.mp3 rename to public/media/blockly/disconnect.mp3 diff --git a/public/media/disconnect.ogg b/public/media/blockly/disconnect.ogg similarity index 100% rename from public/media/disconnect.ogg rename to public/media/blockly/disconnect.ogg diff --git a/public/media/disconnect.wav b/public/media/blockly/disconnect.wav similarity index 100% rename from public/media/disconnect.wav rename to public/media/blockly/disconnect.wav diff --git a/public/media/dropdown-arrow.svg b/public/media/blockly/dropdown-arrow.svg similarity index 100% rename from public/media/dropdown-arrow.svg rename to public/media/blockly/dropdown-arrow.svg diff --git a/public/media/handclosed.cur b/public/media/blockly/handclosed.cur similarity index 100% rename from public/media/handclosed.cur rename to public/media/blockly/handclosed.cur diff --git a/public/media/handdelete.cur b/public/media/blockly/handdelete.cur similarity index 100% rename from public/media/handdelete.cur rename to public/media/blockly/handdelete.cur diff --git a/public/media/handopen.cur b/public/media/blockly/handopen.cur similarity index 100% rename from public/media/handopen.cur rename to public/media/blockly/handopen.cur diff --git a/public/media/pilcrow.png b/public/media/blockly/pilcrow.png similarity index 100% rename from public/media/pilcrow.png rename to public/media/blockly/pilcrow.png diff --git a/public/media/quote0.png b/public/media/blockly/quote0.png similarity index 100% rename from public/media/quote0.png rename to public/media/blockly/quote0.png diff --git a/public/media/quote1.png b/public/media/blockly/quote1.png similarity index 100% rename from public/media/quote1.png rename to public/media/blockly/quote1.png diff --git a/public/media/sprites.png b/public/media/blockly/sprites.png similarity index 100% rename from public/media/sprites.png rename to public/media/blockly/sprites.png diff --git a/public/media/sprites.svg b/public/media/blockly/sprites.svg similarity index 100% rename from public/media/sprites.svg rename to public/media/blockly/sprites.svg diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index 3746676..a31cd15 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -64,7 +64,7 @@ class BlocklyWindow extends Component { colour: '#4EAF47', // senseBox-green snap: false }} - media={'/media/'} + media={'/media/blockly/'} move={this.props.move !== undefined && !this.props.move ? {} : { // https://developers.google.com/blockly/guides/configure/web/move scrollbars: true, From 45509774717efc96013447fd9673114b3de906e3 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 14:39:47 +0200 Subject: [PATCH 02/16] upload, download, compile and reset blocks --- package.json | 1 + src/components/ClearWorkspace.js | 46 ---------- src/components/Compile.js | 34 ++++++- src/components/Home.js | 4 +- src/components/Navbar.js | 2 - src/components/WorkspaceFunc.js | 146 ++++++++++++++++++++++++++----- 6 files changed, 155 insertions(+), 78 deletions(-) delete mode 100644 src/components/ClearWorkspace.js diff --git a/package.json b/package.json index ff3634c..9f78c9a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", "blockly": "^3.20200625.2", + "file-saver": "^2.0.2", "prismjs": "^1.20.0", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/src/components/ClearWorkspace.js b/src/components/ClearWorkspace.js deleted file mode 100644 index 2e31b01..0000000 --- a/src/components/ClearWorkspace.js +++ /dev/null @@ -1,46 +0,0 @@ -import React, {Component} from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { clearStats, onChangeCode } from '../actions/workspaceActions'; -import { initialXml } from './Blockly/initialXml.js'; - -import * as Blockly from 'blockly/core'; - -import ListItem from '@material-ui/core/ListItem'; -import ListItemIcon from '@material-ui/core/ListItemIcon'; -import ListItemText from '@material-ui/core/ListItemText'; - -import { faTrashRestore } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; - -class ClearWorkspace extends Component { - - clearWorkspace = () => { - const workspace = Blockly.getMainWorkspace(); - Blockly.Events.disable(); // https://groups.google.com/forum/#!topic/blockly/m7e3g0TC75Y - // if events are disabled, then the workspace will be cleared AND the blocks are not in the trashcan - const xmlDom = Blockly.Xml.textToDom(initialXml) - Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); - Blockly.Events.enable(); - workspace.options.maxBlocks = Infinity; - this.props.onChangeCode(); - this.props.clearStats(); - } - - render() { - return ( - {this.clearWorkspace(); this.props.onClick();}}> - - - - ); - }; -} - -ClearWorkspace.propTypes = { - clearStats: PropTypes.func.isRequired, - onChangeCode: PropTypes.func.isRequired -}; - - -export default connect(null, { clearStats, onChangeCode })(ClearWorkspace); diff --git a/src/components/Compile.js b/src/components/Compile.js index a6c86c2..e42f5cf 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -10,11 +10,26 @@ import DialogTitle from '@material-ui/core/DialogTitle'; import DialogContent from '@material-ui/core/DialogContent'; import DialogActions from '@material-ui/core/DialogActions'; import Dialog from '@material-ui/core/Dialog'; +import IconButton from '@material-ui/core/IconButton'; +import Tooltip from '@material-ui/core/Tooltip'; + +import { faPlay } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ backdrop: { zIndex: theme.zIndex.drawer + 1, color: '#fff', + }, + button: { + backgroundColor: theme.palette.primary.main, + color: theme.palette.primary.contrastText, + width: '40px', + height: '40px', + '&:hover': { + backgroundColor: theme.palette.primary.main, + color: theme.palette.primary.contrastText, + } } }); @@ -60,10 +75,21 @@ class Compile extends Component { render() { return ( -
- +
+ {this.props.iconButton ? + + this.compile()} + > + + + + : + + } diff --git a/src/components/Home.js b/src/components/Home.js index 5b6f71f..47555f9 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -72,7 +72,8 @@ class Home extends Component { render() { return (
- +
+
@@ -93,7 +94,6 @@ class Home extends Component { : null} -
); }; diff --git a/src/components/Navbar.js b/src/components/Navbar.js index fb5365f..55db003 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -1,7 +1,6 @@ import React, { Component } from 'react'; import { Link } from 'react-router-dom'; -import ClearWorkspace from './ClearWorkspace'; import senseboxLogo from './sensebox_logo.svg'; import { withRouter } from 'react-router-dom'; @@ -105,7 +104,6 @@ class Navbar extends Component { ))} - diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 8c4826c..117bf68 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -1,39 +1,143 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; +import { clearStats, onChangeCode } from '../actions/workspaceActions'; + +import * as Blockly from 'blockly/core'; + +import { saveAs } from 'file-saver'; + +import { initialXml } from './Blockly/initialXml.js'; -import MaxBlocks from './MaxBlocks'; import Compile from './Compile'; +import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import DialogTitle from '@material-ui/core/DialogTitle'; import DialogContent from '@material-ui/core/DialogContent'; import DialogActions from '@material-ui/core/DialogActions'; import Dialog from '@material-ui/core/Dialog'; +import IconButton from '@material-ui/core/IconButton'; +import Tooltip from '@material-ui/core/Tooltip'; + +import { faSave, faUpload, faShare } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +const styles = (theme) => ({ + button: { + backgroundColor: theme.palette.primary.main, + color: theme.palette.primary.contrastText, + width: '40px', + height: '40px', + '&:hover': { + backgroundColor: theme.palette.primary.main, + color: theme.palette.primary.contrastText, + } + } +}); + class WorkspaceFunc extends Component { - state = { - title: '', - content: '', - open: false - } - - getArduinoCode = () => { - this.setState({ title: 'Adurino Code', content: this.props.arduino, open: true }); - } - - getXMLCode = () => { - this.setState({ title: 'XML Code', content: this.props.xml, open: true }); + constructor(props){ + super(props); + this.inputRef = React.createRef(); + this.state = { + title: '', + content: '', + open: false + }; } toggleDialog = () => { this.setState({ open: !this.state }); } + saveXmlFile = (code) => { + // saveTextFileAs + var fileName = 'todo.xml' + var blob = new Blob([code], { type: 'text/xml' }); + saveAs(blob, fileName); + } + + uploadXmlFile = (xmlFile) => { + console.log(xmlFile); + if(xmlFile.type !== 'text/xml'){ + this.setState({ open: true, title: 'Unzulässiger Dateityp', content: 'Die übergebene Datei entsprach nicht dem geforderten Format. Es sind nur XML-Dateien zulässig.' }); + } + else { + var reader = new FileReader(); + reader.readAsText(xmlFile); + reader.onloadend = () => { + var xmlDom = null; + try { + xmlDom = Blockly.Xml.textToDom(reader.result); + const workspace = Blockly.getMainWorkspace(); + var xmlBefore = this.props.xml; + workspace.clear(); + this.props.clearStats(); + Blockly.Xml.domToWorkspace(xmlDom, workspace); + if(workspace.getAllBlocks().length < 1){ + Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xmlBefore), workspace) + this.setState({ open: true, title: 'Keine Blöcke', content: 'Es wurden keine Blöcke detektiert. Bitte überprüfe den XML-Code und versuche es erneut.' }); + } + } catch(err){ + this.setState({ open: true, title: 'Ungültige XML', content: 'Die XML-Datei konnte nicht in Blöcke zerlegt werden. Bitte überprüfe den XML-Code und versuche es erneut.' }); + } + }; + } + } + + resetWorkspace = () => { + const workspace = Blockly.getMainWorkspace(); + Blockly.Events.disable(); // https://groups.google.com/forum/#!topic/blockly/m7e3g0TC75Y + // if events are disabled, then the workspace will be cleared AND the blocks are not in the trashcan + const xmlDom = Blockly.Xml.textToDom(initialXml) + Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); + Blockly.Events.enable(); + workspace.options.maxBlocks = Infinity; + this.props.onChangeCode(); + this.props.clearStats(); + } + render() { return ( -
+
+ + + this.saveXmlFile(this.props.xml)} + > + + + +
+ {this.uploadXmlFile(e.target.files[0])}} + id="open-blocks" + type="file" + /> + +
+ + this.resetWorkspace()} + > + + + {this.state.title} @@ -45,14 +149,6 @@ class WorkspaceFunc extends Component { - - - -
); }; @@ -60,7 +156,9 @@ class WorkspaceFunc extends Component { WorkspaceFunc.propTypes = { arduino: PropTypes.string.isRequired, - xml: PropTypes.string.isRequired + xml: PropTypes.string.isRequired, + clearStats: PropTypes.func.isRequired, + onChangeCode: PropTypes.func.isRequired }; const mapStateToProps = state => ({ @@ -68,4 +166,4 @@ const mapStateToProps = state => ({ xml: state.workspace.code.xml }); -export default connect(mapStateToProps, null)(WorkspaceFunc); +export default connect(mapStateToProps, { clearStats, onChangeCode })(withStyles(styles, {withTheme: true})(WorkspaceFunc)); From 1c29dd21096afba6f798af86a8e83c09f9d31999 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:05:22 +0200 Subject: [PATCH 03/16] display statistics as menu, if screen is too small --- src/components/Home.js | 4 +- src/components/WorkspaceFunc.js | 2 +- src/components/WorkspaceStats.js | 165 +++++++++++++++++++++---------- 3 files changed, 116 insertions(+), 55 deletions(-) diff --git a/src/components/Home.js b/src/components/Home.js index 47555f9..3da011d 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -72,8 +72,8 @@ class Home extends Component { render() { return (
-
-
+
+
diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 117bf68..86a32db 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -102,7 +102,7 @@ class WorkspaceFunc extends Component { render() { return ( -
+
({ @@ -19,65 +22,123 @@ const styles = (theme) => ({ marginLeft: '50px', padding: '3px 10px', // borderRadius: '25%' + }, + menu: { + backgroundColor: theme.palette.secondary.main, + color: theme.palette.secondary.contrastText, + width: '40px', + height: '40px', + '&:hover': { + backgroundColor: theme.palette.secondary.main, + color: theme.palette.primary.main, + } } }); class WorkspaceStats extends Component { + state={ + anchor: null + } + + handleClose = () => { + this.setState({ anchor: null }); + } + + handleClick = (event) => { + this.setState({ anchor: event.currentTarget }); + }; + render() { + const bigDisplay = !isWidthDown('xs', this.props.width); const workspace = Blockly.getMainWorkspace(); const remainingBlocksInfinity = workspace ? workspace.remainingCapacity() !== Infinity : null; + const stats =
+ + } + label={workspace ? workspace.getAllBlocks().length : 0}> + + + + } + label={this.props.create > 0 ? this.props.create : 0}> {/* initialXML is created automatically, Block is not part of the statistics */} + + + + } + label={this.props.change}> + + + + } + label={this.props.move > 0 ? this.props.move : 0}> {/* initialXML is moved automatically, Block is not part of the statistics */} + + + + } + label={this.props.delete}> + + + {remainingBlocksInfinity ? + + + + : null} +
return ( -
- - } - label={workspace ? workspace.getAllBlocks().length : 0}> - - - - } - label={this.props.create > 0 ? this.props.create : 0}> {/* initialXML is created automatically, Block is not part of the statistics */} - - - - } - label={this.props.change}> - - - - } - label={this.props.move > 0 ? this.props.move : 0}> {/* initialXML is moved automatically, Block is not part of the statistics */} - - - - } - label={this.props.delete}> - - - {remainingBlocksInfinity ? - - - - : null} -
+ bigDisplay ? +
+ {stats} +
+ : +
+ + this.handleClick(event)} + > + + + + +
+ {stats} +
+
+
); }; } @@ -98,4 +159,4 @@ const mapStateToProps = state => ({ workspaceChange: state.workspace.change }); -export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(WorkspaceStats)); +export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(withWidth()(WorkspaceStats))); From 427467eb8a8b19fe33a8ad8e57e2f4c4ea4c2dbf Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:21:02 +0200 Subject: [PATCH 04/16] add workspace functions to assessment --- src/components/Tutorial/Assessment.js | 7 ++++--- src/components/Tutorial/SolutionCheck.js | 2 +- src/components/WorkspaceFunc.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index 0ff93e0..275e223 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -5,6 +5,7 @@ import { connect } from 'react-redux'; import BlocklyWindow from '../Blockly/BlocklyWindow'; import SolutionCheck from './SolutionCheck'; import CodeViewer from '../CodeViewer'; +import WorkspaceFunc from '../WorkspaceFunc'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; @@ -21,10 +22,10 @@ class Assessment extends Component { return (
- {currentTask.headline} + {currentTask.headline} +
- - + diff --git a/src/components/Tutorial/SolutionCheck.js b/src/components/Tutorial/SolutionCheck.js index 3156fc6..7d5f979 100644 --- a/src/components/Tutorial/SolutionCheck.js +++ b/src/components/Tutorial/SolutionCheck.js @@ -63,7 +63,7 @@ class SolutionCheck extends Component { this.check()} > diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 86a32db..d0414c1 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -10,6 +10,7 @@ import { saveAs } from 'file-saver'; import { initialXml } from './Blockly/initialXml.js'; import Compile from './Compile'; +import SolutionCheck from './Tutorial/SolutionCheck'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; @@ -103,7 +104,7 @@ class WorkspaceFunc extends Component { render() { return (
- + {this.props.solutionCheck ? : } Date: Tue, 15 Sep 2020 18:42:04 +0200 Subject: [PATCH 05/16] code-window is always visible for an assessment --- src/components/CodeViewer.js | 3 ++- src/components/Tutorial/Assessment.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/CodeViewer.js b/src/components/CodeViewer.js index bdf9677..e4f74da 100644 --- a/src/components/CodeViewer.js +++ b/src/components/CodeViewer.js @@ -7,6 +7,7 @@ import "prismjs/themes/prism.css"; import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; +import withWidth from '@material-ui/core/withWidth'; import { withStyles } from '@material-ui/core/styles'; import MuiAccordion from '@material-ui/core/Accordion'; import MuiAccordionSummary from '@material-ui/core/AccordionSummary'; @@ -136,4 +137,4 @@ const mapStateToProps = state => ({ xml: state.workspace.code.xml }); -export default connect(mapStateToProps, null)(CodeViewer); +export default connect(mapStateToProps, null)(withWidth()(CodeViewer)); diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index 0ff93e0..ba67f0c 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -6,6 +6,7 @@ import BlocklyWindow from '../Blockly/BlocklyWindow'; import SolutionCheck from './SolutionCheck'; import CodeViewer from '../CodeViewer'; +import withWidth, { isWidthDown } from '@material-ui/core/withWidth'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; import Typography from '@material-ui/core/Typography'; @@ -27,12 +28,12 @@ class Assessment extends Component { - + Arbeitsauftrag {currentTask.text1} -
+
@@ -54,4 +55,4 @@ const mapStateToProps = state => ({ currentTutorialId: state.tutorial.currentId }); -export default connect(mapStateToProps, null)(Assessment); +export default connect(mapStateToProps, null)(withWidth()(Assessment)); From f7f95bbf9fa85ecc9a65202bbea55afa59db53c6 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 18:50:12 +0200 Subject: [PATCH 06/16] solution check tooltip arrow --- src/components/Tutorial/SolutionCheck.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Tutorial/SolutionCheck.js b/src/components/Tutorial/SolutionCheck.js index 7d5f979..0057787 100644 --- a/src/components/Tutorial/SolutionCheck.js +++ b/src/components/Tutorial/SolutionCheck.js @@ -60,7 +60,7 @@ class SolutionCheck extends Component { const steps = tutorials.filter(tutorial => tutorial.id === this.props.currentTutorialId)[0].steps; return (
- + Date: Wed, 16 Sep 2020 10:42:18 +0200 Subject: [PATCH 07/16] set filename to save blocks as xml-file --- src/components/WorkspaceFunc.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index d0414c1..c8b6ca7 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -20,6 +20,7 @@ import DialogActions from '@material-ui/core/DialogActions'; import Dialog from '@material-ui/core/Dialog'; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; +import TextField from '@material-ui/core/TextField'; import { faSave, faUpload, faShare } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -46,23 +47,34 @@ class WorkspaceFunc extends Component { this.state = { title: '', content: '', - open: false + open: false, + fileName: '', + file: false }; } toggleDialog = () => { - this.setState({ open: !this.state }); + this.setState({ open: !this.state, fileName: '', file: false }); } saveXmlFile = (code) => { - // saveTextFileAs - var fileName = 'todo.xml' + this.toggleDialog(); + var fileName = this.state.fileName; + if(fileName === '') fileName = 'unbekannt'; + fileName = `${fileName}.xml` var blob = new Blob([code], { type: 'text/xml' }); saveAs(blob, fileName); } + createFileName = () => { + this.setState({ file: true, open: true, title: 'Blöcke speichern', content: 'Bitte gib einen Namen für die Bennenung der XML-Datei ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + } + + setFileName = (e) => { + this.setState({ fileName: e.target.value }); + } + uploadXmlFile = (xmlFile) => { - console.log(xmlFile); if(xmlFile.type !== 'text/xml'){ this.setState({ open: true, title: 'Unzulässiger Dateityp', content: 'Die übergebene Datei entsprach nicht dem geforderten Format. Es sind nur XML-Dateien zulässig.' }); } @@ -108,7 +120,7 @@ class WorkspaceFunc extends Component { this.saveXmlFile(this.props.xml)} + onClick={() => this.createFileName()} > @@ -143,6 +155,12 @@ class WorkspaceFunc extends Component { {this.state.title} {this.state.content} + {this.state.file ? +
+ + +
+ : null}
} From 71e881283d1cb3f3bf6b58b79a19a534eafbf9a4 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Wed, 16 Sep 2020 11:05:20 +0200 Subject: [PATCH 09/16] improved feedback in terms of incorrect block count and success --- src/components/Tutorial/compareXml.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Tutorial/compareXml.js b/src/components/Tutorial/compareXml.js index 5ca4619..40b6fae 100644 --- a/src/components/Tutorial/compareXml.js +++ b/src/components/Tutorial/compareXml.js @@ -12,11 +12,14 @@ const parseXml = (xmlString) => { const compareNumberOfBlocks = (originalBlocks, userBlocks) => { if(originalBlocks.length !== userBlocks.length){ + var blocks; if(originalBlocks.length > userBlocks.length){ - return {text: 'Es wurden zu wenig Blöcke verwendet.', type: 'error'}; + blocks = originalBlocks.length-userBlocks.length; + return {text: `Es wurde${blocks === 1 ? '' : 'n'} ${blocks} Bl${blocks === 1 ? 'ock' : 'öcke'} zu wenig verwendet.`, type: 'error'}; } else { - return {text: 'Es wurden zu viele Blöcke verwendet.', type: 'error'}; + blocks = userBlocks.length-originalBlocks.length; + return {text: `Es wurde${blocks === 1 ? '' : 'n'} ${blocks} Bl${blocks === 1 ? 'ock' : 'öcke'} zu viel verwendet.`, type: 'error'}; } } }; @@ -74,5 +77,5 @@ const compareXml = (originalXml, userXml) => { if(parent){return parent;} } - return {text: 'Super. Alles richtig!', type: 'success'}; + return {text: 'Super, alles richtig! Kompiliere nun die benutzen Blöcke, um eine BIN-Datei zu erhalten und damit das Programm auf die senseBox zu spielen und ausführen zu können.', type: 'success'}; }; From 73c721f237e7a4bf336c4d162c7c0d92f8675e8a Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Wed, 16 Sep 2020 11:15:55 +0200 Subject: [PATCH 10/16] improved colour contrasts concerning tutorial status --- src/components/Tutorial/Requirement.js | 10 +++++----- src/components/Tutorial/TutorialHome.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/Tutorial/Requirement.js b/src/components/Tutorial/Requirement.js index c0c70aa..2d724b8 100644 --- a/src/components/Tutorial/Requirement.js +++ b/src/components/Tutorial/Requirement.js @@ -24,15 +24,15 @@ const styles = theme => ({ color: fade(theme.palette.secondary.main, 0.6) }, outerDivError: { - stroke: fade(theme.palette.error.dark, 0.2), - color: fade(theme.palette.error.dark, 0.2) + stroke: fade(theme.palette.error.dark, 0.6), + color: fade(theme.palette.error.dark, 0.6) }, outerDivSuccess: { - stroke: fade(theme.palette.primary.main, 0.2), - color: fade(theme.palette.primary.main, 0.2) + stroke: fade(theme.palette.primary.main, 0.6), + color: fade(theme.palette.primary.main, 0.6) }, outerDivOther: { - stroke: fade(theme.palette.secondary.main, 0.2) + stroke: fade(theme.palette.secondary.main, 0.6) }, innerDiv: { width: 'inherit', diff --git a/src/components/Tutorial/TutorialHome.js b/src/components/Tutorial/TutorialHome.js index 95f775d..dd804ff 100644 --- a/src/components/Tutorial/TutorialHome.js +++ b/src/components/Tutorial/TutorialHome.js @@ -29,15 +29,15 @@ const styles = (theme) => ({ color: fade(theme.palette.secondary.main, 0.6) }, outerDivError: { - stroke: fade(theme.palette.error.dark, 0.2), - color: fade(theme.palette.error.dark, 0.2) + stroke: fade(theme.palette.error.dark, 0.6), + color: fade(theme.palette.error.dark, 0.6) }, outerDivSuccess: { - stroke: fade(theme.palette.primary.main, 0.2), - color: fade(theme.palette.primary.main, 0.2) + stroke: fade(theme.palette.primary.main, 0.6), + color: fade(theme.palette.primary.main, 0.6) }, outerDivOther: { - stroke: fade(theme.palette.secondary.main, 0.2) + stroke: fade(theme.palette.secondary.main, 0.6) }, innerDiv: { width: 'inherit', From 3c9404c5bec5c40817209517b528a6538787845f Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Wed, 16 Sep 2020 15:18:28 +0200 Subject: [PATCH 11/16] deactivate redux devtools extension --- src/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store.js b/src/store.js index bd28ae1..bf6460e 100644 --- a/src/store.js +++ b/src/store.js @@ -11,7 +11,7 @@ const store = createStore( initialState, compose( applyMiddleware(...middleware), - window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() + // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ) ); From ba84bc512cd99afc6eb0b2609cf2998198c92b97 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Thu, 17 Sep 2020 10:06:29 +0200 Subject: [PATCH 12/16] set filename to save compiled blocks --- src/actions/types.js | 1 + src/actions/workspaceActions.js | 9 ++++- src/components/Compile.js | 56 +++++++++++++++++++++++--------- src/components/WorkspaceFunc.js | 10 +++--- src/reducers/workspaceReducer.js | 10 ++++-- 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/actions/types.js b/src/actions/types.js index 27bd18d..a086a29 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -5,6 +5,7 @@ export const MOVE_BLOCK = 'MOVE_BLOCK'; export const CHANGE_BLOCK = 'CHANGE_BLOCK'; export const DELETE_BLOCK = 'DELETE_BLOCK'; export const CLEAR_STATS = 'CLEAR_STATS'; +export const NAME = 'NAME'; export const TUTORIAL_SUCCESS = 'TUTORIAL_SUCCESS'; diff --git a/src/actions/workspaceActions.js b/src/actions/workspaceActions.js index a9700c8..ab2d4e3 100644 --- a/src/actions/workspaceActions.js +++ b/src/actions/workspaceActions.js @@ -1,4 +1,4 @@ -import { NEW_CODE, CHANGE_WORKSPACE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS } from './types'; +import { NEW_CODE, CHANGE_WORKSPACE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS, NAME } from './types'; import * as Blockly from 'blockly/core'; @@ -72,3 +72,10 @@ export const clearStats = () => (dispatch) => { payload: stats }); }; + +export const workspaceName = (name) => (dispatch) => { + dispatch({ + type: NAME, + payload: name + }) +} diff --git a/src/components/Compile.js b/src/components/Compile.js index 8326d20..9c0894b 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; +import { workspaceName } from '../actions/workspaceActions'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; @@ -12,6 +13,7 @@ import DialogActions from '@material-ui/core/DialogActions'; import Dialog from '@material-ui/core/Dialog'; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; +import TextField from '@material-ui/core/TextField'; import { faCogs } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -38,15 +40,18 @@ class Compile extends Component { state = { progress: false, - open: false + open: false, + file: false, + title: '', + content: '' } compile = () => { + this.setState({ progress: true }); const data = { "board": process.env.REACT_APP_BOARD, "sketch": this.props.arduino }; - this.setState({ progress: true }); fetch(`${process.env.REACT_APP_COMPILER_URL}/compile`, { method: "POST", headers: {'Content-Type': 'application/json'}, @@ -54,23 +59,35 @@ class Compile extends Component { }) .then(response => response.json()) .then(data => { - console.log(data) - this.download(data.data.id) + console.log(data); + this.setState({id: data.data.id}, () => { + this.createFileName(); + }); }) .catch(err => { console.log(err); - this.setState({ progress: false, open: true }); + this.setState({ progress: false, file: false, open: true, title: 'Fehler', content: 'Etwas ist beim Kompilieren schief gelaufen. Versuche es nochmal.' }); }); } - download = (id) => { - const filename = 'sketch' + download = () => { + this.toggleDialog(); + const id = this.state.id; + const filename = this.props.name; window.open(`${process.env.REACT_APP_COMPILER_URL}/download?id=${id}&board=${process.env.REACT_APP_BOARD}&filename=${filename}`, '_self'); this.setState({ progress: false }); } toggleDialog = () => { - this.setState({ open: !this.state }); + this.setState({ open: !this.state, progress: false }); + } + + createFileName = () => { + this.setState({ file: true, open: true, title: 'Blöcke kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + } + + setFileName = (e) => { + this.props.workspaceName(e.target.value); } render() { @@ -86,7 +103,7 @@ class Compile extends Component {
: - } @@ -94,13 +111,19 @@ class Compile extends Component { - Fehler + {this.state.title} - Etwas ist beim Kompilieren schief gelaufen. Versuche es nochmal. + {this.state.content} + {this.state.file ? +
+ + +
+ : null}
@@ -110,11 +133,14 @@ class Compile extends Component { } Compile.propTypes = { - arduino: PropTypes.string.isRequired + arduino: PropTypes.string.isRequired, + name: PropTypes.string, + workspaceName: PropTypes.func.isRequired }; const mapStateToProps = state => ({ - arduino: state.workspace.code.arduino + arduino: state.workspace.code.arduino, + name: state.workspace.name }); -export default connect(mapStateToProps, null)(withStyles(styles, {withTheme: true})(Compile)); +export default connect(mapStateToProps, { workspaceName })(withStyles(styles, {withTheme: true})(Compile)); diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index c8b6ca7..ca87660 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -54,7 +54,7 @@ class WorkspaceFunc extends Component { } toggleDialog = () => { - this.setState({ open: !this.state, fileName: '', file: false }); + this.setState({ open: !this.state, fileName: '' }); } saveXmlFile = (code) => { @@ -76,7 +76,7 @@ class WorkspaceFunc extends Component { uploadXmlFile = (xmlFile) => { if(xmlFile.type !== 'text/xml'){ - this.setState({ open: true, title: 'Unzulässiger Dateityp', content: 'Die übergebene Datei entsprach nicht dem geforderten Format. Es sind nur XML-Dateien zulässig.' }); + this.setState({ open: true, file: false, title: 'Unzulässiger Dateityp', content: 'Die übergebene Datei entsprach nicht dem geforderten Format. Es sind nur XML-Dateien zulässig.' }); } else { var reader = new FileReader(); @@ -92,10 +92,10 @@ class WorkspaceFunc extends Component { Blockly.Xml.domToWorkspace(xmlDom, workspace); if(workspace.getAllBlocks().length < 1){ Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xmlBefore), workspace) - this.setState({ open: true, title: 'Keine Blöcke', content: 'Es wurden keine Blöcke detektiert. Bitte überprüfe den XML-Code und versuche es erneut.' }); + this.setState({ open: true, file: false, title: 'Keine Blöcke', content: 'Es wurden keine Blöcke detektiert. Bitte überprüfe den XML-Code und versuche es erneut.' }); } } catch(err){ - this.setState({ open: true, title: 'Ungültige XML', content: 'Die XML-Datei konnte nicht in Blöcke zerlegt werden. Bitte überprüfe den XML-Code und versuche es erneut.' }); + this.setState({ open: true, file: false, title: 'Ungültige XML', content: 'Die XML-Datei konnte nicht in Blöcke zerlegt werden. Bitte überprüfe den XML-Code und versuche es erneut.' }); } }; } @@ -164,7 +164,7 @@ class WorkspaceFunc extends Component { diff --git a/src/reducers/workspaceReducer.js b/src/reducers/workspaceReducer.js index dc4987f..b9e3681 100644 --- a/src/reducers/workspaceReducer.js +++ b/src/reducers/workspaceReducer.js @@ -1,4 +1,4 @@ -import { CHANGE_WORKSPACE, NEW_CODE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS } from '../actions/types'; +import { CHANGE_WORKSPACE, NEW_CODE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS, NAME } from '../actions/types'; const initialState = { @@ -12,7 +12,8 @@ const initialState = { delete: 0, move: -1 // initialXML is moved automatically, Block is not part of the statistics }, - change: 0 + change: 0, + name: null }; export default function(state = initialState, action){ @@ -36,6 +37,11 @@ export default function(state = initialState, action){ ...state, stats: action.payload }; + case NAME: + return { + ...state, + name: action.payload + } default: return state; } From 5c43ff4648395a71130605b03328766ee58ffc7f Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Thu, 17 Sep 2020 11:55:46 +0200 Subject: [PATCH 13/16] name of the workspace and display of its --- src/components/Compile.js | 43 +++++++++++++++------- src/components/Home.js | 8 ++-- src/components/WorkspaceFunc.js | 63 ++++++++++++++++++++++++-------- src/components/WorkspaceStats.js | 2 +- 4 files changed, 83 insertions(+), 33 deletions(-) diff --git a/src/components/Compile.js b/src/components/Compile.js index 9c0894b..f17e7c9 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -38,14 +38,25 @@ const styles = (theme) => ({ class Compile extends Component { - state = { - progress: false, - open: false, - file: false, - title: '', - content: '' + constructor(props){ + super(props); + this.state = { + progress: false, + open: false, + file: false, + title: '', + content: '', + name: props.name + }; } + componentDidUpdate(props){ + if(props.name !== this.props.name){ + this.setState({name: this.props.name}); + } + } + + compile = () => { this.setState({ progress: true }); const data = { @@ -71,9 +82,10 @@ class Compile extends Component { } download = () => { - this.toggleDialog(); const id = this.state.id; - const filename = this.props.name; + const filename = this.state.name; + this.toggleDialog(); + this.props.workspaceName(filename); window.open(`${process.env.REACT_APP_COMPILER_URL}/download?id=${id}&board=${process.env.REACT_APP_BOARD}&filename=${filename}`, '_self'); this.setState({ progress: false }); } @@ -83,11 +95,16 @@ class Compile extends Component { } createFileName = () => { - this.setState({ file: true, open: true, title: 'Blöcke kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + if(this.state.name){ + this.download(); + } + else{ + this.setState({ file: true, open: true, title: 'Blöcke kompilieren', content: 'Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + } } setFileName = (e) => { - this.props.workspaceName(e.target.value); + this.setState({name: e.target.value}); } render() { @@ -116,13 +133,13 @@ class Compile extends Component { {this.state.content} {this.state.file ?
- - + +
: null} - diff --git a/src/components/Home.js b/src/components/Home.js index 3da011d..1f2b6a4 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { clearStats } from '../actions/workspaceActions'; +import { clearStats, workspaceName } from '../actions/workspaceActions'; import * as Blockly from 'blockly/core'; @@ -58,6 +58,7 @@ class Home extends Component { componentWillUnmount(){ this.props.clearStats(); + this.props.workspaceName(null); } onChange = () => { @@ -100,8 +101,9 @@ class Home extends Component { } Home.propTypes = { - clearStats: PropTypes.func.isRequired + clearStats: PropTypes.func.isRequired, + workspaceName: PropTypes.func.isRequired }; -export default connect(null, { clearStats })(withStyles(styles, { withTheme: true })(Home)); +export default connect(null, { clearStats, workspaceName })(withStyles(styles, { withTheme: true })(Home)); diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index ca87660..52b2006 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; -import { clearStats, onChangeCode } from '../actions/workspaceActions'; +import { clearStats, onChangeCode, workspaceName } from '../actions/workspaceActions'; import * as Blockly from 'blockly/core'; @@ -12,6 +12,7 @@ import { initialXml } from './Blockly/initialXml.js'; import Compile from './Compile'; import SolutionCheck from './Tutorial/SolutionCheck'; +import withWidth, { isWidthDown } from '@material-ui/core/withWidth'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import DialogTitle from '@material-ui/core/DialogTitle'; @@ -21,8 +22,9 @@ import Dialog from '@material-ui/core/Dialog'; import IconButton from '@material-ui/core/IconButton'; import Tooltip from '@material-ui/core/Tooltip'; import TextField from '@material-ui/core/TextField'; +import Typography from '@material-ui/core/Typography'; -import { faSave, faUpload, faShare } from "@fortawesome/free-solid-svg-icons"; +import { faPen, faSave, faUpload, faShare } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ @@ -35,6 +37,15 @@ const styles = (theme) => ({ backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, } + }, + workspaceName: { + backgroundColor: theme.palette.secondary.main, + borderRadius: '25px', + display: 'inline-flex', + cursor: 'pointer', + '&:hover': { + color: theme.palette.primary.main, + } } }); @@ -48,30 +59,37 @@ class WorkspaceFunc extends Component { title: '', content: '', open: false, - fileName: '', - file: false + file: false, + saveXml: false, + name: props.name }; } toggleDialog = () => { - this.setState({ open: !this.state, fileName: '' }); + this.setState({ open: !this.state }); } - saveXmlFile = (code) => { + saveXmlFile = () => { + var code = this.props.xml; this.toggleDialog(); - var fileName = this.state.fileName; - if(fileName === '') fileName = 'unbekannt'; + var fileName = this.state.name; + this.props.workspaceName(fileName); fileName = `${fileName}.xml` var blob = new Blob([code], { type: 'text/xml' }); saveAs(blob, fileName); } createFileName = () => { - this.setState({ file: true, open: true, title: 'Blöcke speichern', content: 'Bitte gib einen Namen für die Bennenung der XML-Datei ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + if(this.state.name){ + this.saveXmlFile(); + } + else{ + this.setState({ file: true, saveXml: true, open: true, title: 'Blöcke speichern', content: 'Bitte gib einen Namen für die Bennenung der XML-Datei ein und bestätige diesen mit einem Klick auf \'Eingabe\'.' }); + } } setFileName = (e) => { - this.setState({ fileName: e.target.value }); + this.setState({name: e.target.value}); } uploadXmlFile = (xmlFile) => { @@ -116,6 +134,16 @@ class WorkspaceFunc extends Component { render() { return (
+ {!this.props.solutionCheck ? + +
{this.setState({file: true, open: true, saveXml: false, title: 'Projekt benennen', content: 'Bitte gib einen Namen für das Projekt ein und bestätige diesen mit einem Klick auf \'Eingabe\'.'})}}> + {this.props.name && !isWidthDown('xs', this.props.width) ? {this.props.name} : null} +
+ +
+
+
+ : null} {this.props.solutionCheck ? : } - - + +
: null} - @@ -176,13 +204,16 @@ class WorkspaceFunc extends Component { WorkspaceFunc.propTypes = { arduino: PropTypes.string.isRequired, xml: PropTypes.string.isRequired, + name: PropTypes.string, clearStats: PropTypes.func.isRequired, - onChangeCode: PropTypes.func.isRequired + onChangeCode: PropTypes.func.isRequired, + workspaceName: PropTypes.func.isRequired }; const mapStateToProps = state => ({ arduino: state.workspace.code.arduino, - xml: state.workspace.code.xml + xml: state.workspace.code.xml, + name: state.workspace.name }); -export default connect(mapStateToProps, { clearStats, onChangeCode })(withStyles(styles, {withTheme: true})(WorkspaceFunc)); +export default connect(mapStateToProps, { clearStats, onChangeCode, workspaceName })(withStyles(styles, {withTheme: true})(withWidth()(WorkspaceFunc))); diff --git a/src/components/WorkspaceStats.js b/src/components/WorkspaceStats.js index 32fbf1d..b072a34 100644 --- a/src/components/WorkspaceStats.js +++ b/src/components/WorkspaceStats.js @@ -50,7 +50,7 @@ class WorkspaceStats extends Component { }; render() { - const bigDisplay = !isWidthDown('xs', this.props.width); + const bigDisplay = !isWidthDown('sm', this.props.width); const workspace = Blockly.getMainWorkspace(); const remainingBlocksInfinity = workspace ? workspace.remainingCapacity() !== Infinity : null; const stats =
From c85c96468c69b4498392e5473ef469e15b5e525a Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Thu, 17 Sep 2020 12:56:43 +0200 Subject: [PATCH 14/16] name of tutorial workspace is automatically derived from the tutorial title and the step heading --- src/components/Compile.js | 2 +- src/components/Tutorial/Assessment.js | 18 ++++++++++++++++-- src/components/Tutorial/Tutorial.js | 8 ++++++-- src/components/WorkspaceFunc.js | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/components/Compile.js b/src/components/Compile.js index f17e7c9..19b35d4 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -120,7 +120,7 @@ class Compile extends Component { : - } diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index ead69ec..da5e7f1 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; +import { workspaceName } from '../../actions/workspaceActions'; import BlocklyWindow from '../Blockly/BlocklyWindow'; import SolutionCheck from './SolutionCheck'; @@ -14,6 +15,18 @@ import Typography from '@material-ui/core/Typography'; class Assessment extends Component { + componentDidMount(){ + // alert(this.props.name); + this.props.workspaceName(this.props.name); + } + + componentDidUpdate(props){ + if(props.name !== this.props.name){ + // alert(this.props.name); + this.props.workspaceName(this.props.name); + } + } + render() { var tutorialId = this.props.currentTutorialId; var currentTask = this.props.step; @@ -47,7 +60,8 @@ class Assessment extends Component { Assessment.propTypes = { currentTutorialId: PropTypes.number, status: PropTypes.array.isRequired, - change: PropTypes.number.isRequired + change: PropTypes.number.isRequired, + workspaceName: PropTypes.func.isRequired }; const mapStateToProps = state => ({ @@ -56,4 +70,4 @@ const mapStateToProps = state => ({ currentTutorialId: state.tutorial.currentId }); -export default connect(mapStateToProps, null)(withWidth()(Assessment)); +export default connect(mapStateToProps, { workspaceName })(withWidth()(Assessment)); diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js index e2a9d38..fb4d452 100644 --- a/src/components/Tutorial/Tutorial.js +++ b/src/components/Tutorial/Tutorial.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; +import { workspaceName } from '../../actions/workspaceActions'; import { tutorialId, tutorialStep } from '../../actions/tutorialActions'; import Breadcrumbs from '../Breadcrumbs'; @@ -29,6 +30,7 @@ class Tutorial extends Component { componentWillUnmount(){ this.props.tutorialId(null); + this.props.workspaceName(null); } render() { @@ -36,6 +38,7 @@ class Tutorial extends Component { var tutorial = tutorials.filter(tutorial => tutorial.id === currentTutorialId)[0]; var steps = tutorial ? tutorial.steps : null; var step = steps ? steps[this.props.activeStep] : null; + var name = step ? `${tutorial.title.replace(/\s/g,'')}_${step.headline.replace(/\s/g,'')}` : null; return ( !Number.isInteger(currentTutorialId) || currentTutorialId < 1 || currentTutorialId > tutorials.length ? @@ -52,7 +55,7 @@ class Tutorial extends Component { {step ? step.type === 'instruction' ? - : // if step.type === 'assessment' + : // if step.type === 'assessment' : null}
@@ -69,6 +72,7 @@ class Tutorial extends Component { Tutorial.propTypes = { tutorialId: PropTypes.func.isRequired, tutorialStep: PropTypes.func.isRequired, + workspaceName: PropTypes.func.isRequired, currentTutorialId: PropTypes.number, status: PropTypes.array.isRequired, change: PropTypes.number.isRequired, @@ -82,4 +86,4 @@ const mapStateToProps = state => ({ activeStep: state.tutorial.activeStep }); -export default connect(mapStateToProps, { tutorialId, tutorialStep })(Tutorial); +export default connect(mapStateToProps, { tutorialId, tutorialStep, workspaceName })(Tutorial); diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 52b2006..856dea5 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -65,6 +65,12 @@ class WorkspaceFunc extends Component { }; } + componentDidUpdate(props){ + if(props.name !== this.props.name){ + this.setState({name: this.props.name}); + } + } + toggleDialog = () => { this.setState({ open: !this.state }); } @@ -112,6 +118,12 @@ class WorkspaceFunc extends Component { Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xmlBefore), workspace) this.setState({ open: true, file: false, title: 'Keine Blöcke', content: 'Es wurden keine Blöcke detektiert. Bitte überprüfe den XML-Code und versuche es erneut.' }); } + else { + if(!this.props.solutionCheck){ + var extensionPosition = xmlFile.name.lastIndexOf('.'); + this.props.workspaceName(xmlFile.name.substr(0, extensionPosition)); + } + } } catch(err){ this.setState({ open: true, file: false, title: 'Ungültige XML', content: 'Die XML-Datei konnte nicht in Blöcke zerlegt werden. Bitte überprüfe den XML-Code und versuche es erneut.' }); } @@ -129,6 +141,9 @@ class WorkspaceFunc extends Component { workspace.options.maxBlocks = Infinity; this.props.onChangeCode(); this.props.clearStats(); + if(!this.props.solutionCheck){ + this.props.workspaceName(null); + } } render() { From bde430dd40d0289968b5de67ca6ce75a1c33011e Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Thu, 17 Sep 2020 13:24:00 +0200 Subject: [PATCH 15/16] detect whitespaces and return readable filename --- src/components/Compile.js | 6 ++++-- src/components/Tutorial/SolutionCheck.js | 2 +- src/components/Tutorial/Tutorial.js | 4 +++- src/components/WorkspaceFunc.js | 5 +++-- .../Tutorial => helpers}/compareXml.js | 0 src/helpers/whitespace.js | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 6 deletions(-) rename src/{components/Tutorial => helpers}/compareXml.js (100%) create mode 100644 src/helpers/whitespace.js diff --git a/src/components/Compile.js b/src/components/Compile.js index 19b35d4..f1945f6 100644 --- a/src/components/Compile.js +++ b/src/components/Compile.js @@ -3,6 +3,8 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { workspaceName } from '../actions/workspaceActions'; +import { detectWhitespacesAndReturnReadableResult } from '../helpers/whitespace'; + import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import Backdrop from '@material-ui/core/Backdrop'; @@ -83,9 +85,9 @@ class Compile extends Component { download = () => { const id = this.state.id; - const filename = this.state.name; + const filename = detectWhitespacesAndReturnReadableResult(this.state.name); this.toggleDialog(); - this.props.workspaceName(filename); + this.props.workspaceName(this.state.name); window.open(`${process.env.REACT_APP_COMPILER_URL}/download?id=${id}&board=${process.env.REACT_APP_BOARD}&filename=${filename}`, '_self'); this.setState({ progress: false }); } diff --git a/src/components/Tutorial/SolutionCheck.js b/src/components/Tutorial/SolutionCheck.js index 0057787..084d2d1 100644 --- a/src/components/Tutorial/SolutionCheck.js +++ b/src/components/Tutorial/SolutionCheck.js @@ -8,7 +8,7 @@ import { withRouter } from 'react-router-dom'; import Compile from '../Compile'; import tutorials from './tutorials.json'; -import { checkXml } from './compareXml'; +import { checkXml } from '../../helpers/compareXml'; import { withStyles } from '@material-ui/core/styles'; import IconButton from '@material-ui/core/IconButton'; diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js index fb4d452..48438d3 100644 --- a/src/components/Tutorial/Tutorial.js +++ b/src/components/Tutorial/Tutorial.js @@ -11,6 +11,8 @@ import Instruction from './Instruction'; import Assessment from './Assessment'; import NotFound from '../NotFound'; +import { detectWhitespacesAndReturnReadableResult } from '../../helpers/whitespace'; + import tutorials from './tutorials.json'; import Card from '@material-ui/core/Card'; @@ -38,7 +40,7 @@ class Tutorial extends Component { var tutorial = tutorials.filter(tutorial => tutorial.id === currentTutorialId)[0]; var steps = tutorial ? tutorial.steps : null; var step = steps ? steps[this.props.activeStep] : null; - var name = step ? `${tutorial.title.replace(/\s/g,'')}_${step.headline.replace(/\s/g,'')}` : null; + var name = step ? `${detectWhitespacesAndReturnReadableResult(tutorial.title)}_${detectWhitespacesAndReturnReadableResult(step.headline)}` : null; return ( !Number.isInteger(currentTutorialId) || currentTutorialId < 1 || currentTutorialId > tutorials.length ? diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 856dea5..2beff96 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -7,6 +7,7 @@ import * as Blockly from 'blockly/core'; import { saveAs } from 'file-saver'; +import { detectWhitespacesAndReturnReadableResult } from '../helpers/whitespace'; import { initialXml } from './Blockly/initialXml.js'; import Compile from './Compile'; @@ -78,8 +79,8 @@ class WorkspaceFunc extends Component { saveXmlFile = () => { var code = this.props.xml; this.toggleDialog(); - var fileName = this.state.name; - this.props.workspaceName(fileName); + var fileName = detectWhitespacesAndReturnReadableResult(this.state.name); + this.props.workspaceName(this.state.name); fileName = `${fileName}.xml` var blob = new Blob([code], { type: 'text/xml' }); saveAs(blob, fileName); diff --git a/src/components/Tutorial/compareXml.js b/src/helpers/compareXml.js similarity index 100% rename from src/components/Tutorial/compareXml.js rename to src/helpers/compareXml.js diff --git a/src/helpers/whitespace.js b/src/helpers/whitespace.js new file mode 100644 index 0000000..e51bae2 --- /dev/null +++ b/src/helpers/whitespace.js @@ -0,0 +1,15 @@ +export const detectWhitespacesAndReturnReadableResult = (word) => { + var readableResult = ''; + var space = false; + for(var i = 0; i < word.length; i++){ + var letter = word[i]; + if(/\s/g.test(letter)){ + space = true; + } + else { + readableResult += space ? letter.toUpperCase() : letter; + space = false; + } + } + return readableResult; +}; From d70207ea1ac3939499ad158e9ea1bf9c39635f4c Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Thu, 17 Sep 2020 14:13:30 +0200 Subject: [PATCH 16/16] breadcrumbs with inital home-link --- src/components/Breadcrumbs.js | 36 ++++++++++++++++++++----- src/components/NotFound.js | 2 +- src/components/Tutorial/Tutorial.js | 2 +- src/components/Tutorial/TutorialHome.js | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/components/Breadcrumbs.js b/src/components/Breadcrumbs.js index 71a57ea..dc0af20 100644 --- a/src/components/Breadcrumbs.js +++ b/src/components/Breadcrumbs.js @@ -1,27 +1,49 @@ import React, { Component } from 'react'; import { Link } from 'react-router-dom'; +import clsx from 'clsx'; -import Breadcrumbs from '@material-ui/core/Breadcrumbs'; +import { withStyles } from '@material-ui/core/styles'; +import MaterialUIBreadcrumbs from '@material-ui/core/Breadcrumbs'; import Typography from '@material-ui/core/Typography'; -class MyBreadcrumbs extends Component { +import { faHome } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +const styles = (theme) => ({ + home: { + color: theme.palette.secondary.main, + width: '20px !important', + height: '20px', + marginTop: '2px' + }, + hover: { + '&:hover': { + color: theme.palette.primary.main + } + } +}); + +class Breadcrumbs extends Component { render() { return ( - this.props.content && this.props.content.length > 1 ? - + this.props.content && this.props.content.length > 0 ? + + + + {this.props.content.splice(0, this.props.content.length-1).map((content, i) => ( - {content.title} + {content.title} ))} {this.props.content.slice(-1)[0].title} - + : null ); }; } -export default MyBreadcrumbs; +export default withStyles(styles, {withTheme: true})(Breadcrumbs); diff --git a/src/components/NotFound.js b/src/components/NotFound.js index 44b3ddb..85a9c6f 100644 --- a/src/components/NotFound.js +++ b/src/components/NotFound.js @@ -11,7 +11,7 @@ class NotFound extends Component { render() { return (
- + Die von Ihnen angeforderte Seite kann nicht gefunden werden. Die gesuchte Seite wurde möglicherweise entfernt, ihr Name wurde geändert oder sie ist vorübergehend nicht verfügbar. {this.props.button ? diff --git a/src/components/Tutorial/Tutorial.js b/src/components/Tutorial/Tutorial.js index 48438d3..acce0c9 100644 --- a/src/components/Tutorial/Tutorial.js +++ b/src/components/Tutorial/Tutorial.js @@ -46,7 +46,7 @@ class Tutorial extends Component { :
- + diff --git a/src/components/Tutorial/TutorialHome.js b/src/components/Tutorial/TutorialHome.js index dd804ff..2bf99f2 100644 --- a/src/components/Tutorial/TutorialHome.js +++ b/src/components/Tutorial/TutorialHome.js @@ -54,7 +54,7 @@ class TutorialHome extends Component { render() { return (
- +

Tutorial-Übersicht