4.1 KiB
4.1 KiB
Implementation Complete
Changes Applied
✅ Code Updates (Automated)
-
Graphs Template - Updated with:
msg.ui_control.tabdetection (notmsg.tab)- 300ms debounce to prevent reconnect floods
- Chart.js instance cleanup (
scope._chartswith.destroy()) - Filter buttons trigger data reload
- No
_graphsBootedflag - reloads every time
-
Machine Cycles - Updated with:
- 4 outputs (was 3)
- Fixed
moldActive.cavitiesobject access - Guarded
produced = Math.max(0, totalProduced - scrapTotal) - 4th output persists
cycle_countto database - Uses
msg.payloadfor MariaDB parameters
-
Work Order Buttons - Updated with:
- KPI timestamp initialization on START
- Consistent
work_order_idin all SQL (notid) - All timestamps set to
Date.now()on start
-
New Nodes Created:
Fetch Graph Data- Converts range to SQL INTERVALFormat Graph Data- Formats DB results for Chart.js + cleans msgDB Guard (Graphs)- Switch node filters SQL stringsDB Guard (Cycles)- Switch node filters SQL strings
⚠️ Manual Steps Required
1. Wire Nodes in Node-RED UI
Open Node-RED editor and create these connections:
Graphs Template output
↓
Fetch Graph Data input
↓
DB Guard (Graphs) input
↓
mariaDB input
↓
Format Graph Data input
↓
Graphs Template input (closes the loop)
Machine Cycles output 4 (new!)
↓
DB Guard (Cycles) input
↓
mariaDB input
2. Run Database Migration
Execute this SQL on your MariaDB database:
ALTER TABLE work_orders ADD COLUMN cycle_count INT DEFAULT 0;
CREATE INDEX idx_work_orders_updated_at ON work_orders(updated_at);
How to run:
- Option A: Node-RED Inject node → function with SQL → mariaDB
- Option B: Direct MariaDB command line
- Option C: phpMyAdmin or similar tool
Key Fixes Applied
| Issue | Fix |
|---|---|
| moldActive.cavities returning NaN | Changed to `Number((global.get("moldActive") |
| Negative produced values | Added Math.max(0, totalProduced - scrapTotal) |
| Inconsistent column names | Using work_order_id everywhere (not id) |
| MariaDB parameter syntax | Using msg.payload array (not msg.params) |
| "Query not defined" errors | Added Switch nodes with typeof msg.topic === 'string' guards |
| Graphs don't auto-reload | Added msg.ui_control.tab watcher with debounce |
| Filter buttons don't reload | selectRange() sends fetch-graph-data message |
| Chart stacking on reload | scope._charts[x].destroy() before creating new charts |
| SQL loops to UI | delete msg.topic; delete msg.payload; in Format node |
Testing Checklist
After wiring and database migration:
- Navigate to Graphs tab → should auto-load charts
- Click filter button (24h → 7d) → should reload charts
- Refresh browser → Graphs tab should still auto-load
- Start work order → produce parts → check cycle_count in DB
- Check Node-RED debug for "query is not defined" errors (should be gone)
- Verify KPIs show values on first START (not 0)
- Produce parts → verify graphs update with real data (not mock)
Rollback
If issues occur:
cd /home/mdares/.node-red/projects/Plastico
cp flows.json flows.json.broken
cp flows.json.backup-$(ls -t flows.json.backup-* | head -1 | cut -d'-' -f2-) flows.json
Then restart Node-RED.
What's NOT Implemented Yet
These were in the original plan but require additional UI work:
- Work Order Resume Prompt - User confirmation to continue vs restart
- Needs modal dialog in Home Template
- Needs
case "continue-work-order"andcase "restart-work-order"handlers - Requires checking DB status before starting
This can be added as a follow-up if needed.
Files Modified
flows.json- Main Node-RED flow configurationflows.json.backup-*- Automatic backup created before changes
Files Created
/tmp/update_flows_corrected.py- Update script with all recommendationsIMPLEMENTATION_COMPLETE.md- This file
Generated: $(date)