fix(M02-흐름도): UnitPick 표준 표를 서버 /standards 로 읽음 - 번들 대신 길 지움
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D2nUMUMTsqm93PbQtipo6c
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
* M02_DF_UnitPick.ts
|
||||
* 단가산출 흐름도 공용 단위 고르기 — 치면 걸러진 목록 · 고르기만(손글 안 받음) · 「-」 = 없음
|
||||
* 목록 = 단위 표준(산림품셈 1-2-2) 단위 + 부른 쪽이 주는 마스터 결과단위 등 + 원
|
||||
* 표준 표 읽는 길은 `setUnitSource` 로 바꿔 끼움(기본 = 처음 값 `_standard/단위표준.json`) — 다른 판도 이것을 씀
|
||||
* 표준 표 읽는 길은 `setUnitSource` 로 바꿔 끼움(기본 = 서버 /standards) — 다른 판도 이것을 씀
|
||||
* 글 [한, 영] 짝은 아래 TEXT
|
||||
* ========================================================================== */
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { createButton, el } from "@ui/ui_template_elements";
|
||||
import { cfStandards } from "./M02_DF_Api";
|
||||
import "./M02_DF_UnitPick.css";
|
||||
|
||||
const TEXT = {
|
||||
@@ -36,9 +37,9 @@ interface StandardRow {
|
||||
"단위수량 소수자리"?: number | null;
|
||||
}
|
||||
|
||||
/** 처음 값 — 번들에 든 표준 표(단위표준.json) */
|
||||
const bundled: UnitSource = async () => {
|
||||
const table = (await import("./_standard/단위표준.json")).default as { 줄: StandardRow[] };
|
||||
/** 서버 표준 표(/standards) — 고친 표가 있으면 그것, 없으면 처음 값 */
|
||||
const fromServer: UnitSource = async () => {
|
||||
const table = (await cfStandards()).unit as { 줄: StandardRow[] };
|
||||
const units = table.줄
|
||||
.flatMap((r) => [r["규격 단위"], r["단위수량 단위"]])
|
||||
.filter((u): u is string => !!u);
|
||||
@@ -52,13 +53,13 @@ const bundled: UnitSource = async () => {
|
||||
const places = Object.fromEntries(
|
||||
Object.entries(count).map(([u, c]) => [
|
||||
u,
|
||||
Number(Object.entries(c).sort((a, b) => b[1] - a[1])[0][0]),
|
||||
Number(Object.entries(c).sort((x, y) => y[1] - x[1])[0][0]),
|
||||
]),
|
||||
);
|
||||
return { units, places };
|
||||
};
|
||||
|
||||
let source: UnitSource = bundled;
|
||||
let source: UnitSource = fromServer;
|
||||
let cache: Promise<UnitStandard> | null = null;
|
||||
|
||||
/** 표준 표 읽는 길 바꾸기(서버에서 고친 표를 읽을 때) — 목록을 다시 받음 */
|
||||
@@ -67,15 +68,20 @@ export function setUnitSource(next: UnitSource): void {
|
||||
cache = null;
|
||||
}
|
||||
|
||||
/** 표준 단위 + 원 — 같은 글은 한 번 · 「없음」 은 뺌 */
|
||||
export function loadStandard(): Promise<UnitStandard> {
|
||||
/** 표준 단위 + 원 — 같은 글은 한 번 · 「없음」 은 뺌 · 서버를 못 읽으면 원만(다음에 다시 읽음) */
|
||||
export async function loadStandard(): Promise<UnitStandard> {
|
||||
cache ??= source().then((std) => {
|
||||
const set = new Set([...std.units, "원"]);
|
||||
set.delete("없음");
|
||||
set.delete(NO_UNIT);
|
||||
return { units: [...set], places: std.places };
|
||||
});
|
||||
return cache;
|
||||
try {
|
||||
return await cache;
|
||||
} catch {
|
||||
cache = null;
|
||||
return { units: ["원"], places: {} };
|
||||
}
|
||||
}
|
||||
|
||||
/** 단위를 고르면 표준 표에서 소수자리 제안 — 없으면 null */
|
||||
|
||||
Reference in New Issue
Block a user