Skip to content

Commit

Permalink
Added trigger block to use file parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Mar 26, 2024
1 parent 95714ba commit 7e6096a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/public/google-blockly/own/blocks_action.js
Expand Up @@ -304,7 +304,7 @@ Blockly.Blocks['http_response'] = {

this.setInputsInline(true);
this.setOutput(true);
this.setColour(Blockly.Trigger.HUE);
this.setColour(Blockly.Action.HUE);
this.setTooltip(Blockly.Translate('http_response_tooltip'));
//this.setHelpUrl(getHelp('http_response'));
},
Expand Down Expand Up @@ -494,7 +494,7 @@ Blockly.Blocks['file_data'] = {

this.setInputsInline(true);
this.setOutput(true);
this.setColour(Blockly.Trigger.HUE);
this.setColour(Blockly.Action.HUE);
this.setTooltip(Blockly.Translate('file_data_tooltip'));
//this.setHelpUrl(getHelp('file_data'));
},
Expand Down
68 changes: 68 additions & 0 deletions src/public/google-blockly/own/blocks_trigger.js
Expand Up @@ -1274,6 +1274,74 @@ Blockly.JavaScript['onFile'] = function (block) {
'});\n';
};

// --- onFile_data -----------------------------------------------------------
Blockly.Trigger.blocks['onFile_data'] =
'<block type="onFile_data">'
+ ' <value name="ATTR">'
+ ' </value>'
+ '</block>';

Blockly.Blocks['onFile_data'] = {
/**
* 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('onFile_data_data'), 'data'],
[Blockly.Translate('onFile_data_filename'), 'fileName'],
[Blockly.Translate('onFile_data_size'), 'size'],
[Blockly.Translate('onFile_data_mimeType'), 'mimeType'],
[Blockly.Translate('onFile_data_id'), 'id'],
]), 'ATTR');

this.setInputsInline(true);
this.setOutput(true);
this.setColour(Blockly.Trigger.HUE);
this.setTooltip(Blockly.Translate('onFile_datatooltip'));
//this.setHelpUrl(getHelp('onFile_data'));
},
/**
* 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('onFile_data_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: ['onFile'],
};
Blockly.JavaScript['onFile_data'] = function(block) {
const attr = block.getFieldValue('ATTR');

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

// --- onFile -----------------------------------------------------------
Blockly.Trigger.blocks['offFile'] =
'<block type="offFile">'
Expand Down
9 changes: 9 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 7e6096a

Please sign in to comment.