- 새 서버 길 PUT /api/projects/{id}/items/{사본 id}/link — 그 시설 조합 칸 하나만 정본에
(관 지점 = pipe_points.json 노선 지문 그대로 · 박스/관 facility 로 가름 · 구조물 = 판번호 +1) → safe_sync
- 구조물도 모달 맨 위 「조합 연결」 칸(새 B08_Quantity_UI_Link) — 칸마다 연결 여부 · [선택]
- B05/B06 세션 초안(구조물 · 관) 있으면 막고 「B05 · B06 [저장] 먼저」 알림 · 저장 뒤 탭 몸통 새로 그림
- 공용 창구 projectItems().link 추가 · 새 시험 test_154_2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01STqEqztUthVFBmEP18wBSz
159 lines
6.1 KiB
TypeScript
159 lines
6.1 KiB
TypeScript
/* =============================================================================
|
|
* B08_Quantity_UI_Drawing.ts
|
|
* 구조물 집계표 행 → 구조물도 모달(PLAN 95-3) — 그 측점에 놓인 조합 전부를 세로로 쌓음.
|
|
* 조합 한 개 = M02 항목 카드(`M02_MasterTemplete_ItemCards`) 그대로 — 도면(도각 포함 · 보기 전용 CAD ·
|
|
* 여러 장이면 장 탭) + 면적산출.
|
|
*
|
|
* 원천 = 그 구조물의 프로젝트 사본만(연결된 사본 · PLAN 143-1) — 없으면 「사본 없음」 · 읽기만
|
|
* 조합 목록 = 집계표와 같음(`B08_Quantity_Summary_Data` `combosAt`)
|
|
* 미연결 시설이 있으면 맨 위 「조합 연결」 칸(`B08_Quantity_UI_Link` · PLAN 154-2) — 저장하면 닫고 다시 셈
|
|
* 카드 · CAD · 스프레드시트는 모달을 열 때만 `import()` · 닫을 때 카드를 모두 정리
|
|
* ========================================================================== */
|
|
|
|
import "./B08_Quantity_UI_Drawing.css";
|
|
import { ui_locales, currentLanguageIndex } from "@ui/ui_template_locale";
|
|
import { openModal } from "@ui/ui_template_modal";
|
|
import { PART_OF, projectItems } from "@ui/ui_template_item_picker_project";
|
|
import type { ItemCardsHandle } from "../M02_MasterTemplete/M02_MasterTemplete_ItemCards";
|
|
import type { ItemSource } from "../M02_MasterTemplete/M02_MasterTemplete_ItemSource";
|
|
import { summaryTooltip, type SummaryItem } from "../common_util/common_util_summary_item";
|
|
import type {
|
|
ComboLabel,
|
|
LinkedSnapshot,
|
|
StationCombo,
|
|
UnlinkedFacility,
|
|
} from "./B08_Quantity_Summary_Data";
|
|
import { linkSection } from "./B08_Quantity_UI_Link";
|
|
|
|
function L(key: keyof typeof ui_locales): string {
|
|
return ui_locales[key][currentLanguageIndex];
|
|
}
|
|
|
|
function note(text: string): HTMLElement {
|
|
const node = document.createElement("p");
|
|
node.className = "ui-general-block__empty";
|
|
node.textContent = text;
|
|
return node;
|
|
}
|
|
|
|
export interface SheetsRequest {
|
|
projectId: string;
|
|
/** 모달 제목에 붙는 측점 글 */
|
|
station: string;
|
|
combos: StationCombo[];
|
|
/** 연결된 사본 `{구조물 id: 사본}`(집계 응답 · 143-1) */
|
|
linked: Record<string, LinkedSnapshot>;
|
|
describe: (item: SummaryItem) => ComboLabel | null;
|
|
/** 그 측점 미연결 시설(154) */
|
|
unlinked: UnlinkedFacility[];
|
|
/** 바로 연결을 저장한 뒤 — 집계표 다시 셈 */
|
|
onLinked: () => void;
|
|
}
|
|
|
|
/** 사본 폴더 읽기 — 그 부분 파일이 없으면 던짐(카드가 「없음」). */
|
|
function sourceOf(projectId: string, folder: string): ItemSource {
|
|
const items = projectItems(projectId);
|
|
return {
|
|
layer: "project",
|
|
projectId,
|
|
read: async (part) => {
|
|
const doc = await items.read(folder, PART_OF[part]);
|
|
if (doc == null) throw new Error(L("B08_Quantity_Sheets_NoCopy"));
|
|
return { 문서: doc };
|
|
},
|
|
};
|
|
}
|
|
|
|
/** 조합 한 칸 — 제목줄(이름 · 원천) + 안내 + 카드. */
|
|
function comboSection(
|
|
request: SheetsRequest,
|
|
combo: StationCombo,
|
|
createItemCards: typeof import("../M02_MasterTemplete/M02_MasterTemplete_ItemCards").createItemCards,
|
|
handles: ItemCardsHandle[],
|
|
): HTMLElement {
|
|
const label = request.describe(combo.item);
|
|
const name = label
|
|
? [label.group, label.name].filter(Boolean).join(" ")
|
|
: combo.item.name || combo.item.key;
|
|
const copy = combo.copyId ? request.linked[combo.copyId] : undefined;
|
|
const section = document.createElement("section");
|
|
section.className = "b08-sheets__combo";
|
|
section.dataset.b08Combo = combo.id;
|
|
const title = document.createElement("h4");
|
|
title.className = "b08-sheets__title";
|
|
title.textContent = name;
|
|
title.title = summaryTooltip(combo.item);
|
|
section.append(title);
|
|
if (!copy) {
|
|
section.append(note(L("B08_Quantity_Drawing_Missing")));
|
|
return section;
|
|
}
|
|
const source = sourceOf(request.projectId, copy.폴더);
|
|
const from = document.createElement("span");
|
|
from.className = "b08-sheets__from";
|
|
from.textContent = L("B08_Quantity_Sheets_FromCopy");
|
|
title.append(from);
|
|
if (!copy.부분.includes("도면")) section.append(note(L("B08_Quantity_Drawing_NoDrawing")));
|
|
const cards = createItemCards({
|
|
source: () => source,
|
|
editable: () => false,
|
|
onEdit: () => undefined,
|
|
warnOnFail: () => false, // 못 읽으면 카드에 「없음」
|
|
});
|
|
handles.push(cards);
|
|
section.append(cards.root);
|
|
void cards.load({ id: copy.폴더, label: name });
|
|
return section;
|
|
}
|
|
|
|
/** 모달을 엶 — 조합이 없으면 안내 한 줄 · 불러오다 실패하면 까닭 한 줄. */
|
|
export function openStructureSheets(request: SheetsRequest): void {
|
|
const handles: ItemCardsHandle[] = [];
|
|
let closed = false;
|
|
openModal({
|
|
title: `${request.station} ${L("B08_Quantity_Sheets_Title")}`,
|
|
closeLabel: L("Common_Btn_Close"),
|
|
dialogClass: "b08-sheets",
|
|
beforeClose: () => {
|
|
closed = true; // 아직 불러오는 중이면 뒤늦게 카드를 만들지 않음
|
|
handles.forEach((cards) => cards.destroy());
|
|
return true;
|
|
},
|
|
mount: (body, close) => {
|
|
const linking = request.unlinked.length
|
|
? [
|
|
linkSection(request.projectId, request.unlinked, () => {
|
|
closed = true;
|
|
handles.forEach((cards) => cards.destroy());
|
|
close();
|
|
request.onLinked();
|
|
}),
|
|
]
|
|
: [];
|
|
if (!request.combos.length)
|
|
return void body.append(
|
|
...linking,
|
|
...(linking.length ? [] : [note(L("B08_Quantity_Summary_NoCombo"))]),
|
|
);
|
|
body.append(...linking, note(L("B08_Quantity_Drawing_Loading")));
|
|
void (async () => {
|
|
try {
|
|
const { createItemCards } =
|
|
await import("../M02_MasterTemplete/M02_MasterTemplete_ItemCards");
|
|
if (closed) return;
|
|
body.replaceChildren(
|
|
...linking,
|
|
...request.combos.map((combo) =>
|
|
comboSection(request, combo, createItemCards, handles),
|
|
),
|
|
);
|
|
} catch (error) {
|
|
if (closed) return;
|
|
const reason = error instanceof Error ? error.message : String(error);
|
|
body.replaceChildren(...linking, note(`${L("B08_Quantity_Drawing_Failed")} — ${reason}`));
|
|
}
|
|
})();
|
|
},
|
|
});
|
|
}
|