Skip to content

Commit

Permalink
Updated blockly learning object rendering using the simulator readonl…
Browse files Browse the repository at this point in the history
…y endpoint (work in progress)
  • Loading branch information
tomneutens committed Nov 4, 2022
1 parent 8e58f5e commit 6109b27
Show file tree
Hide file tree
Showing 303 changed files with 58,553 additions and 3,806 deletions.
40 changes: 36 additions & 4 deletions app/processors/blockly/blockly_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let logger = Logger.getLogger()
class BlocklyProcessor extends Processor {
constructor() {
super();
this.blockly_base_url = process.env.SIMULATOR_BASE_PATH;
this.blockly_base_url = process.env.SIMULATOR_READONLY_BASE_PATH;
}

/**
Expand All @@ -18,7 +18,7 @@ class BlocklyProcessor extends Processor {
* @param {object} args Optional arguments specific to the render function of the BlocklyProcessor
* @returns
*/
render(blocklyXml, args = { language: "nl", id: "" }) {
render(blocklyXml, args = { language: "nl", id: "" }, {height = 315, aspect_ratio = 'iframe-16-9'} = {}) {
if (!args.language || args.language.trim() == "") {
args.language = "nl";
}
Expand All @@ -33,7 +33,39 @@ class BlocklyProcessor extends Processor {
throw new InvalidArgumentError("The blockly XML is undefined. Please provide correct XML code.")
}

let html = `
let simulatorUrl = `${this.blockly_base_url}?lang=${args.language}`

let form = `
<form action="${simulatorUrl}" method="post" id="blockly_form_${args.id}" target="blockly_iframe_${args.id}">
<input type="hidden" value='${blocklyXml}'>
</form>
`

let iframe = `
<div class="iframe-container ${aspect_ratio}"><iframe name="blockly_iframe_${args.id}" width="420px" height="${height}px" src="${simulatorUrl}" allowfullscreen></iframe></div>
`

let code = `(function(){
var auto = setTimeout(function(){ submitform(); }, 100);
function submitform(){
alert('test');
document.forms["blockly_form_${args.id}"].submit();
}
function autoRefresh(){
clearTimeout(auto);
auto = setTimeout(function(){ submitform(); autoRefresh(); }, 10000);
}
})()
`

let script = `<script>${code}</script>`

let html = DOMPurify.sanitize(form + iframe, { ADD_TAGS: ["iframe"], ADD_ATTR: ['allow', 'allowfullscreen', 'frameborder', 'scrolling']});
html = html + script;

/*let html = `
<div id="blocklyDiv_${args.id}" class="blocklyDiv" style="height: 480px; "></div>
<div id="simulator_link">
<form formtarget="_blank" target="_blank" method="post" action="${this.blockly_base_url}" target="_blank">
Expand Down Expand Up @@ -96,7 +128,7 @@ class BlocklyProcessor extends Processor {
}
loadScript${args.id}(0)
</script>
`
`*/
return html; //TODO is not sanitized using DOMPurify.sanitize (problems with script tags)
}

Expand Down
129 changes: 129 additions & 0 deletions app/static/js/arduino_compressed.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions app/static/js/blockly.js

This file was deleted.

1,239 changes: 0 additions & 1,239 deletions app/static/js/blockly_compressed_new.js

This file was deleted.

191 changes: 191 additions & 0 deletions app/static/js/blockly_uncompressed.js

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions app/static/js/blocks/backup2/arduino.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* @license
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Dwenguino blocks for Blockly.
* @author [email protected]
*/
'use strict';

// goog.provide('Blockly.Blocks.arduino');

// goog.require('Blockly.Blocks');

var ArduinoHelpUrl = "http://www.arduino.cc";

// Blockly.Blocks.arduino.HUE = 100;

var setup_loop_arduino_json = {
"type": "setup_loop_structure_arduino",
"message0": MSG.setup + " %1 %2 " + MSG.loop + "%3 %4",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "SETUP"
},
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "LOOP"
}
],
"colour": 100,
"tooltip": MSG.dwenguino_main_program_structure,
"helpUrl": ArduinoHelpUrl,
"data": "testdatastring"
};

Blockly.Blocks['setup_loop_structure_arduino'] = {
init: function () {
this.jsonInit(setup_loop_arduino_json);
}
};

Blockly.Blocks['inout_digital_read'] = {
helpUrl: 'http://arduino.cc/en/Reference/DigitalRead',
init: function () {
this.setColour(230);
this.appendDummyInput()
.appendField("DigitalRead PIN#")
.appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN");
this.setOutput(true, 'Number');
this.setTooltip('');
}
};

Blockly.Blocks['inout_digital_write'] = {
helpUrl: 'http://arduino.cc/en/Reference/DigitalWrite',
init: function () {
this.setColour(230);
this.appendDummyInput()
.appendField("DigitalWrite PIN#")
.appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN")
.appendField("Stat")
.appendField(new Blockly.FieldDropdown([["HIGH", "HIGH"], ["LOW", "LOW"]]), "STAT");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Write digital value to a specific Port');
}
};
125 changes: 125 additions & 0 deletions app/static/js/blocks/backup2/colour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* @license
* Copyright 2012 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Colour blocks for Blockly.
*
* This file is scraped to extract a .json file of block definitions. The array
* passed to defineBlocksWithJsonArray(..) must be strict JSON: double quotes
* only, no outside references, no functions, no trailing commas, etc. The one
* exception is end-of-line comments, which the scraper will remove.
* @author [email protected] (Neil Fraser)
*/



/**
* Unused constant for the common HSV hue for all blocks in this category.
* @deprecated Use Blockly.Msg['COLOUR_HUE']. (2018 April 5)
*/
let colorHue = 20;

Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
// Block for colour picker.
{
"type": "colour_picker",
"message0": "%1",
"args0": [
{
"type": "field_colour",
"name": "COLOUR",
"colour": "#ff0000"
}
],
"output": "Colour",
"helpUrl": "%{BKY_COLOUR_PICKER_HELPURL}",
"style": "colour_blocks",
"tooltip": "%{BKY_COLOUR_PICKER_TOOLTIP}",
"extensions": ["parent_tooltip_when_inline"]
},

// Block for random colour.
{
"type": "colour_random",
"message0": "%{BKY_COLOUR_RANDOM_TITLE}",
"output": "Colour",
"helpUrl": "%{BKY_COLOUR_RANDOM_HELPURL}",
"style": "colour_blocks",
"tooltip": "%{BKY_COLOUR_RANDOM_TOOLTIP}"
},

// Block for composing a colour from RGB components.
{
"type": "colour_rgb",
"message0": "%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3",
"args0": [
{
"type": "input_value",
"name": "RED",
"check": "Number",
"align": "RIGHT"
},
{
"type": "input_value",
"name": "GREEN",
"check": "Number",
"align": "RIGHT"
},
{
"type": "input_value",
"name": "BLUE",
"check": "Number",
"align": "RIGHT"
}
],
"output": "Colour",
"helpUrl": "%{BKY_COLOUR_RGB_HELPURL}",
"style": "colour_blocks",
"tooltip": "%{BKY_COLOUR_RGB_TOOLTIP}"
},

// Block for blending two colours together.
{
"type": "colour_blend",
"message0": "%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} " +
"%1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3",
"args0": [
{
"type": "input_value",
"name": "COLOUR1",
"check": "Colour",
"align": "RIGHT"
},
{
"type": "input_value",
"name": "COLOUR2",
"check": "Colour",
"align": "RIGHT"
},
{
"type": "input_value",
"name": "RATIO",
"check": "Number",
"align": "RIGHT"
}
],
"output": "Colour",
"helpUrl": "%{BKY_COLOUR_BLEND_HELPURL}",
"style": "colour_blocks",
"tooltip": "%{BKY_COLOUR_BLEND_TOOLTIP}"
}
]); // END JSON EXTRACT (Do not delete this comment.)
43 changes: 43 additions & 0 deletions app/static/js/blocks/backup2/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @license
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Dwenguino blocks for Blockly.
* @author [email protected]
*/
'use strict';

// goog.provide('Blockly.Blocks.comments');

// goog.require('Blockly.Blocks');

Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
// Block for text value
{
"type": "line_comment",
"message0": "// %1",
"args0": [{
"type": "field_input",
"name": "TEXT",
"text": ""
}],
"colour": 10,
"previousStatement": null,
"nextStatement": null,
"helpUrl": "",
"tooltip": "",
},
]);
Loading

0 comments on commit 6109b27

Please sign in to comment.