Files
Aislo/M02_MasterTemplete/M02_MasterTemplete_Hopyo_Mine.ts
T
eomsangdonandClaude Opus 5.5 5693aa2cf9 fix(859-8): 불러오기 [내 일위대가로] 뒤 왼쪽 일위대가 목록 · [구조물 조합으로] 바로 뜸
- 만든 SC 키를 호표 머리(만든)에 적고 HOPYO_BUILT 알림 — 전에는 페이지를 다시 열어야 목록 · 단추가 뜸

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 01:08:10 +09:00

68 lines
3.0 KiB
TypeScript

/* =============================================================================
* M02_MasterTemplete_Hopyo_Mine.ts
* 엑셀 보기 오른쪽 호표 목록 줄 [내 일위대가로](PLAN 807-1 · 요구 699) — `Hopyo_Sheet` 목록 줄이 붙임.
* 물음 → 서버 `POST /layers/personal/hopyo-build-all {층, 주인?, 키, 번}`(그 호표 + 하위 → 개인 층 SC ·
* 부르는 단산 = 가져온 식 SK · 같은 내용 = 있는 것 · 못 이은 줄 = 고정 줄 엑셀 숫자 그대로) → 알림(만든 SC · 단가산출 수 · 엑셀과 같음)
* 개인 층은 누구나 씀 · 파일 층 읽기 권한은 서버가 봄
* ========================================================================== */
import {
askConfirm,
createButton,
hideLoadingOverlay,
showLoadingOverlay,
showToast,
} from "@ui/ui_template_elements";
import { t as L } from "@ui/ui_template_locale";
import { call } from "./M02_MasterTemplete_Api_Fetch";
import { at, HOPYO_BUILT, type HopyoBrief, type HopyoScope } from "./M02_MasterTemplete_Hopyo_Api";
interface MineReply {
만듦: { 번: number; 키: string; 남은줄?: number }[];
다름: { 번: number }[];
실패: { 번: number; 까닭?: string }[];
단가산출?: string[];
}
const why = (error: unknown): string => (error instanceof Error ? error.message : String(error));
/** [내 일위대가로] 단추 — `scope` = 파일 층 · `key` = HP 키 */
export function mineButton(scope: HopyoScope, key: string, h: HopyoBrief): HTMLElement {
const b = createButton({
label: L("M02_ToMySc"),
variant: "ghost",
size: "sm",
onClick: async (e) => {
e.stopPropagation();
if (!(await askConfirm({ message: L("M02_ToMyScAsk").replace("{n}", String(h.번)) }))) return;
const file = { 층: scope.layer, ...(scope.owner ? { 주인: scope.owner } : {}) };
showLoadingOverlay();
try {
const got = await call<MineReply>(
at({ layer: "personal", owner: null }, "/hopyo-build-all"),
{
method: "POST",
body: JSON.stringify({ ...file, 키: key, 번: h.번 }),
},
);
const made = got.만듦.find((x) => x.번 === h.번);
if (!made) throw new Error(got.실패.map((x) => x.까닭).join(" · ") || "실패");
h.만든 = made.키; // [수정] 창 [구조물 조합으로] · 칠 — 다시 열지 않아도
document.dispatchEvent(new Event(HOPYO_BUILT)); // 왼쪽 일위대가 목록 · 엑셀 칠 다시 읽음
const same = got.다름.some((x) => x.번 === h.번) ? "다름" : "같음";
const text = L("M02_ToMyScDone")
.replace("{k}", made.키)
.replace("{s}", String(got.단가산출?.length ?? 0))
.replace("{same}", same);
showToast(text, same === "같음" ? "success" : "warning");
} catch (error) {
showToast(why(error), "error");
} finally {
hideLoadingOverlay();
}
},
});
b.setAttribute("data-hopyo-mine", String(h.번));
return b;
}