Merge remote-tracking branch 'origin/sub_laptop_7' into main_laptop_1
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
* 쓰는 조작(재생성·계획선 편집 저장·확정)은 그 응답/재조회로 `replace`·`invalidate`한다.
|
||||
* ========================================================================== */
|
||||
|
||||
import { clearState, readState, writeState } from "../A00_Common/b_page_state";
|
||||
import { clearState, readState, readStateRaw, writeState } from "../A00_Common/b_page_state";
|
||||
import { PIPE_MATCH_M } from "../A00_Common/design/design_selection";
|
||||
import { setGeneralStations, setPlusStations } from "../common_util/common_util_structure_station";
|
||||
import { loadSavedPlusStations, plusStationsOf } from "../B05_Profile/B05_Profile_Api_PlusStations";
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
import { applyStructureAreaRows, structureAreaRows } from "./B06_Section_Structure_Layouts";
|
||||
import { withDraftAdjusts, withPipeOptions } from "./B06_Section_Section_Adjusts";
|
||||
import type {
|
||||
CrossSection,
|
||||
CrossSectionPatch,
|
||||
SectionDetailResponse,
|
||||
StandardCrossSection,
|
||||
@@ -39,6 +40,7 @@ import { fetchSectionDetail, saveSections } from "./B06_Section_Api_Fetch";
|
||||
import { staleKeyAgainstScreen, USER_TOUCHED_KEYS } from "./B06_Section_Cross_Refresh";
|
||||
import { kindChangedChainages, STRUCTURE_ADJUST_KEYS } from "./B06_Section_Api_Culvert_Options";
|
||||
import type { PipelineStation } from "../A00_Common/design/logic/design_pipeline_types";
|
||||
import type { DesignStoreValues } from "../A00_Common/design/design_store";
|
||||
import {
|
||||
carryStationKeys,
|
||||
KEYED_STATES,
|
||||
@@ -126,6 +128,7 @@ export async function loadSectionDetail(
|
||||
const stored = sessionDetail(projectId, routeId); // 세션 글 = 한 번만 풂(387-7)
|
||||
if (stored) {
|
||||
cache.set(key, stored);
|
||||
void checkSessionCanon(projectId, routeId, stored).catch(() => undefined);
|
||||
return withDraftWalls(stored, projectId, routeId);
|
||||
}
|
||||
}
|
||||
@@ -143,6 +146,62 @@ export async function loadSectionDetail(
|
||||
return request;
|
||||
}
|
||||
|
||||
/**
|
||||
* 세션 상세 판 확인(433-16) — 새로고침 · 새 탭 첫 화면은 세션 한 벌로 서고, 뒤에서 서버에 한 번 물음(ETag ·
|
||||
* 같으면 304). 다른 탭 · 다른 PC 가 저장해 판이 다르면 서버 값 위에 **이 탭에서 고친 사용자 칸만**(세션 정본
|
||||
* 사본과 다른 칸) 얹음 — 낡은 캐시가 [저장] patch 바탕(445)으로 서버 값을 되쓰지 않게. 새 상세로 갈아끼워 듣는
|
||||
* 쪽이 다시 그림 · 노선 초안이 옛 상세를 쥐고 있으면(hold) 버릴 때 새 판으로(`renewed`).
|
||||
*/
|
||||
async function checkSessionCanon(
|
||||
projectId: string,
|
||||
routeId: number,
|
||||
stored: SectionDetailResponse,
|
||||
): Promise<void> {
|
||||
const fresh = await fetchSectionDetail(projectId, routeId);
|
||||
if (!Array.isArray(fresh?.cross_sections)) return;
|
||||
const raw = readStateRaw("section-detail", projectId, routeId);
|
||||
if (raw === null || raw === JSON.stringify(fresh)) return; // 같은 판 · 그 사이 버림
|
||||
const key = keyOf(projectId, routeId);
|
||||
const current = cache.get(key);
|
||||
const edits = userEdits(current ?? stored, savedDesigns(projectId, routeId) ?? []);
|
||||
writeState("section-detail", fresh, projectId, routeId);
|
||||
keepCanon(projectId, routeId, fresh);
|
||||
for (const section of fresh.cross_sections) {
|
||||
const edit = edits.find((entry) => Math.abs(entry.chainage_m - section.chainage_m) < 0.01);
|
||||
if (edit && section.design) section.design = { ...section.design, ...edit.cells };
|
||||
}
|
||||
renewed.set(stored, fresh);
|
||||
if (current !== stored) return; // 노선 초안 갈아끼움 중 · 그 사이 새로 받음 — 초안을 버리면 새 판
|
||||
cache.set(key, fresh);
|
||||
await withDraftWalls(fresh, projectId, routeId);
|
||||
if (cache.get(key) !== fresh) return;
|
||||
emitSwap(fresh, new Map());
|
||||
listeners.get(key)?.forEach((fn) => fn(fresh, new Map()));
|
||||
}
|
||||
|
||||
/** 판이 바뀐 세션 상세 → 새 판 상세(433-16) — 노선 초안 hold 가 쥔 옛 객체를 되돌릴 때. */
|
||||
const renewed = new WeakMap<SectionDetailResponse, SectionDetailResponse>();
|
||||
|
||||
/** 측점마다 정본 사본과 다른 사용자 칸(`USER_TOUCHED_KEYS`) — 이 탭에서 고친 것. */
|
||||
function userEdits(
|
||||
detail: SectionDetailResponse,
|
||||
canonRows: ReadonlyArray<{ chainage_m: number; design: CrossSection["design"] }>,
|
||||
): Array<{ chainage_m: number; cells: Record<string, unknown> }> {
|
||||
const out: Array<{ chainage_m: number; cells: Record<string, unknown> }> = [];
|
||||
for (const section of detail.cross_sections) {
|
||||
if (!section.design) continue;
|
||||
const now = section.design as unknown as Record<string, unknown>;
|
||||
const row = canonRows.find((r) => Math.abs(r.chainage_m - section.chainage_m) < 0.01);
|
||||
const was = (row?.design ?? {}) as unknown as Record<string, unknown>;
|
||||
const cells: Record<string, unknown> = {};
|
||||
for (const name of USER_TOUCHED_KEYS)
|
||||
if (now[name] !== undefined && JSON.stringify(now[name]) !== JSON.stringify(was[name]))
|
||||
cells[name] = now[name];
|
||||
if (Object.keys(cells).length) out.push({ chainage_m: section.chainage_m, cells });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const listeners = new Map<string, Set<DetailListener>>();
|
||||
|
||||
/** 상세 객체가 갈아끼워짐(측점 수가 바뀜 · 346-2 4파) — 쥔 옛 객체를 버리고 새것으로 다시 그릴 것. */
|
||||
@@ -230,26 +289,44 @@ function recrossSaved(
|
||||
.catch(() => undefined);
|
||||
}
|
||||
|
||||
/** 노선 초안 전 상태(349-0o) — 상세(초안 전 객체 그대로 · 되돌리면 캐시) · 측점 열쇠 · 측점 열쇠 칸 다섯(횡단 초안). */
|
||||
/** 노선 초안 전 상태(349-0o) — 상세(초안 전 객체 그대로 · 되돌리면 캐시) · 측점 열쇠 · 측점 열쇠 칸 다섯(횡단 초안) ·
|
||||
* 가게 관 · 구조물(440-4 · 묶음이 버릴 때 되씀). */
|
||||
export interface SectionHold {
|
||||
detail: SectionDetailResponse;
|
||||
keys: Keyed[];
|
||||
cells: Array<[KeyedState, unknown]>;
|
||||
facilities: Pick<DesignStoreValues, "pipes" | "structures">;
|
||||
}
|
||||
type HeldDraft = Omit<SectionHold, "detail"> & { routeId: number };
|
||||
|
||||
/** 노선 초안 시작 — 초안 전 상세(`detail` · 객체 그대로 — 갈아끼움은 설계를 사본으로 씀) · 지금 측점 열쇠 · 횡단 초안 칸을 떠 둠. */
|
||||
/**
|
||||
* 노선 초안 시작 — 초안 전 상세(`detail` · 객체 그대로 — 갈아끼움은 설계를 사본으로 씀) · 지금 측점 열쇠 · 횡단 초안 칸 ·
|
||||
* 관 · 구조물을 떠 둠 · 세션에도 한 벌(440-4). 초안 둔 채 새로고침이면 그 한 벌 — 세션 칸 · 열쇠 · 관은 이미 초안
|
||||
* 자리로 옮겨 쓴 값이라 처음 값으로 안 뜸.
|
||||
*/
|
||||
export function holdSectionDetail(
|
||||
projectId: string,
|
||||
routeId: number,
|
||||
detail: SectionDetailResponse,
|
||||
): SectionHold {
|
||||
const kept = readState<HeldDraft>("route-draft-hold", projectId);
|
||||
if (kept?.routeId === routeId && readState("route-draft", projectId)) {
|
||||
const { keys, cells, facilities } = kept;
|
||||
return { detail, keys, cells, facilities };
|
||||
}
|
||||
const sections = detail.cross_sections;
|
||||
const keys = registeredKeys(projectId, routeId, sections, stationIntervalOf(detail));
|
||||
return {
|
||||
detail,
|
||||
const held: HeldDraft = {
|
||||
routeId,
|
||||
keys: sections.map((section, i) => ({ key: keys[i], chainageM: section.chainage_m })),
|
||||
cells: KEYED_STATES.map((name) => [name, readState(name, projectId, routeId)]),
|
||||
facilities: {
|
||||
pipes: readState<DesignStoreValues["pipes"]>("pipes", projectId),
|
||||
structures: readState<DesignStoreValues["structures"]>("structures", projectId),
|
||||
},
|
||||
};
|
||||
writeState("route-draft-hold", held, projectId);
|
||||
return { detail, keys: held.keys, cells: held.cells, facilities: held.facilities };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,11 +344,7 @@ export async function restoreSectionDetail(
|
||||
const key = keyOf(projectId, routeId);
|
||||
const current = cache.get(key);
|
||||
if (!current) return null;
|
||||
const saved = hold.detail;
|
||||
const sections = saved.cross_sections;
|
||||
const same =
|
||||
sections.length === stations.length &&
|
||||
stations.every((station, i) => Math.abs(station.chainageM - sections[i].chainage_m) < 1e-3);
|
||||
const saved = renewed.get(hold.detail) ?? hold.detail; // 그 사이 서버 판이 바뀌었으면 새 판(433-16)
|
||||
const oldKeys = registeredKeys(
|
||||
projectId,
|
||||
routeId,
|
||||
@@ -286,11 +359,18 @@ export async function restoreSectionDetail(
|
||||
moves.set(text(section.chainage_m), text(to.chainageM));
|
||||
});
|
||||
for (const [name, value] of hold.cells) writeState(name, value ?? null, projectId, routeId);
|
||||
useStationKeyList(projectId, routeId, hold.keys);
|
||||
clearState("route-draft-hold", projectId);
|
||||
cache.set(key, saved); // 세션 상세는 정본 그대로(387-7)
|
||||
// 초안 둔 채 새로고침 = 초안 전 상세에 초안 자리 관이 얹혀 있었음 — 되쓴 관 · 구조물로 다시 얹음(440-4)
|
||||
await withDraftStations(saved, projectId, routeId);
|
||||
useStationKeyList(projectId, routeId, hold.keys);
|
||||
await withDraftShapes(saved, projectId);
|
||||
withStructureAreas(saved);
|
||||
if (cache.get(key) !== saved) return null; // 그 사이 다른 갈아끼움 · 새로 받음
|
||||
const sections = saved.cross_sections; // 다시 얹은 뒤 측점(440-4)
|
||||
const same =
|
||||
sections.length === stations.length &&
|
||||
stations.every((station, i) => Math.abs(station.chainageM - sections[i].chainage_m) < 1e-3);
|
||||
emitSwap(saved, moves);
|
||||
listeners.get(key)?.forEach((fn) => fn(saved, moves));
|
||||
return { detail: saved, same };
|
||||
|
||||
Reference in New Issue
Block a user