diff --git a/src/public/google-blockly/own/blocks_action.js b/src/public/google-blockly/own/blocks_action.js index 08da5498b..d9c390d02 100644 --- a/src/public/google-blockly/own/blocks_action.js +++ b/src/public/google-blockly/own/blocks_action.js @@ -11,7 +11,7 @@ Blockly.CustomBlocks.push('Action'); Blockly.Action = { HUE: 330, - blocks: {} + blocks: {}, }; // --- action exec -------------------------------------------------- @@ -116,6 +116,48 @@ Blockly.JavaScript['exec'] = function(block) { } }; +// --- action http_get -------------------------------------------------- +Blockly.Action.blocks['http_get'] = + '' + + ' ' + + ' ' + + ' http://' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + +Blockly.Blocks['http_get'] = { + init: function() { + this.appendValueInput('URL') + .appendField(Blockly.Translate('http_get')); + + this.appendStatementInput('STATEMENT') + .setCheck(null); + + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + + this.setColour(Blockly.Action.HUE); + this.setTooltip(Blockly.Translate('http_get_tooltip')); + this.setHelpUrl(getHelp('http_get_help')); + } +}; + +Blockly.JavaScript['http_get'] = function(block) { + const URL = Blockly.JavaScript.valueToCode(block, 'URL', Blockly.JavaScript.ORDER_ATOMIC); + const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT'); + + return `httpGet(${URL}, { timeout: 2000 }, async (response) => {\n` + + Blockly.JavaScript.prefixLines(`if (response && response.err) {`, Blockly.JavaScript.INDENT) + '\n' + + Blockly.JavaScript.prefixLines(`console.error(response.err);`, Blockly.JavaScript.INDENT + Blockly.JavaScript.INDENT) + '\n' + + Blockly.JavaScript.prefixLines(`}`, Blockly.JavaScript.INDENT) + '\n' + + statement + + '});\n'; +}; + // --- action request -------------------------------------------------- Blockly.Action.blocks['request'] = '' @@ -202,6 +244,8 @@ Blockly.JavaScript['request'] = function(block) { logText = ''; } + logText += `console.warn('request blockly block is deprecated - please use "http get" instead');\n`; + if (withStatement === 'TRUE' || withStatement === 'true' || withStatement === true) { const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT'); if (statement) { diff --git a/src/public/google-blockly/own/blocks_words.js b/src/public/google-blockly/own/blocks_words.js index d1886f002..a4dcf4009 100644 --- a/src/public/google-blockly/own/blocks_words.js +++ b/src/public/google-blockly/own/blocks_words.js @@ -43,8 +43,14 @@ Blockly.Words['exec_log_debug'] = {'en': 'debug', Blockly.Words['exec_log_warn'] = {'en': 'warning', 'de': 'warning', 'ru': 'warning', 'pt': 'atenção', 'nl': 'waarschuwing', 'fr': 'Attention', 'it': 'avvertimento', 'es': 'advertencia', 'pl': 'warning', 'zh-cn': '警告信息', 'uk': 'УВАГА'}; Blockly.Words['exec_log_error'] = {'en': 'error', 'de': 'error', 'ru': 'ошибка', 'pt': 'erro', 'nl': 'fout', 'fr': 'Erreur', 'it': 'errore', 'es': 'error', 'pl': 'error', 'zh-cn': '错误信息', 'uk': 'помилка'}; +// --- action http_get -------------------------------------------------- + +Blockly.Words['http_get'] = {'en': 'http (GET)', 'de': 'http (GET)', 'ru': 'http (GET)', 'pt': 'http (GET)', 'nl': 'http (GET)', 'fr': 'http (GET)', 'it': 'http (GET)', 'es': 'http (GET)', 'pl': 'http (GET)', 'zh-cn': 'http (GET)', 'uk': 'http (GET)'}; +Blockly.Words['http_get_tooltip'] = {'en': 'Request ressources via http', 'de': 'Ressourcen anfordern via http', 'ru': 'Запрос ресурсов через http', 'pt': 'Solicitar recursos via http', 'nl': 'Resources aanvragen via http', 'fr': 'Demander des ressources via http', 'it': 'Richiesta di risorse via http', 'es': 'Solicitar ressources via http', 'pl': 'Wniosek o ponowne źródła informacji za pośrednictwem http', 'zh-cn': '通过 http 请求资源源', 'uk': 'Запит ресурсів через HTTP'}; +Blockly.Words['http_get_help'] = {'en': 'httpGet', 'de': 'httpGet', 'ru': 'httpGet', 'pt': 'httpGet', 'nl': 'httpGet', 'fr': 'httpGet', 'it': 'httpGet', 'es': 'httpGet', 'pl': 'httpGet', 'zh-cn': 'httpGet', 'uk': 'httpGet'}; + // --- action request -------------------------------------------------- -Blockly.Words['request'] = {'en': 'request', 'de': 'request', 'ru': 'request', 'pt': 'request', 'nl': 'verzoek', 'fr': 'demande', 'it': 'richiesta', 'es': 'solicitud', 'pl': 'request', 'zh-cn': '请求网址', 'uk': 'запит'}; +Blockly.Words['request'] = {'en': 'request (deprecated)', 'de': 'request (deprecated)', 'ru': 'request (deprecated)', 'pt': 'request (deprecated)', 'nl': 'verzoek (deprecated)', 'fr': 'demande (deprecated)', 'it': 'richiesta (deprecated)', 'es': 'solicitud (deprecated)', 'pl': 'request (deprecated)', 'zh-cn': '请求网址 (deprecated)', 'uk': 'запит (deprecated)'}; Blockly.Words['request_url'] = {'en': 'URL', 'de': 'URL', 'ru': 'URL', 'pt': 'URL', 'nl': 'URL', 'fr': 'URL', 'it': 'URL', 'es': 'URL', 'pl': 'URL', 'zh-cn': '网址', 'uk': 'URL'}; Blockly.Words['request_statement'] = {'en': 'with results', 'de': 'mit Ergebnissen', 'ru': 'анализировать результаты', 'pt': 'com resultados', 'nl': 'met resultaten', 'fr': 'avec des résultats', 'it': 'con risultati', 'es': 'con resultados', 'pl': 'with results', 'zh-cn': '处理返回值', 'uk': 'з результатами'}; Blockly.Words['request_tooltip'] = {'en': 'Request URL', 'de': 'URL abfragen', 'ru': 'Запросить URL', 'pt': 'URL solitado', 'nl': 'Verzoek om URL', 'fr': 'Demander une URL', 'it': 'URL di richiesta', 'es': 'URL de solicitud', 'pl': 'Request URL', 'zh-cn': '请求网址', 'uk': 'URL запиту'};