forked from jappel/leistungsbilanz-ts
Add buildings above floors and a building structure page
Projects with several buildings could not be structured: floors and rooms hung directly off the project. Floors can now belong to a building (migration 0009: table buildings, nullable floors.building_id). Rooms and distribution boards keep their floor; their building follows from it. Existing floors stay without a building. Buildings use the location-structure command store with project-building.insert/.update/.delete, inverses and persistent Undo/Redo; deleting a building with assigned floors is rejected. Floor commands carry buildingId since command version 2. Version 1 floor commands from existing history predate buildings and are upgraded with buildingId = null before they are executed and persisted, so forward and inverse keep one version. Project snapshot schema 7 stores buildings and floor.buildingId; versions 1-6 are upgraded without buildings. Restore and portable transfer include buildings, and the transfer remaps building ids. Buildings, floors and rooms move from the project overview to their own page /projects/:id/struktur with three columns (Gebäude -> Etagen -> Räume) that filter each other, and a sidebar entry. Floor selects in the board and room dialogs are grouped by building. Unchanged dialogs close without a command. Details in docs/building-structure.md; see issue #6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7692699ee2
commit
cd89c4a499
42 changed files with 5883 additions and 373 deletions
284
tests/building-structure-view.test.ts
Normal file
284
tests/building-structure-view.test.ts
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import type {
|
||||
BuildingDto,
|
||||
FloorDto,
|
||||
RoomDto,
|
||||
} from "../src/frontend/types.js";
|
||||
import {
|
||||
ALL_SELECTION,
|
||||
UNASSIGNED_SELECTION,
|
||||
countFloorsByBuilding,
|
||||
countRoomsByFloor,
|
||||
defaultBuildingIdForNewFloor,
|
||||
defaultFloorIdForNewRoom,
|
||||
describeRoomLocation,
|
||||
filterFloorsByBuilding,
|
||||
filterRooms,
|
||||
groupFloorsByBuilding,
|
||||
hasFloorsWithoutBuilding,
|
||||
hasRoomsWithoutFloor,
|
||||
normalizeBuildingSelection,
|
||||
normalizeFloorSelection,
|
||||
showsRoomsWithoutFloorEntry,
|
||||
} from "../src/frontend/utils/building-structure.js";
|
||||
|
||||
function building(id: string, name: string, sortOrder: number): BuildingDto {
|
||||
return { id, projectId: "project-1", name, sortOrder };
|
||||
}
|
||||
|
||||
function floor(
|
||||
id: string,
|
||||
name: string,
|
||||
buildingId: string | null,
|
||||
sortOrder = 0
|
||||
): FloorDto {
|
||||
return { id, projectId: "project-1", name, sortOrder, buildingId };
|
||||
}
|
||||
|
||||
function room(id: string, floorId: string | null, roomNumber = id): RoomDto {
|
||||
return {
|
||||
id,
|
||||
projectId: "project-1",
|
||||
floorId,
|
||||
roomNumber,
|
||||
roomName: `Raum ${roomNumber}`,
|
||||
};
|
||||
}
|
||||
|
||||
const buildings = [building("b-a", "Haus A", 0), building("b-b", "Haus B", 1)];
|
||||
const floors = [
|
||||
floor("f-free", "Außenanlage", null, 0),
|
||||
floor("f-a-eg", "EG", "b-a", 1),
|
||||
floor("f-b-eg", "EG", "b-b", 2),
|
||||
floor("f-a-og", "1. OG", "b-a", 3),
|
||||
floor("f-orphan", "Keller", "b-deleted", 4),
|
||||
];
|
||||
const rooms = [
|
||||
room("r-a-eg", "f-a-eg"),
|
||||
room("r-a-og", "f-a-og"),
|
||||
room("r-b-eg", "f-b-eg"),
|
||||
room("r-free", "f-free"),
|
||||
room("r-orphan-floor", "f-orphan"),
|
||||
room("r-none", null),
|
||||
room("r-missing-floor", "f-deleted"),
|
||||
];
|
||||
|
||||
const ids = (entries: ReadonlyArray<{ id: string }>) =>
|
||||
entries.map((entry) => entry.id);
|
||||
|
||||
describe("building structure view", () => {
|
||||
it("groups floors in building order and puts unassigned floors last", () => {
|
||||
const groups = groupFloorsByBuilding(floors, buildings);
|
||||
assert.deepEqual(
|
||||
groups.map((group) => ({
|
||||
buildingId: group.buildingId,
|
||||
label: group.label,
|
||||
floors: ids(group.floors),
|
||||
})),
|
||||
[
|
||||
{ buildingId: "b-a", label: "Haus A", floors: ["f-a-eg", "f-a-og"] },
|
||||
{ buildingId: "b-b", label: "Haus B", floors: ["f-b-eg"] },
|
||||
{
|
||||
buildingId: null,
|
||||
label: "Ohne Gebäude",
|
||||
floors: ["f-free", "f-orphan"],
|
||||
},
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("omits empty groups", () => {
|
||||
const groups = groupFloorsByBuilding(
|
||||
[floor("f-1", "EG", "b-b")],
|
||||
buildings
|
||||
);
|
||||
assert.deepEqual(
|
||||
groups.map((group) => group.buildingId),
|
||||
["b-b"]
|
||||
);
|
||||
assert.deepEqual(groupFloorsByBuilding([], buildings), []);
|
||||
});
|
||||
|
||||
it("filters floors by building selection", () => {
|
||||
assert.deepEqual(
|
||||
ids(filterFloorsByBuilding(floors, buildings, ALL_SELECTION)),
|
||||
ids(floors)
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterFloorsByBuilding(floors, buildings, "b-a")),
|
||||
["f-a-eg", "f-a-og"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterFloorsByBuilding(floors, buildings, UNASSIGNED_SELECTION)),
|
||||
["f-free", "f-orphan"]
|
||||
);
|
||||
});
|
||||
|
||||
it("detects floors without building and rooms without floor", () => {
|
||||
assert.equal(hasFloorsWithoutBuilding(floors, buildings), true);
|
||||
assert.equal(
|
||||
hasFloorsWithoutBuilding([floor("f-1", "EG", "b-a")], buildings),
|
||||
false
|
||||
);
|
||||
assert.equal(hasRoomsWithoutFloor(rooms, floors), true);
|
||||
assert.equal(hasRoomsWithoutFloor([room("r-1", "f-a-eg")], floors), false);
|
||||
});
|
||||
|
||||
it("filters rooms for building and floor selections", () => {
|
||||
assert.deepEqual(
|
||||
ids(filterRooms(rooms, floors, buildings, ALL_SELECTION, ALL_SELECTION)),
|
||||
ids(rooms)
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterRooms(rooms, floors, buildings, "b-a", ALL_SELECTION)),
|
||||
["r-a-eg", "r-a-og"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterRooms(rooms, floors, buildings, "b-a", "f-a-og")),
|
||||
["r-a-og"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterRooms(rooms, floors, buildings, ALL_SELECTION, "f-b-eg")),
|
||||
["r-b-eg"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(
|
||||
filterRooms(
|
||||
rooms,
|
||||
floors,
|
||||
buildings,
|
||||
UNASSIGNED_SELECTION,
|
||||
ALL_SELECTION
|
||||
)
|
||||
),
|
||||
["r-free", "r-orphan-floor", "r-none", "r-missing-floor"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(
|
||||
filterRooms(
|
||||
rooms,
|
||||
floors,
|
||||
buildings,
|
||||
ALL_SELECTION,
|
||||
UNASSIGNED_SELECTION
|
||||
)
|
||||
),
|
||||
["r-none", "r-missing-floor"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
ids(filterRooms(rooms, floors, buildings, "b-a", UNASSIGNED_SELECTION)),
|
||||
[]
|
||||
);
|
||||
});
|
||||
|
||||
it("offers 'Ohne Etage' only where rooms without floor can belong", () => {
|
||||
assert.equal(showsRoomsWithoutFloorEntry(rooms, floors, ALL_SELECTION), true);
|
||||
assert.equal(
|
||||
showsRoomsWithoutFloorEntry(rooms, floors, UNASSIGNED_SELECTION),
|
||||
true
|
||||
);
|
||||
assert.equal(showsRoomsWithoutFloorEntry(rooms, floors, "b-a"), false);
|
||||
assert.equal(
|
||||
showsRoomsWithoutFloorEntry([room("r-1", "f-a-eg")], floors, ALL_SELECTION),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to 'Alle' for vanished or hidden selections", () => {
|
||||
assert.equal(normalizeBuildingSelection("b-a", floors, buildings), "b-a");
|
||||
assert.equal(
|
||||
normalizeBuildingSelection("b-deleted", floors, buildings),
|
||||
ALL_SELECTION
|
||||
);
|
||||
assert.equal(
|
||||
normalizeBuildingSelection(UNASSIGNED_SELECTION, floors, buildings),
|
||||
UNASSIGNED_SELECTION
|
||||
);
|
||||
assert.equal(
|
||||
normalizeBuildingSelection(
|
||||
UNASSIGNED_SELECTION,
|
||||
[floor("f-1", "EG", "b-a")],
|
||||
buildings
|
||||
),
|
||||
ALL_SELECTION
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
normalizeFloorSelection("f-a-og", rooms, floors, buildings, "b-a"),
|
||||
"f-a-og"
|
||||
);
|
||||
assert.equal(
|
||||
normalizeFloorSelection("f-b-eg", rooms, floors, buildings, "b-a"),
|
||||
ALL_SELECTION
|
||||
);
|
||||
assert.equal(
|
||||
normalizeFloorSelection("f-deleted", rooms, floors, buildings, ALL_SELECTION),
|
||||
ALL_SELECTION
|
||||
);
|
||||
assert.equal(
|
||||
normalizeFloorSelection(
|
||||
UNASSIGNED_SELECTION,
|
||||
rooms,
|
||||
floors,
|
||||
buildings,
|
||||
ALL_SELECTION
|
||||
),
|
||||
UNASSIGNED_SELECTION
|
||||
);
|
||||
assert.equal(
|
||||
normalizeFloorSelection(UNASSIGNED_SELECTION, rooms, floors, buildings, "b-a"),
|
||||
ALL_SELECTION
|
||||
);
|
||||
});
|
||||
|
||||
it("preselects the selected building and floor for new entries", () => {
|
||||
assert.equal(defaultBuildingIdForNewFloor("b-a"), "b-a");
|
||||
assert.equal(defaultBuildingIdForNewFloor(ALL_SELECTION), "");
|
||||
assert.equal(defaultBuildingIdForNewFloor(UNASSIGNED_SELECTION), "");
|
||||
assert.equal(defaultFloorIdForNewRoom("f-a-eg"), "f-a-eg");
|
||||
assert.equal(defaultFloorIdForNewRoom(ALL_SELECTION), "");
|
||||
assert.equal(defaultFloorIdForNewRoom(UNASSIGNED_SELECTION), "");
|
||||
});
|
||||
|
||||
it("counts floors per building and rooms per floor", () => {
|
||||
assert.deepEqual(
|
||||
[...countFloorsByBuilding(floors, buildings)],
|
||||
[
|
||||
[null, 2],
|
||||
["b-a", 2],
|
||||
["b-b", 1],
|
||||
]
|
||||
);
|
||||
assert.deepEqual(
|
||||
[...countRoomsByFloor(rooms, floors)],
|
||||
[
|
||||
["f-a-eg", 1],
|
||||
["f-a-og", 1],
|
||||
["f-b-eg", 1],
|
||||
["f-free", 1],
|
||||
["f-orphan", 1],
|
||||
[null, 2],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("describes a room location with floor and building", () => {
|
||||
assert.equal(
|
||||
describeRoomLocation(room("r", "f-a-og"), floors, buildings),
|
||||
"1. OG · Haus A"
|
||||
);
|
||||
assert.equal(
|
||||
describeRoomLocation(room("r", "f-free"), floors, buildings),
|
||||
"Außenanlage"
|
||||
);
|
||||
assert.equal(
|
||||
describeRoomLocation(room("r", "f-orphan"), floors, buildings),
|
||||
"Keller"
|
||||
);
|
||||
assert.equal(
|
||||
describeRoomLocation(room("r", null), floors, buildings),
|
||||
"Ohne Etage"
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue