refactor(m02-df): 입력 판 자재 찾기를 서버 길(cfMaterials)로 — 대신 길 지움

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ACSGaHdLgnkEkoA4LDtMU
This commit is contained in:
2026-10-01 20:03:12 +09:00
co-authored by Claude Sonnet 5.5
parent 3e5dd641f1
commit 67e631ac8c
2 changed files with 6 additions and 78 deletions
@@ -1,11 +1,10 @@
/* =============================================================================
* M02_DF_InputPanel_Material.ts
* 입력 판 — 재료 요소 방식 셋(고정 · 선택 자리 · 조건 찾기) · 자재 찾기(띄어쓰기 AND · 규격까지 · 쪽 넘기기 · 전체 수)
* 서버 `/api/m02/df/materials` 를 먼저 부르고 아직 없으면 M01 `/pick?kind=price` 로 같은 모양을 만듦
* 서버 `/api/m02/df/materials`(cfMaterials)
* 글 [한, 영] 짝은 아래 TEXT · 단추는 공용 작은 크기
* ========================================================================== */
import { API_BASE_URL } from "@config/config_frontend";
import { currentLanguageIndex } from "@ui/ui_template_locale";
import {
createButton,
@@ -15,7 +14,7 @@ import {
showToast,
} from "@ui/ui_template_elements";
import { fetchFiles, fetchSubs, type SubInfo } from "../../M01_MasterData/M01_MasterData_Api_Fetch";
import { cfValues } from "./M02_DF_Api";
import { cfMaterials, cfValues } from "./M02_DF_Api";
import type { CfElementRef, CfLogic, CfMaterialMode, CfMaterialRule } from "./M02_DF_Model";
import {
catchNote,
@@ -101,48 +100,9 @@ export interface MatPage {
items: MatItem[];
}
async function getJson<T>(path: string): Promise<T> {
const res = await fetch(`${API_BASE_URL}${path}`, { credentials: "include" });
if (!res.ok) throw new Error(String(res.status));
return (await res.json()) as T;
}
/** 서버가 없으면 M01 값 줄에서 같은 모양으로 — 띄어쓰기 AND(이름 + 규격) · 쪽은 앞에서 잘라 줌 */
async function fallback(q: MatQuery): Promise<MatPage> {
const r = await getJson<{ items: Record<string, unknown>[] }>(
`/m01/pick?${new URLSearchParams({ kind: "price", q: q.q, limit: "200" })}`,
);
const rows = r.items.filter((i) => !q.sub || i["구분"] === q.sub);
const items = rows.map((i): MatItem => ({
ref: String(i["ref"]),
name: String(i["이름"] ?? ""),
spec: String(i["규격"] ?? ""),
unit: String(i["단위"] ?? ""),
price: typeof i["값"] === "number" ? i["값"] : null,
구분: String(i["구분"] ?? ""),
}));
const from = (q.page - 1) * q.size;
return {
total: items.length,
page: q.page,
size: q.size,
items: items.slice(from, from + q.size),
};
}
/** 서버 자재 찾기 — 띄어쓰기로 나눈 말을 모두 포함 · 쪽 넘기기 · 전체 수 */
export async function searchMaterials(q: MatQuery): Promise<MatPage> {
const params = new URLSearchParams({
q: q.q,
page: String(q.page),
size: String(q.size),
sub: q.sub ?? "",
detail: q.detail ?? "",
});
try {
return await getJson<MatPage>(`/m02/df/materials?${params}`);
} catch {
return fallback(q);
}
return cfMaterials({ q: q.q, sub: q.sub, detail: q.detail, page: q.page, size: q.size });
}
let subsCache: SubInfo[] | null = null;