diff --git a/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Build.ts b/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Build.ts index b98570887..46d22c4ae 100644 --- a/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Build.ts +++ b/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Build.ts @@ -334,6 +334,28 @@ export function masterRef( : ref; } +/** 옛 로직 줄(입력 · 자동값)에서 바로 읽은 다른 로직 입력 값 — 흐름 변환이 아직 비어 있을 때 · 받는 알약 = 입력마다 · 예시값 = 자동값 */ +export function rowRef( + key: string, + name: string, + resultUnit: string, + inputs: { 이름: string; 단위?: string }[], + auto: Record, +): CfLogicRef { + const examples: Record = {}; + for (const i of inputs) { + const v = auto[i.이름]; + if (typeof v === "number" || (typeof v === "string" && v !== "")) examples[i.이름] = v; + } + return { + key, + name, + outputs: COST_OUTPUTS.map((n) => ({ name: n, unit: resultUnit || "-" })), + designs: inputs.map((i) => ({ name: i.이름, unit: i.단위 || "-" })), + ...(Object.keys(examples).length ? { examples } : {}), + }; +} + /** 이 로직이 자기 자신을 부르거나 돌고 도나 — `load` 가 로직을 주면 입력 상자의 「다른 로직」 을 따라가 봄(깊이 8) */ export async function wouldCycle( selfKey: string | null, diff --git a/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Logic.ts b/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Logic.ts index 3ac1c5507..d23404fed 100644 --- a/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Logic.ts +++ b/M02_MasterTemplete/DataFlow/M02_DF_InputPanel_Logic.ts @@ -14,7 +14,11 @@ import { el, showToast, } from "@ui/ui_template_elements"; -import { fetchLogics } from "../../M01_MasterData/M01_MasterData_UI_Logic_Api"; +import { + fetchAuto, + fetchLogic, + fetchLogics, +} from "../../M01_MasterData/M01_MasterData_UI_Logic_Api"; import { cfGet, cfList, cfLogicFlow, cfLogicValue, cfPlain } from "./M02_DF_Api"; import type { CfLogic, CfLogicRef } from "./M02_DF_Model"; import { @@ -23,6 +27,7 @@ import { logicChapters, logicRefOf, masterRef, + rowRef, pageRange, setKind, setLogicInput, @@ -235,9 +240,14 @@ export function renderLogicInput( if (await wouldCycle(lg.key, i.키, loadForCycle)) return void showToast(t("Cycle"), "error"); const got = await flowOf(i); readNotes.set(i.키, { converted: got.converted, notes: got.notes }); - const picked = got.converted - ? masterRef(i.키, got.flow, true, i.결과단위) - : { ...logicRefOf(i.키, got.flow), name: i.이름 }; + // 옛 로직을 흐름도로 바꾼 것이 아직 비어 있으면 옛 줄의 입력 · 자동값에서 바로 읽음 + const empty = got.converted && got.flow.boxes.length === 0; + const row = empty ? await fetchLogic(i.키).catch(() => null) : null; + const picked = row + ? rowRef(i.키, i.이름, i.결과단위, row.logic.입력 ?? [], await fetchAuto(i.키)) + : got.converted + ? masterRef(i.키, got.flow, true, i.결과단위) + : { ...logicRefOf(i.키, got.flow), name: i.이름 }; const done = setLogicInput(lg, boxId, picked); // 기본 이름이면 고른 로직 이름으로 on.change({ diff --git a/resources/tester/test_m02_df_input_logic.py b/resources/tester/test_m02_df_input_logic.py index 1b5dd1765..d5351d187 100644 --- a/resources/tester/test_m02_df_input_logic.py +++ b/resources/tester/test_m02_df_input_logic.py @@ -252,3 +252,17 @@ def test_조건_찾기_요소와_검사(): assert call("checkGroupRule", el, [el]) == "같은 이름의 알약이 이미 있음" no_pill = call("groupRuleElement", "노임", "이름", {"box": "", "name": ""}) assert "변수 알약" in call("checkGroupRule", no_pill, []) + + +def test_옛_줄_입력과_자동값으로_다른_로직_입력을_읽음(): + inputs = [{"이름": "뒷길이", "단위": "㎝"}, {"이름": "돌"}, {"이름": "쌓기"}] + auto = {"뒷길이": 25, "돌": "깬잡석", "쌓기": "", "남는": 1} + ref = call("rowRef", "GF000219", "돌쌓기 메쌓기(인력)", "원/㎡", inputs, auto) + assert ref["key"] == "GF000219" + assert [o["name"] for o in ref["outputs"]] == ["노무비", "재료비", "경비", "계"] + assert ref["designs"] == [ + {"name": "뒷길이", "unit": "㎝"}, + {"name": "돌", "unit": "-"}, + {"name": "쌓기", "unit": "-"}, + ] + assert ref["examples"] == {"뒷길이": 25, "돌": "깬잡석"} # 빈 글 · 입력에 없는 이름은 뺌