fix bugs concerning uploading json
This commit is contained in:
parent
7579be52c9
commit
3ba35751ea
@ -1,5 +1,7 @@
|
||||
import { PROGRESS, BUILDER_CHANGE, BUILDER_ERROR, BUILDER_TITLE, BUILDER_ID, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP, BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from './types';
|
||||
|
||||
import data from '../data/hardware.json';
|
||||
|
||||
export const changeTutorialBuilder = () => (dispatch) => {
|
||||
dispatch({
|
||||
type: BUILDER_CHANGE
|
||||
@ -162,8 +164,23 @@ export const setSubmitError = () => (dispatch, getState) => {
|
||||
}
|
||||
for(var i = 0; i < builder.steps.length; i++){
|
||||
builder.steps[i].id = i+1;
|
||||
if(i === 0 && (builder.steps[i].hardware === undefined || builder.steps[i].hardware.length < 1)){
|
||||
dispatch(setError(i, 'hardware'));
|
||||
if(i === 0){
|
||||
if(builder.steps[i].requirements && builder.steps[i].requirements.length > 0){
|
||||
var requirements = builder.steps[i].requirements.filter(requirement => typeof(requirement)==='number');
|
||||
if(requirements.length < builder.steps[i].requirements.length){
|
||||
dispatch(changeContent(i, 'requirements', requirements));
|
||||
}
|
||||
}
|
||||
if(builder.steps[i].hardware === undefined || builder.steps[i].hardware.length < 1){
|
||||
dispatch(setError(i, 'hardware'));
|
||||
}
|
||||
else{
|
||||
var hardwareIds = data.map(hardware => hardware.id);
|
||||
var hardware = builder.steps[i].hardware.filter(hardware => hardwareIds.includes(hardware));
|
||||
if(hardware.length < builder.steps[i].hardware.length){
|
||||
dispatch(changeContent(i, 'hardware', hardware));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(builder.steps[i].headline === undefined || builder.steps[i].headline === ''){
|
||||
dispatch(setError(i, 'headline'));
|
||||
|
@ -79,8 +79,18 @@ class BlocklyExample extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
moment.locale('de', localization);
|
||||
var initialXml = this.props.value;
|
||||
// check if value is valid xml;
|
||||
try{
|
||||
Blockly.Xml.textToDom(initialXml);
|
||||
}
|
||||
catch(err){
|
||||
initialXml = null;
|
||||
this.props.setError(this.props.index, 'xml');
|
||||
}
|
||||
return (
|
||||
<div style={{marginBottom: '10px'}}>
|
||||
<FormControlLabel
|
||||
@ -100,34 +110,23 @@ class BlocklyExample extends Component {
|
||||
<FormHelperText style={{lineHeight: 'initial', marginBottom: '10px'}} className={this.props.classes.errorColor}>Reiche deine Blöcke ein, indem du auf den rot gefärbten Button klickst.</FormHelperText>
|
||||
: <FormHelperText style={{lineHeight: 'initial', marginBottom: '10px'}}>Die letzte Einreichung erfolgte um {this.state.input} Uhr.</FormHelperText>
|
||||
: null}
|
||||
{this.state.checked ? () => {
|
||||
var initialXml = this.props.value;
|
||||
// check if value is valid xml;
|
||||
try{
|
||||
Blockly.Xml.textToDom(initialXml);
|
||||
}
|
||||
catch(err){
|
||||
initialXml = null;
|
||||
this.props.setError(this.props.index, 'xml');
|
||||
}
|
||||
return(
|
||||
<div>
|
||||
<Grid container className={!this.props.value ? this.props.classes.errorBorder : null}>
|
||||
<Grid item xs={12}>
|
||||
<BlocklyWindow initialXml={initialXml}/>
|
||||
</Grid>
|
||||
{this.state.checked ?
|
||||
<div>
|
||||
<Grid container className={!this.props.value ? this.props.classes.errorBorder : null}>
|
||||
<Grid item xs={12}>
|
||||
<BlocklyWindow initialXml={initialXml}/>
|
||||
</Grid>
|
||||
<Button
|
||||
className={!this.props.value || this.props.error.steps[this.props.index].xml ? this.props.classes.errorButton : null }
|
||||
style={{marginTop: '5px', height: '40px'}}
|
||||
variant='contained'
|
||||
color='primary'
|
||||
onClick={() => {this.props.changeContent(this.props.index, 'xml', this.props.xml); this.setState({input: moment(Date.now()).format('LTS')})}}
|
||||
>
|
||||
{this.props.task ? 'Musterlösung einreichen' : 'Beispiel einreichen'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</Grid>
|
||||
<Button
|
||||
className={!this.props.value || this.props.error.steps[this.props.index].xml ? this.props.classes.errorButton : null }
|
||||
style={{marginTop: '5px', height: '40px'}}
|
||||
variant='contained'
|
||||
color='primary'
|
||||
onClick={() => {this.props.changeContent(this.props.index, 'xml', this.props.xml); this.setState({input: moment(Date.now()).format('LTS')})}}
|
||||
>
|
||||
{this.props.task ? 'Musterlösung einreichen' : 'Beispiel einreichen'}
|
||||
</Button>
|
||||
</div>
|
||||
: null}
|
||||
</div>
|
||||
);
|
||||
|
@ -67,15 +67,12 @@ class Builder extends Component {
|
||||
reader.onloadend = () => {
|
||||
try {
|
||||
var result = JSON.parse(reader.result);
|
||||
if(this.checkSteps(result.steps)){
|
||||
alert('Hier');
|
||||
this.props.readJSON(result);
|
||||
}
|
||||
else{
|
||||
this.props.progress(false);
|
||||
alert('die JSON-Datei hat nicht die richtige Form');
|
||||
if(!this.checkSteps(result.steps)){
|
||||
result.steps = [{}];
|
||||
}
|
||||
this.props.readJSON(result);
|
||||
} catch(err){
|
||||
console.log(err);
|
||||
this.props.progress(false);
|
||||
alert('ungültige JSON-Datei');
|
||||
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.' });
|
||||
@ -86,34 +83,8 @@ class Builder extends Component {
|
||||
|
||||
checkSteps = (steps) => {
|
||||
if(!(steps && steps.length > 0)){
|
||||
alert(1);
|
||||
return false;
|
||||
}
|
||||
steps.map((step, i) => {
|
||||
if(i === 0){
|
||||
if(!(step.requirements &&
|
||||
step.requirements.length > 0 &&
|
||||
step.requirements.filter(requirement => typeof(requirement) === 'number').length === step.requirements.length)){
|
||||
alert(3);
|
||||
return false;
|
||||
}
|
||||
var hardwareIds = data.map(hardware => hardware.id);
|
||||
if(!(step.hardware &&
|
||||
step.hardware.length > 0 &&
|
||||
step.hardware.filter(hardware => typeof(hardware) === 'string' && hardwareIds.includes(hardware)).length === step.hardware.length)){
|
||||
alert(4);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!(step.headline && typeof(step.headline)==='string')){
|
||||
alert(5);
|
||||
return false;
|
||||
}
|
||||
if(!(step.text && typeof(step.text)==='string')){
|
||||
alert(6);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user