Initial commit, 90% there
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import uuid
|
||||
|
||||
# Read flows.json
|
||||
with open('/home/mdares/.node-red/flows.json', 'r') as f:
|
||||
flows = json.load(f)
|
||||
|
||||
# Find key nodes
|
||||
work_order_buttons_node = None
|
||||
stop_reason_ui_node = None
|
||||
main_tab_id = None
|
||||
|
||||
for node in flows:
|
||||
if node.get('id') == '9bbd4fade968036d':
|
||||
work_order_buttons_node = node
|
||||
elif node.get('type') == 'ui_template' and 'Stop Reason' in node.get('name', ''):
|
||||
stop_reason_ui_node = node
|
||||
elif node.get('type') == 'tab' and node.get('label') == 'Flow 1':
|
||||
main_tab_id = node['id']
|
||||
|
||||
print(f"Work Order buttons: {work_order_buttons_node['id']}")
|
||||
print(f"Stop Reason UI: {stop_reason_ui_node['id']}")
|
||||
print(f"Main tab: {main_tab_id}")
|
||||
|
||||
# Current wiring of Work Order buttons output 2
|
||||
current_output_2_destination = work_order_buttons_node['wires'][1][0] if len(work_order_buttons_node['wires']) > 1 and work_order_buttons_node['wires'][1] else None
|
||||
print(f"Current output 2 destination: {current_output_2_destination}")
|
||||
|
||||
# Create a Switch node to route messages based on _mode
|
||||
switch_node_id = str(uuid.uuid4()).replace('-', '')[:16]
|
||||
|
||||
switch_node = {
|
||||
"id": switch_node_id,
|
||||
"type": "switch",
|
||||
"z": main_tab_id,
|
||||
"name": "Route Stop Messages",
|
||||
"property": "msg._mode",
|
||||
"propertyType": "msg",
|
||||
"rules": [
|
||||
{
|
||||
"t": "eq",
|
||||
"v": "stop-prompt",
|
||||
"vt": "str"
|
||||
},
|
||||
{
|
||||
"t": "eq",
|
||||
"v": "select",
|
||||
"vt": "str"
|
||||
},
|
||||
{
|
||||
"t": "else"
|
||||
}
|
||||
],
|
||||
"checkall": "true",
|
||||
"repair": False,
|
||||
"outputs": 3,
|
||||
"x": work_order_buttons_node['x'] + 200,
|
||||
"y": work_order_buttons_node['y'] + 50,
|
||||
"wires": [
|
||||
[stop_reason_ui_node['id']], # stop-prompt goes to Stop Reason UI
|
||||
[current_output_2_destination] if current_output_2_destination else [], # select goes to MySQL
|
||||
[current_output_2_destination] if current_output_2_destination else [] # else goes to MySQL
|
||||
]
|
||||
}
|
||||
|
||||
# Add the switch node
|
||||
flows.append(switch_node)
|
||||
|
||||
# Update Work Order buttons output 2 to go to switch node
|
||||
work_order_buttons_node['wires'][1] = [switch_node_id]
|
||||
|
||||
print(f"\n✅ Created Switch node: {switch_node_id}")
|
||||
print(f" - Rule 1: _mode = 'stop-prompt' → Stop Reason UI")
|
||||
print(f" - Rule 2: _mode = 'select' → MySQL ({current_output_2_destination})")
|
||||
print(f" - Rule 3: else → MySQL ({current_output_2_destination})")
|
||||
|
||||
print(f"\n✅ Updated Work Order buttons output 2:")
|
||||
print(f" - Now goes to: Switch node ({switch_node_id})")
|
||||
print(f" - Switch routes to appropriate destination")
|
||||
|
||||
# Verify Stop Reason UI output is still wired to Work Order buttons
|
||||
if stop_reason_ui_node['wires'] and stop_reason_ui_node['wires'][0]:
|
||||
print(f"\n✅ Stop Reason UI output verified:")
|
||||
print(f" - Goes to: {stop_reason_ui_node['wires'][0]}")
|
||||
else:
|
||||
print(f"\n⚠️ WARNING: Stop Reason UI output not wired!")
|
||||
print(f" - Should go to Work Order buttons for 'stop-reason' action")
|
||||
|
||||
# Write updated flows
|
||||
with open('/home/mdares/.node-red/flows.json', 'w') as f:
|
||||
json.dump(flows, f, indent=4)
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("✅ PRIORITY 1 FIX COMPLETE")
|
||||
print("="*60)
|
||||
print("\n📋 What was fixed:")
|
||||
print(" 1. Added Switch node to route messages by _mode")
|
||||
print(" 2. stop-prompt messages now go to Stop Reason UI")
|
||||
print(" 3. Other messages continue to MySQL")
|
||||
print("\n🧪 To test:")
|
||||
print(" 1. Restart Node-RED")
|
||||
print(" 2. Start a work order")
|
||||
print(" 3. Click STOP button")
|
||||
print(" 4. You should see the stop reason modal!")
|
||||
print("\n⚠️ If modal doesn't show:")
|
||||
print(" - Check browser console (F12) for errors")
|
||||
print(" - Verify Stop Reason UI node is on correct dashboard group")
|
||||
Reference in New Issue
Block a user