fix(M02): 도면 양식 CAD 머리 글을 「도면 양식 편집」으로 · 저장 단추는 페이지 머리 한 곳 · 자동백업 칸에 층(과 프로젝트)을 붙임

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PxvYb5ufV1kWdBvZbpDfu6
This commit is contained in:
2026-09-25 12:01:51 +09:00
co-authored by Claude Sonnet 5
parent d6302a9695
commit c0eb280c32
6 changed files with 68 additions and 27 deletions
@@ -24,12 +24,42 @@ export interface DrawingTemplateDoc extends CadHostDrawing {
}
export interface DrawingTemplateOptions {
/** [저장] 을 누르면 편집본을 넘긴다. 없으면 [저장] 단추를 두지 않는다. */
/** 쓰지 않음 — 저장은 페이지 머리 [저장] 한 곳(`getDoc()` 으로 편집본을 가져감 · 판 · 409 흐름). */
onSave?: (doc: DrawingTemplateDoc) => void | Promise<void>;
/** 보기 전용 — CAD 그리기·수정 · 작도 영역 · 불러오기가 막힌다. */
readOnly?: boolean;
/** 양식 이름 — CAD 자동백업 칸을 양식마다 나눈다(B07 도면 백업과도 안 겹침). */
name?: string;
/** 양식 층 — 같은 이름도 층마다 백업 칸이 갈린다(`m02:층:이름`). */
layer?: string;
/** 프로젝트 층이면 프로젝트 id — 칸이 `m02:project:프로젝트id:이름` 이 된다. */
projectId?: string | null;
}
const RECOVERY_PREFIX = "OPEN_WEB_CAD__RECOVERY__";
/** 자동백업 칸 이름 — 층(과 프로젝트)을 붙여 같은 이름의 양식끼리 안 겹치게 한다. */
function recoveryScopeOf(options: DrawingTemplateOptions): string {
const name = options.name ?? "drawing";
if (!options.layer) return `m02:${name}`;
const project = options.layer === "project" ? `:${options.projectId ?? ""}` : "";
return `m02:${options.layer}${project}:${name}`;
}
/** 층 없는 옛 칸(`m02:이름`)을 새 칸으로 한 번 옮기고 지운다 — 새 칸에 이미 있으면 그대로 두고 지움. */
function migrateOldRecovery(options: DrawingTemplateOptions, scope: string): void {
const old = `${RECOVERY_PREFIX}m02:${options.name ?? "drawing"}`;
if (!options.layer || old === `${RECOVERY_PREFIX}${scope}`) return;
try {
const value = localStorage.getItem(old);
if (value === null) return;
if (localStorage.getItem(`${RECOVERY_PREFIX}${scope}`) === null) {
localStorage.setItem(`${RECOVERY_PREFIX}${scope}`, value);
}
localStorage.removeItem(old);
} catch {
// 저장소를 못 써도 편집은 됨
}
}
export interface DrawingTemplateHandle {
@@ -79,7 +109,8 @@ export function mountDrawingTemplate(
options: DrawingTemplateOptions = {},
): DrawingTemplateHandle {
const readOnly = options.readOnly === true;
const recoveryScope = `m02:${options.name ?? "drawing"}`;
const recoveryScope = recoveryScopeOf(options);
migrateOldRecovery(options, recoveryScope);
let base: DrawingTemplateDoc = doc;
const root = document.createElement("div");
@@ -139,7 +170,13 @@ export function mountDrawingTemplate(
const cad = createCadHost<DrawingTemplateDoc>({ title: "도면 양식" });
const load = (drawing: DrawingTemplateDoc): void => {
cad.beginLoading();
cad.load(drawing, null, !readOnly, {}, { recoveryScope, readOnly });
cad.load(
drawing,
null,
!readOnly,
{},
{ recoveryScope, readOnly, hostTitle: "도면 양식 편집" },
);
};
const actions = document.createElement("div");
@@ -184,27 +221,6 @@ export function mountDrawingTemplate(
return base;
};
if (options.onSave && !readOnly) {
const onSave = options.onSave;
const saveButton = createButton({
label: "저장",
variant: "filled",
onClick: () => {
saveButton.disabled = true;
getDoc()
.then((next) => onSave(next))
.catch((error) =>
showToast(
error instanceof Error ? error.message : "양식을 저장하지 못했습니다.",
"error",
),
)
.finally(() => (saveButton.disabled = false));
},
});
actions.append(saveButton);
}
toolbar.append(area, fields, actions);
root.append(toolbar, cad.element);
container.append(root);
@@ -116,6 +116,8 @@ export function createMain(isAdmin: boolean): MainHandle {
onSave: () => void doSave(),
readOnly,
name: at.name,
layer: at.layer,
projectId: at.projectId,
});
return;
}