From f543b3796852294472fc112c6b539f377f027f94 Mon Sep 17 00:00:00 2001 From: Fontaine Date: Mon, 6 Jan 2020 14:51:30 +0100 Subject: [PATCH] v1.7 --- www/blocs&generateurs/_iot.js | 705 ++++++++++++++++++++++++++++++++++ 1 file changed, 705 insertions(+) create mode 100644 www/blocs&generateurs/_iot.js diff --git a/www/blocs&generateurs/_iot.js b/www/blocs&generateurs/_iot.js new file mode 100644 index 00000000..2960d66f --- /dev/null +++ b/www/blocs&generateurs/_iot.js @@ -0,0 +1,705 @@ +"use strict"; +goog.provide("Blockly.Blocks.arduino"); +goog.require("Blockly.Blocks"); + //////////// + /* html */ +//////////// +Blockly.Blocks['emptyVar'] = { + init: function() { + this.jsonInit({ + "message0": '%1', + "args0": [ + { + "type": "field_variable", + "name": "VAR", + "variable": Blockly.Msg.VARIABLES_GET_ITEM + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": "#FFA500" + }); + } +}; +Blockly.Arduino['emptyVar'] = function(block) { + var value = block.getFieldValue('value'); + var code = '");\n'; + code += ''+looseEscape(value)+'");\n'; + return code +}; +Blockly.Python['emptyVar'] = function(block) { + return "'''+ "+Blockly.Python.variableDB_.getName(block.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE)+" +'''" +}; +////////////// +Blockly.Blocks['emptytext'] = { + init: function() { + this.jsonInit({ + "message0": '%1', + "args0": [ + { + "type": "field_input", + "name": "content", + "text": "un texte." + } + ], + "previousStatement": "textcontainer", + "nextStatement": "textcontainer", + "colour": "#FD6C9E" + }); + } +}; +Blockly.Arduino['emptytext'] = function(block) { + var text_content = block.getFieldValue('content'); + return looseEscape(text_content) +}; +Blockly.Python['emptytext'] = function(block) { + var text_content = block.getFieldValue('content'); + return looseEscape(text_content) +}; +////////////// +Blockly.Blocks['textmod'] = { + init: function() { + this.jsonInit({ + "message0": '< %1 > %2 %3 ', + "args0": [ + { + "type": "field_dropdown", + "name": "type", + "options": [ + [ + "gras", + "strong" + ], + [ + "italique", + "em" + ] + ] + }, + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "content" + } + ], + "previousStatement": "textcontainer", + "nextStatement": "textcontainer", + "colour": "#FD6C9E" + }); + } +}; +Blockly.Arduino['textmod'] = function(block){ + var content = Blockly.Arduino.statementToCode(block,'content'); + var type = block.getFieldValue("type"); + return '<' + type + '>' + content + '' +}; +Blockly.Python['textmod'] = function(block){ + var content = Blockly.Python.statementToCode(block,'content'); + var type = block.getFieldValue("type"); + return '<' + type + '>' + content + '' +}; +////////////// +Blockly.Blocks['paragraph'] = { + init: function() { + this.jsonInit({ + "message0": '

%1 %2

', + "args0": [ + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": "textcontainer" + } + ], + "previousStatement": "html", + "nextStatement": "html", + "colour": "#000000" + }); + } +}; +Blockly.Arduino['paragraph'] = function(block) { + var statements_content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier'); + return '' + statements_content + '

");\n' +}; +Blockly.Python['paragraph'] = function(block) { + var statements_content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier'); + return '' + statements_content + '

\n' +}; +////////////// +Blockly.Blocks['header'] = { + init: function() { + this.jsonInit({ + "message0": ' %2 %3 ', + "args0": [ + { + "type": "field_dropdown", + "name": "size", + "options": [["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"], +] + }, + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": "textcontainer" + } + ], + "previousStatement": "html", + "nextStatement": "html", + "colour": "#000000" + }); + } +}; +Blockly.Arduino['header'] = function(block) { + var statements_content = Blockly.Arduino.statementToCode(block, 'content'); + var header_size = block.getFieldValue("size"); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + statements_content + '");\n' +}; +Blockly.Python['header'] = function(block) { + var statements_content = Blockly.Python.statementToCode(block, 'content'); + var header_size = block.getFieldValue("size"); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + statements_content + '\n' +}; +////////////// +Blockly.Blocks['link'] = { + init: function() { + this.jsonInit({ + "message0": ' %2 %3 ', + "args0": [ + { + "type": "field_input", + "name": "target", + "text": "http://" + }, + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "content", + "check": "textcontainer" + } + ], + "previousStatement": "textcontainer", + "nextStatement": "textcontainer", + "colour": "#FD6C9E" + }); + } +}; +Blockly.Arduino['link'] = function(block){ + var text = Blockly.Arduino.statementToCode(block, 'content'); + var link = URLInput(block.getFieldValue('target')); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + text + '' +}; +Blockly.Python['link'] = function(block){ + var text = Blockly.Python.statementToCode(block, 'content'); + var link = URLInput(block.getFieldValue('target')); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Python.ORDER_ATOMIC); + return '' + text + '' +}; +////////////// +Blockly.Blocks['table'] = { + init: function() { + this.jsonInit({ + "message0": ' %1 %2
', + "args0": [ + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": "table" + } + ], + "previousStatement": "html", + "nextStatement": "html", + "colour": "#727272" + }); + } +}; +Blockly.Arduino['table'] = function(block){ + var content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + content + '");\n' +}; +Blockly.Python['table'] = function(block){ + var content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Python.ORDER_ATOMIC); + return '\n' + content + '\n' +}; +////////////// +Blockly.Blocks['tablerow'] = { + init: function() { + this.jsonInit({ + "message0": ' %1 %2 ', + "args0": [ + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": "tablerow" + } + ], + "previousStatement": "table", + "nextStatement": "table", + "colour": "#727272" + }); + } +}; +Blockly.Arduino['tablerow'] = function(block){ + var content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + content + '' +}; +Blockly.Python['tablerow'] = function(block){ + var content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + content + '\n' +}; +////////////// +Blockly.Blocks['tableheading'] = { + init: function() { + this.jsonInit({ + "message0": ' %1 %2 ', + "args0": [ + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": ["html","textcontainer"] + } + ], + "previousStatement": "tablerow", + "nextStatement": "tablerow", + "colour": "#727272" + }); + } +}; +Blockly.Arduino['tableheading'] = function(block){ + var content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + content + '' +}; +Blockly.Python['tableheading'] = function(block){ + var content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Python.ORDER_ATOMIC); + return '' + content + '\n' +}; +////////////// +Blockly.Blocks['tabledata'] = { + init: function() { + this.jsonInit({ + "message0": ' %1 %2 ', + "args0": [ + { + "type": "input_value", + "name": "modifier", + "check": "attributes" + }, + { + "type": "input_statement", + "name": "content", + "check": ["html","textcontainer"] + } + ], + "previousStatement": "tablerow", + "nextStatement": "tablerow", + "colour": "#727272" + }); + } +}; +Blockly.Arduino['tabledata'] = function(block){ + var content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '' + content + '' +}; +Blockly.Python['tabledata'] = function(block){ + var content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Python.ORDER_ATOMIC); + return '' + content + '' +}; +////////////// +Blockly.Blocks['image'] = { + init: function() { + this.jsonInit({ + "message0": '', + "args0": [ + { + "type": "field_input", + "name": "source", + "text": "http://lesormeaux.net/img/puzzle-piece.png" + } + ], + "previousStatement": "html", + "nextStatement": "html", + "colour": "#000000" + }); + } +}; +Blockly.Arduino['image'] = function(block){ + var source = block.getFieldValue('source'); + var code = '");\n'; + return code +}; +Blockly.Python['image'] = function(block){ + var source = block.getFieldValue('source'); + var code = '\n'; + return code +}; +////////////// +Blockly.Blocks['args'] = { + init: function() { + this.jsonInit({ + "message0": 'style : %1 %2', + "args0": [ + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "content", + "check": "stylecontent" + } + ], + "colour": "#00CC00", + "output": "attributes" + }); + } +}; +Blockly.Arduino['args'] = function(block) { + var code = Blockly.Arduino.statementToCode(block, 'content'); + return 'style=\\"' + code + '\\"' +}; +Blockly.Python['args'] = function(block) { + var code = Blockly.Python.statementToCode(block, 'content'); + return 'style=\"' + code + '\"' +}; +////////////// +Blockly.Blocks['color'] = { + init: function() { + this.jsonInit({ + "message0": 'color: %1 ;', + "args0": [ + { + "type": "field_colour", + "name": "value", + "colour": "#FF0000" + + } + ], + "previousStatement": "stylecontent", + "nextStatement": "stylecontent", + "colour": "#00CC00" + }); + } +}; +Blockly.Arduino['color'] = function(block){ + var color = block.getFieldValue('value'); + return 'color : ' + color + ' ; ' +}; +Blockly.Python['color'] = function(block){ + var color = block.getFieldValue('value'); + return 'color: ' + color + '; ' +}; +////////////// +Blockly.Blocks['bgcolor'] = { + init: function() { + this.jsonInit({ + "message0": 'background-color: %1 ;', + "args0": [ + { + "type": "field_colour", + "name": "value", + "colour": "#339999" + } + ], + "previousStatement": "stylecontent", + "nextStatement": "stylecontent", + "colour": "#00CC00" + }); + } +}; +Blockly.Arduino['bgcolor'] = function(block){ + var color = block.getFieldValue('value'); + return 'background-color : ' + color + ' ; ' +}; +Blockly.Python['bgcolor'] = function(block){ + var color = block.getFieldValue('value'); + return 'background-color: ' + color + '; ' +}; +////////////// +Blockly.Blocks['textalign'] = { + init: function(){ + this.jsonInit({ + "message0": "text-align: %1 ;", + "args0": [ + { + "type": "field_dropdown", + "name": "value", + "options": [ + ["center", "center"], + ["left", "left"], + ["right", "right"] + ] + } + ], + "previousStatement": "stylecontent", + "nextStatement": "stylecontent", + "colour": "#00CC00" + }) + } +}; +Blockly.Arduino['textalign'] = function(block){ + var value = block.getFieldValue('value'); + return 'text-align : ' + value + ' ; ' +}; +Blockly.Python['textalign'] = function(block){ + var value = block.getFieldValue('value'); + return 'text-align: ' + value + '; ' +}; +////////////// +Blockly.Blocks['border'] = { + init: function() { + this.jsonInit({ + "message0": 'border: %1 px %2 %3 ;', + "args0": [ + { + "type": "field_number", + "name": "width", + "value": 2, + "min": 1 + }, + { + "type": "field_dropdown", + "name": "type", + "options": [ + [ + "solid", + "solid" + ], + [ + "dotted", + "dotted" + ], + [ + "dashed", + "dashed" + ], + [ + "double", + "double" + ] + ] + }, + { + "type": "field_colour", + "name": "color", + "colour": "#000000" + } + ], + "previousStatement": "stylecontent", + "nextStatement": "stylecontent", + "colour": "#00CC00" + }); + } +}; +Blockly.Arduino['border'] = function(block){ + var width = fullEscape(block.getFieldValue('width')); + var type = block.getFieldValue('type'); + var color = block.getFieldValue('color'); + return 'border : ' + width + 'px ' + type + ' ' + color + ' ; ' +}; +Blockly.Python['border'] = function(block){ + var width = fullEscape(block.getFieldValue('width')); + var type = block.getFieldValue('type'); + var color = block.getFieldValue('color'); + return 'border: ' + width + 'px ' + type + ' ' + color + '; ' +}; +////////////// +Blockly.Blocks['input'] = { + init: function() { + this.jsonInit({ + "message0": '', + "args0": [ + { + "type": "field_dropdown", + "name": "type", + "options": [["checkbox","checkbox"],["radio","radio"],["submit","submit"],["text","text"]] + }, + { + "type": "field_input", + "name": "value", + "text": "" + } + ], + "previousStatement": "form", + "nextStatement": "form", + "colour": "#154360" + }); + } +}; +Blockly.Arduino['input'] = function(block){ + var type = block.getFieldValue('type'); + var value = looseEscape(block.getFieldValue('value')); + return ''; +}; +Blockly.Python['input'] = function(block){ + var type = block.getFieldValue('type'); + var value = looseEscape(block.getFieldValue('value')); + return '\n'; +}; +////////////// +Blockly.Blocks['form'] = { + init: function() { + this.jsonInit({ + "message0": '
%3 %4
', + "args0": [ + { + "type": "field_input", + "name": "action", + "text": "/" + }, + { + "type": "field_dropdown", + "name": "method", + "options": [["GET","GET"],["POST","POST"],["PUT","PUT"]] + }, + { + "type": "input_dummy" + }, + { + "type": "input_statement", + "name": "content", + "check": "form" + } + ], + "previousStatement": "html", + "nextStatement": "html", + "colour": "#154360" + }); + } +}; +Blockly.Arduino['form'] = function(block){ + var action = block.getFieldValue('action'); + var method = block.getFieldValue('method'); + var content = Blockly.Arduino.statementToCode(block, 'content'); + var block_modifier = Blockly.Arduino.statementToCode(block, 'modifier', Blockly.Arduino.ORDER_ATOMIC); + return '
' + content + '
");\n' +}; +Blockly.Python['form'] = function(block){ + var action = block.getFieldValue('action'); + var method = block.getFieldValue('method'); + var content = Blockly.Python.statementToCode(block, 'content'); + var block_modifier = Blockly.Python.statementToCode(block, 'modifier', Blockly.Python.ORDER_ATOMIC); + return '
\n' + content + '
\n' +}; +////////////// +Blockly.Blocks['label'] = { + init: function() { + this.jsonInit({ + "message0": '', + "args0": [ + { + "type": "field_input", + "name": "for", + "text": "" + }, + { + "type": "field_input", + "name": "value", + "text": "" + } + ], + "previousStatement": "form", + "nextStatement": "form", + "colour": "#154360" + }); + } +}; +Blockly.Arduino['label'] = function(block){ + var content = block.getFieldValue('value'); + var for_value = block.getFieldValue('for'); + return '\n' +}; +Blockly.Python['label'] = function(block){ + var content = block.getFieldValue('value'); + var for_value = block.getFieldValue('for'); + return '\n' +}; +////////////// +Blockly.Blocks['br'] = { + init: function() { + this.jsonInit({ + "message0": '
', + "args0": [ + { + "type": "field_dummy" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": "#000000" + }); + } +}; +Blockly.Arduino['br'] = function(block){ + return '
' +}; +Blockly.Python['br'] = function(block){ + return '
\n' +}; + //////////////// + /* function */ +//////////////// +function fullEscape(input){ + return escape(input) + .replace(/%25/g, "%"); +} +function looseEscape(input) { + return input + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} +function CSSEscape(input) { + return input + .replace(/;/g, "") + .replace(/{/g, "") + .replace(/}/g, "") + .replace(/