Initial commit, 90% there
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
|
||||
with open('/home/mdares/.node-red/flows.json', 'r') as f:
|
||||
flows = json.load(f)
|
||||
|
||||
# JavaScript code to add tab activation listener
|
||||
tab_refresh_code = '''
|
||||
// Phase 7: Tab activation listener - refresh data when returning to Home
|
||||
scope.$on('$destroy', function() {
|
||||
if (scope.tabRefreshInterval) {
|
||||
clearInterval(scope.tabRefreshInterval);
|
||||
}
|
||||
});
|
||||
|
||||
// Request current state when tab becomes visible
|
||||
scope.refreshHomeData = function() {
|
||||
scope.send({ action: "get-current-state" });
|
||||
};
|
||||
|
||||
// Poll for updates when on Home tab (every 2 seconds)
|
||||
// This ensures UI stays fresh when returning from other tabs
|
||||
scope.tabRefreshInterval = setInterval(function() {
|
||||
// Only refresh if we're on the Home tab (check if element is visible)
|
||||
var homeElement = document.getElementById('oee');
|
||||
if (homeElement && homeElement.offsetParent !== null) {
|
||||
scope.refreshHomeData();
|
||||
}
|
||||
}, 2000);
|
||||
'''
|
||||
|
||||
# Find Home Template and add the tab refresh code
|
||||
for node in flows:
|
||||
if node.get('name') == 'Home Template':
|
||||
template = node.get('format', '')
|
||||
|
||||
# Check if already has tab refresh code
|
||||
if 'tabRefreshInterval' in template:
|
||||
print("⚠ Tab refresh code already exists - skipping")
|
||||
else:
|
||||
# Find a good place to insert - after gotoTab function definition
|
||||
goto_idx = template.find('scope.gotoTab = function(tabName)')
|
||||
if goto_idx != -1:
|
||||
# Find the end of the gotoTab function (closing brace and semicolon)
|
||||
end_idx = template.find('};', goto_idx)
|
||||
if end_idx != -1:
|
||||
# Insert after the gotoTab function
|
||||
insert_pos = end_idx + 2 # After '};'
|
||||
template = template[:insert_pos] + '\n' + tab_refresh_code + template[insert_pos:]
|
||||
|
||||
node['format'] = template
|
||||
print("✓ Added tab refresh listener to Home Template")
|
||||
else:
|
||||
print("✗ Could not find end of gotoTab function")
|
||||
else:
|
||||
print("✗ Could not find gotoTab function")
|
||||
break
|
||||
|
||||
with open('/home/mdares/.node-red/flows.json', 'w') as f:
|
||||
json.dump(flows, f, indent=4)
|
||||
|
||||
print("✓ flows.json updated")
|
||||
Reference in New Issue
Block a user