Files
2025-12-02 16:27:21 +00:00

148 lines
5.4 KiB
Python

#!/usr/bin/env python3
import json
with open('/home/mdares/.node-red/flows.json', 'r') as f:
flows = json.load(f)
print("EMERGENCY FIX - 3 ISSUES")
print("="*60)
for node in flows:
if node.get('id') == '1821c4842945ecd8':
template = node.get('format', '')
# FIX 1: Make stop prompt 2 columns
old_grid = 'grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));'
new_grid = 'grid-template-columns: 1fr 1fr;'
if old_grid in template:
template = template.replace(old_grid, new_grid)
print("✅ FIX 1: Made stop reasons 2 columns")
# FIX 2: Reduce modal height
old_modal_style = '.stop-reason-content {\n background: var(--bg-1);\n padding: 0;\n border-radius: 0.5rem;\n max-width: 600px;'
new_modal_style = '.stop-reason-content {\n background: var(--bg-1);\n padding: 0;\n border-radius: 0.5rem;\n max-width: 700px;\n max-height: 80vh;\n overflow-y: auto;'
if old_modal_style in template:
template = template.replace(old_modal_style, new_modal_style)
print("✅ FIX 2: Made modal scrollable for small screens")
# FIX 3: Fix selectStopReason to use SCOPE (not window)
# This is the killer - mixing window and scope breaks everything
if 'window.selectStopReason' in template:
# Replace ALL window.* with scope.* for stop modal
template = template.replace('window._stopCategory', 'scope._stopCategory')
template = template.replace('window._stopReason', 'scope._stopReason')
template = template.replace('window.selectStopReason', 'scope.selectStopReason')
template = template.replace('window.submitStopReason', 'scope.submitStopReason')
template = template.replace('window.hideStopPrompt', 'scope.hideStopPrompt')
print("✅ FIX 3: Converted all window.* to scope.* for consistency")
# FIX 4: Fix selectStopReason parameters (remove 'element' param, use event)
old_select = '''scope.selectStopReason = function(category, reason, element) {
scope._stopCategory = category;
scope._stopReason = reason;
console.log('[SELECT] Category:', category, 'Reason:', reason);
// Update UI - remove all selected classes
document.querySelectorAll('.stop-reason-option').forEach(btn => {
btn.classList.remove('selected');
});
// Add selected class to clicked button
element.classList.add('selected');
// Enable submit button
document.getElementById('submitStopReason').disabled = false;
};'''
new_select = '''scope.selectStopReason = function(category, reason) {
scope._stopCategory = category;
scope._stopReason = reason;
console.log('[SELECT] Category:', category, 'Reason:', reason);
// Update UI - remove all selected classes
document.querySelectorAll('.stop-reason-option').forEach(btn => {
btn.classList.remove('selected');
});
// Add selected class to clicked button (use event from ng-click)
var btn = event.currentTarget;
btn.classList.add('selected');
// Enable submit button
document.getElementById('submitStopReason').disabled = false;
};'''
if old_select in template:
template = template.replace(old_select, new_select)
print("✅ FIX 4: Fixed selectStopReason to use event.currentTarget")
# FIX 5: Update onclick to ng-click (Angular way)
template = template.replace('onclick="selectStopReason(', 'ng-click="selectStopReason(')
template = template.replace(', this)"', ')"') # Remove the 'this' parameter
template = template.replace('onclick="submitStopReason()"', 'ng-click="submitStopReason()"')
template = template.replace('onclick="hideStopPrompt()"', 'ng-click="hideStopPrompt()"')
print("✅ FIX 5: Converted onclick to ng-click (Angular)")
# FIX 6: Fix submitStopReason to use scope and $apply
old_submit = template[template.find('scope.submitStopReason = function()'):template.find('scope.hideStopPrompt')]
new_submit = '''scope.submitStopReason = function() {
var category = scope._stopCategory;
var reason = scope._stopReason;
if (!category || !reason) {
alert('Please select a stop reason');
return;
}
var notes = document.getElementById('stopReasonNotes').value;
console.log('[STOP SUBMIT] Sending stop-reason:', category, reason);
// Send stop-reason action to backend
scope.send({
action: 'stop-reason',
payload: {
category: category,
reason: reason,
notes: notes
}
});
// Update UI - production stopped
scope.isProductionRunning = false;
// Close modal
scope.hideStopPrompt();
};
'''
template = template.replace(old_submit, new_submit)
print("✅ FIX 6: Fixed submitStopReason")
node['format'] = template
break
with open('/home/mdares/.node-red/flows.json', 'w') as f:
json.dump(flows, f, indent=4)
print("\n" + "="*60)
print("✅ ALL FIXES APPLIED")
print("="*60)
print("\nWhat was fixed:")
print(" 1. Stop reasons now 2 columns (fits small screen)")
print(" 2. Modal has max height and scrolls")
print(" 3. ALL functions use scope.* (consistent with Angular)")
print(" 4. Button selection uses event.currentTarget (works)")
print(" 5. All onclick → ng-click (Angular way)")
print(" 6. Submit properly stops production")
print("\nRESTART NODE-RED NOW - THIS WILL WORK!")
EOF