Skip to content

Commit

Permalink
Added count attribute to getHistory in blockly (#1809)
Browse files Browse the repository at this point in the history
Co-authored-by: Bluefox <[email protected]>
  • Loading branch information
klein0r and GermanBluefox authored Jan 21, 2025
1 parent 9da69f3 commit c9a9ba6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Executes Javascript, Typescript Scripts.
-->
### **WORK IN PROGRESS**
* (@GermanBluefox) Migrated GUI to Typescript
* (@klein0r) Added count attribute to getHistory in blockly

### 8.8.3 (2024-09-05)
* (bluefox) Fixed object selector in rules
Expand Down
13 changes: 10 additions & 3 deletions src-editor/public/google-blockly/own/blocks_sendto.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ Blockly.Sendto.blocks['sendto_gethistory'] =
' <field name="INSTANCE">default</field>' +
' <field name="AGGREGATE">none</field>' +
' <field name="STEP">0</field>' +
' <field name="UNIT">ms</field>' +
' <field name="COUNT">500</field>' +
' <field name="UNIT">min</field>' +
' <value name="OID">' +
' <shadow type="field_oid">' +
' </shadow>' +
Expand Down Expand Up @@ -584,7 +585,7 @@ Blockly.Blocks['sendto_gethistory'] = {
[Blockly.Translate('sendto_gethistory_cnt'), 'count'],
]), 'AGGREGATE');

this.appendDummyInput()
this.appendDummyInput('UNIT')
.appendField(Blockly.Translate('sendto_gethistory_step'))
.appendField(new Blockly.FieldTextInput(0), 'STEP')
.appendField(new Blockly.FieldDropdown([
Expand All @@ -595,6 +596,10 @@ Blockly.Blocks['sendto_gethistory'] = {
[Blockly.Translate('sendto_gethistory_day'), 'day'],
]), 'UNIT');

this.appendDummyInput('COUNT')
.appendField(Blockly.Translate('sendto_gethistory_count'))
.appendField(new Blockly.FieldTextInput(0), 'COUNT');

this.appendStatementInput('STATEMENT')
.setCheck(null);

Expand All @@ -616,8 +621,9 @@ Blockly.JavaScript.forBlock['sendto_gethistory'] = function (block) {
const vEnd = Blockly.JavaScript.valueToCode(block, 'END', Blockly.JavaScript.ORDER_ATOMIC);
const fAggregate = block.getFieldValue('AGGREGATE');
const fUnit = block.getFieldValue('UNIT');
const fCount = parseInt(block.getFieldValue('COUNT'));

let fStep = block.getFieldValue('STEP');
let fStep = parseFloat(block.getFieldValue('STEP'));
if (fUnit === 'day') {
fStep *= 24 * 60 * 60 * 1000;
} else if (fUnit === 'hour') {
Expand Down Expand Up @@ -646,6 +652,7 @@ Blockly.JavaScript.forBlock['sendto_gethistory'] = function (block) {
` start: ${vStart},\n` +
` end: ${vEnd},\n`+
(fStep > 0 && fAggregate !== 'none' ? ` step: ${fStep},\n` : '') +
(fStep === 0 || fAggregate === 'none' ? ` count: ${fCount},\n` : '') +
` aggregate: '${fAggregate}',\n` +
` removeBorderValues: true,\n`+
`}, async (err, result) => {\n` +
Expand Down
3 changes: 2 additions & 1 deletion src-editor/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 c9a9ba6

Please sign in to comment.