- 부품 모달에 갈래 묻기 askChoice(취소 + 단추 여럿 · 고른 값 · 취소 = null) · 부품 모음 견본 한 칸 - 새 M02_MasterTemplete_Library_SameAsk.ts — 409 같은것 → 「그것을 씀 / 그래도 새로」 → 몸 씀 · 새로 로 다시 부름 - from-line(단가산출로도 저장 · 단가산출로 저장) · 공유 승인 · B09 내 자료집에 물음 · 취소 = 저장 안 함 - 새로 만들기(나무 · 목록 [생성])는 빈 문서라 서버가 묻지 않음 — 화면 손대지 않음 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
/* =============================================================================
|
|
* M02_MasterTemplete_Sangeun_Cover.ts
|
|
* 단가산출(SK) 셈 길 부름 · 뺀 줄 띠(PLAN 717-2b · 717-3 · 724-1)
|
|
* · 셈 = `calcSangeun`(`POST /layers/{층}/sangeun/calc` · 저장 안 함 · 부르는 쪽이 최신 응답만 받음) ·
|
|
* [단가산출로 저장] = `sangeunFromLine`(`/sangeun/from-line`)
|
|
* · 고침 표는 공용 상세(`M01_MasterData_UI_LogicLab_Ho` · 724-1) — 여기는 뺀 줄 되살림 띠만
|
|
* ========================================================================== */
|
|
|
|
import { createBadge } from "@ui/ui_template_badge";
|
|
import { createButton } from "@ui/ui_template_button";
|
|
import { el } from "@ui/ui_template_elements";
|
|
import { t as L } from "@ui/ui_template_locale";
|
|
import { createText } from "@ui/ui_template_text";
|
|
import { call, type Layer } from "./M02_MasterTemplete_Api_Fetch";
|
|
import { withSameAsk } from "./M02_MasterTemplete_Library_SameAsk";
|
|
import type { PatchRow, SkAnswer } from "./logic/M02_Sangeun_Cover_Model";
|
|
import "./M02_MasterTemplete_Sangeun.css";
|
|
|
|
export interface SkScope {
|
|
layer: Layer;
|
|
owner: string | null;
|
|
}
|
|
const q = (scope: SkScope): string =>
|
|
scope.owner && scope.layer !== "system" ? `?owner=${encodeURIComponent(scope.owner)}` : "";
|
|
|
|
/** 셈(저장 안 함) — 문서 = 화면 문서 · `given` = 시험 입력(빈 칸 뺌) · 서버가 M01 엔진 한 벌로 셈 */
|
|
export function calcSangeun<T = SkAnswer>(
|
|
scope: SkScope,
|
|
doc: Record<string, unknown>,
|
|
given: Record<string, string> = {},
|
|
): Promise<T> {
|
|
const 입력값 = Object.fromEntries(Object.entries(given).filter(([, v]) => String(v).trim()));
|
|
return call<T>(`/layers/${scope.layer}/sangeun/calc${q(scope)}`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ 문서: doc, 입력값 }),
|
|
});
|
|
}
|
|
|
|
/** [단가산출로 저장] — 그 층 새 SK · 답 = 새 키 + 그 SK 참조 줄 · 같은 내용이 있으면 물음(733-3 ·
|
|
* 그것을 씀 = 그 키 · 그래도 새로) · 취소 = null */
|
|
export const sangeunFromLine = (
|
|
scope: SkScope,
|
|
line: PatchRow & Record<string, unknown>,
|
|
이름: string,
|
|
단위: string,
|
|
): Promise<{ 이름: string; 줄: Record<string, unknown> } | null> =>
|
|
withSameAsk((extra) =>
|
|
call(`/layers/${scope.layer}/sangeun/from-line${q(scope)}`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ 줄: line, 이름, 단위, ...extra }),
|
|
}),
|
|
);
|
|
|
|
/** 뺀 줄(cid · 이름) 띠 — 고칠 수 있으면 [되살림] */
|
|
export function removedStrip(
|
|
removed: { cid: string; 이름: string }[],
|
|
edit: boolean,
|
|
onRestore: (cid: string) => void,
|
|
): HTMLElement[] {
|
|
if (!removed.length) return [];
|
|
return [
|
|
el("div", {
|
|
className: "m02-sk__removed",
|
|
attrs: { "data-removed": "" },
|
|
children: [
|
|
createText(L("M02_SangeunRemoved")),
|
|
...removed.map((x) =>
|
|
el("span", {
|
|
className: "m02-sk__removed-item",
|
|
children: [
|
|
createBadge(x.이름, "neutral"),
|
|
...(edit
|
|
? [
|
|
createButton({
|
|
label: L("M02_SangeunRestore"),
|
|
variant: "ghost",
|
|
size: 22,
|
|
onClick: () => onRestore(x.cid),
|
|
}),
|
|
]
|
|
: []),
|
|
],
|
|
}),
|
|
),
|
|
],
|
|
}),
|
|
];
|
|
}
|