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
|
|
@ -20,6 +20,7 @@ import { circuits } from "../src/db/schema/circuits.js";
|
|||
import { distributionBoardComponentProtectionDevices } from "../src/db/schema/distribution-board-component-protection-devices.js";
|
||||
import { distributionBoardComponents } from "../src/db/schema/distribution-board-components.js";
|
||||
import { distributionBoards } from "../src/db/schema/distribution-boards.js";
|
||||
import { buildings } from "../src/db/schema/buildings.js";
|
||||
import { floors } from "../src/db/schema/floors.js";
|
||||
import { projectDevices } from "../src/db/schema/project-devices.js";
|
||||
import { projectSnapshots } from "../src/db/schema/project-snapshots.js";
|
||||
|
|
@ -59,6 +60,15 @@ function createTestDatabase(): DatabaseContext {
|
|||
.where(eq(circuitSections.circuitListId, list.id))
|
||||
.get();
|
||||
assert.ok(section);
|
||||
context.db
|
||||
.insert(buildings)
|
||||
.values({
|
||||
id: "building-1",
|
||||
projectId: "project-1",
|
||||
name: "Haus A",
|
||||
sortOrder: 0,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.insert(floors)
|
||||
.values({
|
||||
|
|
@ -66,6 +76,7 @@ function createTestDatabase(): DatabaseContext {
|
|||
projectId: "project-1",
|
||||
name: "EG",
|
||||
sortOrder: 10,
|
||||
buildingId: "building-1",
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
|
|
@ -248,7 +259,9 @@ describe("project snapshot repository", () => {
|
|||
"device-1"
|
||||
);
|
||||
assert.equal(state.projectDevices.length, 1);
|
||||
assert.equal(state.buildings.length, 1);
|
||||
assert.equal(state.floors.length, 1);
|
||||
assert.equal(state.floors[0].buildingId, "building-1");
|
||||
assert.equal(state.rooms.length, 1);
|
||||
assert.deepEqual(repository.listByProject("project-1"), [
|
||||
created,
|
||||
|
|
@ -400,8 +413,14 @@ describe("project snapshot repository", () => {
|
|||
schemaVersion: number;
|
||||
project: Record<string, unknown>;
|
||||
distributionBoards: Array<Record<string, unknown>>;
|
||||
buildings?: unknown;
|
||||
floors: Array<Record<string, unknown>>;
|
||||
};
|
||||
payload.schemaVersion = 5;
|
||||
delete payload.buildings;
|
||||
for (const floor of payload.floors) {
|
||||
delete floor.buildingId;
|
||||
}
|
||||
for (const field of ["siteAddress", "workStage", "projectLead", "projectEditor"]) {
|
||||
delete payload.project[field];
|
||||
}
|
||||
|
|
@ -434,6 +453,9 @@ describe("project snapshot repository", () => {
|
|||
(board) => board.boardNumber === null && board.fedFrom === null
|
||||
)
|
||||
);
|
||||
// Version 5 predates buildings: the upgraded state has none.
|
||||
assert.deepEqual(targetState.buildings, []);
|
||||
assert.ok(targetState.floors.every((floor) => floor.buildingId === null));
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
|
|
@ -497,6 +519,11 @@ describe("portable project transfer", () => {
|
|||
copied.state.distributionBoards[0].floorId,
|
||||
copied.state.floors[0].id
|
||||
);
|
||||
assert.notEqual(copied.state.buildings[0].id, "building-1");
|
||||
assert.equal(
|
||||
copied.state.floors[0].buildingId,
|
||||
copied.state.buildings[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.distributionBoards[0].supplyType,
|
||||
"SV"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue