Skip to content

Commit

Permalink
Added new block for http response
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Mar 18, 2024
1 parent 1e93c05 commit f6d588a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -46,6 +46,10 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
<!--
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**

* (klein0r) Added new block for http response

### 7.9.1 (2024-03-15)

* (klein0r) Configurable trigger warning limit (default: 100 per script)
Expand Down
64 changes: 64 additions & 0 deletions src/public/google-blockly/own/blocks_action.js
Expand Up @@ -212,6 +212,70 @@ Blockly.JavaScript['http_post'] = function(block) {
'});\n';
};

// --- get info about event -----------------------------------------------------------
Blockly.Action.blocks['http_response'] =
'<block type="http_response">'
+ ' <value name="ATTR">'
+ ' </value>'
+ '</block>';

Blockly.Blocks['http_response'] = {
/**
* Block for conditionally returning a value from a procedure.
* @this Blockly.Block
*/
init: function() {
this.appendDummyInput()
.appendField('🌐');

this.appendDummyInput('ATTR')
.appendField(new Blockly.FieldDropdown([
[Blockly.Translate('http_response_data'), 'response.data'],
]), 'ATTR');

this.setInputsInline(true);
this.setOutput(true);
this.setColour(Blockly.Trigger.HUE);
this.setTooltip(Blockly.Translate('http_response_tooltip'));
//this.setHelpUrl(getHelp('http_response'));
},
/**
* Called whenever anything on the workspace changes.
* Add warning if this flow block is not nested inside a loop.
* @param {!Blockly.Events.Abstract} e Change event.
* @this Blockly.Block
*/
onchange: function(e) {
let legal = false;
// Is the block nested in a trigger?
let block = this;
do {
if (this.FUNCTION_TYPES.includes(block.type)) {
legal = true;
break;
}
block = block.getSurroundParent();
} while (block);

if (legal) {
this.setWarningText(null, this.id);
} else {
this.setWarningText(Blockly.Translate('http_response_warning'), this.id);
}
},
/**
* List of block types that are functions and thus do not need warnings.
* To add a new function type add this to your code:
* Blockly.Blocks['procedures_ifreturn'].FUNCTION_TYPES.push('custom_func');
*/
FUNCTION_TYPES: ['http_get', 'http_post'],
};
Blockly.JavaScript['http_response'] = function(block) {
const attr = block.getFieldValue('ATTR');

return [attr, Blockly.JavaScript.ORDER_ATOMIC];
};

// --- action request --------------------------------------------------
Blockly.Action.blocks['request'] =
'<block type="request">'
Expand Down
6 changes: 6 additions & 0 deletions src/public/google-blockly/own/blocks_words.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6d588a

Please sign in to comment.