[st] - fix: 하수관로 관종별 현황, 입력 가능 연도만 매설연장 컬럼 수정가능, 관리자 계정일 시 엑셀 업로드로 모든 cell 수정 가능
This commit is contained in:
@@ -28,14 +28,22 @@ function flattenColumnLayoutNames(layout: ColumnLayoutItem[]): string[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
export type ExcelImportColumnFieldNamesOptions = {
|
||||
/** false면 editable:false 컬럼도 import (기본 true — 읽기전용·계산 컬럼은 엑셀 값 무시) */
|
||||
skipNonEditable?: boolean;
|
||||
};
|
||||
|
||||
/** 엑셀 가져오기 — N번째 열을 그리드 N번째 fieldName에 매핑 (보내기 컬럼 순서와 동일) */
|
||||
export function getExcelImportColumnFieldNames(
|
||||
columns: ColumnConfig[],
|
||||
columnLayout?: ColumnLayoutItem[],
|
||||
options?: ExcelImportColumnFieldNamesOptions,
|
||||
): string[] {
|
||||
const skipNonEditable = options?.skipNonEditable !== false;
|
||||
const excludedNames = new Set(
|
||||
columns.filter((c) => c.excludeFromExcelExport).map((c) => c.name),
|
||||
);
|
||||
const columnByName = new Map(columns.map((c) => [c.name, c]));
|
||||
const fieldByName = new Map(
|
||||
columns
|
||||
.filter((c) => c.fieldName)
|
||||
@@ -54,11 +62,72 @@ export function getExcelImportColumnFieldNames(
|
||||
const fieldName = fieldByName.get(name);
|
||||
if (!fieldName) continue;
|
||||
seen.add(name);
|
||||
const col = columnByName.get(name);
|
||||
if (skipNonEditable && col?.editable === false) {
|
||||
fieldNames.push("");
|
||||
continue;
|
||||
}
|
||||
fieldNames.push(fieldName);
|
||||
}
|
||||
return fieldNames;
|
||||
}
|
||||
|
||||
/** 엑셀 import 시 기존 값을 유지할 fieldName 목록 (editable:false) */
|
||||
export function getNonEditableColumnFieldNames(
|
||||
columns: ColumnConfig[],
|
||||
columnLayout?: ColumnLayoutItem[],
|
||||
): string[] {
|
||||
const excludedNames = new Set(
|
||||
columns.filter((c) => c.excludeFromExcelExport).map((c) => c.name),
|
||||
);
|
||||
const columnByName = new Map(columns.map((c) => [c.name, c]));
|
||||
|
||||
const layoutNames =
|
||||
columnLayout && columnLayout.length > 0
|
||||
? flattenColumnLayoutNames(columnLayout)
|
||||
: columns.map((c) => c.name);
|
||||
|
||||
const seen = new Set<string>();
|
||||
const fieldNames: string[] = [];
|
||||
for (const name of layoutNames) {
|
||||
if (excludedNames.has(name) || seen.has(name)) continue;
|
||||
const col = columnByName.get(name);
|
||||
const fieldName = col?.fieldName;
|
||||
if (!fieldName || col.editable !== false) continue;
|
||||
seen.add(name);
|
||||
fieldNames.push(fieldName);
|
||||
}
|
||||
return fieldNames;
|
||||
}
|
||||
|
||||
/** 엑셀 import 결과를 기존 행과 병합 — preserveFieldNames는 기존 그리드 값 유지 */
|
||||
export function mergeExcelImportWithExistingRows(
|
||||
existingRows: Record<string, string | number>[],
|
||||
importedRows: Record<string, string | number>[],
|
||||
options?: { preserveFieldNames?: readonly string[] },
|
||||
): Record<string, string | number>[] {
|
||||
const preserveSet =
|
||||
options?.preserveFieldNames && options.preserveFieldNames.length > 0
|
||||
? new Set(options.preserveFieldNames)
|
||||
: null;
|
||||
|
||||
return importedRows.map((importedRow, index) => {
|
||||
const existingRow = existingRows[index];
|
||||
if (!existingRow) return { ...importedRow };
|
||||
|
||||
const merged: Record<string, string | number> = { ...existingRow, ...importedRow };
|
||||
if (preserveSet) {
|
||||
for (const fieldName of preserveSet) {
|
||||
const preserved = existingRow[fieldName];
|
||||
if (preserved !== undefined) {
|
||||
merged[fieldName] = preserved;
|
||||
}
|
||||
}
|
||||
}
|
||||
return merged;
|
||||
});
|
||||
}
|
||||
|
||||
export type ExcelExportVisibilitySnapshot = Map<string, boolean>;
|
||||
|
||||
/** 엑셀보내기 직전: 제외 컬럼 숨김, 그리드용 숨김(visible:false) 컬럼은 export에만 표시 */
|
||||
|
||||
Reference in New Issue
Block a user