forked from jappel/leistungsbilanz-ts
Add distribution power summaries
This commit is contained in:
parent
dcb303284c
commit
9ea081179d
28 changed files with 2668 additions and 77 deletions
|
|
@ -299,6 +299,7 @@ export function updateDistributionBoard(
|
|||
input: {
|
||||
floorId: string | null;
|
||||
supplyType: NonNullable<DistributionBoardDto["supplyType"]>;
|
||||
simultaneityFactor: number;
|
||||
},
|
||||
expectedRevision: number
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -124,6 +124,96 @@ export const defaultVisibleColumnKeys = allColumns
|
|||
.filter((column) => column.defaultVisible)
|
||||
.map((column) => column.key);
|
||||
|
||||
const projectColumnLayoutStoragePrefix =
|
||||
"circuitTreeEditor.columnLayout.v2";
|
||||
|
||||
export interface CircuitColumnLayout {
|
||||
order: CellKey[];
|
||||
visible: CellKey[];
|
||||
}
|
||||
|
||||
const circuitSectionLabels: Record<string, string> = {
|
||||
lighting: "Licht",
|
||||
single_phase: "Einphasig",
|
||||
three_phase: "Dreiphasig",
|
||||
unassigned: "Nicht zugeordnet",
|
||||
};
|
||||
|
||||
export function getCircuitSectionLabel(
|
||||
section: { key: string; displayName: string }
|
||||
): string {
|
||||
return circuitSectionLabels[section.key] ?? section.displayName;
|
||||
}
|
||||
|
||||
export function getProjectColumnLayoutStorageKey(
|
||||
projectId: string
|
||||
): string {
|
||||
return `${projectColumnLayoutStoragePrefix}.${projectId}`;
|
||||
}
|
||||
|
||||
export function normalizeColumnOrder(keys: CellKey[]): CellKey[] {
|
||||
const unique = [...new Set(keys)];
|
||||
const allKeys = allColumns.map((column) => column.key);
|
||||
const merged = [
|
||||
...unique,
|
||||
...allKeys.filter((key) => !unique.includes(key)),
|
||||
];
|
||||
return [
|
||||
"equipmentIdentifier",
|
||||
...merged.filter((key) => key !== "equipmentIdentifier"),
|
||||
];
|
||||
}
|
||||
|
||||
export function parseStoredColumnLayout(
|
||||
serialized: string | null
|
||||
): CircuitColumnLayout | null {
|
||||
if (!serialized) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(serialized) as {
|
||||
order?: unknown;
|
||||
visible?: unknown;
|
||||
};
|
||||
if (
|
||||
!Array.isArray(parsed.order) ||
|
||||
!Array.isArray(parsed.visible)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const validKeys = new Set(
|
||||
allColumns.map((column) => column.key)
|
||||
);
|
||||
const order = parsed.order.filter(
|
||||
(key): key is CellKey =>
|
||||
typeof key === "string" &&
|
||||
validKeys.has(key as CellKey)
|
||||
);
|
||||
const visible = [
|
||||
...new Set(
|
||||
parsed.visible.filter(
|
||||
(key): key is CellKey =>
|
||||
typeof key === "string" &&
|
||||
validKeys.has(key as CellKey)
|
||||
)
|
||||
),
|
||||
];
|
||||
if (
|
||||
!order.length ||
|
||||
!visible.length ||
|
||||
!visible.includes("equipmentIdentifier")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
order: normalizeColumnOrder(order),
|
||||
visible,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const deviceOnlyColumns = new Set<CellKey>([
|
||||
"quantity",
|
||||
"powerPerUnit",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue