feat(m01-lb): 로직 만들기 판 단계 안내 Wizard 완성 — 표 칸 역할 · 문장 틀 · 항목 연결 · 값 종류 · 시험
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ACSGaHdLgnkEkoA4LDtMU
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
* 글 [한, 영] 짝은 아래 TEXT · 용어는 정함 9 · 이 폴더째 지워도 됨
|
||||
* ========================================================================== */
|
||||
|
||||
import { API_BASE_URL } from "@config/config_frontend";
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import {
|
||||
createButton,
|
||||
@@ -16,7 +15,7 @@ import {
|
||||
showToast,
|
||||
} from "@ui/ui_template_elements";
|
||||
import { openModal } from "@ui/ui_template_modal";
|
||||
import { ApiError, type CalcAnswer } from "../M01_MasterData_UI_Logic_Api";
|
||||
import { type CalcAnswer } from "../M01_MasterData_UI_Logic_Api";
|
||||
import { calcLater, plainError } from "../EasyCalc/M01_EasyCalc_Api";
|
||||
import { readLogic, type LbLogic } from "./M01_LB_Blocks";
|
||||
import { autoLinks, stepCalc, stepLink } from "./M01_LB_Wizard_Calc";
|
||||
@@ -30,6 +29,13 @@ import {
|
||||
type WCtx,
|
||||
type WTable,
|
||||
} from "./M01_LB_Wizard_Build";
|
||||
import {
|
||||
get,
|
||||
tablePreview,
|
||||
toTable,
|
||||
type SectionItem,
|
||||
type TableHead,
|
||||
} from "./M01_LB_Wizard_Parts";
|
||||
import "./M01_LB_Wizard.css";
|
||||
|
||||
const TEXT = {
|
||||
@@ -67,6 +73,7 @@ const TEXT = {
|
||||
Unused: ["쓰지 않음", "Unused"],
|
||||
Choices: ["선택 목록", "Choices"],
|
||||
Free: ["숫자 입력", "Number input"],
|
||||
PickTable: ["표를 하나 골라 주세요", "Pick a table"],
|
||||
NeedResult: ["결과 칸이 하나는 있어야 함", "At least one result column"],
|
||||
FixedVal: ["고정값", "Fixed value"],
|
||||
BaseUnit: ["표 기준 「{b}」", "Table base “{b}”"],
|
||||
@@ -95,32 +102,7 @@ const t = (key: TKey, v: Record<string, string | number> = {}): string =>
|
||||
|
||||
const fmt = (n: number): string => Number(n.toPrecision(6)).toLocaleString("ko-KR");
|
||||
|
||||
async function get<T>(path: string, params: Record<string, string>): Promise<T> {
|
||||
const res = await fetch(`${API_BASE_URL}/m01${path}?${new URLSearchParams(params)}`, {
|
||||
credentials: "include",
|
||||
});
|
||||
const data = (await res.json().catch(() => ({}))) as { detail?: unknown } & T;
|
||||
if (!res.ok) throw new ApiError(res.status, data.detail ?? res.statusText);
|
||||
return data;
|
||||
}
|
||||
|
||||
interface SectionItem {
|
||||
section: string;
|
||||
title: string;
|
||||
chapter: string;
|
||||
tables: number;
|
||||
logics: number;
|
||||
}
|
||||
interface TableHead {
|
||||
file: string;
|
||||
키: string;
|
||||
이름: string;
|
||||
기준: string;
|
||||
조건: Record<string, string>;
|
||||
값칸: Record<string, string>;
|
||||
count: number;
|
||||
}
|
||||
|
||||
const LBL = { preview: t("Preview"), notes: t("Notes") };
|
||||
const BOOKS = ["산림품셈", "건설품셈"];
|
||||
const UNITS = ["㎡", "㎥", "m", "km", "ha", "개소", "개", "ton", "본", "100㎡", "100m", "10m"];
|
||||
|
||||
@@ -233,7 +215,7 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
const per = a.resultUnit.replace(/^원\//, "");
|
||||
const v = money ? (ans.sums?.["계"] ?? Number(ans.result ?? 0)) : Number(ans.result);
|
||||
result.textContent = money
|
||||
? t("AmountPer", { p: per, m: fmt(v) })
|
||||
? t("AmountPer", { p: per, m: Math.round(v).toLocaleString("ko-KR") })
|
||||
: t("ValueIs", { c: col, v: fmt(v), u: a.table.값칸[col] ?? "" });
|
||||
});
|
||||
};
|
||||
@@ -369,7 +351,7 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
tables
|
||||
.querySelectorAll(".m01-lbw__row")
|
||||
.forEach((n, i) => n.classList.toggle("is-on", heads[i]?.키 === h.키));
|
||||
preview.replaceChildren(tablePreview(a.table));
|
||||
preview.replaceChildren(tablePreview(a.table, LBL));
|
||||
renderNav();
|
||||
};
|
||||
let timer = 0;
|
||||
@@ -379,8 +361,8 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
);
|
||||
main.replaceChildren(bookBox.root, q.root, list, tables, preview);
|
||||
void load();
|
||||
if (a.table.key) preview.replaceChildren(tablePreview(a.table));
|
||||
return () => (a.table.key ? null : t("Tables"));
|
||||
if (a.table.key) preview.replaceChildren(tablePreview(a.table, LBL));
|
||||
return () => (a.table.key ? null : t("PickTable"));
|
||||
};
|
||||
|
||||
/* ── 2단계 칸 역할 ── */
|
||||
@@ -471,7 +453,7 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
box.replaceChildren(
|
||||
el("p", { className: "m01-lbw__muted", text: t("RoleHint") }),
|
||||
...chips,
|
||||
tablePreview(a.table, a.roles),
|
||||
tablePreview(a.table, LBL, a.roles),
|
||||
);
|
||||
renderNav();
|
||||
};
|
||||
@@ -580,9 +562,12 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
stepCalc(ctx, main);
|
||||
valid = () => null;
|
||||
} else if (step === 5) {
|
||||
stepLink(ctx, main);
|
||||
if (!linked)
|
||||
((linked = true), void autoLinks(ctx).then(() => step === 5 && stepLink(ctx, main)));
|
||||
if (linked) stepLink(ctx, main);
|
||||
else {
|
||||
linked = true;
|
||||
main.replaceChildren(el("p", { className: "m01-lbw__muted", text: t("Loading") }));
|
||||
void autoLinks(ctx).then(() => step === 5 && stepLink(ctx, main));
|
||||
}
|
||||
valid = () => null;
|
||||
} else valid = stepName();
|
||||
side.hidden = step === 1;
|
||||
@@ -641,58 +626,3 @@ export function openWizard(): Promise<LbLogic | null> {
|
||||
draw();
|
||||
});
|
||||
}
|
||||
|
||||
/** 서버 표 답 → WTable */
|
||||
function toTable(raw: WTable & { 키: string }, file: string): WTable {
|
||||
return {
|
||||
key: raw.키,
|
||||
file,
|
||||
이름: raw.이름,
|
||||
기준: raw.기준 ?? "",
|
||||
출처: raw.출처 ?? "",
|
||||
조건: raw.조건,
|
||||
값칸: raw.값칸,
|
||||
범위규칙: raw.범위규칙 ?? null,
|
||||
줄: raw.줄,
|
||||
주: raw.주 ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
const cellText = (v: unknown): string =>
|
||||
Array.isArray(v)
|
||||
? v.map((x) => x ?? "").join("~")
|
||||
: v === null || v === undefined
|
||||
? ""
|
||||
: String(v);
|
||||
|
||||
/** 원문 표 앞 몇 줄 + 주 — 칸 머리 색 = 역할 */
|
||||
function tablePreview(tb: WTable, roles?: Record<string, Role>): HTMLElement {
|
||||
const cols = [...Object.keys(tb.조건), ...Object.keys(tb.값칸)];
|
||||
const head = el("tr", {
|
||||
children: cols.map((c) =>
|
||||
el("th", { className: `is-${roles?.[c] ?? (c in tb.조건 ? "조건" : "결과")}`, text: c }),
|
||||
),
|
||||
});
|
||||
const rows = tb.줄
|
||||
.slice(0, 6)
|
||||
.map((r) => el("tr", { children: cols.map((c) => el("td", { text: cellText(r[c]) })) }));
|
||||
return el("div", {
|
||||
className: "m01-lbw__table",
|
||||
children: [
|
||||
el("h5", { text: `${t("Preview")} — ${tb.이름} (${tb.기준 || "—"})` }),
|
||||
el("div", {
|
||||
className: "m01-lbw__scroll",
|
||||
children: [el("table", { children: [head, ...rows] })],
|
||||
}),
|
||||
...(tb.줄.length > 6
|
||||
? [el("p", { className: "m01-lbw__muted", text: `… ${tb.줄.length} 줄` })]
|
||||
: []),
|
||||
...(tb.주.length
|
||||
? [
|
||||
el("h5", { text: t("Notes") }),
|
||||
...tb.주.map((n) => el("p", { className: "m01-lbw__note-line", text: n })),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,12 +184,25 @@ function inputsOf(a: WAnswers): LogicInput[] {
|
||||
if (m.k === "할증" && m.rate.t === "cond") add({ 이름: m.rate.input });
|
||||
if (m.k === "나누기" && m.by.t === "input") add({ 이름: m.by.name });
|
||||
}
|
||||
for (const l of a.links) for (const n of l.needInputs ?? []) add(n);
|
||||
if (a.kind === "금액")
|
||||
for (const l of a.links)
|
||||
if (l.kind !== "없음" && a.roles[l.col] === "결과")
|
||||
for (const n of l.needInputs ?? []) add(n);
|
||||
return out;
|
||||
}
|
||||
|
||||
const COST: Record<string, string> = { 노무: "노무비", 재료: "재료비" };
|
||||
|
||||
/** 사람 줄 노임 합 글 — 「(수량 * 노임 키 + …)」 · 사람 줄이 없으면 0 */
|
||||
const personSum = (ho: HoLine[]): string => {
|
||||
const terms = ho
|
||||
.filter((h) => h.종류 === "인력")
|
||||
.map(
|
||||
(h) => `${/^[\p{L}\p{N}_.]+$/u.test(h.수량) ? h.수량 : `(${h.수량})`} * ${String(h.요소)}`,
|
||||
);
|
||||
return `(${terms.length ? terms.join(" + ") : "0"})`;
|
||||
};
|
||||
|
||||
/** 답 → 로직 줄 */
|
||||
export function buildRow(a: WAnswers): LogicRow {
|
||||
const mids: { 이름: string; 식: string; 출처?: string }[] = [];
|
||||
@@ -222,7 +235,11 @@ export function buildRow(a: WAnswers): LogicRow {
|
||||
}));
|
||||
const 덧줄 = a.extras.map((e) =>
|
||||
e.k === "비율"
|
||||
? { 이름: e.name, 식: `${e.base} * ${num(e.rate)} / 100`, 비목: e.cost }
|
||||
? {
|
||||
이름: e.name,
|
||||
식: `${e.base === "사람줄합" ? personSum(호표) : e.base} * ${num(e.rate)} / 100`,
|
||||
비목: e.cost,
|
||||
}
|
||||
: { 이름: e.name, 식: num(e.amount), 비목: e.cost },
|
||||
);
|
||||
return { ...base, 입력: inputsOf(a), 중간: mids, 호표, 덧줄, 끝수: null };
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
* ========================================================================== */
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { createButton, createInputField, createSelectField, el } from "@ui/ui_template_elements";
|
||||
import {
|
||||
createButton,
|
||||
createInputField,
|
||||
createSelectField,
|
||||
el,
|
||||
showToast,
|
||||
} from "@ui/ui_template_elements";
|
||||
import { fetchPick } from "../M01_MasterData_Api_Fetch";
|
||||
import { openEasyPick } from "../EasyCalc/M01_EasyCalc_Pick";
|
||||
import { plainError } from "../EasyCalc/M01_EasyCalc_Api";
|
||||
@@ -50,9 +56,11 @@ const TEXT = {
|
||||
DSurchargeNum: ["{p} % 를 더함", "add {p} %"],
|
||||
DSurchargeIn: ["「{n}」 % 를 더함(입력값)", "add “{n}” % (input)"],
|
||||
DSurchargeCond: [
|
||||
"「{i}」 가 {l} {o} 이면 0 · 넘으면 「{t}」 의 {c} % 를 더함",
|
||||
"if “{i}” {o} {l} add 0, else “{t}” {c} %",
|
||||
"「{i}」 가 {l} {o}이면 0 · 아니면 「{t}」 의 {c} % 를 더함",
|
||||
"if “{i}” is {l} {o} add 0, else “{t}” {c} %",
|
||||
],
|
||||
OpLe: ["이하", "or less"],
|
||||
OpLt: ["미만", "under"],
|
||||
DDivNum: ["{n} 로 나눔", "divide by {n}"],
|
||||
DDivIn: ["「{n}」 로 나눔(입력값)", "divide by “{n}” (input)"],
|
||||
DMin: ["{n} 보다 작은 값", "smaller of value and {n}"],
|
||||
@@ -127,7 +135,7 @@ const describe = (m: Mod): string => {
|
||||
: t("DSurchargeCond", {
|
||||
i: r.input,
|
||||
l: r.limit,
|
||||
o: r.op === "<=" ? "≤" : "<",
|
||||
o: t(r.op === "<=" ? "OpLe" : "OpLt"),
|
||||
t: r.table.이름,
|
||||
c: r.col,
|
||||
});
|
||||
@@ -371,7 +379,7 @@ export function stepCalc(ctx: WCtx, host: HTMLElement): void {
|
||||
export async function autoLinks(ctx: WCtx): Promise<void> {
|
||||
const { a } = ctx;
|
||||
for (const col of colsOf(a, "결과")) {
|
||||
if (a.links.some((l) => l.col === col)) continue;
|
||||
if (a.links.some((l) => l.col === col && l.kind !== "없음")) continue;
|
||||
const unit = a.table.값칸[col] ?? "";
|
||||
const link: Link = { col, kind: "없음", name: col, spec: "", unit, element: null };
|
||||
try {
|
||||
@@ -393,6 +401,7 @@ export async function autoLinks(ctx: WCtx): Promise<void> {
|
||||
} catch {
|
||||
/* 못 찾으면 연결 안 함으로 둠 */
|
||||
}
|
||||
a.links = a.links.filter((l) => l.col !== col);
|
||||
a.links.push(link);
|
||||
}
|
||||
ctx.changed();
|
||||
@@ -441,7 +450,10 @@ export function stepLink(ctx: WCtx, host: HTMLElement): void {
|
||||
attrs: { type: "button" },
|
||||
text: t(label),
|
||||
});
|
||||
b.addEventListener("click", () => void pick(kind, pk).catch((e) => alert(plainError(e))));
|
||||
b.addEventListener(
|
||||
"click",
|
||||
() => void pick(kind, pk).catch((e) => showToast(plainError(e), "error")),
|
||||
);
|
||||
return b;
|
||||
});
|
||||
const none = el("button", {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/* =============================================================================
|
||||
* M01_LB_Wizard_Parts.ts
|
||||
* 단계 안내 곁부품 — 서버 읽기(절 · 표) · 표 → WTable · 원문 표 미리 보기 · `M01_LB_Wizard.ts` 가 부름
|
||||
* ========================================================================== */
|
||||
|
||||
import { API_BASE_URL } from "@config/config_frontend";
|
||||
import { el } from "@ui/ui_template_elements";
|
||||
import { ApiError } from "../M01_MasterData_UI_Logic_Api";
|
||||
import type { Role, WTable } from "./M01_LB_Wizard_Build";
|
||||
|
||||
export async function get<T>(path: string, params: Record<string, string>): Promise<T> {
|
||||
const res = await fetch(`${API_BASE_URL}/m01${path}?${new URLSearchParams(params)}`, {
|
||||
credentials: "include",
|
||||
});
|
||||
const data = (await res.json().catch(() => ({}))) as { detail?: unknown } & T;
|
||||
if (!res.ok) throw new ApiError(res.status, data.detail ?? res.statusText);
|
||||
return data;
|
||||
}
|
||||
|
||||
export interface SectionItem {
|
||||
section: string;
|
||||
title: string;
|
||||
chapter: string;
|
||||
tables: number;
|
||||
logics: number;
|
||||
}
|
||||
export interface TableHead {
|
||||
file: string;
|
||||
키: string;
|
||||
이름: string;
|
||||
기준: string;
|
||||
조건: Record<string, string>;
|
||||
값칸: Record<string, string>;
|
||||
count: number;
|
||||
}
|
||||
|
||||
/** 서버 표 답 → WTable */
|
||||
export function toTable(raw: WTable & { 키: string }, file: string): WTable {
|
||||
return {
|
||||
key: raw.키,
|
||||
file,
|
||||
이름: raw.이름,
|
||||
기준: raw.기준 ?? "",
|
||||
출처: raw.출처 ?? "",
|
||||
조건: raw.조건,
|
||||
값칸: raw.값칸,
|
||||
범위규칙: raw.범위규칙 ?? null,
|
||||
줄: raw.줄,
|
||||
주: raw.주 ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
const cellText = (v: unknown): string =>
|
||||
Array.isArray(v)
|
||||
? v.map((x) => x ?? "").join("~")
|
||||
: v === null || v === undefined
|
||||
? ""
|
||||
: String(v);
|
||||
|
||||
/** 원문 표 앞 몇 줄 + 주 — 칸 머리 색 = 역할 */
|
||||
export function tablePreview(
|
||||
tb: WTable,
|
||||
labels: { preview: string; notes: string },
|
||||
roles?: Record<string, Role>,
|
||||
): HTMLElement {
|
||||
const cols = [...Object.keys(tb.조건), ...Object.keys(tb.값칸)];
|
||||
const head = el("tr", {
|
||||
children: cols.map((c) =>
|
||||
el("th", { className: `is-${roles?.[c] ?? (c in tb.조건 ? "조건" : "결과")}`, text: c }),
|
||||
),
|
||||
});
|
||||
const rows = tb.줄
|
||||
.slice(0, 6)
|
||||
.map((r) => el("tr", { children: cols.map((c) => el("td", { text: cellText(r[c]) })) }));
|
||||
return el("div", {
|
||||
className: "m01-lbw__table",
|
||||
children: [
|
||||
el("h5", { text: `${labels.preview} — ${tb.이름} (${tb.기준 || "—"})` }),
|
||||
el("div", {
|
||||
className: "m01-lbw__scroll",
|
||||
children: [el("table", { children: [head, ...rows] })],
|
||||
}),
|
||||
...(tb.줄.length > 6
|
||||
? [el("p", { className: "m01-lbw__muted", text: `… ${tb.줄.length} 줄` })]
|
||||
: []),
|
||||
...(tb.주.length
|
||||
? [
|
||||
el("h5", { text: labels.notes }),
|
||||
...tb.주.map((n) => el("p", { className: "m01-lbw__note-line", text: n })),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user