Files
Aislo/M02_MasterTemplete/M02_MasterTemplete_Labor_RowModal.ts
T
eomsangdonandClaude Opus 5.5 d6715dcec5 refactor(856-1): 단가산출 상세 몸 걷기 — 줄 쌓기 한 벌 · 열 때 서버 셈 한 번
- 지움: M01 LogicLab_Ho · LogicLab_Cover · M02 Sangeun_Cover_Model · Sangeun_Undo · Sangeun_BaseHead · Labor_RowSk
- Sangeun_Detail: 숨긴 몸 · 바탕 원값(bare) 셈 · 덮개 고침 · 재료 고름 · 키 글자 약속(SK-000000) 걷음 → 모드 옵션(page · ref · memory)
- Sangeun_Tabs: 몸 그릇 · 숨김 걷음 · Sangeun_Cover: 뺀 줄 띠 걷음 · 셈 보기 덧칸 끔(머리 띠는 안 씀) · 머리 띠 타입만 둠(856-2 에서 파일째)
- 일위대가 줄 모달: 로직 줄 · 셈 주입 줄 = 안내 한 줄(856-3 까지) · 상세 · [적용] 걷음 · 줄 패치 칸 · 타입 걷음(저장본 0)
- M01 LogicLab_Detail: M02 몸 칸 걷음(M01 보기 그대로) · 지운 파일만 쓰던 글 키 16 · CSS 규칙 걷음
- 시험: 지운 몸만 붙든 시험 지움(717_3 · 722 · 748_0 · helper 728_2 · 748_0) · 섞인 파일은 몸 꼴 · 글 대조 함수 · 줄만 지움(서버 셈 시험 남김) · 856-0 단언 뒤집음
- 수치: 열 때 /sangeun/calc 2 → 1 · 숨은 몸 DOM 2 → 0 · 화면 파일 줄 −1.9 천 안팎

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 19:36:59 +09:00

173 lines
6.7 KiB
TypeScript

/* =============================================================================
* M02_MasterTemplete_Labor_RowModal.ts
* 일위대가표 줄 누름 모달(PLAN 723-2 · 요구서_내역16 2장 4 · 5 · 856-1) — 일위대가표에서 빠진 줄 동작을 모달 안으로.
* · 로직 줄(단가산출 문서 없음) · 셈 주입 줄(프로젝트 사본) = 머리(이름 · 「1 ㎡ 당」 · 옵션 값 · 메모) + 안내 한 줄
* (856-1 — 옛 단가산출 상세 몸 · [적용] 걷음 · 고침 = 단가산출 줄 쌓기 · 856-3 에서 줄 쌓기 보기로) ·
* 로직 자재(바꾸기 · 기본 · 세 칸 · `Labor_LogicMats`)
* · 사용자 자재 줄 = 자재 모달(세 칸 · `Labor_MatTable` 한 줄)
* · 고침 = 그 줄 화면 캐시(저장은 [저장]) · 금액은 표가 다시 셈 → `watch` 로 받아 다시 그림
* ========================================================================== */
import { createBanner } from "@ui/ui_template_banner";
import { el, showToast } from "@ui/ui_template_elements";
import { openModal } from "@ui/ui_template_modal";
import { createText } from "@ui/ui_template_text";
import type { ItemLogic } from "./M02_MasterTemplete_Api_Fetch";
import type { LaborCalc, LaborMat, LaborRow, MatMarkKey } from "./M02_MasterTemplete_Labor_Api";
import { logicMatRows } from "./M02_MasterTemplete_Labor_LogicMats";
import { setLogicMark, setMark } from "./M02_MasterTemplete_Labor_MatMarks";
import { matTable } from "./M02_MasterTemplete_Labor_MatTable";
import { tc } from "./M02_MasterTemplete_Labor_Text";
import { valueLine } from "./M02_Labor_Values_Model";
/** 표가 다시 센 답을 받음 — 돌려준 함수 = 그만 받음 */
export type CalcWatch = (fn: (calc: LaborCalc | null) => void) => () => void;
export interface RowModalOptions {
row: LaborRow;
logic: ItemLogic | null;
title: string;
/** 일위대가 머리(이름 · 「1 ㎡ 당」) */
head: string;
readOnly: boolean;
/** 셈 주입(프로젝트 복사본) — 안내 글이 다름 */
inject: boolean;
/** 사용자 자재 코드 — 로직 자재 [바꾸기]로 같은 품목 막음 */
userMats: string[];
watch: CalcWatch;
/** 고침 뒤 — `again` = 서버 다시 셈(입력 · 고름 · 별도계상) · 아니면 화면만 */
done: (again: boolean) => void;
}
const TEXT = {
NoDoc: [
"M01 로직을 바로 담은 줄 — 단가산출 화면 없음 · 고침은 단가산출로 담아(일위대가 [로직 추가]) 그 줄에서",
"Uses the M01 logic directly — add it as a build-up to edit",
],
FromSk: [
"단가산출 「{k}」 에서 담아 온 줄 — 고침은 그 단가산출에서 고쳐 다시 담음",
"Copied from build-up 「{k}」 — edit it there and re-add",
],
Inject: [
"프로젝트 사본 줄 — 단가산출 화면 없음 · 수식 고침은 M02 단가산출에서 고쳐 [재생성]",
"Project copy line — edit the build-up in M02 and regenerate",
],
} as const;
const t = (k: keyof typeof TEXT): string => TEXT[k][0];
export function openRowModal(o: RowModalOptions): void {
const row = o.row;
const edit = !o.readOnly;
const info = el("div", { attrs: { "data-row-head": "" } });
const mats = el("div", { attrs: { "data-row-mats": "" } });
let calc: LaborCalc | null = null;
const draw = (): void => {
const values = valueLine(o.logic?.입력 ?? [], row.입력값);
info.replaceChildren(
createText(o.head, "muted", 14),
...(values.text ? [createText(values.text)] : []),
...(values.empty
? [createText(tc("Labor_Empty").replace("{n}", String(values.empty)), "error")]
: []),
...(row.켜쌓기율 != null
? [createText(tc("Labor_Layer").replace("{n}", String(row.켜쌓기율)), "muted")]
: []),
...(row.메모 ? [createText(row.메모, "muted")] : []),
);
const lead = row.참조
? []
: logicMatRows([row], calc, !calc, {
open: () => undefined,
...(edit
? {
swap: (_r: number, at: number, key: string) => {
if (o.userMats.includes(key))
return showToast(tc("Labor_AlreadyMat").replace("{value}", key), "error");
row.고름 = { ...row.고름, [String(at)]: key };
o.done(true);
},
reset: (_r: number, at: number) => {
if (!row.고름) return;
delete row.고름[String(at)];
if (!Object.keys(row.고름).length) delete row.고름;
o.done(true);
},
mark: (_r: number, at: number, key: MatMarkKey, v: string) => {
setLogicMark(row, at, key, v);
o.done(key === "별도계상");
draw();
},
}
: {}),
});
mats.replaceChildren(
...(lead.length
? [el("h4", { text: tc("Labor_Mats") }), matTable({ mats: [], calc, lead })]
: []),
);
};
// 안내 한 줄(856-1) — 로직 줄 = 온 단가산출(`본뜬`) · 셈 주입 = 프로젝트 사본
const from = row.본뜬 && typeof row.본뜬.이름 === "string" ? row.본뜬.이름 : "";
const note = createBanner({
tone: "info",
text: o.inject ? t("Inject") : from ? t("FromSk").replace("{k}", from) : t("NoDoc"),
});
const stop = o.watch((c) => {
calc = c;
draw();
});
openModal({
title: o.title,
closeLabel: tc("In_Close"),
width: "1100px",
wide: true,
beforeClose: () => (stop(), true),
mount: (body) => body.append(info, note, mats),
});
draw();
}
export interface MatModalOptions {
mat: LaborMat;
watch: CalcWatch;
readOnly: boolean;
/** 세 칸 고침 뒤 — `money` = 별도계상(금액에 닿음) */
done: (money: boolean) => void;
}
/** 사용자 자재 줄 — 세 칸(148-4 · 222-1) · 가격 다섯 보기 */
export function openMatModal(o: MatModalOptions): void {
const host = el("div", { attrs: { "data-row-mat": o.mat.코드 } });
let calc: LaborCalc | null = null;
const draw = (): void =>
host.replaceChildren(
matTable(
{ mats: [o.mat], calc },
o.readOnly
? { open: () => undefined }
: {
open: () => undefined,
mark: (_i, key, v) => {
setMark(o.mat, key, v);
o.done(key === "별도계상");
draw();
},
},
),
);
const stop = o.watch((c) => {
calc = c;
draw();
});
openModal({
title: `${o.mat.코드} ${o.mat.이름 ?? ""}`.trim(),
closeLabel: tc("In_Close"),
width: "1100px",
beforeClose: () => (stop(), true),
mount: (body) => body.append(host),
});
draw();
}