Impressum
|
diff --git a/src/components/Home.js b/src/components/Home.js
index 64b4237..7aed6c4 100644
--- a/src/components/Home.js
+++ b/src/components/Home.js
@@ -1,51 +1,55 @@
import React, { Component } from 'react';
+import * as Blockly from 'blockly/core';
+
import WorkspaceStats from './WorkspaceStats';
import WorkspaceFunc from './WorkspaceFunc';
+import BlocklyWindow from './Blockly/BlocklyWindow';
+import CodeViewer from './CodeViewer';
-import BlocklyComponent, { Block, Value, Field, Shadow, Category } from './Blockly';
-import * as Blockly from 'blockly/core';
-import * as De from './Blockly/msg/de'; // de locale files
-//import * as En from './Blockly/msg/en'; // de locale files
-import './Blockly/blocks/';
-import './Blockly/generator/';
+import Grid from '@material-ui/core/Grid';
+import FormControlLabel from '@material-ui/core/FormControlLabel';
+import Switch from '@material-ui/core/Switch';
+class Home extends Component {
-
-
-class Home extends React.Component {
- constructor(props) {
- super(props);
-
- this.simpleWorkspace = React.createRef();
- this.state = { generatedCode: 'Click text' }
+ state = {
+ codeOn: false
}
- componentDidMount() {
-
- let workspace = Blockly.getMainWorkspace();
- workspace.addChangeListener(this.generateCode);
+ componentDidUpdate() {
+ /* Resize and reposition all of the workspace chrome (toolbox, trash,
+ scrollbars etc.) This should be called when something changes that requires
+ recalculating dimensions and positions of the trash, zoom, toolbox, etc.
+ (e.g. window resize). */
+ const workspace = Blockly.getMainWorkspace();
+ Blockly.svgResize(workspace);
}
- generateCode = () => {
- var code = Blockly.Arduino.workspaceToCode(this.workspace);
- console.log(code);
- this.setState({ generatedCode: code })
+ onChange = () => {
+ this.setState({ codeOn: !this.state.codeOn });
}
render() {
return (
-
-
+
+
+ }
+ label="Code"
+ />
+
+
+ {this.state.codeOn ?
+
+
+
+ : null}
+
+
);
};
diff --git a/src/components/MaxBlocks.js b/src/components/MaxBlocks.js
index 014fe2e..bf4981a 100644
--- a/src/components/MaxBlocks.js
+++ b/src/components/MaxBlocks.js
@@ -1,7 +1,9 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
-import { setWorkspace } from '../actions/workspaceActions';
+import { workspaceChange } from '../actions/workspaceActions';
+
+import * as Blockly from 'blockly/core';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
@@ -16,20 +18,23 @@ class MaxBlocks extends Component {
this.setState({ [e.target.name]: e.target.value});
}
+ setMaxBlocks = () => {
+ const workspace = Blockly.getMainWorkspace();
+ workspace.options.maxBlocks = this.state.max;
+ this.props.workspaceChange();
+ }
+
render() {
- // var blockLeft = Object.keys(this.props.newWorkspace).length > 0 ?
{this.props.newWorkspace.remainingCapacity()} verbleibende Blöcke möglich
: null
- // var error = this.state.error ?
{this.state.error}
: null;
return (
-
@@ -38,12 +43,7 @@ class MaxBlocks extends Component {
}
MaxBlocks.propTypes = {
- newWorkspace: PropTypes.object.isRequired,
- setWorkspace: PropTypes.func.isRequired
+ workspaceChange: PropTypes.func.isRequired
};
-const mapStateToProps = state => ({
- newWorkspace: state.workspace.new
-});
-
-export default connect(mapStateToProps, { setWorkspace })(MaxBlocks);
+export default connect(null, { workspaceChange })(MaxBlocks);
diff --git a/src/components/Navbar.js b/src/components/Navbar.js
index a72d41a..cd6ebf7 100644
--- a/src/components/Navbar.js
+++ b/src/components/Navbar.js
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import ClearWorkspace from './ClearWorkspace';
+import senseboxLogo from './sensebox_logo.svg';
import { withStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
@@ -51,7 +52,7 @@ class Navbar extends Component {
style={{height: '50px', marginBottom: '30px'}}
classes={{root: this.props.classes.appBarColor}}
>
-
+
+
+
+
-
-
-
+
+
+
+
+
+
);
}
}
diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js
index 110324e..2bf4c11 100644
--- a/src/components/WorkspaceFunc.js
+++ b/src/components/WorkspaceFunc.js
@@ -18,11 +18,12 @@ class WorkspaceFunc extends Component {
open: false
}
-
+ getArduinoCode = () => {
+ this.setState({ title: 'Adurino Code', content: this.props.arduino, open: true });
+ }
getXMLCode = () => {
- var code = window.Ardublockly.generateXml();
- this.setState({ title: 'XML Code', content: code, open: true });
+ this.setState({ title: 'XML Code', content: this.props.xml, open: true });
}
toggleDialog = () => {
@@ -43,15 +44,12 @@ class WorkspaceFunc extends Component {
- this.props.generateCode()}>
+ this.getArduinoCode()}>
Get Adurino Code
- this.getXMLCode()}>
+ this.getXMLCode()}>
Get XML Code
- { var blocks = this.props.newWorkspace; console.log(blocks); }}>
- Get workspace
-
);
@@ -59,11 +57,13 @@ class WorkspaceFunc extends Component {
}
WorkspaceFunc.propTypes = {
- newWorkspace: PropTypes.object.isRequired
+ arduino: PropTypes.string.isRequired,
+ xml: PropTypes.string.isRequired
};
const mapStateToProps = state => ({
- newWorkspace: state.workspace.new
+ arduino: state.workspace.code.arduino,
+ xml: state.workspace.code.xml
});
export default connect(mapStateToProps, null)(WorkspaceFunc);
diff --git a/src/components/WorkspaceStats.js b/src/components/WorkspaceStats.js
index 7eadd99..2317d79 100644
--- a/src/components/WorkspaceStats.js
+++ b/src/components/WorkspaceStats.js
@@ -2,11 +2,13 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
+import * as Blockly from 'blockly/core';
+
import { withStyles } from '@material-ui/core/styles';
import Tooltip from '@material-ui/core/Tooltip';
import Typography from '@material-ui/core/Typography';
-import { faPuzzlePiece, faTrash, faPlus, faPen } from "@fortawesome/free-solid-svg-icons";
+import { faPuzzlePiece, faTrash, faPlus, faPen, faArrowsAlt } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
const styles = (theme) => ({
@@ -22,13 +24,14 @@ const styles = (theme) => ({
class WorkspaceStats extends Component {
render() {
- // var check = Object.keys(this.props.newWorkspace).length > 0 && this.props.create - this.props.delete !== this.props.newWorkspace.getAllBlocks().length ?
FEHLER!
: null;
+ const workspace = Blockly.getMainWorkspace();
+ const remainingBlocksInfinity = workspace ? workspace.remainingCapacity() !== Infinity : null;
return (
-
+
- {Object.keys(this.props.newWorkspace).length > 0 ? this.props.newWorkspace.getAllBlocks().length : 0}
+ {workspace ? workspace.getAllBlocks().length : 0}
@@ -45,6 +48,13 @@ class WorkspaceStats extends Component {
{this.props.change}
+
+
+
+
+ {this.props.move}
+
+
@@ -52,29 +62,29 @@ class WorkspaceStats extends Component {
{this.props.delete}
- {Object.keys(this.props.newWorkspace).length > 0 ? this.props.newWorkspace.remainingCapacity() !== Infinity ?
+ {remainingBlocksInfinity ?
- {this.props.delete} verbleibende Blöcke
- : null : null}
+
{workspace.remainingCapacity()} verbleibende Blöcke
+ : null}
);
};
}
WorkspaceStats.propTypes = {
- newWorkspace: PropTypes.object.isRequired,
create: PropTypes.number.isRequired,
change: PropTypes.number.isRequired,
delete: PropTypes.number.isRequired,
- test: PropTypes.number.isRequired
+ move: PropTypes.number.isRequired,
+ worskpaceChange: PropTypes.number.isRequired
};
const mapStateToProps = state => ({
- newWorkspace: state.workspace.new,
create: state.workspace.stats.create,
change: state.workspace.stats.change,
delete: state.workspace.stats.delete,
- test: state.workspace.test
+ move: state.workspace.stats.move,
+ worskpaceChange: state.workspace.change
});
export default connect(mapStateToProps, null)(withStyles(styles, {withTheme: true})(WorkspaceStats));
diff --git a/src/components/sensebox_logo.svg b/src/components/sensebox_logo.svg
new file mode 100644
index 0000000..82eb0e1
--- /dev/null
+++ b/src/components/sensebox_logo.svg
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/src/reducers/workspaceReducer.js b/src/reducers/workspaceReducer.js
index df9e4bb..c5bc543 100644
--- a/src/reducers/workspaceReducer.js
+++ b/src/reducers/workspaceReducer.js
@@ -1,27 +1,34 @@
-import { NEW_WORKSPACE, CREATE_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 } from '../actions/types';
const initialState = {
- old: {},
- new: {},
+ code: {
+ arduino: '',
+ xml: ''
+ },
stats: {
create: 0,
change: 0,
delete: 0,
+ move: 0
},
- test: 0
+ change: 0
};
export default function(state = initialState, action){
switch(action.type){
- case NEW_WORKSPACE:
+ case NEW_CODE:
return {
...state,
- old: action.payload.old,
- new: action.payload.new,
- test: state.test += 1
+ code: action.payload
+ };
+ case CHANGE_WORKSPACE:
+ return {
+ ...state,
+ change: state.change += 1
};
case CREATE_BLOCK:
+ case MOVE_BLOCK:
case CHANGE_BLOCK:
case DELETE_BLOCK:
case CLEAR_STATS: