Skip to content

Commit

Permalink
Translated log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed May 3, 2024
1 parent 887402b commit ead7b29
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/public/google-blockly/own/blocks_action.js
Expand Up @@ -23,7 +23,7 @@ Blockly.Action.blocks['exec'] =
+ ' <field name="TEXT">pwd</field>'
+ ' </shadow>'
+ ' </value>'
+ ' <value name="LOG">'
+ ' <value name="LOG_LEVEL">'
+ ' </value>'
+ ' <value name="WITH_STATEMENT">'
+ ' </value>'
Expand All @@ -44,15 +44,15 @@ Blockly.Blocks['exec'] = {
this.sourceBlock_.updateShape_(option === true || option === 'true' || option === 'TRUE');
}), 'WITH_STATEMENT');

this.appendDummyInput('LOG')
.appendField(Blockly.Translate('exec_log'))
this.appendDummyInput('LOG_LEVEL')
.appendField(Blockly.Translate('loglevel'))
.appendField(new Blockly.FieldDropdown([
[Blockly.Translate('exec_log_none'), ''],
[Blockly.Translate('exec_log_info'), 'log'],
[Blockly.Translate('exec_log_debug'), 'debug'],
[Blockly.Translate('exec_log_warn'), 'warn'],
[Blockly.Translate('exec_log_error'), 'error']
]), 'LOG');
[Blockly.Translate('loglevel_none'), ''],
[Blockly.Translate('loglevel_debug'), 'debug'],
[Blockly.Translate('loglevel_info'), 'info'],
[Blockly.Translate('loglevel_warn'), 'warn'],
[Blockly.Translate('loglevel_error'), 'error'],
]), 'LOG_LEVEL');

this.setInputsInline(false);
this.setPreviousStatement(true, null);
Expand Down Expand Up @@ -90,8 +90,8 @@ Blockly.Blocks['exec'] = {
};

Blockly.JavaScript['exec'] = function(block) {
const logLevel = block.getFieldValue('LOG');
const value_command = Blockly.JavaScript.valueToCode(block, 'COMMAND', Blockly.JavaScript.ORDER_ATOMIC);
const logLevel = block.getFieldValue('LOG_LEVEL');
const withStatement = block.getFieldValue('WITH_STATEMENT');

let logText;
Expand Down
15 changes: 11 additions & 4 deletions src/public/google-blockly/own/blocks_system.js
Expand Up @@ -58,6 +58,8 @@ Blockly.System.blocks['debug'] =
+ ' <field name="TEXT">test</field>'
+ ' </shadow>'
+ ' </value>'
+ ' <value name="LOG_LEVEL">'
+ ' </value>'
+ '</block>';

Blockly.Blocks['debug'] = {
Expand All @@ -66,8 +68,13 @@ Blockly.Blocks['debug'] = {
.setCheck(null)
.appendField(Blockly.Translate('debug'));

this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([['info', 'log'], ['debug', 'debug'], ['warning', 'warn'], ['error', 'error']]), 'Severity');
this.appendDummyInput('LOG_LEVEL')
.appendField(new Blockly.FieldDropdown([
[Blockly.Translate('loglevel_debug'), 'debug'],
[Blockly.Translate('loglevel_info'), 'info'],
[Blockly.Translate('loglevel_warn'), 'warn'],
[Blockly.Translate('loglevel_error'), 'error'],
]), 'LOG_LEVEL');

this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
Expand All @@ -80,9 +87,9 @@ Blockly.Blocks['debug'] = {

Blockly.JavaScript['debug'] = function(block) {
const value_text = Blockly.JavaScript.valueToCode(block, 'TEXT', Blockly.JavaScript.ORDER_ATOMIC);
const dropdown_severity = block.getFieldValue('Severity');
const logLevel = block.getFieldValue('LOG_LEVEL');

return `console.${dropdown_severity}(${value_text});\n`;
return `console.${logLevel}(${value_text});\n`;
};

// --- comment --------------------------------------------------
Expand Down
13 changes: 7 additions & 6 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 ead7b29

Please sign in to comment.