fix(M01): 일위대가 조합 화면 — 계약 9장대로 맞춤 · 수량은 저장하지 않고 미리 보기 때만 보냄
- 담은 로직 줄 = {로직, 메모} 뿐 · 입력값(수량)은 화면 안 메모로만 두고 조합에 안 저장
- 서버 길 실제 이름으로 맞춤: /combo/new · /combo/edit(판본) · /combo/delete(판본) · 422 검사 글·409 낡은 판본 안내
- 미리 보기는 화면이 로직마다 부르지 않고 POST /combo/preview 한 번에 받아 비목별 합계를 찍음
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WRFJmmhPi4exAzHgPZHMT
This commit is contained in:
@@ -12,12 +12,13 @@ import {
|
||||
showConfirmDialog,
|
||||
showToast,
|
||||
} from "@ui/ui_template_elements";
|
||||
import { fetchLogics, type LogicSummary } from "./M01_MasterData_UI_Logic_Api";
|
||||
import { ApiError, fetchLogics, type LogicSummary } from "./M01_MasterData_UI_Logic_Api";
|
||||
import {
|
||||
deleteCombo,
|
||||
editCombo,
|
||||
fetchCombo,
|
||||
fetchCombos,
|
||||
saveCombo,
|
||||
newCombo,
|
||||
type Combo,
|
||||
type ComboSummary,
|
||||
} from "./M01_MasterData_UI_Combo_Api";
|
||||
@@ -32,13 +33,25 @@ const FILTER_ID = "조합|";
|
||||
const blankCombo = (): Combo => ({
|
||||
키: "",
|
||||
이름: "",
|
||||
구분: "",
|
||||
상세구분: "",
|
||||
단위: "",
|
||||
비고: "",
|
||||
로직: [],
|
||||
구분: null,
|
||||
상세구분: null,
|
||||
단위: null,
|
||||
담은로직: [],
|
||||
출처: "자체",
|
||||
소유: "현장",
|
||||
비고: null,
|
||||
});
|
||||
|
||||
/** 서버가 준 까닭 — 422 는 검사 글 목록 · 409 는 낡은 판본 */
|
||||
function reason(error: unknown): string {
|
||||
if (error instanceof ApiError && typeof error.detail === "object" && error.detail) {
|
||||
const d = error.detail as { errors?: string[]; stale?: string[] };
|
||||
if (d.errors) return d.errors.join(" / ");
|
||||
if (d.stale) return tc("Stale");
|
||||
}
|
||||
return error instanceof Error ? error.message : tc("Load_Failed");
|
||||
}
|
||||
|
||||
export interface ComboHandle {
|
||||
/** 컨테이너를 펼칠 때 — 목록을 새로 받아 그림 */
|
||||
show: () => Promise<void>;
|
||||
@@ -71,13 +84,15 @@ export function mountM01Combo(
|
||||
|
||||
/* --- 왼쪽 거름 --- */
|
||||
const drawFilter = (): void => {
|
||||
const subs = [...new Set(items.map((x) => x.구분).filter(Boolean))].map((name) => ({
|
||||
name,
|
||||
book: null,
|
||||
details: [...new Set(items.filter((x) => x.구분 === name).map((x) => x.상세구분))].filter(
|
||||
Boolean,
|
||||
),
|
||||
}));
|
||||
const subs = [...new Set(items.map((x) => x.구분).filter((v): v is string => !!v))].map(
|
||||
(name) => ({
|
||||
name,
|
||||
book: null,
|
||||
details: [...new Set(items.filter((x) => x.구분 === name).map((x) => x.상세구분))].filter(
|
||||
(v): v is string => !!v,
|
||||
),
|
||||
}),
|
||||
);
|
||||
filterHost.replaceChildren(
|
||||
side.filter({
|
||||
id: FILTER_ID,
|
||||
@@ -99,7 +114,11 @@ export function mountM01Combo(
|
||||
el("div", {
|
||||
className: "m01-logic__section-head",
|
||||
children: [
|
||||
createButton({ label: tc("New"), variant: "filled", onClick: () => draw(blankCombo()) }),
|
||||
createButton({
|
||||
label: tc("New"),
|
||||
variant: "filled",
|
||||
onClick: () => draw(blankCombo(), ""),
|
||||
}),
|
||||
...more,
|
||||
],
|
||||
});
|
||||
@@ -120,8 +139,8 @@ export function mountM01Combo(
|
||||
const tr = el("tr", {
|
||||
className: "m01-master__table-row",
|
||||
attrs: { "data-combo-key": x.키 },
|
||||
children: [x.키, x.이름, x.구분, x.상세구분, x.단위, String(x.로직수)].map((v) =>
|
||||
el("td", { text: v }),
|
||||
children: [x.키, x.이름, x.구분 ?? "", x.상세구분 ?? "", x.단위 ?? "", String(x.count)].map(
|
||||
(v) => el("td", { text: v }),
|
||||
),
|
||||
});
|
||||
tr.addEventListener("click", () => void open(x.키));
|
||||
@@ -150,41 +169,46 @@ export function mountM01Combo(
|
||||
|
||||
const open = async (key: string): Promise<void> => {
|
||||
try {
|
||||
draw(await fetchCombo(key));
|
||||
const one = await fetchCombo(key);
|
||||
draw(one.combo, one.version);
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : tc("Load_Failed"), "error");
|
||||
}
|
||||
};
|
||||
|
||||
/* --- 상세 --- */
|
||||
const draw = (combo: Combo): void => {
|
||||
const draw = (combo: Combo, version: string): void => {
|
||||
const field = (label: string, name: "이름" | "구분" | "상세구분" | "단위" | "비고") => {
|
||||
const f = createInputField({ type: "text", label });
|
||||
f.input.value = combo[name];
|
||||
f.input.value = combo[name] ?? "";
|
||||
f.input.setAttribute("data-combo-field", name);
|
||||
f.input.addEventListener("input", () => (combo[name] = f.input.value));
|
||||
f.input.addEventListener("input", () => {
|
||||
const v = f.input.value;
|
||||
if (name === "이름") combo.이름 = v;
|
||||
else combo[name] = v || null;
|
||||
});
|
||||
return f.root;
|
||||
};
|
||||
const preview = buildPreview(() => combo.로직);
|
||||
const preview = buildPreview(() => combo);
|
||||
const table = el("div");
|
||||
const drawTable = (): void => {
|
||||
const move = (i: number, d: number): void => {
|
||||
const j = i + d;
|
||||
if (j < 0 || j >= combo.로직.length) return;
|
||||
[combo.로직[i], combo.로직[j]] = [combo.로직[j], combo.로직[i]];
|
||||
if (j < 0 || j >= combo.담은로직.length) return;
|
||||
[combo.담은로직[i], combo.담은로직[j]] = [combo.담은로직[j], combo.담은로직[i]];
|
||||
drawTable();
|
||||
};
|
||||
const trs = combo.로직.map((row, i) => {
|
||||
const info = logics.get(row.키);
|
||||
const trs = combo.담은로직.map((row, i) => {
|
||||
const info = logics.get(row.로직);
|
||||
const memo = createInputField({ type: "text" });
|
||||
memo.input.value = row.메모;
|
||||
memo.input.addEventListener("input", () => (row.메모 = memo.input.value));
|
||||
memo.input.value = row.메모 ?? "";
|
||||
memo.input.addEventListener("input", () => (row.메모 = memo.input.value || null));
|
||||
const name = el("button", {
|
||||
className: "ui-btn ui-btn--ghost",
|
||||
text: info?.이름 ?? row.키,
|
||||
text: info?.이름 ?? row.로직,
|
||||
attrs: { type: "button", title: tc("Open") },
|
||||
});
|
||||
name.addEventListener("click", () => onOpenLogic(row.키));
|
||||
name.addEventListener("click", () => onOpenLogic(row.로직));
|
||||
const btns = el("div", {
|
||||
className: "m01-logic__chips",
|
||||
children: [
|
||||
@@ -194,17 +218,17 @@ export function mountM01Combo(
|
||||
label: tc("Remove"),
|
||||
variant: "ghost",
|
||||
onClick: () => {
|
||||
combo.로직.splice(i, 1);
|
||||
combo.담은로직.splice(i, 1);
|
||||
drawTable();
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
return el("tr", {
|
||||
attrs: { "data-combo-logic": row.키 },
|
||||
attrs: { "data-combo-logic": row.로직 },
|
||||
children: [
|
||||
el("td", { text: String(i + 1) }),
|
||||
el("td", { text: row.키 }),
|
||||
el("td", { text: row.로직 }),
|
||||
el("td", { children: [name] }),
|
||||
el("td", { text: info?.결과단위 ?? "" }),
|
||||
el("td", { children: [memo.root] }),
|
||||
@@ -241,7 +265,7 @@ export function mountM01Combo(
|
||||
onClick: () =>
|
||||
openLogicPicker((x) => {
|
||||
if (!logics.has(x.키)) logics.set(x.키, x);
|
||||
combo.로직.push({ 키: x.키, 메모: "", 입력: {} });
|
||||
combo.담은로직.push({ 로직: x.키, 메모: null });
|
||||
drawTable();
|
||||
}),
|
||||
});
|
||||
@@ -251,12 +275,13 @@ export function mountM01Combo(
|
||||
onClick: async () => {
|
||||
if (!combo.이름.trim()) return showToast(tc("NeedName"), "error");
|
||||
try {
|
||||
const saved = await saveCombo(combo);
|
||||
const key = combo.키 ? combo.키 : (await newCombo(combo)).key;
|
||||
if (combo.키) await editCombo(combo.키, version, combo);
|
||||
showToast(tc("Saved"), "success");
|
||||
await load();
|
||||
draw(saved);
|
||||
await open(key);
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : tc("Load_Failed"), "error");
|
||||
showToast(reason(error), "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -266,11 +291,11 @@ export function mountM01Combo(
|
||||
onClick: async () => {
|
||||
if (!combo.키 || !(await showConfirmDialog(tc("DeleteAsk")))) return;
|
||||
try {
|
||||
await deleteCombo(combo.키);
|
||||
await deleteCombo(combo.키, version);
|
||||
showToast(tc("Deleted"), "success");
|
||||
await load();
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : tc("Load_Failed"), "error");
|
||||
showToast(reason(error), "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user