diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index efd8bf7..21f7392 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -1,20 +1,18 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { onChangeWorkspace, clearStats } from '../../actions/workspaceActions'; +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { connect } from "react-redux"; +import { onChangeWorkspace, clearStats } from "../../actions/workspaceActions"; -import BlocklyComponent from './BlocklyComponent'; -import BlocklySvg from './BlocklySvg'; +import BlocklyComponent from "./BlocklyComponent"; +import BlocklySvg from "./BlocklySvg"; -import * as Blockly from 'blockly/core'; -import './blocks/index'; -import './generator/index'; - -import { initialXml } from './initialXml.js'; +import * as Blockly from "blockly/core"; +import "./blocks/index"; +import "./generator/index"; +import { initialXml } from "./initialXml.js"; class BlocklyWindow extends Component { - constructor(props) { super(props); this.simpleWorkspace = React.createRef(); @@ -41,6 +39,7 @@ class BlocklyWindow extends Component { Blockly.Events.disableOrphans(event); } }); + Blockly.svgResize(workspace); } @@ -64,46 +63,65 @@ class BlocklyWindow extends Component { // workspace.updateToolbox(toolbox.toolboxDef_); } Blockly.svgResize(workspace); - } render() { return (
- - - {this.props.svg && this.props.initialXml ? : null} + grid={ + this.props.grid !== undefined && !this.props.grid + ? {} + : { + // https://developers.google.com/blockly/guides/configure/web/grid + spacing: 20, + length: 1, + colour: "#4EAF47", // senseBox-green + snap: false, + } + } + media={"/media/blockly/"} + move={ + this.props.move !== undefined && !this.props.move + ? {} + : { + // https://developers.google.com/blockly/guides/configure/web/move + scrollbars: true, + drag: true, + wheel: false, + } + } + initialXml={ + this.props.initialXml ? this.props.initialXml : initialXml + } + > + {this.props.svg && this.props.initialXml ? ( + + ) : null}
); - }; + } } BlocklyWindow.propTypes = { @@ -114,10 +132,12 @@ BlocklyWindow.propTypes = { workspaceXML: PropTypes.string.isRequired, }; -const mapStateToProps = state => ({ +const mapStateToProps = (state) => ({ renderer: state.general.renderer, language: state.general.language.Blockly, workspaceXML: state.workspace.code.xml, }); -export default connect(mapStateToProps, { onChangeWorkspace, clearStats })(BlocklyWindow); +export default connect(mapStateToProps, { onChangeWorkspace, clearStats })( + BlocklyWindow +); diff --git a/src/components/Blockly/blocks/variables.js b/src/components/Blockly/blocks/variables.js index 6984263..8e19984 100644 --- a/src/components/Blockly/blocks/variables.js +++ b/src/components/Blockly/blocks/variables.js @@ -1,43 +1,46 @@ -import Blockly from 'blockly/core'; -import { getColour } from '../helpers/colour'; -import { getCompatibleTypes } from '../helpers/types' - - -Blockly.Blocks['variables_set_dynamic'] = { - init: function () { - - // const type = myVar.type; - this.setColour(getColour().variables); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.appendValueInput('VALUE') - .appendField('set', 'set') - .appendField('', 'type') - .appendField(new Blockly.FieldVariable('VAR'), 'VAR') - .appendField('to'); - }, - onchange: function (e) { - let variableID = this.getFieldValue('VAR'); - let variable = Blockly.getMainWorkspace().getVariableMap().getVariableById(variableID) - this.getField('type').setValue(variable.type); - this.getInput('VALUE').setCheck(getCompatibleTypes(variable.type)); +import Blockly from "blockly/core"; +import { getColour } from "../helpers/colour"; +import { getCompatibleTypes } from "../helpers/types"; +Blockly.Blocks["variables_set_dynamic"] = { + init: function () { + // const type = myVar.type; + this.setColour(getColour().variables); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.appendValueInput("VALUE") + .appendField("set", "set") + .appendField("", "type") + .appendField(new Blockly.FieldVariable("VAR"), "VAR") + .appendField("to"); + }, + onchange: function (e) { + let variableID = this.getFieldValue("VAR"); + let variable = Blockly.getMainWorkspace() + .getVariableMap() + .getVariableById(variableID); + if (variable !== null) { + this.getField("type").setValue(variable.type); + this.getInput("VALUE").setCheck(getCompatibleTypes(variable.type)); } -} - -Blockly.Blocks['variables_get_dynamic'] = { - init: function () { - this.setColour(getColour().variables); - this.appendDummyInput() - .appendField('', 'type') - .appendField(new Blockly.FieldVariable('VAR'), 'VAR'); - this.setOutput(true); - }, - onchange: function (e) { - let variableID = this.getFieldValue('VAR'); - let variable = Blockly.getMainWorkspace().getVariableMap().getVariableById(variableID) - this.getField('type').setValue(variable.type); + }, +}; +Blockly.Blocks["variables_get_dynamic"] = { + init: function () { + this.setColour(getColour().variables); + this.appendDummyInput() + .appendField("", "type") + .appendField(new Blockly.FieldVariable("VAR"), "VAR"); + this.setOutput(true); + }, + onchange: function (e) { + let variableID = this.getFieldValue("VAR"); + let variable = Blockly.getMainWorkspace() + .getVariableMap() + .getVariableById(variableID); + if (variable !== null) { + this.getField("type").setValue(variable.type); } -} - + }, +}; diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 06b9f76..3c8b238 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -10,6 +10,16 @@ export const UI = { toolbox_time: "Zeit", toolbox_functions: "Funktionen", toolbox_variables: "Variablen", + variable_NUMBER: "Zahl (int)", + variable_SHORT_NUMBER: "char", + variable_LONG: "große Zahl (long)", + variable_DECIMAL: "Kommazahl (float)", + variables_TEXT: "Text (string)", + variables_ARRAY: "Array (array)", + variables_CHARACTER: "char (char)", + variables_BOOLEAN: "Boolean (boolean)", + variables_NULL: "void (void)", + variables_UNDEF: "undefined", /** * Tooltips diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index 3428980..63089be 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -10,6 +10,16 @@ export const UI = { toolbox_time: "Time", toolbox_functions: "Functions", toolbox_variables: "Variables", + variable_NUMBER: "Number (int)", + variable_SHORT_NUMBER: "char", + variable_LONG: " Zahl (long)", + variable_DECIMAL: "Decimal (float)", + variables_TEXT: "Text (string)", + variables_ARRAY: "Array (array)", + variables_CHARACTER: "char (char)", + variables_BOOLEAN: "Boolean (boolean)", + variables_NULL: "void (void)", + variables_UNDEF: "undefined", /** * Tooltips diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 713bce3..9d65862 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -1,495 +1,557 @@ -import React from 'react'; -import { Block, Value, Field, Shadow, Category } from '../'; -import { getColour } from '../helpers/colour' -import '@blockly/block-plus-minus'; -import { TypedVariableModal } from '@blockly/plugin-typed-variable-modal'; -import * as Blockly from 'blockly/core'; - - - +import React from "react"; +import { Block, Value, Field, Shadow, Category } from "../"; +import { getColour } from "../helpers/colour"; +import "@blockly/block-plus-minus"; +import { TypedVariableModal } from "@blockly/plugin-typed-variable-modal"; +import * as Blockly from "blockly/core"; class Toolbox extends React.Component { + componentDidUpdate() { + this.props.workspace.registerToolboxCategoryCallback( + "CREATE_TYPED_VARIABLE", + this.createFlyout + ); - componentDidUpdate() { - this.props.workspace.registerToolboxCategoryCallback('CREATE_TYPED_VARIABLE', this.createFlyout); + const typedVarModal = new TypedVariableModal( + this.props.workspace, + "callbackName", + [ + [`${Blockly.Msg.variable_SHORT_NUMBER}`, "char"], + [`${Blockly.Msg.variable_NUMBER}`, "int"], + [`${Blockly.Msg.variable_LONG}`, "long"], + [`${Blockly.Msg.variable_DECIMAL}`, "float"], + [`${Blockly.Msg.variables_TEXT}`, "String"], + [`${Blockly.Msg.variables_ARRAY}`, "Array"], + [`${Blockly.Msg.variables_CHARACTER}`, "char"], + [`${Blockly.Msg.variables_BOOLEAN}`, "boolean"], + [`${Blockly.Msg.variables_NULL}`, "void"], + [`${Blockly.Msg.variables_UNDEF}`, "undefined"], + ] + ); + typedVarModal.init(); + } - const typedVarModal = new TypedVariableModal(this.props.workspace, 'callbackName', [['SHORT_NUMBER', 'char'], ['NUMBER', 'int'], ['DECIMAL', 'float'], ['TEXT', 'String'], ['ARRAY', 'Array'], ['CHARACTER', 'char'], ['BOOLEAN', 'boolean'], ['NULL', 'void'], ['UNDEF', 'undefined']]); - typedVarModal.init(); - } + createFlyout(workspace) { + let xmlList = []; - createFlyout(workspace) { + // Add your button and give it a callback name. + const button = document.createElement("button"); + button.setAttribute("text", "Create Typed Variable"); + button.setAttribute("callbackKey", "callbackName"); - let xmlList = []; + xmlList.push(button); - // Add your button and give it a callback name. - const button = document.createElement('button'); - button.setAttribute('text', 'Create Typed Variable'); - button.setAttribute('callbackKey', 'callbackName'); + // This gets all the variables that the user creates and adds them to the + // flyout. + const blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace); + xmlList = xmlList.concat(blockList); + return xmlList; + } - xmlList.push(button); - - // This gets all the variables that the user creates and adds them to the - // flyout. - const blockList = Blockly.VariablesDynamic.flyoutCategoryBlocks(workspace); - xmlList = xmlList.concat(blockList); - return xmlList; - }; - - render() { - return ( - - - - - - - - - - - - - - - - {/* */} - - - - - - - - - - - - - - - - - - - - - - 1 - - - - - 30 - - - - - - - 0 - - - - - 0 - - - - - - - - - 100 - - - - - 50 - - - - - 0 - - - - - - - - - - - - 1 - - - - - 0 - - - - - 0 - - - - - - - Title - - - - - Unit - - - - - Title - - - - - Unit - - - - - - - - - - - - - - - - - - - 0 - - - - - 15 - - - - - 0 - - - - - 50 - - - - - 5 - - - - - 0 - - - - - 15 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - latitude - - - - - longitude - - - - - altitude - - - - - pDOP - - - - - fixType - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {/* */} - - - - - - - - - - - - - - - 10 - - - - - - - - 1 - - - - - 10 - - - - - 1 - - - - - - - - - - - - - - - - - - - - - 1000 - - - - - - - 100 - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - - 1 - - - - - 100 - - - - - - - 1 - - - - - 100 - - - - - - - - - - - 220 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 100 - - - - - {/* this block is the initial block of the workspace; not necessary + render() { + return ( + + + + + + + + + + + + + + + + {/* */} + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + 30 + + + + + + + 0 + + + + + 0 + + + + + + + + + 100 + + + + + 50 + + + + + 0 + + + + + + + + + + + + 1 + + + + + 0 + + + + + 0 + + + + + + + Title + + + + + Unit + + + + + Title + + + + + Unit + + + + + + + + + + + + + + + + 0 + + + + + 15 + + + + + 0 + + + + + 50 + + + + + 5 + + + + + 0 + + + + + 15 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + latitude + + + + + longitude + + + + + altitude + + + + + pDOP + + + + + fixType + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {/* */} + + + + + + + + + + + + + + + 10 + + + + + + + + 1 + + + + + 10 + + + + + 1 + + + + + + + + + + + + + + + + + + + + + 1000 + + + + + + + 100 + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + 1 + + + + + 100 + + + + + + + 1 + + + + + 100 + + + + + + + + + + + 220 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + {/* this block is the initial block of the workspace; not necessary to display, because it can only be used once anyway */} - - ); - }; + + ); + } } export default Toolbox; diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index fa4d1c4..5dd24b7 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -1,20 +1,20 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import { workspaceName } from '../../actions/workspaceActions'; +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 CodeViewer from '../CodeViewer'; -import WorkspaceFunc from '../Workspace/WorkspaceFunc'; +import BlocklyWindow from "../Blockly/BlocklyWindow"; +import CodeViewer from "../CodeViewer"; +import WorkspaceFunc from "../Workspace/WorkspaceFunc"; -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'; -import * as Blockly from 'blockly' +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"; +import * as Blockly from "blockly"; +import { initialXml } from "../Blockly/initialXml"; class Assessment extends Component { - componentDidMount() { this.props.workspaceName(this.props.name); } @@ -28,48 +28,90 @@ class Assessment extends Component { render() { var tutorialId = this.props.tutorial._id; var currentTask = this.props.step; - var status = this.props.status.filter(status => status._id === tutorialId)[0]; - var taskIndex = status.tasks.findIndex(task => task._id === currentTask._id); + var status = this.props.status.filter( + (status) => status._id === tutorialId + )[0]; + var taskIndex = status.tasks.findIndex( + (task) => task._id === currentTask._id + ); var statusTask = status.tasks[taskIndex]; return ( -
- {currentTask.headline} -
- +
+ + {currentTask.headline} + +
+ +
+ - - - {Blockly.Msg.tutorials_assessment_task} + + + + {Blockly.Msg.tutorials_assessment_task} + {currentTask.text} -
+
); - }; + } } Assessment.propTypes = { status: PropTypes.array.isRequired, change: PropTypes.number.isRequired, workspaceName: PropTypes.func.isRequired, - tutorial: PropTypes.object.isRequired + tutorial: PropTypes.object.isRequired, }; -const mapStateToProps = state => ({ +const mapStateToProps = (state) => ({ change: state.tutorial.change, status: state.tutorial.status, - tutorial: state.tutorial.tutorials[0] + tutorial: state.tutorial.tutorials[0], }); -export default connect(mapStateToProps, { workspaceName })(withWidth()(Assessment)); +export default connect(mapStateToProps, { workspaceName })( + withWidth()(Assessment) +); diff --git a/src/components/Tutorial/Instruction.js b/src/components/Tutorial/Instruction.js index ade6dfb..fc72447 100644 --- a/src/components/Tutorial/Instruction.js +++ b/src/components/Tutorial/Instruction.js @@ -1,57 +1,95 @@ -import React, { Component } from 'react'; +import React, { Component } from "react"; -import Hardware from './Hardware'; -import Requirement from './Requirement'; -import BlocklyWindow from '../Blockly/BlocklyWindow'; - -import Grid from '@material-ui/core/Grid'; -import Typography from '@material-ui/core/Typography'; -import ReactMarkdown from 'react-markdown' +import Hardware from "./Hardware"; +import Requirement from "./Requirement"; +import BlocklyWindow from "../Blockly/BlocklyWindow"; +import Grid from "@material-ui/core/Grid"; +import Typography from "@material-ui/core/Typography"; +import ReactMarkdown from "react-markdown"; class Instruction extends Component { - render() { var step = this.props.step; var isHardware = step.hardware && step.hardware.length > 0; var areRequirements = step.requirements && step.requirements.length > 0; return (
- {step.headline} - {step.text} - {isHardware ? - : null} - {areRequirements > 0 ? - : null} - {step.media ? - step.media.picture ? -
- -
- : step.media.youtube ? - /*16:9; width: 800px; height: width/16*9=450px*/ -
-
-