From 345e7303c17c9f9bf511307d9af10eade0e4d001 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Tue, 29 Sep 2026 17:40:06 +0200 Subject: [PATCH] feat(flows): ren statusfunktion + farver til Flows-listen --- FS25_ADSmartPickup/adFlowView.lua | 19 +++++++++++++++++++ tests/test_flowStatus.lua | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/test_flowStatus.lua diff --git a/FS25_ADSmartPickup/adFlowView.lua b/FS25_ADSmartPickup/adFlowView.lua index ff6baaa..dceed79 100644 --- a/FS25_ADSmartPickup/adFlowView.lua +++ b/FS25_ADSmartPickup/adFlowView.lua @@ -166,3 +166,22 @@ function ADFlowView.wrapText(text, maxChars) if line ~= indent then table.insert(lines, line) end return lines end + +-- ---- status pr. flow (Flows-listen) ---- + +ADFlowView.LEVEL_COLORS = { + running = {0.30, 0.75, 0.35, 1}, + waiting = {0.95, 0.80, 0.25, 1}, + error = {0.90, 0.35, 0.30, 1}, + stopped = {0.55, 0.55, 0.55, 1}, +} + +-- s = {running, total, stopped, canStop, warning, reason, lastStartFailed} -> "running"|"waiting"|"error"|"stopped" +function ADFlowView.flowStatus(s) + if s.stopped then return "stopped" end + if s.warning ~= nil then return "error" end + if (s.running or 0) == 0 and s.lastStartFailed then return "error" end + if (s.running or 0) > 0 and s.reason == nil then return "running" end + if (s.running or 0) > 0 or s.canStop then return "waiting" end + return "stopped" +end diff --git a/tests/test_flowStatus.lua b/tests/test_flowStatus.lua new file mode 100644 index 0000000..0beeedf --- /dev/null +++ b/tests/test_flowStatus.lua @@ -0,0 +1,21 @@ +-- Kør: luajit tests/test_flowStatus.lua (fra repo-roden) +dofile("FS25_ADSmartPickup/adFlowView.lua") +local V = ADFlowView +local failures = 0 +local function check(name, actual, expected) + if actual == expected then print("OK " .. name) else + failures = failures + 1 + print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual))) + end +end +check("kører", V.flowStatus({running = 3, total = 4, canStop = true}), "running") +check("kører men holder (begrundelse)", V.flowStatus({running = 2, total = 2, canStop = true, reason = "intet at hente"}), "waiting") +check("startet, venter på vogn", V.flowStatus({running = 0, total = 2, canStop = true}), "waiting") +check("advarsel", V.flowStatus({running = 1, total = 2, canStop = true, warning = "mål mangler"}), "error") +check("start afvist (ingen vogn)", V.flowStatus({running = 0, total = 2, lastStartFailed = true}), "error") +check("stoppet", V.flowStatus({running = 0, total = 2, stopped = true}), "stopped") +check("aldrig startet", V.flowStatus({running = 0, total = 2}), "stopped") +check("stoppet vinder over gammel afvisning", V.flowStatus({running = 0, total = 2, stopped = true, lastStartFailed = true}), "stopped") +check("farver findes", V.LEVEL_COLORS ~= nil and V.LEVEL_COLORS.waiting ~= nil and V.LEVEL_COLORS.stopped ~= nil, true) +print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) +os.exit(failures == 0 and 0 or 1)