Add time range buttons (1H/6H/24H) to flow rate popup

Replace static tag-history binding with expression binding using
runScript to call flowrate.queryHistory(), which dynamically queries
tag history based on the selected time range. Buttons highlight
blue when active, grey when inactive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dohertj2
2026-02-22 06:07:14 -05:00
parent 6ee1c9e522
commit f78c290074
3 changed files with 39 additions and 74 deletions

View File

@@ -1,7 +1,6 @@
{
"custom": {
"timeAmount": 1,
"timeUnits": "HOUR"
"timeHours": 1
},
"params": {},
"props": {
@@ -19,7 +18,7 @@
"dom": {
"onClick": {
"config": {
"script": "\tself.view.custom.timeAmount = 1\n\tself.view.custom.timeUnits = \"HOUR\""
"script": "\tself.view.custom.timeHours = 1"
},
"scope": "G",
"type": "script"
@@ -37,7 +36,7 @@
"props.style.backgroundColor": {
"binding": {
"config": {
"expression": "if({view.custom.timeAmount} = 1 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
"expression": "if({view.custom.timeHours} = 1, '#4747FF', '#AAAAAA')"
},
"type": "expr"
}
@@ -58,7 +57,7 @@
"dom": {
"onClick": {
"config": {
"script": "\tself.view.custom.timeAmount = 6\n\tself.view.custom.timeUnits = \"HOUR\""
"script": "\tself.view.custom.timeHours = 6"
},
"scope": "G",
"type": "script"
@@ -76,7 +75,7 @@
"props.style.backgroundColor": {
"binding": {
"config": {
"expression": "if({view.custom.timeAmount} = 6 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
"expression": "if({view.custom.timeHours} = 6, '#4747FF', '#AAAAAA')"
},
"type": "expr"
}
@@ -97,7 +96,7 @@
"dom": {
"onClick": {
"config": {
"script": "\tself.view.custom.timeAmount = 24\n\tself.view.custom.timeUnits = \"HOUR\""
"script": "\tself.view.custom.timeHours = 24"
},
"scope": "G",
"type": "script"
@@ -115,7 +114,7 @@
"props.style.backgroundColor": {
"binding": {
"config": {
"expression": "if({view.custom.timeAmount} = 24 && \"{view.custom.timeUnits}\" = \"HOUR\", '#4747FF', '#AAAAAA')"
"expression": "if({view.custom.timeHours} = 24, '#4747FF', '#AAAAAA')"
},
"type": "expr"
}
@@ -130,45 +129,6 @@
"text": "24H"
},
"type": "ia.input.button"
},
{
"events": {
"dom": {
"onClick": {
"config": {
"script": "\tself.view.custom.timeAmount = 7\n\tself.view.custom.timeUnits = \"DAY\""
},
"scope": "G",
"type": "script"
}
}
},
"meta": {
"name": "Btn7D"
},
"position": {
"basis": "60px",
"shrink": 0
},
"propConfig": {
"props.style.backgroundColor": {
"binding": {
"config": {
"expression": "if({view.custom.timeAmount} = 7 && \"{view.custom.timeUnits}\" = \"DAY\", '#4747FF', '#AAAAAA')"
},
"type": "expr"
}
}
},
"props": {
"style": {
"color": "#FFFFFF",
"fontWeight": "bold",
"margin": 2
},
"text": "7D"
},
"type": "ia.input.button"
}
],
"meta": {
@@ -202,34 +162,9 @@
"props.series[0].data": {
"binding": {
"config": {
"aggregate": "Average",
"avoidScanClassValidation": true,
"dateRange": {
"mostRecent": "{view.custom.timeAmount}",
"mostRecentUnits": "{view.custom.timeUnits}"
"expression": "runScript('flowrate.queryHistory', 30000, {view.custom.timeHours})"
},
"enableValueCache": true,
"ignoreBadQuality": false,
"polling": {
"enabled": true,
"rate": "30"
},
"preventInterpolation": false,
"returnFormat": "Wide",
"returnSize": {
"delay": "1",
"delayUnits": "MIN",
"type": "INTERVAL"
},
"tags": [
{
"alias": "Flow Rate",
"path": "[CoreDB/ignition-ignition:default]watermeter/prefilterflowrate"
}
],
"valueFormat": "DATASET"
},
"type": "tag-history"
"type": "expr"
}
}
},

View File

@@ -0,0 +1,14 @@
def queryHistory(timeHours):
from java.util import Date
end = Date()
start = Date(end.getTime() - long(timeHours * 3600000))
return system.tag.queryTagHistory(
paths=["[CoreDB/ignition-ignition:default]watermeter/prefilterflowrate"],
startDate=start,
endDate=end,
returnSize=120,
aggregationMode="Average",
returnFormat="Wide"
)

View File

@@ -0,0 +1,16 @@
{
"scope": "A",
"version": 1,
"restricted": false,
"overridable": true,
"files": [
"code.py"
],
"attributes": {
"lastModification": {
"actor": "dohertj2",
"timestamp": "2026-02-22T00:00:00Z"
},
"hintScope": 2
}
}