- [로직 복사/생성] 누름 = 기본정보 창(있는 askBasicInfo · 원본 값 채움) → /logic/copy 로 원본 문서를 새 자체 GX 문서로 복제 → 그 기초를 줄 쌓기로 엶
- 걷음: 화면 LogicLab_Copy.ts · Logic_Calc.ts(부르는 곳 = 서로뿐) · API fetchLogicFormula · saveLogicFormula · previewLogicFormula · 꼴 셋 · 글 키 · CSS m01copy (서버 길 /logic/formula · save · preview 는 앞 auto 커밋 cce57c298 에서 걷음 · openapi 뜻한 셋만 빠짐)
- 시험: test_modal_top_and_add_word 복사 시트 창 줄 뺌(걷은 파일 · CSS 의 글자 대조 줄)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
119 lines
4.2 KiB
TypeScript
119 lines
4.2 KiB
TypeScript
/* =============================================================================
|
|
* M01_MasterData_UI_LogicLab_Basic.ts
|
|
* 「신규 로직」 기본정보 칸 — 이름 · 원문번호 · 결과 단위 · 출처(구분 = 자체). 확인하면 값을 돌려줌 · 취소면 null
|
|
* 저장은 하지 않음 — 부른 쪽이 빈 시트 줄로 캐시(drafts)에 넣고 [저장] 때 서버가 GX 새 키를 줌.
|
|
* [로직 복사/생성]도 이 창(원본 값을 채워 엶 · 855 L3 ⓐ) — 부른 쪽이 `/logic/copy` 로 문서를 복제.
|
|
* ========================================================================== */
|
|
|
|
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
|
import { createButton, createInputField, createSelectField, el } from "@ui/ui_template_elements";
|
|
import { openModal } from "@ui/ui_template_modal";
|
|
|
|
const TEXT = {
|
|
Title: ["신규 로직", "New logic"],
|
|
CopyTitle: ["로직 복사/생성", "Copy / create logic"],
|
|
Name: ["이름", "Name"],
|
|
NamePh: ["예: 돌쌓기 메쌓기(인력)", "e.g. dry stone wall (labour)"],
|
|
Number: ["원문번호", "Source number"],
|
|
NumberPh: ["예: 13-4-1 · 없으면 비움", "e.g. 13-4-1 · may be empty"],
|
|
Unit: ["결과 단위", "Result unit"],
|
|
Source: ["출처", "Source"],
|
|
Ok: ["만들기", "Create"],
|
|
Cancel: ["취소", "Cancel"],
|
|
Close: ["닫기", "Close"],
|
|
NeedName: ["이름을 넣어 주세요", "Enter a name"],
|
|
} as const;
|
|
|
|
const tb = (key: keyof typeof TEXT): string => TEXT[key][currentLanguageIndex === 1 ? 1 : 0];
|
|
|
|
export interface BasicInfo {
|
|
이름: string;
|
|
원문번호: string;
|
|
결과단위: string;
|
|
출처: string;
|
|
}
|
|
|
|
/** 기본정보 묻기 — units = 결과 단위 후보(마스터 로직의 결과단위) · start = 처음 값(복사 = 원본 값) */
|
|
export function askBasicInfo(units: string[], start?: BasicInfo): Promise<BasicInfo | null> {
|
|
return new Promise((resolve) => {
|
|
let done = false;
|
|
const finish = (v: BasicInfo | null): void => {
|
|
if (done) return;
|
|
done = true;
|
|
resolve(v);
|
|
};
|
|
const name = createInputField({
|
|
label: tb("Name"),
|
|
placeholder: tb("NamePh"),
|
|
value: start?.이름 ?? "",
|
|
compact: true,
|
|
});
|
|
const number = createInputField({
|
|
label: tb("Number"),
|
|
placeholder: tb("NumberPh"),
|
|
value: start?.원문번호 ?? "",
|
|
compact: true,
|
|
});
|
|
if (start?.결과단위 && !units.includes(start.결과단위)) units = [start.결과단위, ...units];
|
|
const unit = createSelectField({
|
|
label: tb("Unit"),
|
|
options: units.map((u) => ({ value: u, text: u })),
|
|
value: start?.결과단위 || (units[0] ?? "원"),
|
|
compact: true,
|
|
});
|
|
const source = createInputField({
|
|
label: tb("Source"),
|
|
value: start?.출처 || "자체",
|
|
compact: true,
|
|
});
|
|
const why = el("p", { className: "ui-text ui-text--muted", attrs: { role: "alert" } });
|
|
const modal = openModal({
|
|
title: tb(start ? "CopyTitle" : "Title"),
|
|
closeLabel: tb("Close"),
|
|
beforeClose: () => {
|
|
finish(null);
|
|
return true;
|
|
},
|
|
mount: (body, close) => {
|
|
const ok = (): void => {
|
|
const 이름 = name.input.value.trim();
|
|
if (!이름) {
|
|
why.textContent = tb("NeedName");
|
|
return void name.input.focus();
|
|
}
|
|
finish({
|
|
이름,
|
|
원문번호: number.input.value.trim(),
|
|
결과단위: unit.select.value,
|
|
출처: source.input.value.trim() || "자체",
|
|
});
|
|
close();
|
|
};
|
|
name.input.addEventListener("keydown", (ev) => ev.key === "Enter" && ok());
|
|
body.append(
|
|
name.root,
|
|
number.root,
|
|
unit.root,
|
|
source.root,
|
|
why,
|
|
el("div", {
|
|
className: "ui-toolbar m01-logic__bar",
|
|
children: [
|
|
createButton({ label: tb("Ok"), size: "sm", onClick: ok }),
|
|
createButton({
|
|
label: tb("Cancel"),
|
|
variant: "ghost",
|
|
size: "sm",
|
|
onClick: () => {
|
|
finish(null);
|
|
modal.close();
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
);
|
|
},
|
|
});
|
|
});
|
|
}
|