fix bugs concerning uploading json
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user