- 새 Labor_Detail.ts(mountLaborDetail · 차례 = 정보 → 담은 로직 → 자재목록 → 다이어그램 · 고칠 때마다 calc 를 뒤에서 · 최신 답만 · 같은 로직 · 자재 두 번 막음) - 새 Labor_Input.ts(담은 로직 줄 입력 모달 · 빈 칸 = 자동값 · 메모 · 수량 = 이은 칸 / 손 입력 / 면적산출에서 잇기 · 사라진 입력값 알림 · 자재 수량 모달) - 새 Labor_Rows.ts(작은 글 「지역 서울 · 수량 B6 = 12.5㎡」 · 빈 값 n 붉게 · 금액 칸 넷 두 줄(위 기준 · 아래 반영) · 합계 줄 · 보기 갈래는 손잡이 없이) - Labor_Api.ts: labor 문서 · calc 답 모양 · calcLabor · fetchLogicInputs · previewCombo 지움 - Labor_Diagram.ts: buildDiagramData → buildLaborDiagram(줄 입력값 + calc · 수량 있으면 반영 · 없으면 기준 표기 · 자재목록 카드 하나 → 재료비 · 알약 = 입력 모달) - 미리 보기 지움: Labor_Preview.ts · M02 preview 길 · Combo_Store.preview · 옛 조합 상세의 미리 보기 · 다이어그램 칸 - 시험: test_m02_labor_diagram 새 모양 · test_m01_combo 미리 보기 시험은 같은 계산(combo_preview)을 바로 부름 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MgChuAcyBqUkhHMTXomQC7
316 lines
11 KiB
TypeScript
316 lines
11 KiB
TypeScript
/* =============================================================================
|
|
* M02_MasterTemplete_Labor_Api.ts
|
|
* 일위대가 조합 서버 길 — 층(마스터 UA · 회사 UC · 개인 UP) 조합 표 `일위대가조합.json`
|
|
* 길 = `/api/m02/layers/{layer}/combos`(PLAN 27-2a) · 키 하나 = `/api/m02/combos/key/{키}` ·
|
|
* 세 층 = `/api/m02/combos/all` · 담을 로직 읽기 = `/api/m02/logic-lib/…` · 모양 = `_화면_계약.md` 9장
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import {
|
|
ApiError,
|
|
type LogicOne,
|
|
type LogicSummary,
|
|
type SubBrief,
|
|
} from "../M01_MasterData/M01_MasterData_UI_Logic_Api";
|
|
import {
|
|
getActiveLayer,
|
|
getActiveOwner,
|
|
type ItemLogic,
|
|
type Layer,
|
|
} from "./M02_MasterTemplete_Api_Fetch";
|
|
|
|
/** 담은 로직 한 줄 — 로직 키와 메모뿐(수량·계산은 마스터에 두지 않음 · 계약 9장) */
|
|
export interface ComboLogic {
|
|
로직: string;
|
|
메모: string | null;
|
|
}
|
|
/** 조합 한 줄 통째 — `_틀.md` 10장 · 키·소유는 서버 것이 이김 */
|
|
export interface Combo {
|
|
키: string;
|
|
이름: string;
|
|
구분: string | null;
|
|
상세구분: string | null;
|
|
단위: string | null;
|
|
담은로직: ComboLogic[];
|
|
출처: string | null;
|
|
소유: string | null;
|
|
/** 이 조합을 본떠 만든 원본 키 — 비면 원본(M02 가 갈라 낸 조합에 채워짐) */
|
|
본뜬키: string | null;
|
|
비고: string | null;
|
|
}
|
|
export interface ComboSummary extends Combo {
|
|
count: number;
|
|
blocked: boolean;
|
|
reasons: string[];
|
|
}
|
|
/** `GET /combo` 의 `줄` — 담은 로직에 이름을 붙인 것 */
|
|
export interface ComboLine {
|
|
차례: number;
|
|
로직: string;
|
|
메모: string | null;
|
|
ok: boolean;
|
|
까닭?: string;
|
|
이름?: string;
|
|
구분?: string;
|
|
상세구분?: string;
|
|
결과단위?: string;
|
|
}
|
|
export interface ComboOne {
|
|
file: string;
|
|
version: string;
|
|
combo: Combo;
|
|
줄: ComboLine[];
|
|
}
|
|
/** 조합 층 — 층 + 주인(회사 `7` · 개인 `7/42` · 없으면 내 것) */
|
|
export interface LaborScope {
|
|
layer: Exclude<Layer, "project">;
|
|
owner: string | null;
|
|
}
|
|
export const SYSTEM_SCOPE: LaborScope = { layer: "system", owner: null };
|
|
|
|
/** 폴더 = [구분] · [구분, 상세구분] — 깊이 2(PLAN 27-2a) */
|
|
export interface ComboList {
|
|
판: string;
|
|
폴더: string[][];
|
|
줄: ComboSummary[];
|
|
}
|
|
export interface ComboLayerList extends ComboList {
|
|
layer: LaborScope["layer"];
|
|
owner: string | null;
|
|
}
|
|
export interface ComboTreeEdit {
|
|
op: "add-folder" | "rename" | "move" | "delete";
|
|
경로?: string[];
|
|
이름?: string;
|
|
새경로?: string[];
|
|
키?: string;
|
|
판: string;
|
|
}
|
|
|
|
async function request<T>(url: string, method = "GET", body?: unknown): Promise<T> {
|
|
const response = await fetch(`${API_BASE_URL}/m02${url}`, {
|
|
method,
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
});
|
|
const data = (await response.json().catch(() => ({}))) as { detail?: unknown } & T;
|
|
if (!response.ok) throw new ApiError(response.status, data.detail ?? response.statusText);
|
|
return data;
|
|
}
|
|
|
|
const enc = encodeURIComponent;
|
|
/** 층 길 — `path` 뒤에 주인 · 더 붙일 물음 */
|
|
const at = (scope: LaborScope, path = "", more: Record<string, string> = {}): string => {
|
|
const params = new URLSearchParams(more);
|
|
if (scope.owner) params.set("owner", scope.owner);
|
|
const q = params.toString();
|
|
return `/layers/${scope.layer}/combos${path}${q ? `?${q}` : ""}`;
|
|
};
|
|
|
|
export const fetchComboList = (scope: LaborScope = SYSTEM_SCOPE): Promise<ComboList> =>
|
|
request(at(scope));
|
|
|
|
export const fetchCombos = (scope: LaborScope = SYSTEM_SCOPE): Promise<ComboSummary[]> =>
|
|
fetchComboList(scope).then((d) => d.줄);
|
|
|
|
/** 세 층 목록 — 고르기(use-combo · 갈라 내기) */
|
|
export const fetchAllCombos = (): Promise<ComboLayerList[]> => request("/combos/all");
|
|
|
|
/** 조합 고르기(PLAN 27-2c) — 이 층 항목이 쓸 수 있는 조합: 마스터 · 회사(회사 · 개인 층) · 개인(개인 층) ·
|
|
* 차례 = 마스터 → 회사 → 개인 · `layer` = 그 조합의 층 */
|
|
export async function fetchUsableCombos(
|
|
layer: Layer,
|
|
): Promise<(ComboSummary & { layer: LaborScope["layer"] })[]> {
|
|
const usable: LaborScope["layer"][] =
|
|
layer === "personal" || layer === "project"
|
|
? ["system", "company", "personal"]
|
|
: layer === "company"
|
|
? ["system", "company"]
|
|
: ["system"];
|
|
const all = await fetchAllCombos();
|
|
return all
|
|
.filter((group) => usable.includes(group.layer))
|
|
.flatMap((group) => group.줄.map((c) => ({ ...c, layer: group.layer })));
|
|
}
|
|
|
|
/** 조합 알약 물량 하나 — 키 = 「이름|단위」 · 담은 로직 결과단위 분모(같은 이름 · 단위는 합침) · `배` = 원/10㎡ 의 10 */
|
|
export interface ComboQuantity {
|
|
키: string;
|
|
이름: string;
|
|
단위: string;
|
|
로직: string[];
|
|
배?: number;
|
|
}
|
|
|
|
/** 조합 알약(어느 층이든 · 옛 M01 `/combo/{키}/inputs`) */
|
|
export const fetchComboInputs = (
|
|
key: string,
|
|
): Promise<{ 키: string; 이름: string; 물량: ComboQuantity[]; 조건: unknown[] }> =>
|
|
request(`/combos/key/${enc(key)}/inputs`);
|
|
|
|
/** 키 하나 — 어느 층이든(그 층 읽기 권한) · `version` = 그 층 조합 표 판 */
|
|
export const fetchCombo = (key: string): Promise<ComboOne & LaborScope> =>
|
|
request<Omit<ComboOne, "file" | "version"> & LaborScope & { 판: string }>(
|
|
`/combos/key/${enc(key)}`,
|
|
).then((d) => ({ ...d, file: "일위대가조합.json", version: d.판 }));
|
|
|
|
export const newCombo = (
|
|
combo: Combo,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<{ version: string; key: string }> =>
|
|
request<{ 키: string; 판: string }>(at(scope), "POST", { combo }).then((d) => ({
|
|
version: d.판,
|
|
key: d.키,
|
|
}));
|
|
|
|
export const editCombo = (
|
|
key: string,
|
|
version: string,
|
|
combo: Combo,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<{ version: string }> =>
|
|
request<{ 판: string }>(at(scope, `/${enc(key)}`), "PUT", { combo, 판: version }).then((d) => ({
|
|
version: d.판,
|
|
}));
|
|
|
|
export const deleteCombo = (
|
|
key: string,
|
|
version: string,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<unknown> => request(at(scope, `/${enc(key)}`, { 판: version }), "DELETE");
|
|
|
|
/** 나무 고침 — 폴더 더하기 · 이름 · 옮기기(폴더 · 조합) · 지우기 → 새 목록 */
|
|
export const editComboTree = (
|
|
body: ComboTreeEdit,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<ComboList & { 지운조합: string[] }> => request(at(scope, "/tree"), "POST", body);
|
|
|
|
/** 여러 개 옮기기 · 지우기(PLAN 30-3) — 나무 고침 여럿을 차례대로 · 저장 한 번 */
|
|
export const editComboTreeMany = (
|
|
ops: Omit<ComboTreeEdit, "판">[],
|
|
판: string,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<ComboList & { 지운조합: string[] }> =>
|
|
request(at(scope, "/tree-many"), "POST", { 판, ops });
|
|
|
|
/** 층 사이 복사(PLAN 30-3) — `from` 층의 조합 · 폴더를 이 층 `경로` 폴더에 새 키로 */
|
|
export const pasteCombos = (
|
|
from: LaborScope,
|
|
pick: { 키?: string[]; 폴더?: string[][] },
|
|
경로: string[],
|
|
판: string,
|
|
scope: LaborScope = SYSTEM_SCOPE,
|
|
): Promise<ComboList & { 새키: { 원본: string; 새키: string }[] }> =>
|
|
request(at(scope, "/paste"), "POST", {
|
|
from_layer: from.layer,
|
|
from_owner: from.owner,
|
|
...pick,
|
|
경로,
|
|
판,
|
|
});
|
|
|
|
/* --- 담을 로직(읽기만 · 로그인) — M01 로직 길과 같은 모양 --- */
|
|
export const fetchLibLogics = (): Promise<LogicSummary[]> =>
|
|
request<{ logics: LogicSummary[] }>("/logic-lib/logics").then((d) => d.logics);
|
|
|
|
export const fetchLibLogicSubs = (): Promise<SubBrief[]> =>
|
|
request<{ subs: SubBrief[] }>("/logic-lib/subs").then((d) => d.subs);
|
|
|
|
export const fetchLibLogic = (key: string): Promise<LogicOne> =>
|
|
request(`/logic-lib/logic?key=${enc(key)}`);
|
|
|
|
export const fetchLibAuto = (key: string): Promise<Record<string, unknown>> =>
|
|
request<{ 값?: Record<string, unknown> }>(`/logic-lib/auto?key=${enc(key)}`)
|
|
.then((d) => d.값 ?? {})
|
|
.catch(() => ({}));
|
|
|
|
/* --- 일위대가 문서(39 · 구조물 열마다 `labor/<열>.json` · 틀 = sub7 39-1a) --- */
|
|
|
|
/** 손 입력 수량 — `null` 이면 면적산출 알약 연결(칸)을 따름 · 손이 칸보다 앞섬 */
|
|
export type LaborQty = { 손: number } | null;
|
|
/** 담은 로직 한 줄 — 입력값 = 그 로직 입력 이름만(빈 값 = 자동값) */
|
|
export interface LaborRow {
|
|
로직: string;
|
|
메모: string | null;
|
|
입력값: Record<string, string | number>;
|
|
수량: LaborQty;
|
|
}
|
|
export interface LaborMat {
|
|
코드: string;
|
|
이름: string | null;
|
|
규격: string | null;
|
|
단위: string | null;
|
|
수량: LaborQty;
|
|
}
|
|
export interface LaborDoc {
|
|
종류: "일위대가";
|
|
판?: number;
|
|
열: string;
|
|
일위대가번?: string;
|
|
단위: string | null;
|
|
본뜬?: { 층: string; 주인: string | null; 키: string } | null;
|
|
담은로직: LaborRow[];
|
|
자재: LaborMat[];
|
|
계산값?: unknown;
|
|
}
|
|
export interface LaborCost {
|
|
노무비: number;
|
|
재료비: number;
|
|
경비: number;
|
|
계: number;
|
|
}
|
|
/** calc 줄 — 기준 = 결과단위 그대로 · 반영 = 기준 × 수량 ÷ 배(수량 없거나 돈 아닌 로직은 null) */
|
|
export interface LaborCalcLine {
|
|
로직: string;
|
|
분모: string | null;
|
|
배: number | null;
|
|
수량: number | null;
|
|
수량출처: string | null;
|
|
기준: LaborCost | null;
|
|
반영: LaborCost | null;
|
|
결과?: number | null;
|
|
까닭: string | null;
|
|
}
|
|
export interface LaborCalcMat {
|
|
코드: string;
|
|
기준단가: number | null;
|
|
수량: number | null;
|
|
수량출처: string | null;
|
|
반영: number | null;
|
|
까닭: string | null;
|
|
}
|
|
export interface LaborCalc {
|
|
줄: LaborCalcLine[];
|
|
자재: LaborCalcMat[];
|
|
기준합: Partial<LaborCost>;
|
|
반영합: Partial<LaborCost>;
|
|
}
|
|
|
|
/** 지금 층이면 `owner` 를 붙인 층 길(`/layers/{층}/labor/{열}…`) */
|
|
const laborAt = (layer: Layer, column: string, tail: string): string => {
|
|
const owner = layer === getActiveLayer() ? getActiveOwner() : null;
|
|
const q = owner && layer !== "system" && layer !== "project" ? `?owner=${enc(owner)}` : "";
|
|
return `/layers/${layer}/labor/${enc(column)}${tail}${q}`;
|
|
};
|
|
|
|
/** 계산(서버 · 저장 안 함) — `doc` = 화면 캐시(없으면 저장본) · `수량` = 칸 값 바꿔 끼우기 */
|
|
export const calcLabor = (
|
|
layer: Layer,
|
|
column: string,
|
|
doc: LaborDoc | null,
|
|
수량?: Record<string, number>,
|
|
): Promise<LaborCalc> =>
|
|
request(laborAt(layer, column, "/calc"), "POST", {
|
|
...(doc ? { doc } : {}),
|
|
...(수량 ? { 수량 } : {}),
|
|
});
|
|
|
|
/** 담은 로직 입력 목록 + 자동값(입력 모달 · `M02_Labor_Inputs`) */
|
|
export const fetchLogicInputs = (
|
|
keys: string[],
|
|
): Promise<{ 로직: ItemLogic[]; 빠진로직: string[] }> =>
|
|
keys.length
|
|
? request(`/logic-lib/inputs?keys=${enc(keys.join(","))}`)
|
|
: Promise.resolve({ 로직: [], 빠진로직: [] });
|