#!/usr/bin/env python3 import json with open('/home/mdares/.node-red/flows.json', 'r') as f: flows = json.load(f) print("IMPLEMENTING CLEAN STOP PROMPT") print("="*60) # ============================================================================ # STEP 1: Update Work Order buttons STOP case # ============================================================================ for node in flows: if node.get('id') == '9bbd4fade968036d': # Work Order buttons func = node.get('func', '') # Find and replace the STOP case old_stop = ''' case "stop": { // Manual STOP button clicked from Home dashboard global.set("trackingEnabled", false); node.warn("[STOP] Production tracking disabled"); return [null, null, null, null, null]; }''' new_stop = ''' case "stop": { // Manual STOP button clicked from Home dashboard // Immediately disable tracking global.set("trackingEnabled", false); node.warn("[STOP] Tracking disabled - prompting for reason"); // Send response back to Home to show prompt msg._stopPrompt = true; msg.topic = "showStopPrompt"; msg.payload = { timestamp: Date.now(), workOrderId: (global.get("activeWorkOrder") || {}).id || null }; // Return on output 1 (goes to Base64 -> link out 3 -> link in 3 -> Home) return [msg, null, null, null, null]; }''' func = func.replace(old_stop, new_stop) node['func'] = func print("✅ Updated Work Order buttons STOP case") print(" - Returns msg on output 1 with _stopPrompt flag") break # ============================================================================ # STEP 2: Update Home Template to show prompt on showStopPrompt topic # ============================================================================ for node in flows: if node.get('id') == '1821c4842945ecd8': # Home Template template = node.get('format', '') # Add handler for showStopPrompt in the message watch # Find where to insert - after machineStatus handler insert_point = template.find("if (msg.topic === 'kpiUpdate')") if insert_point > 0: stop_prompt_handler = ''' // Show stop reason prompt if (msg.topic === 'showStopPrompt' || msg._stopPrompt) { console.log('[STOP PROMPT] Showing prompt'); document.getElementById('stopReasonModal').style.display = 'flex'; return; } ''' template = template[:insert_point] + stop_prompt_handler + template[insert_point:] print("✅ Added showStopPrompt handler to Home Template") # Now ensure the modal div has an ID and uses display:none instead of ng-show # Find the stop modal div modal_div_pos = template.find('