feat: add branch overviews scoped outdoor plans and complete room moves
This commit is contained in:
1 parent
382d6e04f2
commit
16eddacebf
35 files changed
+2598
-2116
No files matched your search
@@ -21,7 +21,7 @@ import type { HomeAssistant } from "./types.ts";
|
||||
import { withCoverControls } from "./entities/cover-controls.ts";
|
||||
import { withSymconWeather } from "./symcon-weather.ts";
|
||||
import { isSymcon } from "./entities/symcon-values.ts";
|
||||
import { ALL_TOPOLOGY, floorSelection, topologyOutsideFloors, topologyParent, type TopologySelection } from "./topology.ts";
|
||||
import { ALL_TOPOLOGY, floorSelection, isOutdoorFloor, outsideFloor, topologyOutsideFloors, topologyParent, type TopologySelection } from "./topology.ts";
|
||||
import type { WallMode } from "./viewer/viewer3d.ts";
|
||||
import { lookNow } from "./themes.ts";
|
||||
|
||||
@@ -212,7 +212,7 @@ export class NextFloorCard extends LitElement {
|
||||
|
||||
private openTopology(s:TopologySelection):void {
|
||||
const b=this.plan();if(!b)return;
|
||||
this._floorId=s.kind==="room"?s.floorId??null:s.kind==="floor"?s.id??null:s.kind==="outside"?b.floors.find((f)=>f.outdoor_location_id===s.id)?.id??null:null;
|
||||
this._floorId=s.kind==="room"?s.floorId??null:s.kind==="floor"?s.id??null:outsideFloor(b,s)?.id??null;
|
||||
this._roomId=s.kind==="room"?s.id??null:null;this._topologyGroup=s;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ export class NextFloorCard extends LitElement {
|
||||
private renderRoomButtons(s: Stage): TemplateResult | typeof nothing {
|
||||
const b = this.plan();
|
||||
if (!this._config?.room_buttons || !b || this._clean) return nothing;
|
||||
if(b.topology&&(!s.floorId||b.floors.find((f)=>f.id===s.floorId)?.outdoor_location_id))return nothing;
|
||||
if(b.topology&&(!s.floorId||isOutdoorFloor(b.floors.find((f)=>f.id===s.floorId))))return nothing;
|
||||
const groups = roomButtons(b, s.floorId);
|
||||
if (!groups.length) return nothing;
|
||||
const several = groups.length > 1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editorFloors, editorScopeChoices, editorScopeFromKey, editorScopeKey, moveSelectedFloor, reconcileEditorContext, scopeForFloor, selectEditorScope, type EditorScope } from "./editor/editor-context.ts";
|
||||
import "./editor/hierarchy-manager.ts";
|
||||
import { floorSelection, floorTopologyPath, normalizeTopology, topologyFloors } from "../topology.ts";
|
||||
import { floorSelection, floorTopologyPath, isOutdoorFloor, normalizeTopology, topologyFloors, topologyItems } from "../topology.ts";
|
||||
// 2D editor: floors, rooms (rectangles and free shapes), snapping, undo, background template.
|
||||
|
||||
import { html, LitElement, nothing, svg, type PropertyValues, type TemplateResult } from "lit";
|
||||
@@ -78,6 +78,7 @@ import "./editor/wall-view.ts";
|
||||
import "./editor/ble-locate.ts";
|
||||
import { LibraryState, renderLibrary, renderPreview, type LibraryActions } from "./editor/forms/library.ts";
|
||||
import { arcFreeWall, arcRoomEdge, insertCorner } from "./editor/ops/rooms.ts";
|
||||
import { moveRoomToFloor, roomMovePosition } from "./editor/ops/room-move.ts";
|
||||
import type { ArcActions, ArcEdit } from "./editor/forms/arc.ts";
|
||||
import { dragStep, facingAngle, gridPositionAfter, hasLeftStart, headingAngle, outlineWithCornerAt, shifted, steppedDelta, straightEnd } from "./editor/ops/drags.ts";
|
||||
import { snapOutdoorMove, snapToPlan, type SnapOptions } from "./editor/ops/snapping.ts";
|
||||
@@ -86,7 +87,7 @@ import { devicesLayer, furnitureLayer, notesLayer } from "./editor/canvas/items.
|
||||
import { dimensionsLayer } from "./editor/canvas/plan.ts";
|
||||
import { renderNoteForm } from "./editor/forms/note.ts";
|
||||
import { openingsLayer } from "./editor/canvas/openings.ts";
|
||||
import { cutMarksLayer, floorBelowLayer, freeWallsLayer, gridLayer, meterLayer, outdoorHandlesLayer, outdoorLayer, roomHandlesLayer, roomsLayer, wallsLayer } from "./editor/canvas/plan.ts";
|
||||
import { cutMarksLayer, floorBelowLayer, freeWallsLayer, gridLayer, meterLayer, outdoorHandlesLayer, outdoorLayer, roomHandlesLayer, roomsLayer, scopeOverviewLayer, wallsLayer } from "./editor/canvas/plan.ts";
|
||||
import { renderEdgeHeights, type EdgeActions } from "./editor/forms/edges.ts";
|
||||
import { clearWallSlope, cutEdge, joinAtCut, moveCut, setPartHeight, setWallHeight, setWallSlope, setWallThickness } from "./editor/ops/edges.ts";
|
||||
import { renderDeviceForm, type DeviceActions } from "./editor/forms/device.ts";
|
||||
@@ -209,6 +210,7 @@ export class NfEditor extends LitElement {
|
||||
_floorId: { state: true },
|
||||
_editorScope: { state: true },
|
||||
_floorMove: { state: true },
|
||||
_roomMove: { state: true },
|
||||
_energyNote: { state: true },
|
||||
_ctx: { state: true },
|
||||
_fixedHint: { state: true },
|
||||
@@ -267,6 +269,7 @@ export class NfEditor extends LitElement {
|
||||
private declare _floorId: string | null;
|
||||
private declare _editorScope: EditorScope | null;
|
||||
private declare _floorMove: {floorId:string;targetId:string} | null;
|
||||
private declare _roomMove: {sourceId:string;roomId:string;buildingId:string;targetId:string;x:number;z:number;error:string} | null;
|
||||
/** What the import from the energy dashboard did (shown under its button). */
|
||||
private declare _energyNote: string | null;
|
||||
/** Open context menu (right-click, long press) at a plan point, for one item. */
|
||||
@@ -333,7 +336,7 @@ export class NfEditor extends LitElement {
|
||||
this.narrow = false;
|
||||
this.roomLabels = true;
|
||||
this._floorId = null;
|
||||
this._editorScope=null;this._floorMove=null;
|
||||
this._editorScope=null;this._floorMove=null;this._roomMove=null;
|
||||
this._arcEdit = null;
|
||||
this._routeDraft = null;
|
||||
this.roof.sectionId = null;
|
||||
@@ -794,6 +797,7 @@ export class NfEditor extends LitElement {
|
||||
if (!this.floor?.rooms.some((r) => r.id === this.sel.room)) this.sel.room = null;
|
||||
}
|
||||
if(changed.has("_doc"))this.syncEditorContext();
|
||||
if(changed.has("_size")&&(this._editorScope?.kind==="branch"||this._editorScope?.kind==="location"))this.fit();
|
||||
}
|
||||
|
||||
protected firstUpdated(): void {
|
||||
@@ -1062,6 +1066,7 @@ export class NfEditor extends LitElement {
|
||||
<nf-view3d
|
||||
.hass=${this.hass ? withSymconWeather(withCoverControls(this.hass, this._doc3d.floors), this._doc3d.settings) : undefined}
|
||||
.building=${this._doc3d}
|
||||
.topologySelection=${this._editorScope}
|
||||
.floorId=${this.houseTool ? null : this._floorId}
|
||||
.roomId=${null}
|
||||
.wallMode=${this.houseTool ? "auto" : this._wall3d}
|
||||
@@ -1158,6 +1163,8 @@ export class NfEditor extends LitElement {
|
||||
const valid=editorScopeFromKey(this._doc,editorScopeKey(scope));if(!valid)return;
|
||||
const next=selectEditorScope(this._doc,valid);
|
||||
this._editorScope=next.scope;this._floorId=next.floorId;
|
||||
if(scope.kind==="branch"||scope.kind==="location")this._tool="select";
|
||||
this.reframe3d=true;
|
||||
this.clearPlanSelection();this.fit();
|
||||
}
|
||||
|
||||
@@ -1167,7 +1174,7 @@ export class NfEditor extends LitElement {
|
||||
}
|
||||
|
||||
private async openFloorMove():Promise<void> {
|
||||
if(!this.isAdmin||!this.floor||this.floor.outdoor_location_id||!this._doc.topology)return;
|
||||
if(!this.isAdmin||!this.floor||isOutdoorFloor(this.floor)||!this._doc.topology)return;
|
||||
this._floorMove={floorId:this.floor.id,targetId:""};await this.updateComplete;
|
||||
const dialog=this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog");
|
||||
if(dialog&&!dialog.open)dialog.showModal();
|
||||
@@ -1181,20 +1188,62 @@ export class NfEditor extends LitElement {
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog")?.close();
|
||||
}
|
||||
|
||||
private async openRoomMove():Promise<void> {
|
||||
if(!this.isAdmin||!this.floor||!this.room)return;
|
||||
this._roomMove={sourceId:this.floor.id,roomId:this.room.id,buildingId:"",targetId:"",x:0,z:0,error:""};
|
||||
await this.updateComplete;
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.showModal();
|
||||
}
|
||||
|
||||
private applyRoomMove():void {
|
||||
const move=this._roomMove;
|
||||
if(!this.isAdmin||!move||move.sourceId!==this.floor?.id||move.roomId!==this.room?.id)return;
|
||||
const next=structuredClone(this._doc),target=next.floors.find((f)=>f.id===move.targetId);
|
||||
if(!target||target.building_id!==move.buildingId)return;
|
||||
const error=moveRoomToFloor(next,move.sourceId,move.roomId,move.targetId,[move.x,move.z]);
|
||||
if(error){this._roomMove={...move,error};return;}
|
||||
this.setDoc(next);this.adoptFloor(move.targetId);this.selectItem("room",move.roomId);this.fit();
|
||||
this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.close();
|
||||
}
|
||||
|
||||
private renderRoomMoveDialog():TemplateResult {
|
||||
const move=this._roomMove,source=this._doc.floors.find((f)=>f.id===move?.sourceId),room=source?.rooms.find((r)=>r.id===move?.roomId);
|
||||
const buildings=editorScopeChoices(this._doc).filter(([key])=>key.startsWith("building:"));
|
||||
const floors=this._doc.floors.filter((f)=>!isOutdoorFloor(f)&&f.building_id===move?.buildingId&&f.id!==move?.sourceId);
|
||||
return html`<dialog class="nf-room-move-dialog" aria-label="Raum verschieben" @close=${(e:Event)=>{if(!(e.target as HTMLDialogElement).open)this._roomMove=null;}} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<header><h2>Raum verschieben</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector<HTMLDialogElement>(".nf-room-move-dialog")?.close()}>×</button></header>
|
||||
${move&&source&&room?html`<p>${floorTopologyPath(this._doc,source)} / ${room.name}</p>
|
||||
<div class="nf-form">
|
||||
<label class="nf-field nf-wide">Zielgebäude<select class="nf-room-move-building" @change=${(e:Event)=>this._roomMove={...move,buildingId:(e.target as HTMLSelectElement).value,targetId:"",error:""}}>
|
||||
<option value="" .selected=${!move.buildingId}>Gebäude auswählen</option>${buildings.map(([key,name])=>html`<option value=${key.slice(9)} .selected=${move.buildingId===key.slice(9)}>${name}</option>`)}
|
||||
</select></label>
|
||||
<label class="nf-field nf-wide">Zieletage<select class="nf-room-move-floor" ?disabled=${!move.buildingId} @change=${(e:Event)=>{const targetId=(e.target as HTMLSelectElement).value,f=floors.find((f)=>f.id===targetId),[x,z]=f?roomMovePosition(f):[0,0];this._roomMove={...move,targetId,x,z,error:""};}}>
|
||||
<option value="" .selected=${!move.targetId}>${move.buildingId&&!floors.length?"Keine andere Etage in diesem Gebäude":"Etage auswählen"}</option>${floors.map((f)=>html`<option value=${f.id} .selected=${move.targetId===f.id}>${f.name}</option>`)}
|
||||
</select></label>
|
||||
${(["x","z"] as const).map((axis)=>html`<label class="nf-field">${axis.toUpperCase()} (m)<input class="nf-room-move-${axis}" type="number" step="0.05" .value=${String(move[axis])} ?disabled=${!move.targetId} @change=${(e:Event)=>this._roomMove={...move,[axis]:(e.target as HTMLInputElement).valueAsNumber,error:""}} /></label>`)}
|
||||
${hint("Der Raum wird zusammen mit seinen Türen, Fenstern, Möbeln, platzierten Geräten und Notizen verschoben. Datenpunktverknüpfungen bleiben erhalten. X und Z bestimmen die linke obere Ecke auf der Zieletage; vorgeschlagen wird ein freier Platz neben den vorhandenen Räumen.","nf-wide")}
|
||||
${move.error?html`<p class="nf-room-move-error nf-wide" role="alert">${move.error}</p>`:nothing}
|
||||
</div>
|
||||
<button class="nf-btn nf-primary nf-room-move-apply" ?disabled=${!this.isAdmin||!floors.some((f)=>f.id===move.targetId)||![move.x,move.z].every(Number.isFinite)||this.floor?.id!==move.sourceId||this.room?.id!==move.roomId} @click=${()=>this.applyRoomMove()}>Raum „${room.name}“ verschieben</button>`:nothing}
|
||||
</dialog>`;
|
||||
}
|
||||
|
||||
private renderEditorNavigation():TemplateResult|typeof nothing {
|
||||
if(!this._doc.topology)return isSymcon(this.hass)?html`<div class="nf-editor-context"><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>`:nothing;
|
||||
const scope=this._editorScope,choices=editorScopeChoices(this._doc),floors=editorFloors(this._doc,scope);
|
||||
const label=choices.find(([key])=>key===editorScopeKey(scope))?.[1]??"Gebäude auswählen";
|
||||
const overview=scope?.kind==="branch"||scope?.kind==="location";
|
||||
const label=choices.find(([key])=>key===editorScopeKey(scope))?.[1]??"Ansicht auswählen";
|
||||
return html`<div class="nf-editor-context">
|
||||
<div class="nf-editor-building-row"><label>Gebäude<select class="nf-editor-building-select" aria-label="Gebäude" title=${label} @change=${(e:Event)=>{const s=editorScopeFromKey(this._doc,(e.target as HTMLSelectElement).value);if(s)this.selectBuilding(s);}}>
|
||||
${!scope?html`<option value="">Gebäude auswählen</option>`:nothing}
|
||||
${choices.map(([key,name])=>html`<option value=${key} .selected=${key===editorScopeKey(scope)}>${name}</option>`)}
|
||||
<div class="nf-editor-building-row"><label>Ansicht<select class="nf-editor-building-select" aria-label="Ort, Niederlassung oder Gebäude" title=${label} @change=${(e:Event)=>{const s=editorScopeFromKey(this._doc,(e.target as HTMLSelectElement).value);if(s)this.selectBuilding(s);}}>
|
||||
${!scope?html`<option value="">Ansicht auswählen</option>`:nothing}
|
||||
${choices.map(([key,name])=>html`<option value=${key} .selected=${key===editorScopeKey(scope)}>${key.startsWith("branch:")?"Niederlassung · ":key.startsWith("location:")?"Ort · ":""}${name}</option>`)}
|
||||
</select></label><button class="nf-btn nf-hierarchy-open" @click=${()=>this.openHierarchy()}>Hierarchie</button></div>
|
||||
<nav class="nf-editor-floor-nav" aria-label="Etagen des gewählten Gebäudes">
|
||||
<span class="nf-muted">${scope?.kind==="outside"?"Außenplan":"Etagen"}</span>
|
||||
${[...floors].reverse().map((f)=>html`<button class="nf-chip" data-editor-floor=${f.id} aria-pressed=${f.id===this._floorId} @click=${()=>{this.adoptFloor(f.id);this.fit();}}>${f.name}</button>`)}
|
||||
<nav class="nf-editor-floor-nav" aria-label="Untergeordnete Pläne">
|
||||
<span class="nf-muted">${overview?"Auswahl":scope?.kind==="outside"?"Außenplan":"Etagen"}</span>
|
||||
${overview?topologyItems(this._doc,scope).map((n)=>html`<button class="nf-chip" data-editor-scope=${n.key} @click=${()=>this.selectBuilding(n.selection as EditorScope)}>${n.name}</button>`):[...floors].reverse().map((f)=>html`<button class="nf-chip" data-editor-floor=${f.id} aria-pressed=${f.id===this._floorId} @click=${()=>{this.adoptFloor(f.id);this.fit();}}>${f.name}</button>`)}
|
||||
${scope?.kind==="building"?topologyItems(this._doc,scope).filter((n)=>n.selection.kind==="outside").map((n)=>html`<button class="nf-chip" data-editor-scope=${n.key} @click=${()=>this.selectBuilding(n.selection as EditorScope)}>🌳 Außen</button>`):nothing}
|
||||
${scope?.kind==="building"?html`<button class="nf-btn nf-editor-add-floor" ?disabled=${!this.isAdmin} @click=${()=>this.addFloor(null)}>+ Etage</button>`:nothing}
|
||||
${this.floor&&!this.floor.outdoor_location_id?html`<button class="nf-link nf-editor-move-floor" ?disabled=${!this.isAdmin} @click=${()=>void this.openFloorMove()}>Ausgewählte Etage verschieben…</button>`:nothing}
|
||||
${this.floor&&!isOutdoorFloor(this.floor)?html`<button class="nf-link nf-editor-move-floor" ?disabled=${!this.isAdmin} @click=${()=>void this.openFloorMove()}>Ausgewählte Etage verschieben…</button>`:nothing}
|
||||
</nav>
|
||||
</div>`;
|
||||
}
|
||||
@@ -1208,7 +1257,7 @@ export class NfEditor extends LitElement {
|
||||
@hierarchy-change=${(e:CustomEvent<{building:Building}>)=>{e.stopPropagation();if(this.isAdmin)this.setDoc(e.detail.building);}}
|
||||
@hierarchy-open=${(e:CustomEvent<EditorScope>)=>{e.stopPropagation();this.selectBuilding(e.detail);this.renderRoot.querySelector<HTMLDialogElement>(".nf-hierarchy-dialog")?.close();}}></nf-hierarchy-manager>
|
||||
</dialog>
|
||||
<dialog class="nf-floor-move-dialog" aria-label="Ausgewählte Etage verschieben" @close=${()=>this._floorMove=null} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<dialog class="nf-floor-move-dialog" aria-label="Ausgewählte Etage verschieben" @close=${(e:Event)=>{if(!(e.target as HTMLDialogElement).open)this._floorMove=null;}} @keydown=${(e:KeyboardEvent)=>e.stopPropagation()}>
|
||||
<header><h2>Ausgewählte Etage verschieben</h2><button class="nf-btn" aria-label="Schließen" @click=${()=>this.renderRoot.querySelector<HTMLDialogElement>(".nf-floor-move-dialog")?.close()}>×</button></header>
|
||||
${move&&source?html`<p class="nf-floor-move-source">${floorTopologyPath(this._doc,source)}</p>
|
||||
<label class="nf-field">Zielgebäude<select class="nf-floor-move-target" @change=${(e:Event)=>this._floorMove={...move,targetId:(e.target as HTMLSelectElement).value}}>
|
||||
@@ -1308,7 +1357,8 @@ export class NfEditor extends LitElement {
|
||||
}
|
||||
|
||||
private fit(): void {
|
||||
const pts = this.floor?.rooms.flatMap((r) => r.points) ?? [];
|
||||
const floors=this.floor?[this.floor]:this._doc.topology?editorFloors(this._doc,this._editorScope):[];
|
||||
const pts = floors.flatMap((f)=>[...f.rooms.flatMap((r)=>r.points),...f.outdoor.flatMap((a)=>a.points),...f.furniture.map((p):Vec2=>[p.x,p.z]),...f.placements.map((p):Vec2=>[p.x,p.z])]);
|
||||
const b = pts.length ? bounds(pts) : { x0: 0, z0: 0, x1: 10, z1: 8 };
|
||||
const margin = 1.5;
|
||||
const w = b.x1 - b.x0 + 2 * margin;
|
||||
@@ -1348,6 +1398,8 @@ export class NfEditor extends LitElement {
|
||||
// ------------------------------------------------------------------ pointer input
|
||||
|
||||
private onPointerDown(e: PointerEvent): void {
|
||||
const overview=(e.target as Element)?.closest("[data-overview-floor]")?.getAttribute("data-overview-floor");
|
||||
if(overview){this.adoptFloor(overview);this.fit();return;}
|
||||
// a form is waiting for one place on the plan: this tap is it
|
||||
if (this._pick) {
|
||||
const [sx, sy] = this.localPoint(e);
|
||||
@@ -2256,6 +2308,8 @@ export class NfEditor extends LitElement {
|
||||
|
||||
private readonly onKey = (e: KeyboardEvent) => {
|
||||
const path = e.composedPath();
|
||||
const overview=path.find((el)=>el instanceof Element&&el.hasAttribute("data-overview-floor")) as Element|undefined;
|
||||
if(overview&&(e.key==="Enter"||e.key===" ")){e.preventDefault();this.adoptFloor(overview.getAttribute("data-overview-floor"));this.fit();return;}
|
||||
if (path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement || el instanceof HTMLTextAreaElement)) return;
|
||||
if (!this.isConnected || !this.offsetParent) return;
|
||||
if (e.key === "Escape" && this._pick) {
|
||||
@@ -2352,7 +2406,7 @@ export class NfEditor extends LitElement {
|
||||
${outdoorHandlesLayer(ctx, this.outdoorArea, this._tool)}
|
||||
${room && this._tool === "select" ? cutMarksLayer(ctx, room) : nothing}
|
||||
${headroomLayer(ctx, floor)}`
|
||||
: nothing}
|
||||
: this._doc.topology?scopeOverviewLayer(ctx,editorFloors(this._doc,this._editorScope)):nothing}
|
||||
${this._tool === "roof" ? svg`${roofSectionsLayer(ctx, this.roof)}${roofWindowsLayer(ctx, this.roof)}${chimneysLayer(ctx, this.roof)}` : this._tool === "energy" ? svg`${roofSectionsLayer(ctx, this.roof)}${solarLayer(ctx, this.roof)}${energyRoutesLayer(ctx, this.floor, this._doc.energy.routes ?? [], this._routeDraft)}${energyMarkersLayer(ctx, this.floor, this.sel.furniture)}` : nothing}
|
||||
${draftLayer(ctx, sketch, this._tool, this._draft, this._cursor)} ${guidesLayer(ctx, this._guides, this._size)}`;
|
||||
}
|
||||
@@ -2497,6 +2551,7 @@ export class NfEditor extends LitElement {
|
||||
removeCorner: (index) => this.deleteVertex(index),
|
||||
duplicate: () => this.duplicateRoom(),
|
||||
remove: () => this.deleteRoom(),
|
||||
move: () => {if(this.room?.id===room.id)void this.openRoomMove();},
|
||||
rememberView: () => this.rememberRoomView(),
|
||||
applyPackage: (pkg) => this.applyPackage(room, pkg),
|
||||
openSpots: () => {
|
||||
@@ -3260,6 +3315,7 @@ export class NfEditor extends LitElement {
|
||||
const walls = floor ? generateWalls(floor.rooms, { exterior: this._doc.settings.wall_exterior, interior: this._doc.settings.wall_interior }, floor.walls ?? []) : null;
|
||||
return html`
|
||||
${this.renderHierarchyDialogs()}
|
||||
${this.renderRoomMoveDialog()}
|
||||
${renderPreview(this.host, this.lib.preview)}
|
||||
${this._wallView
|
||||
? html`<nf-wall-view .host=${this.host} .doc=${this._doc} .roomId=${this._wallView.roomId} .edge=${this._wallView.edge} @close=${() => (this._wallView = null)}></nf-wall-view>`
|
||||
|
||||
@@ -7,6 +7,7 @@ import { bounds, centroid, isFixed, polygonArea, roomsReachingUp, type Floor, ty
|
||||
import type { Wall } from "../../../geometry/walls.ts";
|
||||
import { edgePlus, pointsAttribute, type CanvasContext } from "./context.ts";
|
||||
import { formatArea, formatLength } from "../../../units.ts";
|
||||
import { isOutdoorFloor } from "../../../topology.ts";
|
||||
|
||||
type Layer = TemplateResult | typeof nothing;
|
||||
|
||||
@@ -41,7 +42,7 @@ export function gridLayer(ctx: CanvasContext, size: { w: number; h: number }): L
|
||||
/** The rooms of the floor below, faintly, as orientation; rooms below that rise through this floor are hatched – it stays open there. */
|
||||
export function floorBelowLayer(ctx: CanvasContext): Layer {
|
||||
const current=ctx.host.doc.floors.find((f)=>f.id===ctx.floorId);
|
||||
const floors = ctx.host.doc.topology?ctx.host.doc.floors.filter((f)=>current?.outdoor_location_id?f.outdoor_location_id===current.outdoor_location_id:!f.outdoor_location_id&&f.building_id===current?.building_id):ctx.host.doc.floors;
|
||||
const floors = ctx.host.doc.topology?ctx.host.doc.floors.filter((f)=>isOutdoorFloor(current)?f.id===current?.id:!isOutdoorFloor(f)&&f.building_id===current?.building_id):ctx.host.doc.floors;
|
||||
const at = floors.findIndex((f) => f.id === ctx.floorId);
|
||||
const below = at > 0 ? floors[at - 1] : undefined;
|
||||
if (!below) return nothing;
|
||||
@@ -51,6 +52,18 @@ export function floorBelowLayer(ctx: CanvasContext): Layer {
|
||||
)}</g>`;
|
||||
}
|
||||
|
||||
/** Read-only overview; clicking an outline first opens its actual floor for editing. */
|
||||
export function scopeOverviewLayer(ctx: CanvasContext, floors: readonly Floor[]): Layer {
|
||||
return svg`<g class="nf-scope-overview">${floors.map((f)=>{
|
||||
const points=[...f.rooms.flatMap((r)=>r.points),...f.outdoor.flatMap((a)=>a.points)];
|
||||
const c=points.length?centroid(points):null;
|
||||
return svg`<g data-overview-floor=${f.id} tabindex="0" role="button" aria-label=${f.name}>
|
||||
<title>${f.name}</title>${[...f.rooms.map((r)=>r.points),...f.outdoor.map((a)=>a.points)].map((p)=>svg`<polygon points=${pointsAttribute(ctx,p)} />`)}
|
||||
${c?svg`<text x=${ctx.toScreen(c)[0]} y=${ctx.toScreen(c)[1]}>${f.name}</text>`:nothing}
|
||||
</g>`;
|
||||
})}</g>`;
|
||||
}
|
||||
|
||||
/** The wall pieces; outer ones are drawn stronger, and walls lower than the floor lighter. */
|
||||
export function wallsLayer(ctx: CanvasContext, walls: readonly Wall[]): Layer {
|
||||
const full = ctx.host.floor?.height ?? 2.5;
|
||||
|
||||
@@ -40,5 +40,14 @@ test("location outside plans are separate editor scopes and cannot be silently t
|
||||
const scope={kind:"outside" as const,id:"u"};assert.deepEqual(editorFloors(b,scope).map((f)=>f.id),["garden"]);
|
||||
assert.equal(moveSelectedFloor(b,"garden","garden","a"),false);
|
||||
assert.deepEqual(editorScopeFromKey(b,"outside:u"),scope);assert.equal(editorScopeFromKey(b,"building:unknown"),null);
|
||||
assert.deepEqual(editorScopeChoices(b),[["building:a","Urbach / Zentrale / RAS19"],["building:b","Urbach / Zentrale / RAS21"],["building:empty","Urbach / Zentrale / Neu"],["outside:u","Urbach / Außen"]]);
|
||||
assert.deepEqual(editorScopeChoices(b),[["location:u","Urbach"],["branch:nl","Urbach / Zentrale"],["building:a","Urbach / Zentrale / RAS19"],["building:b","Urbach / Zentrale / RAS21"],["building:empty","Urbach / Zentrale / Neu"],["outside:u","Urbach / Außen"]]);
|
||||
});
|
||||
|
||||
test("selecting an entire location or branch shows its descendants without an implicit editable floor",()=>{
|
||||
const b=project(),before=structuredClone(b),scope={kind:"branch" as const,id:"nl"};
|
||||
const context=selectEditorScope(b,scope);
|
||||
assert.deepEqual(context,{scope,floorId:null});assert.deepEqual(reconcileEditorContext(b,context),context);
|
||||
assert.deepEqual(editorFloors(b,scope).map((f)=>f.id),["eg-a","eg-b"]);
|
||||
assert.deepEqual(selectEditorScope(b,{kind:"location",id:"u"}).floorId,null);
|
||||
assert.deepEqual(b,before);
|
||||
});
|
||||
@@ -1,24 +1,27 @@
|
||||
import type { Building, Floor } from "../../model.ts";
|
||||
import { isOutdoorFloor, outdoorOwner, outsideFloor, outsideSelection, topologyFloors, topologyKey, topologyPath, type OutsideOwnerKind } from "../../topology.ts";
|
||||
|
||||
export interface EditorScope { kind: "building" | "outside"; id: string }
|
||||
export interface EditorScope { kind: "location" | "branch" | "building" | "outside"; id: string; ownerKind?: OutsideOwnerKind }
|
||||
export interface EditorContext { scope: EditorScope | null; floorId: string | null }
|
||||
export const editorScopeKey = (s: EditorScope | null): string => s ? `${s.kind}:${s.id}` : "";
|
||||
export const editorScopeKey = (s: EditorScope | null): string => s ? topologyKey(s) : "";
|
||||
|
||||
export function scopeForFloor(f: Floor | undefined): EditorScope | null {
|
||||
if(!f)return null;
|
||||
return f.outdoor_location_id ? {kind:"outside",id:f.outdoor_location_id} : f.building_id ? {kind:"building",id:f.building_id} : null;
|
||||
const owner=outdoorOwner(f);
|
||||
return owner ? outsideSelection(owner) as EditorScope : f.building_id ? {kind:"building",id:f.building_id} : null;
|
||||
}
|
||||
export function editorScopeExists(b: Building, s: EditorScope | null): boolean {
|
||||
return !!s && !!b.topology && (s.kind === "building" ? b.topology.buildings.some((g)=>g.id===s.id) : b.topology.locations.some((l)=>l.id===s.id)&&b.floors.some((f)=>f.outdoor_location_id===s.id));
|
||||
if(!s||!b.topology)return false;
|
||||
return s.kind==="outside"?!!outsideFloor(b,s):b.topology[s.kind==="building"?"buildings":s.kind==="branch"?"branches":"locations"].some((g)=>g.id===s.id);
|
||||
}
|
||||
export function editorFloors(b: Building, s: EditorScope | null): Floor[] {
|
||||
if (!b.topology) return b.floors;
|
||||
if (!editorScopeExists(b,s)) return [];
|
||||
return b.floors.filter((f)=>s!.kind==="outside"?f.outdoor_location_id===s!.id:!f.outdoor_location_id&&f.building_id===s!.id);
|
||||
return topologyFloors(b,s!).filter((f)=>s!.kind!=="building"||!isOutdoorFloor(f));
|
||||
}
|
||||
/** Navigation returns a context only: choosing a building never edits a floor's parent. */
|
||||
export function selectEditorScope(b: Building, s: EditorScope): EditorContext {
|
||||
return {scope:s,floorId:editorFloors(b,s)[0]?.id??null};
|
||||
return {scope:s,floorId:s.kind==="branch"||s.kind==="location"?null:editorFloors(b,s)[0]?.id??null};
|
||||
}
|
||||
/** In particular an empty, explicitly selected building must never fall back to another building's first floor. */
|
||||
export function reconcileEditorContext(b: Building, current: EditorContext): EditorContext {
|
||||
@@ -26,23 +29,22 @@ export function reconcileEditorContext(b: Building, current: EditorContext): Edi
|
||||
const scope = editorScopeExists(b,current.scope) ? current.scope : scopeForFloor(b.floors.find((f)=>f.id===current.floorId)??b.floors[0])
|
||||
?? (b.topology.buildings[0]?{kind:"building" as const,id:b.topology.buildings[0].id}:null);
|
||||
const floors=editorFloors(b,scope);
|
||||
if(scope?.kind==="branch"||scope?.kind==="location")return {scope,floorId:null};
|
||||
return {scope,floorId:floors.some((f)=>f.id===current.floorId)?current.floorId:floors[0]?.id??null};
|
||||
}
|
||||
export function editorScopeChoices(b: Building): [string,string][] {
|
||||
const t=b.topology;if(!t)return [];
|
||||
return [...t.buildings.map((g):[string,string]=>{
|
||||
const branch=t.branches.find((n)=>n.id===g.branch_id),location=t.locations.find((l)=>l.id===branch?.location_id);
|
||||
return [`building:${g.id}`,[location?.name,branch?.name,g.name].filter(Boolean).join(" / ")];
|
||||
}),...t.locations.filter((l)=>b.floors.some((f)=>f.outdoor_location_id===l.id)).map((l):[string,string]=>[`outside:${l.id}`,`${l.name} / Außen`])];
|
||||
const scopes:EditorScope[]=[...t.locations.map((l):EditorScope=>({kind:"location",id:l.id})),...t.branches.map((n):EditorScope=>({kind:"branch",id:n.id})),...t.buildings.map((g):EditorScope=>({kind:"building",id:g.id})),...b.floors.filter(isOutdoorFloor).map((f)=>scopeForFloor(f)!)];
|
||||
return scopes.map((s)=>[editorScopeKey(s),topologyPath(b,s).slice(1).map((n)=>n.name).join(" / ")]);
|
||||
}
|
||||
export function editorScopeFromKey(b: Building, key: string): EditorScope | null {
|
||||
const split=key.indexOf(":"),kind=key.slice(0,split),id=key.slice(split+1);
|
||||
const s=kind==="building"||kind==="outside"?{kind,id} as EditorScope:null;
|
||||
const [kind,...rest]=key.split(":"),ownerKind=kind==="outside"&&rest.length>1?rest.shift() as OutsideOwnerKind:undefined,id=rest.join(":");
|
||||
const s=["building","branch","location","outside"].includes(kind)?{kind,id,...(ownerKind?{ownerKind}:{})} as EditorScope:null;
|
||||
return editorScopeExists(b,s)?s:null;
|
||||
}
|
||||
/** Explicitly moves the captured, still-selected floor; stale dialogs cannot reassign another floor. */
|
||||
export function moveSelectedFloor(b: Building, selectedFloorId: string|null, sourceFloorId: string, buildingId: string): boolean {
|
||||
const f=b.floors.find((f)=>f.id===sourceFloorId);
|
||||
if(selectedFloorId!==sourceFloorId||!f||f.outdoor_location_id||!b.topology?.buildings.some((g)=>g.id===buildingId)||f.building_id===buildingId)return false;
|
||||
if(selectedFloorId!==sourceFloorId||!f||isOutdoorFloor(f)||!b.topology?.buildings.some((g)=>g.id===buildingId)||f.building_id===buildingId)return false;
|
||||
f.building_id=buildingId;return true;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { formatArea } from "../../../units.ts";
|
||||
import type { EditorHost } from "../host.ts";
|
||||
import { freeHaFloors, linkableHaFloors, unplacedAreas } from "../ops/floors.ts";
|
||||
import type { SideState } from "../side-state.ts";
|
||||
import { isOutdoorFloor } from "../../../topology.ts";
|
||||
|
||||
/** What the floor form makes the editor do. */
|
||||
export interface FloorActions {
|
||||
@@ -48,7 +49,7 @@ function areaRow(host: EditorHost, floor: Floor, floorActions: FloorActions): Te
|
||||
/** The chips of the floors, top floor first, and the button that adds one: straight away, or after choosing a floor of Home Assistant. */
|
||||
function floorChips(host: EditorHost, state: SideState, floorActions: FloorActions, selected: string | null): TemplateResult {
|
||||
const free = freeHaFloors(host.doc, host.hass?.floors);
|
||||
const shown=host.doc.floors.filter((f)=>!host.doc.topology||!host.floor||(host.floor.outdoor_location_id?f.outdoor_location_id===host.floor.outdoor_location_id:f.building_id===host.floor.building_id&&!f.outdoor_location_id));
|
||||
const shown=host.doc.floors.filter((f)=>!host.doc.topology||!host.floor||(isOutdoorFloor(host.floor)?f.id===host.floor.id:f.building_id===host.floor.building_id&&!isOutdoorFloor(f)));
|
||||
const addClicked = () => (free.length > 0 ? (state.floorMenu = !state.floorMenu) : floorActions.addFloor(null));
|
||||
return html`<div class="nf-floor-list">
|
||||
${[...shown].reverse().map((f) => html`<button class="nf-chip" aria-pressed=${f.id === selected} @click=${() => floorActions.openFloor(f.id)}>${f.name}</button>`)}
|
||||
@@ -76,7 +77,7 @@ function shiftRow(host: EditorHost, state: SideState, floorActions: FloorActions
|
||||
${floor.start_view ? html`<button class="nf-btn" title=${host.t("floor_start_view_reset")} @click=${() => host.change((_, f) => (f.start_view = null))}>↺</button>` : nothing}
|
||||
<label class="nf-check nf-wide" title=${host.t("floor_shift_all_hint")}
|
||||
><input type="checkbox" .checked=${state.shiftAll} @change=${(e: Event) => (state.shiftAll = (e.target as HTMLInputElement).checked)} />
|
||||
${host.doc.topology ? floor.outdoor_location_id ? "Gesamten Außenplan mitnehmen" : "Alle Stockwerke dieses Gebäudes mitnehmen" : host.t("floor_shift_all")}</label
|
||||
${host.doc.topology ? isOutdoorFloor(floor) ? "Gesamten Außenplan mitnehmen" : "Alle Stockwerke dieses Gebäudes mitnehmen" : host.t("floor_shift_all")}</label
|
||||
>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface RoomActions {
|
||||
removeCorner(index: number): void;
|
||||
duplicate(): void;
|
||||
remove(): void;
|
||||
move(): void;
|
||||
rememberView(): void;
|
||||
applyPackage(pkg: PackageId): void;
|
||||
openSpots(): void;
|
||||
@@ -164,6 +165,7 @@ export function renderRoomForm(host: EditorHost, state: SideState, room: Room, a
|
||||
return html`<section>
|
||||
<div class="nf-h3row"><h3>${t("room")}</h3>${actions.lockButton}</div>
|
||||
${host.doc.topology&&host.floor?html`<div class="nf-room-context" title=${floorTopologyPath(host.doc,host.floor)}>${floorTopologyPath(host.doc,host.floor)}</div>`:nothing}
|
||||
${host.doc.topology?html`<button class="nf-btn nf-room-move-open" ?disabled=${!host.admin} @click=${()=>actions.move()}>Raum verschieben…</button>`:nothing}
|
||||
<div class="nf-form">
|
||||
${textField(host, t("room_name"), room.name, (v) => actions.patch({ name: v }), { wide: true })}
|
||||
${selectField(host, isSymcon(host.hass)?"Bereich (Symcon)":t("area"), room.area_id ?? "", areaChoices, (id) => actions.setArea(id), { wide: true })}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { css, html, LitElement, nothing, type PropertyValues } from "lit";
|
||||
import { uid, type Building, type PlanTopology } from "../../model.ts";
|
||||
import { addLocationOutside, enableTopology } from "../../topology.ts";
|
||||
import { addTopologyOutside, enableTopology, isOutdoorFloor, outsideFloor, outsideSelection, type OutsideOwner } from "../../topology.ts";
|
||||
import { tokens } from "../../styles.ts";
|
||||
import { hint } from "./fields.ts";
|
||||
import type { EditorScope } from "./editor-context.ts";
|
||||
@@ -31,6 +31,13 @@ class HierarchyManager extends LitElement {
|
||||
}
|
||||
private publish(next:Building){this.doc=next;this.dispatchEvent(new CustomEvent("hierarchy-change",{detail:{building:next},bubbles:true,composed:true}));}
|
||||
private open(scope:EditorScope){this.dispatchEvent(new CustomEvent("hierarchy-open",{detail:scope,bubbles:true,composed:true}));}
|
||||
private outsideButton(owner:OutsideOwner){
|
||||
const found=!!outsideFloor(this.doc,outsideSelection(owner));
|
||||
return html`<button class="outside outside-${owner.kind}" ?disabled=${!this.admin&&!found} @click=${()=>{
|
||||
if(!found)this.edit((b)=>{addTopologyOutside(b,owner);});
|
||||
this.open(outsideSelection(owner) as EditorScope);
|
||||
}}>🌳 ${found?"Außenplan öffnen":"Außenplan anlegen"}</button>`;
|
||||
}
|
||||
private name(label:string,value:string,save:(name:string)=>void){
|
||||
return html`<label>${label}<input maxlength="100" .value=${value} ?disabled=${!this.admin} @change=${(e:Event)=>save((e.target as HTMLInputElement).value.trim())}/></label>`;
|
||||
}
|
||||
@@ -44,10 +51,8 @@ class HierarchyManager extends LitElement {
|
||||
<section aria-label="Orte"><h3>Orte</h3><div class="items">${t.locations.map((s)=>html`<button class="pick" data-location=${s.id} aria-pressed=${s.id===this.locationId} @click=${()=>{this.locationId=s.id;this.branchId="";this.buildingId="";}}>${s.name}</button>`)}</div>
|
||||
<button class="add-location" ?disabled=${!this.admin} @click=${()=>{const id=uid("location");this.edit((_,p)=>p.locations.push({id,name:`Ort ${p.locations.length+1}`}));this.locationId=id;this.branchId="";this.buildingId="";}}>+ Ort</button>
|
||||
${l?html`<div class="details">${this.name("Name des Ortes",l.name,(name)=>{if(this.locationId===l.id)this.edit((_,p)=>{p.locations.find((s)=>s.id===l.id)!.name=name;});})}
|
||||
<button class="outside" ?disabled=${!this.admin&&!this.doc.floors.some((f)=>f.outdoor_location_id===l.id)} @click=${()=>{
|
||||
if(!this.doc.floors.some((f)=>f.outdoor_location_id===l.id))this.edit((b)=>{addLocationOutside(b,l.id);});
|
||||
this.open({kind:"outside",id:l.id});
|
||||
}}>🌳 ${this.doc.floors.some((f)=>f.outdoor_location_id===l.id)?"Außenplan öffnen":"Außenplan anlegen"}</button>
|
||||
<button class="open-location primary" @click=${()=>this.open({kind:"location",id:l.id})}>Ort im Editor anzeigen</button>
|
||||
${this.outsideButton({kind:"location",id:l.id})}
|
||||
<button class="delete" ?disabled=${!this.admin||t.branches.some((s)=>s.location_id===l.id)||this.doc.floors.some((f)=>f.outdoor_location_id===l.id)} @click=${()=>this.edit((_,p)=>{p.locations=p.locations.filter((s)=>s.id!==l.id);})}>Ort entfernen</button>
|
||||
</div>`:nothing}
|
||||
</section>
|
||||
@@ -55,15 +60,18 @@ class HierarchyManager extends LitElement {
|
||||
<button class="add-branch" ?disabled=${!this.admin||!l} @click=${()=>{if(!l)return;const id=uid("branch");this.edit((_,p)=>p.branches.push({id,name:`Niederlassung ${p.branches.length+1}`,location_id:l.id}));this.branchId=id;this.buildingId="";}}>+ Niederlassung</button>
|
||||
${n?html`<div class="details">${this.name("Name der Niederlassung",n.name,(name)=>{if(this.branchId===n.id)this.edit((_,p)=>{p.branches.find((s)=>s.id===n.id)!.name=name;});})}
|
||||
<label>Ort der Niederlassung<select ?disabled=${!this.admin} .value=${n.location_id} @change=${(e:Event)=>{const id=(e.target as HTMLSelectElement).value;if(this.branchId!==n.id||!t.locations.some((l)=>l.id===id))return;this.edit((_,p)=>{p.branches.find((s)=>s.id===n.id)!.location_id=id;});this.locationId=id;}}>${t.locations.map((l)=>html`<option value=${l.id} .selected=${l.id===n.location_id}>${l.name}</option>`)}</select></label>
|
||||
<button class="delete" ?disabled=${!this.admin||t.buildings.some((s)=>s.branch_id===n.id)} @click=${()=>this.edit((_,p)=>{p.branches=p.branches.filter((s)=>s.id!==n.id);})}>Niederlassung entfernen</button>
|
||||
<button class="open-branch primary" @click=${()=>this.open({kind:"branch",id:n.id})}>Niederlassung im Editor anzeigen</button>
|
||||
${this.outsideButton({kind:"branch",id:n.id})}
|
||||
<button class="delete" ?disabled=${!this.admin||t.buildings.some((s)=>s.branch_id===n.id)||this.doc.floors.some((f)=>f.outdoor_branch_id===n.id)} @click=${()=>this.edit((_,p)=>{p.branches=p.branches.filter((s)=>s.id!==n.id);})}>Niederlassung entfernen</button>
|
||||
</div>`:nothing}
|
||||
</section>
|
||||
<section aria-label="Gebäude"><h3>Gebäude</h3><div class="items">${t.buildings.filter((s)=>s.branch_id===this.branchId).map((s)=>html`<button class="pick" data-building=${s.id} aria-pressed=${s.id===this.buildingId} @click=${()=>this.buildingId=s.id}>${s.name}<small>${this.doc.floors.filter((f)=>!f.outdoor_location_id&&f.building_id===s.id).length} Etagen</small></button>`)}</div>
|
||||
<section aria-label="Gebäude"><h3>Gebäude</h3><div class="items">${t.buildings.filter((s)=>s.branch_id===this.branchId).map((s)=>html`<button class="pick" data-building=${s.id} aria-pressed=${s.id===this.buildingId} @click=${()=>this.buildingId=s.id}>${s.name}<small>${this.doc.floors.filter((f)=>!isOutdoorFloor(f)&&f.building_id===s.id).length} Etagen</small></button>`)}</div>
|
||||
<button class="add-building" ?disabled=${!this.admin||!n} @click=${()=>{if(!n)return;const id=uid("building");this.edit((_,p)=>p.buildings.push({id,name:`Gebäude ${p.buildings.length+1}`,branch_id:n.id}));this.buildingId=id;}}>+ Gebäude</button>
|
||||
${g?html`<div class="details">${this.name("Name des Gebäudes",g.name,(name)=>{if(this.buildingId===g.id)this.edit((_,p)=>{p.buildings.find((s)=>s.id===g.id)!.name=name;});})}
|
||||
<label>Niederlassung des Gebäudes<select ?disabled=${!this.admin} .value=${g.branch_id} @change=${(e:Event)=>{const id=(e.target as HTMLSelectElement).value,branch=t.branches.find((s)=>s.id===id);if(this.buildingId!==g.id||!branch)return;this.edit((_,p)=>{p.buildings.find((s)=>s.id===g.id)!.branch_id=id;});this.branchId=id;this.locationId=branch.location_id;}}>${t.branches.map((s)=>html`<option value=${s.id} .selected=${s.id===g.branch_id}>${t.locations.find((l)=>l.id===s.location_id)?.name} / ${s.name}</option>`)}</select></label>
|
||||
<button class="open-building primary" @click=${()=>this.open({kind:"building",id:g.id})}>Im Editor auswählen</button>
|
||||
<button class="delete" ?disabled=${!this.admin||this.doc.floors.some((f)=>f.building_id===g.id)} @click=${()=>this.edit((_,p)=>{p.buildings=p.buildings.filter((s)=>s.id!==g.id);})}>Gebäude entfernen</button>
|
||||
${this.outsideButton({kind:"building",id:g.id})}
|
||||
<button class="delete" ?disabled=${!this.admin||this.doc.floors.some((f)=>f.building_id===g.id||f.outdoor_building_id===g.id)} @click=${()=>this.edit((_,p)=>{p.buildings=p.buildings.filter((s)=>s.id!==g.id);})}>Gebäude entfernen</button>
|
||||
</div>`:nothing}
|
||||
</section>
|
||||
</div>`;
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
import { floorElevation, newFloor, uid, type Building, type Floor, type Furniture } from "../../../model.ts";
|
||||
import type { HassArea, HassFloor } from "../../../types.ts";
|
||||
import { isOutdoorFloor, outdoorOwner, topologyKey } from "../../../topology.ts";
|
||||
|
||||
/** A new floor, named after a Home Assistant floor when it comes from one, and placed at that floor's level or on top of the house. */
|
||||
export function newFloorFor(doc: Building, from: HassFloor | null, names: { first: string; next(n: number): string }, parent?: string | null): Floor {
|
||||
const building_id = doc.topology ? parent || doc.topology.buildings[0]?.id : undefined;
|
||||
const floors = doc.topology ? doc.floors.filter((f)=>!f.outdoor_location_id&&f.building_id===building_id) : doc.floors;
|
||||
const floors = doc.topology ? doc.floors.filter((f)=>!isOutdoorFloor(f)&&f.building_id===building_id) : doc.floors;
|
||||
const count = floors.length;
|
||||
const name = from?.name ?? (count === 0 ? names.first : names.next(count));
|
||||
return { ...newFloor(uid("floor"), name, floorElevation(floors, from?.level)), ha_floor: from?.floor_id ?? null, ...(building_id?{building_id}:{}) };
|
||||
@@ -67,7 +68,8 @@ export interface FloorCopyOptions {
|
||||
*/
|
||||
export function copyOfFloor(doc: Building, floor: Floor, name: string, options: FloorCopyOptions, id: (prefix: string) => string = uid): Floor {
|
||||
const copy = structuredClone(floor);
|
||||
const top = doc.floors.filter((f)=>!doc.topology||f.building_id===floor.building_id).reduce((max, f) => Math.max(max, f.elevation + f.height), floor.elevation + floor.height);
|
||||
const owner=outdoorOwner(floor);
|
||||
const top = doc.floors.filter((f)=>!doc.topology||(owner?topologyKey(outdoorOwner(f)??{kind:"all"})===topologyKey(owner):!isOutdoorFloor(f)&&f.building_id===floor.building_id)).reduce((max, f) => Math.max(max, f.elevation + f.height), floor.elevation + floor.height);
|
||||
const rooms = new Map<string, string>();
|
||||
const walls = new Map<string, string>();
|
||||
copy.id = id("floor");
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { emptyBuilding, newFloor, type Placement } from "../../../model.ts";
|
||||
import { box, opening } from "../../../entities/fixtures.ts";
|
||||
import { moveRoomToFloor, roomMovePosition } from "./room-move.ts";
|
||||
|
||||
function project(){
|
||||
const b=emptyBuilding(),a={...newFloor("a","EG",0),building_id:"a"},z={...newFloor("z","OG",3),building_id:"z"};
|
||||
a.rooms=[{...box("it",0,0,5,5,"symcon-category-100"),name:"IT",climate:{temperature:"sensor.1"},start_view:{theta:1,phi:1,radius:5,target:{x:2,y:0,z:3}}},box("stay",8,0,12,5)];
|
||||
a.furniture=[{id:"f",type:"desk",variant:null,x:1,z:1,w:1,d:1,h:1,rotation:20,power:"sensor.2"},{id:"stay-f",type:"desk",variant:null,x:9,z:2,w:1,d:1,h:1,rotation:0}];
|
||||
a.placements=[{entity_id:"light.1",x:2,z:2,y:1},{entity_id:"sensor.outside",x:2,z:2,y:1,outside:true},{entity_id:"light.stay",x:9,z:2,y:1}] as Placement[];
|
||||
a.openings=[opening("door","it","door"),opening("stay-o","stay","door")];
|
||||
a.walls=[{id:"partition",a:[1,1],b:[2,1],height:2.5,thickness:0.1}];
|
||||
a.notes=[{id:"n",text:"Filter",x:3,z:3},{id:"stay-n",text:"Elsewhere",x:10,z:2}];
|
||||
z.rooms=[box("target",20,20,25,25)];b.floors=[a,z,newFloor("other","Unchanged",0)];
|
||||
b.energy.routes=[{key:"grid",points:[{floor_id:"a",x:1,z:1},{floor_id:"a",x:9,z:1}]}];return b;
|
||||
}
|
||||
test("moving a room transfers its geometry, openings, contents and links once and preserves unrelated rooms",()=>{
|
||||
const b=project(),before=structuredClone(b),pos=roomMovePosition(b.floors[1]);assert.deepEqual(pos,[26,20]);
|
||||
assert.equal(moveRoomToFloor(b,"a","it","z",pos),null);
|
||||
const [a,z]=b.floors,r=z.rooms.find((r)=>r.id==="it")!;
|
||||
assert.deepEqual(a.rooms,[before.floors[0].rooms[1]]);assert.equal(r.area_id,"symcon-category-100");assert.equal(r.climate?.temperature,"sensor.1");
|
||||
assert.deepEqual(r.points,[[26,20],[31,20],[31,25],[26,25]]);assert.deepEqual(r.start_view?.target,{x:28,y:0,z:23});
|
||||
assert.deepEqual(z.furniture,[{...before.floors[0].furniture[0],x:27,z:21}]);assert.deepEqual(a.furniture,[before.floors[0].furniture[1]]);
|
||||
assert.deepEqual(z.placements,[{...before.floors[0].placements[0],x:28,z:22}]);assert.deepEqual(a.placements,before.floors[0].placements.slice(1));
|
||||
assert.equal(z.openings[0].id,"door");assert.equal(z.openings[0].room_id,"it");assert.deepEqual(a.openings,[before.floors[0].openings[1]]);
|
||||
assert.deepEqual(z.walls?.[0].a,[27,21]);assert.equal(a.walls?.length,0);assert.deepEqual(z.notes,[{id:"n",text:"Filter",x:29,z:23}]);
|
||||
assert.deepEqual(b.energy.routes?.[0].points,[{floor_id:"z",x:27,z:21},{floor_id:"a",x:9,z:1}]);
|
||||
assert.deepEqual(b.floors[2],before.floors[2]);
|
||||
});
|
||||
test("invalid targets, duplicate devices and stale room IDs reject the entire move before any mutation",()=>{
|
||||
for(const invalid of ["same","missing","outdoor","duplicate","room","position"]){
|
||||
const b=project();if(invalid==="outdoor")b.floors[1].outdoor_branch_id="hq";
|
||||
if(invalid==="duplicate")b.floors[1].placements.push({...b.floors[0].placements[0]});
|
||||
const before=structuredClone(b);
|
||||
assert.ok(moveRoomToFloor(b,"a",invalid==="room"?"gone":"it",invalid==="same"?"a":invalid==="missing"?"gone":"z",invalid==="position"?[NaN,0]:[0,0]));assert.deepEqual(b,before);
|
||||
}
|
||||
});
|
||||
test("a shared free wall remains for its other room and only the moved opening gets a new wall host",()=>{
|
||||
const b=project(),a=b.floors[0];a.walls=[{id:"shared",a:[1,1],b:[4,1],height:2.5,thickness:0.1}];
|
||||
a.openings=[{...opening("own","it","door"),wall:"shared"},{...opening("other","stay","window"),wall:"shared"}];
|
||||
const original=structuredClone(a.walls[0]);assert.equal(moveRoomToFloor(b,"a","it","z",[26,20]),null);
|
||||
assert.deepEqual(a.walls,[original]);assert.equal(a.openings[0].wall,"shared");assert.notEqual(b.floors[1].openings[0].wall,"shared");
|
||||
assert.equal(b.floors[1].openings[0].wall,b.floors[1].walls![0].id);
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import { bounds, pointInPolygon, uid, type Building, type Floor, type Vec2 } from "../../../model.ts";
|
||||
import { isOutdoorFloor } from "../../../topology.ts";
|
||||
|
||||
/** Offer a free spot next to the target plan; the dialog lets the user adjust both coordinates. */
|
||||
export function roomMovePosition(target: Floor): Vec2 {
|
||||
const points=target.rooms.flatMap((r)=>r.points);
|
||||
if(!points.length)return [0,0];
|
||||
const box=bounds(points);return [box.x1+1,box.z0];
|
||||
}
|
||||
|
||||
/** Move, never copy, the room and its contents. A rejected operation leaves the document untouched. */
|
||||
export function moveRoomToFloor(b: Building, sourceId: string, roomId: string, targetId: string, position: Vec2): string | null {
|
||||
const source=b.floors.find((f)=>f.id===sourceId),target=b.floors.find((f)=>f.id===targetId);
|
||||
const room=source?.rooms.find((r)=>r.id===roomId);
|
||||
if(!source||!target||!room)return "Raum oder Zieletage ist nicht mehr vorhanden.";
|
||||
if(source===target||isOutdoorFloor(target))return "Bitte eine andere Gebäudeetage auswählen.";
|
||||
if(!position.every(Number.isFinite))return "Die Zielposition muss aus gültigen Zahlen bestehen.";
|
||||
const belongs=(x:number,z:number)=>source.rooms.find((r)=>pointInPolygon([x,z],r.points))?.id===roomId;
|
||||
const furniture=source.furniture.filter((p)=>belongs(p.x,p.z));
|
||||
const placements=source.placements.filter((p)=>!p.outside&&belongs(p.x,p.z));
|
||||
const notes=(source.notes??[]).filter((p)=>belongs(p.x,p.z));
|
||||
const openings=source.openings.filter((o)=>o.room_id===roomId);
|
||||
if(target.rooms.some((r)=>r.id===roomId)||furniture.some((p)=>target.furniture.some((q)=>q.id===p.id))||placements.some((p)=>target.placements.some((q)=>q.entity_id===p.entity_id))||openings.some((o)=>target.openings.some((q)=>q.id===o.id))||notes.some((n)=>target.notes?.some((q)=>q.id===n.id)))return "Die Zieletage enthält bereits einen Raum oder ein Gerät mit derselben Kennung.";
|
||||
|
||||
const originalPoints=room.points,box=bounds(originalPoints),dx=position[0]-box.x0,dz=position[1]-box.z0;
|
||||
const at=([x,z]:Vec2):Vec2=>[Math.round((x+dx)*1000)/1000,Math.round((z+dz)*1000)/1000];
|
||||
const shift=(p:{x:number;z:number})=>[p.x,p.z]=at([p.x,p.z]);
|
||||
const movingWalls=new Set<string>(),copiedWalls=new Map<string,string>();
|
||||
let wallConflict=false;
|
||||
const walls=(source.walls??[]).flatMap((w)=>{
|
||||
const own=openings.some((o)=>o.wall===w.id),shared=source.openings.some((o)=>o.wall===w.id&&o.room_id!==roomId);
|
||||
if(!own&&(shared||!belongs(w.a[0],w.a[1])||!belongs(w.b[0],w.b[1])))return [];
|
||||
if(shared){const id=uid("wall");copiedWalls.set(w.id,id);return [{...structuredClone(w),id}];}
|
||||
if(target.walls?.some((q)=>q.id===w.id)){wallConflict=true;return [];}
|
||||
movingWalls.add(w.id);return [w];
|
||||
});
|
||||
if(wallConflict||openings.some((o)=>o.wall&&!movingWalls.has(o.wall)&&!copiedWalls.has(o.wall)))return "Eine zugehörige Wand kann nicht eindeutig auf die Zieletage verschoben werden.";
|
||||
|
||||
source.rooms=source.rooms.filter((r)=>r!==room);target.rooms.push(room);
|
||||
const transfer=<T>(items:T[],from:T[],to:T[]):T[]=>{const set=new Set(items);to.push(...items);return from.filter((p)=>!set.has(p));};
|
||||
source.furniture=transfer(furniture,source.furniture,target.furniture);
|
||||
source.placements=transfer(placements,source.placements,target.placements);
|
||||
source.openings=transfer(openings,source.openings,target.openings);
|
||||
if(notes.length){target.notes??=[];source.notes=transfer(notes,source.notes??[],target.notes);}
|
||||
if(walls.length){source.walls=(source.walls??[]).filter((w)=>!movingWalls.has(w.id));target.walls??=[];target.walls.push(...walls);}
|
||||
room.points=room.points.map(at);
|
||||
if(room.start_view?.target)shift(room.start_view.target);
|
||||
for(const item of [...furniture,...placements,...notes])shift(item);
|
||||
for(const w of walls){w.a=at(w.a);w.b=at(w.b);}
|
||||
for(const o of openings)if(o.wall&&copiedWalls.has(o.wall))o.wall=copiedWalls.get(o.wall)!;
|
||||
for(const route of b.energy.routes??[])for(const p of route.points)if(p.floor_id===sourceId&&pointInPolygon([p.x,p.z],originalPoints)){p.floor_id=targetId;shift(p);}
|
||||
return null;
|
||||
}
|
||||
@@ -2,15 +2,16 @@ import { css } from "lit";
|
||||
|
||||
/** The editor's own styles: the plan canvas, the side panel with its forms and libraries, the 3D pane and the phone layout. */
|
||||
export const editorStyles = css`
|
||||
.nf-scope-overview [data-overview-floor]{cursor:pointer}.nf-scope-overview polygon{fill:#03a9f41a;stroke:#03a9f4;stroke-width:1.5}.nf-scope-overview [data-overview-floor]:hover polygon,.nf-scope-overview [data-overview-floor]:focus polygon{fill:#03a9f44d}.nf-scope-overview text{fill:var(--nf-text);font-size:11px;text-anchor:middle;pointer-events:none}.nf-room-move-open{width:100%;margin-bottom:12px}.nf-room-move-error{color:var(--nf-warm)}
|
||||
.nf-editor-context{display:grid;gap:8px;padding:10px 12px;border-bottom:1px solid var(--nf-line)}
|
||||
.nf-editor-building-row,.nf-editor-floor-nav{display:flex;gap:8px;align-items:center;flex-wrap:wrap;min-width:0}
|
||||
.nf-editor-building-row>label{display:flex;gap:8px;align-items:center;font-size:12px;min-width:0;flex:1}
|
||||
.nf-editor-building-select{font:inherit;color:var(--nf-text);background:var(--nf-chrome-solid);border:1px solid var(--nf-line);border-radius:8px;padding:7px 10px;min-width:0;width:min(100%,480px)}
|
||||
.nf-editor-floor-nav{font-size:12px}.nf-editor-floor-nav .nf-editor-move-floor{margin-left:auto;font-size:11px}
|
||||
.nf-hierarchy-dialog,.nf-floor-move-dialog{box-sizing:border-box;width:min(1050px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;padding:18px;border:1px solid var(--nf-line);border-radius:14px;color:var(--nf-text);background:var(--nf-chrome-solid,#1c1c1c);box-shadow:0 20px 70px #0008;font:13px/1.4 system-ui}
|
||||
.nf-hierarchy-dialog::backdrop,.nf-floor-move-dialog::backdrop{background:#050b16a6;backdrop-filter:blur(3px)}
|
||||
.nf-hierarchy-dialog>header,.nf-floor-move-dialog>header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}.nf-hierarchy-dialog h2,.nf-floor-move-dialog h2{font-size:17px;margin:0}
|
||||
.nf-floor-move-dialog{width:min(650px,calc(100vw - 24px))}.nf-floor-move-source{overflow-wrap:anywhere}.nf-floor-move-dialog>.nf-btn{margin-top:16px}
|
||||
.nf-hierarchy-dialog,.nf-floor-move-dialog,.nf-room-move-dialog{box-sizing:border-box;width:min(1050px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow:auto;padding:18px;border:1px solid var(--nf-line);border-radius:14px;color:var(--nf-text);background:var(--nf-chrome-solid,#1c1c1c);box-shadow:0 20px 70px #0008;font:13px/1.4 system-ui}
|
||||
.nf-hierarchy-dialog::backdrop,.nf-floor-move-dialog::backdrop,.nf-room-move-dialog::backdrop{background:#050b16a6;backdrop-filter:blur(3px)}
|
||||
.nf-hierarchy-dialog>header,.nf-floor-move-dialog>header,.nf-room-move-dialog>header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}.nf-hierarchy-dialog h2,.nf-floor-move-dialog h2,.nf-room-move-dialog h2{font-size:17px;margin:0}
|
||||
.nf-floor-move-dialog,.nf-room-move-dialog{width:min(650px,calc(100vw - 24px))}.nf-floor-move-source,.nf-room-move-dialog p{overflow-wrap:anywhere}.nf-floor-move-dialog>.nf-btn,.nf-room-move-dialog>.nf-btn{margin-top:16px}
|
||||
.nf-room-area-group h4{font-size:11px;color:var(--nf-muted);margin:12px 0 4px}.nf-room-context{font-size:11px;color:var(--nf-muted);margin:4px 0 12px;overflow-wrap:anywhere}
|
||||
.nf-value-links h4 { margin: 12px 0; }
|
||||
.nf-value-add { min-width: 30px; font-size: 18px; padding: 3px 8px; }
|
||||
|
||||
@@ -439,6 +439,9 @@ export interface Floor {
|
||||
building_id?: string | null;
|
||||
/** A separate outdoor plan belonging directly to a location, outside the building/storey hierarchy. */
|
||||
outdoor_location_id?: string | null;
|
||||
/** Independent outdoor plans may also belong to a branch or building. Exactly one outdoor owner is set. */
|
||||
outdoor_branch_id?: string | null;
|
||||
outdoor_building_id?: string | null;
|
||||
elevation: number;
|
||||
height: number;
|
||||
cut_height: number;
|
||||
|
||||
@@ -24,7 +24,7 @@ import type { HomeAssistant } from "./types.ts";
|
||||
import { withCoverControls } from "./entities/cover-controls.ts";
|
||||
import { withSymconWeather } from "./symcon-weather.ts";
|
||||
import { isSymcon } from "./entities/symcon-values.ts";
|
||||
import { ALL_TOPOLOGY, floorSelection, topologyOutsideFloors, topologyParent, topologyPath, type TopologySelection } from "./topology.ts";
|
||||
import { ALL_TOPOLOGY, floorSelection, isOutdoorFloor, outsideFloor, outsideSelection, topologyOutsideFloors, topologyParent, topologyPath, type TopologySelection, type OutsideOwner } from "./topology.ts";
|
||||
import { allOffPlan, floorSwitchables, type ServiceCall } from "./live/all-off.ts";
|
||||
import type { FloorStack, Quality, WallMode } from "./viewer/viewer3d.ts";
|
||||
|
||||
@@ -192,7 +192,7 @@ export class NextFloorPanel extends LitElement {
|
||||
private openTopology(selection: TopologySelection): void {
|
||||
const b=this.data.building;if(!b)return;
|
||||
this._roomId=selection.kind==="room"?selection.id??null:null;
|
||||
this._floorId=selection.kind==="room"?selection.floorId??null:selection.kind==="floor"?selection.id??null:selection.kind==="outside"?b.floors.find((f)=>f.outdoor_location_id===selection.id)?.id??null:null;
|
||||
this._floorId=selection.kind==="room"?selection.floorId??null:selection.kind==="floor"?selection.id??null:outsideFloor(b,selection)?.id??null;
|
||||
this._topologyGroup=selection;this._outside=false;
|
||||
}
|
||||
|
||||
@@ -217,11 +217,11 @@ export class NextFloorPanel extends LitElement {
|
||||
private openOutside(floorId?: string): void {
|
||||
const b=this.data.building;
|
||||
if(b?.topology){
|
||||
const location=topologyPath(b,floorId?floorSelection(b,floorId):this.topologySelection(b)).find((n)=>n.selection.kind==="location");
|
||||
if(!location)return;
|
||||
const f=b.floors.find((f)=>f.outdoor_location_id===location?.selection.id);
|
||||
if(f){const open=!this._outside;this.openTopology({kind:"outside",id:f.outdoor_location_id!});this._outside=open;return;}
|
||||
const open=!this._outside;this.openTopology(location.selection);this._outside=open;return;
|
||||
const path=topologyPath(b,floorId?floorSelection(b,floorId):this.topologySelection(b));
|
||||
const direct=path.find((n)=>n.selection.kind==="outside")?.selection;
|
||||
const owner=[...path].reverse().find((n)=>["building","branch","location"].includes(n.selection.kind)&&outsideFloor(b,outsideSelection(n.selection as OutsideOwner)));
|
||||
const target=direct??(owner?outsideSelection(owner.selection as OutsideOwner):path.find((n)=>n.selection.kind==="location")?.selection);
|
||||
if(target){const open=!this._outside;this.openTopology(target);this._outside=open;}return;
|
||||
}
|
||||
const open = !this._outside;
|
||||
this.openFloor(null);
|
||||
@@ -516,7 +516,7 @@ export class NextFloorPanel extends LitElement {
|
||||
private renderNav(building: Building) {
|
||||
if(building.topology){
|
||||
const floor=building.floors.find((f)=>f.id===this._floorId);
|
||||
if(!floor||floor.outdoor_location_id)return nothing;
|
||||
if(!floor||isOutdoorFloor(floor))return nothing;
|
||||
return html`<nav class="nf-nav nf-topology-floor-nav" aria-label=${floor.name}>
|
||||
${floor.rooms.map((room)=>html`<button class="nf-chip nf-room-chip" aria-pressed=${room.id===this._roomId} @click=${()=>{this._roomId=this._roomId===room.id?null:room.id;this._outside=false;}}>${room.name}</button>`)}
|
||||
${this.allOffChip(building)}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { emptyBuilding, newFloor, normalizeBuilding } from "./model.ts";
|
||||
import { ALL_TOPOLOGY, addLocationOutside, enableTopology, floorSelection, floorTopologyPath, normalizeTopology, topologyFloors, topologyItems, topologyOutsideFloors, topologyParent, topologyPath, topologyTree } from "./topology.ts";
|
||||
import { ALL_TOPOLOGY, addLocationOutside, addTopologyOutside, enableTopology, floorSelection, floorTopologyPath, isOutdoorFloor, normalizeTopology, outsideSelection, topologyFloors, topologyItems, topologyKey, topologyOutsideFloors, topologyParent, topologyPath, topologyTree } from "./topology.ts";
|
||||
import { copyOfFloor, newFloorFor } from "./components/editor/ops/floors.ts";
|
||||
import { translate } from "./components/editor/ops/transform.ts";
|
||||
import { box } from "./entities/fixtures.ts";
|
||||
@@ -84,3 +84,24 @@ test("automatic roofs cover each building independently and leave location outdo
|
||||
assert.deepEqual(buildRoof(b).map((p)=>p.floor.building_id).sort(),["ras19","ras21","ulm1"]);
|
||||
assert.equal(buildRoof({...b,floors:b.floors.filter((f)=>!!f.outdoor_location_id)}).length,0);
|
||||
});
|
||||
|
||||
test("locations, branches and buildings own independent outdoor plans with unambiguous paths and scene membership",()=>{
|
||||
const b=project(),location=addLocationOutside(b,"urbach"),branch=addTopologyOutside(b,{kind:"branch",id:"hq"}),building=addTopologyOutside(b,{kind:"building",id:"ras19"});
|
||||
assert.equal(addTopologyOutside(b,{kind:"branch",id:"hq"}),branch);
|
||||
assert.equal(addTopologyOutside(b,{kind:"building",id:"ras19"}),building);
|
||||
assert.deepEqual(topologyPath(b,floorSelection(b,branch.id)).slice(1).map((n)=>n.name),["Urbach","Zentrale","Außen"]);
|
||||
assert.equal(floorTopologyPath(b,building),"Urbach / Zentrale / RAS19 / Außen");
|
||||
assert.deepEqual(topologyParent(b,floorSelection(b,building.id)),{kind:"building",id:"ras19"});
|
||||
const branchIds=topologyFloors(b,{kind:"branch",id:"hq"}).map((f)=>f.id);
|
||||
assert.ok(branchIds.includes(branch.id)&&branchIds.includes(building.id)&&!branchIds.includes(location.id)&&!branchIds.includes("west-eg"));
|
||||
assert.deepEqual(topologyFloors(b,floorSelection(b,branch.id)).map((f)=>f.id),[branch.id]);
|
||||
building.rooms=[box("garden-room",0,0,3,3)];
|
||||
assert.deepEqual(topologyFloors(b,floorSelection(b,building.id,"garden-room"),true).map((f)=>f.id),[building.id],"a room in an outdoor plan does not accidentally render indoor floors");
|
||||
assert.deepEqual(new Set(topologyOutsideFloors(b,floorSelection(b,building.id)).map((f)=>f.id)),new Set(["eg","og",building.id]));
|
||||
assert.equal(new Set(["location","branch","building"].map((kind)=>topologyKey(outsideSelection({kind:kind as "location"|"branch"|"building",id:"same"})))).size,3);
|
||||
normalizeBuilding(b);const saved=normalizeBuilding(JSON.parse(JSON.stringify(b)));
|
||||
assert.equal(saved.floors.find((f)=>f.id===branch.id)?.outdoor_branch_id,"hq");
|
||||
assert.equal(saved.floors.find((f)=>f.id===building.id)?.outdoor_building_id,"ras19");
|
||||
b.settings.roof.type="gable";
|
||||
assert.equal(buildRoof({...b,floors:b.floors.filter(isOutdoorFloor)}).length,0);
|
||||
});
|
||||
+48
-16
@@ -1,13 +1,25 @@
|
||||
import { newFloor, uid, type Building, type Floor, type PlanTopology } from "./model.ts";
|
||||
|
||||
export type TopologyKind = "all" | "location" | "branch" | "building" | "floor" | "room" | "outside";
|
||||
export interface TopologySelection { kind: TopologyKind; id?: string; floorId?: string }
|
||||
export type OutsideOwnerKind = "location" | "branch" | "building";
|
||||
export interface OutsideOwner { kind: OutsideOwnerKind; id: string }
|
||||
export interface TopologySelection { kind: TopologyKind; id?: string; floorId?: string; ownerKind?: OutsideOwnerKind }
|
||||
export interface TopologyNode {
|
||||
key: string; name: string; selection: TopologySelection; floorIds: string[]; children: TopologyNode[];
|
||||
room?: { floorId: string; roomId: string };
|
||||
}
|
||||
export const ALL_TOPOLOGY: TopologySelection = { kind: "all" };
|
||||
export const topologyKey = (s: TopologySelection): string => [s.kind, s.floorId, s.id].filter(Boolean).join(":");
|
||||
export const topologyKey = (s: TopologySelection): string => [s.kind, s.ownerKind, s.floorId, s.id].filter(Boolean).join(":");
|
||||
export function outdoorOwner(f: Floor | undefined): OutsideOwner | null {
|
||||
return f?.outdoor_building_id ? {kind:"building",id:f.outdoor_building_id}
|
||||
: f?.outdoor_branch_id ? {kind:"branch",id:f.outdoor_branch_id}
|
||||
: f?.outdoor_location_id ? {kind:"location",id:f.outdoor_location_id} : null;
|
||||
}
|
||||
export const isOutdoorFloor = (f: Floor | undefined): boolean => !!outdoorOwner(f);
|
||||
export const outsideSelection = (owner: OutsideOwner): TopologySelection => ({kind:"outside",id:owner.id,...(owner.kind!=="location"?{ownerKind:owner.kind}:{})});
|
||||
export function outsideFloor(b: Building, s: TopologySelection): Floor | undefined {
|
||||
return s.kind==="outside" ? b.floors.find((f)=>{const o=outdoorOwner(f);return o?.kind===(s.ownerKind??"location")&&o.id===s.id;}) : undefined;
|
||||
}
|
||||
|
||||
/** Enable the hierarchy without moving geometry or changing the stable floor/room IDs used by grants. */
|
||||
export function enableTopology(b: Building, name = "Gebäude 1"): void {
|
||||
@@ -39,21 +51,31 @@ export function normalizeTopology(b: Building): void {
|
||||
for (const s of t.branches) s.location_id = location(s.location_id);
|
||||
for (const s of t.buildings) s.branch_id = branch(s.branch_id);
|
||||
for (const f of b.floors) {
|
||||
if (f.outdoor_location_id) { f.outdoor_location_id=location(f.outdoor_location_id); f.building_id=null; }
|
||||
else f.building_id=building(f.building_id);
|
||||
const owner=outdoorOwner(f);
|
||||
if (owner) {
|
||||
const id=owner.kind==="building"?building(owner.id):owner.kind==="branch"?branch(owner.id):location(owner.id);
|
||||
f.outdoor_location_id=owner.kind==="location"?id:null;
|
||||
f.outdoor_branch_id=owner.kind==="branch"?id:null;
|
||||
f.outdoor_building_id=owner.kind==="building"?id:null;
|
||||
f.building_id=null;
|
||||
} else f.building_id=building(f.building_id);
|
||||
}
|
||||
}
|
||||
|
||||
export function addLocationOutside(b: Building, locationId: string): Floor {
|
||||
const found=b.floors.find((f)=>f.outdoor_location_id===locationId);
|
||||
return addTopologyOutside(b,{kind:"location",id:locationId});
|
||||
}
|
||||
export function addTopologyOutside(b: Building, owner: OutsideOwner): Floor {
|
||||
const found=outsideFloor(b,outsideSelection(owner));
|
||||
if(found)return found;
|
||||
const f={...newFloor(uid("outside"),"Außen",0),outdoor_location_id:locationId,building_id:null};
|
||||
const f={...newFloor(uid("outside"),"Außen",0),[owner.kind==="building"?"outdoor_building_id":owner.kind==="branch"?"outdoor_branch_id":"outdoor_location_id"]:owner.id,building_id:null};
|
||||
b.floors.push(f);return f;
|
||||
}
|
||||
|
||||
export function floorSelection(b: Building, floorId: string, roomId?: string | null): TopologySelection {
|
||||
const f=b.floors.find((f)=>f.id===floorId);
|
||||
return roomId ? {kind:"room",id:roomId,floorId} : f?.outdoor_location_id ? {kind:"outside",id:f.outdoor_location_id} : {kind:"floor",id:floorId};
|
||||
const owner=outdoorOwner(f);
|
||||
return roomId ? {kind:"room",id:roomId,floorId} : owner ? outsideSelection(owner) : {kind:"floor",id:floorId};
|
||||
}
|
||||
|
||||
export function topologyTree(b: Building): TopologyNode {
|
||||
@@ -64,12 +86,20 @@ export function topologyTree(b: Building): TopologyNode {
|
||||
const floorNode=(f:Floor)=>make("floor",f.id,f.name,f.rooms.map((r)=>make("room",r.id,r.name,[],[f.id],{floorId:f.id,roomId:r.id})),[f.id]);
|
||||
if(!b.topology)return make("all",undefined,"Alle Etagen",[...b.floors].sort((a,z)=>z.elevation-a.elevation).map(floorNode));
|
||||
const t=b.topology;
|
||||
return make("all",undefined,"Alle Orte",t.locations.map((l)=>{
|
||||
const children=t.branches.filter((n)=>n.location_id===l.id).map((n)=>make("branch",n.id,n.name,t.buildings.filter((g)=>g.branch_id===n.id).map((g)=>make("building",g.id,g.name,b.floors.filter((f)=>!f.outdoor_location_id&&f.building_id===g.id).sort((a,z)=>z.elevation-a.elevation).map(floorNode)))));
|
||||
const outside=b.floors.filter((f)=>f.outdoor_location_id===l.id);
|
||||
if(outside.length)children.push(make("outside",l.id,"Außen",outside.flatMap((f)=>f.rooms.map((r)=>make("room",r.id,r.name,[],[f.id],{floorId:f.id,roomId:r.id}))),outside.map((f)=>f.id)));
|
||||
return make("location",l.id,l.name,children);
|
||||
}));
|
||||
const withOutside=(owner:OutsideOwner,children:TopologyNode[]):TopologyNode[]=>{
|
||||
const f=outsideFloor(b,outsideSelection(owner));if(!f)return children;
|
||||
const node=make("outside",owner.id,"Außen",f.rooms.map((r)=>make("room",r.id,r.name,[],[f.id],{floorId:f.id,roomId:r.id})),[f.id]);
|
||||
node.selection=outsideSelection(owner);node.key=topologyKey(node.selection);
|
||||
return [...children,node];
|
||||
};
|
||||
const buildingNode=(g:PlanTopology["buildings"][number]):TopologyNode=>{
|
||||
const floors=b.floors.filter((f)=>!isOutdoorFloor(f)&&f.building_id===g.id).sort((a,z)=>z.elevation-a.elevation);
|
||||
return make("building",g.id,g.name,withOutside({kind:"building",id:g.id},floors.map(floorNode)));
|
||||
};
|
||||
const branchNode=(n:PlanTopology["branches"][number]):TopologyNode=>make("branch",n.id,n.name,
|
||||
withOutside({kind:"branch",id:n.id},t.buildings.filter((g)=>g.branch_id===n.id).map(buildingNode)));
|
||||
return make("all",undefined,"Alle Orte",t.locations.map((l)=>make("location",l.id,l.name,
|
||||
withOutside({kind:"location",id:l.id},t.branches.filter((n)=>n.location_id===l.id).map(branchNode)))));
|
||||
}
|
||||
|
||||
export function topologyPath(b:Building,s:TopologySelection):TopologyNode[] {
|
||||
@@ -91,14 +121,16 @@ export function topologyItems(b:Building,s:TopologySelection):TopologyNode[] {
|
||||
export function topologyFloors(b:Building,s:TopologySelection,withStack=false):Floor[] {
|
||||
if(!b.topology||s.kind==="all")return b.floors;
|
||||
const path=topologyPath(b,s);
|
||||
const node=(withStack&&(s.kind==="floor"||s.kind==="room")?path.find((n)=>n.selection.kind==="building"):null)??path.at(-1)!;
|
||||
const node=(withStack&&(s.kind==="floor"||s.kind==="room")?path.find((n)=>n.selection.kind==="outside")??path.find((n)=>n.selection.kind==="building"):null)??path.at(-1)!;
|
||||
const ids=new Set(node.floorIds);return b.floors.filter((f)=>ids.has(f.id));
|
||||
}
|
||||
export const topologyPlan=(b:Building,s:TopologySelection,withStack=false):Building=>({...b,floors:topologyFloors(b,s,withStack)});
|
||||
/** Outside readouts also include legacy outdoor devices drawn on a location's building floors. */
|
||||
/** Outside views cover only their owner's descendants, including legacy outdoor pins on indoor floors. */
|
||||
export function topologyOutsideFloors(b:Building,s:TopologySelection):Floor[] {
|
||||
if(!b.topology)return b.floors;
|
||||
const location=topologyPath(b,s).find((n)=>n.selection.kind==="location");
|
||||
const path=topologyPath(b,s),outside=path.find((n)=>n.selection.kind==="outside");
|
||||
if(outside){const owner=topologyParent(b,outside.selection);return topologyFloors(b,owner);}
|
||||
const location=path.find((n)=>n.selection.kind==="location");
|
||||
return location?topologyFloors(b,location.selection):[];
|
||||
}
|
||||
export function floorTopologyPath(b:Building,f:Floor):string {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// house view only; the viewer lifts it and fades it out when the camera zooms in.
|
||||
|
||||
import type { Building } from "../../model.ts";
|
||||
import { isOutdoorFloor } from "../../topology.ts";
|
||||
import { pushChimneys, pushRoofWindows, pushSolar, type RoofWindowState } from "./fittings.ts";
|
||||
import { buildSections } from "./sections.ts";
|
||||
import { buildSingleRoof } from "./single.ts";
|
||||
@@ -13,7 +14,7 @@ export function buildRoof(b: Building, windows: ReadonlyMap<string, RoofWindowSt
|
||||
// Automatic roofs belong to independent buildings, never to a location's outdoor plan or the global highest storey.
|
||||
if (b.topology && roof?.type !== "custom") {
|
||||
const groups = new Map<string, typeof b.floors>();
|
||||
for (const f of b.floors) if (!f.outdoor_location_id) {
|
||||
for (const f of b.floors) if (!isOutdoorFloor(f)) {
|
||||
const id = f.building_id ?? "legacy";
|
||||
groups.set(id, [...(groups.get(id) ?? []), f]);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { TopologyNode } from "../topology.ts";
|
||||
import { isOutdoorFloor, type TopologyNode } from "../topology.ts";
|
||||
// 3D view (separate bundle, loaded on demand). Renders only when something changes.
|
||||
//
|
||||
// Floors are shown in three levels: the whole house (floors pulled apart or stacked), one floor
|
||||
@@ -1913,7 +1913,7 @@ export class NextFloorViewer {
|
||||
}
|
||||
this.floors.push({
|
||||
floor,
|
||||
rank: b.topology ? floor.outdoor_location_id ? 0 : ordered.filter((f)=>!f.outdoor_location_id&&f.building_id===floor.building_id).indexOf(floor) : ordered.indexOf(floor),
|
||||
rank: b.topology ? isOutdoorFloor(floor) ? 0 : ordered.filter((f)=>!isOutdoorFloor(f)&&f.building_id===floor.building_id).indexOf(floor) : ordered.indexOf(floor),
|
||||
group,
|
||||
geo,
|
||||
floorMesh,
|
||||
|
||||
@@ -112,6 +112,60 @@ try {
|
||||
assert.equal(await page.evaluate(() => new Set(e._doc.floors.filter((f) => f.outdoor_location_id).map((f) => f.outdoor_location_id)).size), 2);
|
||||
assert.equal(await page.evaluate(() => !!e.shadowRoot.querySelector(".nf-editor-add-floor")), false, "outdoor plans do not add indoor storeys");
|
||||
|
||||
// Branches and buildings get their own outdoor plans, alongside existing location plans.
|
||||
for(const kind of ["branch","building"]){
|
||||
await page.evaluate(async(kind)=>{
|
||||
e.shadowRoot.querySelector(".nf-hierarchy-open").click();await settle();
|
||||
manager().shadowRoot.querySelector('[data-location="u"]').click();await manager().updateComplete;
|
||||
manager().shadowRoot.querySelector('[data-branch="nl"]').click();await manager().updateComplete;
|
||||
manager().shadowRoot.querySelector('[data-building="b"]').click();await manager().updateComplete;
|
||||
manager().shadowRoot.querySelector(`.outside-${kind}`).click();await settle();
|
||||
},kind);
|
||||
assert.equal(await page.evaluate(()=>e._editorScope.ownerKind),kind);
|
||||
assert.equal(await page.evaluate(()=>e.floor.building_id),null);
|
||||
assert.equal(await page.evaluate(()=>e.floor.outdoor_location_id),null);
|
||||
}
|
||||
await page.evaluate(async()=>{
|
||||
window.beforeGroup=JSON.stringify(e._doc);window.beforeGroupWrites=writes;
|
||||
const s=e.shadowRoot.querySelector(".nf-editor-building-select");s.value="branch:nl";s.dispatchEvent(new Event("change",{bubbles:true}));await settle();
|
||||
e._split=true;await settle();
|
||||
});
|
||||
assert.equal(await page.evaluate(()=>e._floorId),null,"branch overview must not implicitly edit a floor");
|
||||
assert.equal(await page.evaluate(()=>JSON.stringify(e._doc)),await page.evaluate(()=>window.beforeGroup));
|
||||
assert.equal(await page.evaluate(()=>writes),await page.evaluate(()=>window.beforeGroupWrites));
|
||||
assert.equal(await page.evaluate(()=>!!e.shadowRoot.querySelector(".nf-editor-add-floor")),false);
|
||||
assert.ok(await page.evaluate(()=>e.shadowRoot.querySelector('[data-editor-scope="outside:branch:nl"]')));
|
||||
await page.waitForFunction(()=>e.shadowRoot.querySelector("nf-view3d")?.viewer);
|
||||
assert.deepEqual(await page.evaluate(()=>e.shadowRoot.querySelector("nf-view3d").viewer.floors.map((f)=>f.floor.id).sort()),await page.evaluate(()=>{
|
||||
const buildings=new Set(e._doc.topology.buildings.filter((g)=>g.branch_id==="nl").map((g)=>g.id));
|
||||
return e._doc.floors.filter((f)=>buildings.has(f.building_id)||f.outdoor_branch_id==="nl"||buildings.has(f.outdoor_building_id)).map((f)=>f.id).sort();
|
||||
}));
|
||||
await page.screenshot({path:join(out,"symcon-editor-branch-overview.png")});
|
||||
|
||||
// A complete room move is explicit, cancellable and rejects a duplicate target device with visible feedback.
|
||||
await page.evaluate(async()=>{
|
||||
e._split=false;await pickBuilding("b");e.adoptFloor("eg-a");e.selectItem("room","it-a");
|
||||
e.change((b,f)=>{f.furniture.push({id:"moved-desk",type:"desk",variant:null,x:1,z:1,w:1,d:1,h:1,rotation:0,power:"sensor.100"});f.placements.push({entity_id:"switch.100",x:2,z:2,y:1});b.floors.find((f)=>f.id===window.addedFloor).placements.push({entity_id:"switch.100",x:0,z:0,y:1});});await settle();
|
||||
window.moveBefore=JSON.stringify(e._doc);e.shadowRoot.querySelector(".nf-room-move-open").click();await settle();
|
||||
window.chooseRoomTarget=async()=>{const g=e.shadowRoot.querySelector(".nf-room-move-building");g.value="empty";g.dispatchEvent(new Event("change",{bubbles:true}));await settle();const f=e.shadowRoot.querySelector(".nf-room-move-floor");f.value=window.addedFloor;f.dispatchEvent(new Event("change",{bubbles:true}));await settle();};
|
||||
await chooseRoomTarget();
|
||||
});
|
||||
assert.equal(await page.evaluate(()=>JSON.stringify(e._doc)),await page.evaluate(()=>window.moveBefore));
|
||||
await page.evaluate(async()=>{e.shadowRoot.querySelector(".nf-room-move-apply").click();await settle();});
|
||||
assert.match(await page.evaluate(()=>e.shadowRoot.querySelector(".nf-room-move-error").textContent),/Kennung/);
|
||||
assert.equal(await page.evaluate(()=>JSON.stringify(e._doc)),await page.evaluate(()=>window.moveBefore));
|
||||
await page.evaluate(async()=>{e.shadowRoot.querySelector(".nf-room-move-dialog header button").click();await settle();e.change((b)=>{b.floors.find((f)=>f.id===window.addedFloor).placements=[];});await settle();window.moveBefore=JSON.stringify(e._doc);e.shadowRoot.querySelector(".nf-room-move-open").click();await settle();await chooseRoomTarget();});
|
||||
await page.waitForFunction(()=>e.shadowRoot.querySelector(".nf-room-move-dialog").open&&e.shadowRoot.querySelector(".nf-room-move-floor"));
|
||||
await page.screenshot({path:join(out,"symcon-editor-room-move.png")});
|
||||
await page.evaluate(async()=>{e.shadowRoot.querySelector(".nf-room-move-dialog header button").click();await settle();});
|
||||
assert.equal(await page.evaluate(()=>JSON.stringify(e._doc)),await page.evaluate(()=>window.moveBefore),"cancelling a room move must preserve the full plan");
|
||||
await page.evaluate(async()=>{e.shadowRoot.querySelector(".nf-room-move-open").click();await settle();await chooseRoomTarget();e.shadowRoot.querySelector(".nf-room-move-apply").click();await settle();});
|
||||
const moved=await page.evaluate(()=>[e._floorId,e.room?.id,e.room?.name,e.room?.area_id,e.floor?.furniture[0]?.id,e.floor?.furniture[0]?.power,e.floor?.placements[0]?.entity_id]);
|
||||
if(!moved.at(-1))console.log(await page.evaluate(()=>({move:e._roomMove,floors:e._doc.floors.map((f)=>({id:f.id,rooms:f.rooms.map((r)=>({id:r.id,points:r.points})),devices:f.placements,furniture:f.furniture.map((f)=>({id:f.id,x:f.x,z:f.z}))}))})));
|
||||
assert.deepEqual(moved,[await page.evaluate(()=>window.addedFloor),"it-a","IT","symcon-category-200","moved-desk","sensor.100","switch.100"]);
|
||||
assert.equal(await page.evaluate(()=>e._doc.floors.find((f)=>f.id==="eg-a").rooms.length),0);
|
||||
assert.equal(await page.evaluate(()=>e._doc.floors.find((f)=>f.id==="eg-a").furniture.length),0);
|
||||
|
||||
await page.setViewport({ width: 390, height: 844 });
|
||||
await page.evaluate(async () => { e.shadowRoot.querySelector(".nf-hierarchy-open").click(); await settle(); });
|
||||
assert.ok(await page.evaluate(() => { const d = e.shadowRoot.querySelector(".nf-hierarchy-dialog"), r = d.getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth && r.height <= innerHeight && d.scrollWidth <= d.clientWidth; }), "hierarchy dialog must fit a phone without horizontal scrolling");
|
||||
@@ -125,7 +179,7 @@ try {
|
||||
assert.deepEqual(await page.evaluate(() => e._doc.floors.map(({ building_id, ...f }) => f)), await page.evaluate(() => window.legacyFloors));
|
||||
assert.equal(await page.evaluate(() => new Set(e._doc.floors.map((f) => f.building_id)).size), 1);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("OK: separate hierarchy dialog, pure building navigation and refresh, selected-building storeys, native room category links, stale form guards, explicit/cancelled floor moves, metadata without implicit storeys, per-location outdoors, legacy migration and mobile layout");
|
||||
console.log("OK: separate hierarchy dialog, pure building/branch navigation and scoped 3D overview, selected-building storeys, native room links, floor moves, independent location/branch/building outdoors, explicit/cancelled room moves with contents and duplicate-device feedback, legacy migration and mobile layout");
|
||||
} finally {
|
||||
await browser?.close(); await new Promise((done) => server.close(done));
|
||||
}
|
||||
@@ -30,10 +30,11 @@ try{
|
||||
});
|
||||
await page.waitForFunction(()=>window.nfPanel.shadowRoot.querySelector("nf-view3d")?.viewer);
|
||||
await page.evaluate(()=>{window.topoHost=window.nfPanel;window.topoView=()=>window.topoHost.shadowRoot.querySelector("nf-view3d");});
|
||||
const select=async(kind,id)=>{
|
||||
await page.waitForFunction((kind,id)=>window.topoView().shadowRoot.querySelector(`.nf-thumb[data-topology-kind="${kind}"][data-topology-key="${kind}:${id}"]`),{},kind,id);
|
||||
await page.evaluate((kind,id)=>window.topoView().shadowRoot.querySelector(`.nf-thumb[data-topology-kind="${kind}"][data-topology-key="${kind}:${id}"]`).click(),kind,id);
|
||||
await page.waitForFunction((kind,id)=>window.topoView().topologySelection?.kind===kind&&window.topoView().topologySelection?.id===id,{},kind,id);
|
||||
const select=async(kind,id,ownerKind)=>{
|
||||
const key=[kind,ownerKind,id].filter(Boolean).join(":");
|
||||
await page.waitForFunction((key)=>window.topoView().shadowRoot.querySelector(`.nf-thumb[data-topology-key="${key}"]`),{},key);
|
||||
await page.evaluate((key)=>window.topoView().shadowRoot.querySelector(`.nf-thumb[data-topology-key="${key}"]`).click(),key);
|
||||
await page.waitForFunction((kind,id,owner)=>window.topoView().topologySelection?.kind===kind&&window.topoView().topologySelection?.id===id&&(window.topoView().topologySelection?.ownerKind??null)===(owner??null),{},kind,id,ownerKind);
|
||||
};
|
||||
const noTopMenu=async()=>assert.equal(await page.evaluate(()=>!!window.topoHost.shadowRoot.querySelector("nav.nf-nav,.nf-card-rooms")),false,"upper room menu is absent above the floor level and outdoors");
|
||||
const scene=()=>page.evaluate(()=>window.topoView().viewer.floors.map((f)=>f.floor.id).sort());
|
||||
@@ -83,11 +84,34 @@ try{
|
||||
assert.deepEqual(await page.evaluate(()=>window.nfPanel.shadowRoot.querySelector("nf-room-panel").outside),["sensor.903"],"legacy outdoor pins stay within their location even without a dedicated outdoor floor");
|
||||
await page.evaluate(()=>window.nfPanel.shadowRoot.querySelector("nf-room-panel").dispatchEvent(new CustomEvent("close",{bubbles:true,composed:true})));
|
||||
|
||||
// Branch/building outdoor views have separate scenes, breadcrumbs, values and pin targets.
|
||||
await page.evaluate(async()=>{
|
||||
const p=window.nfPanel,b=structuredClone(window.topologyProject),base=b.floors.find((f)=>f.id==="outside-a");
|
||||
for(const [id,field,parent,sensor]of[["outside-hq","outdoor_branch_id","hq",905],["outside-ras19","outdoor_building_id","ras19",906]]){
|
||||
const f={...structuredClone(base),id,outdoor_location_id:null,[field]:parent};f.outdoor[0].id=id;f.outdoor[0].temp_entity=`sensor.${sensor}`;b.floors.push(f);
|
||||
p.hass={...p.hass,states:{...p.hass.states,[`sensor.${sensor}`]:{entity_id:`sensor.${sensor}`,state:"22",attributes:{symcon_id:sensor,symcon_variable_type:2,symcon_value:22,symcon_formatted:"22 °C",unit_of_measurement:"°C"}}}};
|
||||
}
|
||||
window.topologyProject=structuredClone(b);p.data.edit(b);p.openTopology({kind:"all"});await p.updateComplete;
|
||||
});
|
||||
await select("location","urbach");await select("branch","hq");assert.deepEqual(await scene(),["eg","og","outside-hq","outside-ras19"]);await noTopMenu();
|
||||
await select("outside","hq","branch");assert.deepEqual(await scene(),["outside-hq"]);await noTopMenu();
|
||||
await page.evaluate(()=>window.topoView().dispatchEvent(new CustomEvent("room-tap",{detail:{floorId:"outside-hq",roomId:"nf-outside"},bubbles:true,composed:true})));
|
||||
await page.waitForFunction(()=>window.nfPanel._outside&&window.nfPanel.shadowRoot.querySelector("nf-room-panel")?.outside?.includes("sensor.905"));
|
||||
assert.deepEqual(await page.evaluate(()=>window.nfPanel.shadowRoot.querySelector("nf-room-panel").outside.slice().sort()),["sensor.903","sensor.905","sensor.906"]);
|
||||
await page.evaluate(()=>{window.nfPanel.shadowRoot.querySelector("nf-room-panel").dispatchEvent(new CustomEvent("close",{bubbles:true,composed:true}));window.topoView().shadowRoot.querySelector('.nf-topology-crumbs [data-topology-key="branch:hq"]').click();});
|
||||
await select("building","ras19");await select("outside","ras19","building");assert.deepEqual(await scene(),["outside-ras19"]);await noTopMenu();
|
||||
await page.evaluate(()=>window.topoView().dispatchEvent(new CustomEvent("room-tap",{detail:{floorId:"outside-ras19",roomId:"nf-outside"},bubbles:true,composed:true})));
|
||||
await page.waitForFunction(()=>window.nfPanel._outside&&window.nfPanel.shadowRoot.querySelector("nf-room-panel")?.outside?.includes("sensor.906"));
|
||||
assert.deepEqual(await page.evaluate(()=>window.nfPanel.shadowRoot.querySelector("nf-room-panel").outside.slice().sort()),["sensor.903","sensor.906"]);
|
||||
await page.screenshot({path:join(out,"symcon-topology-building-outside.png")});
|
||||
|
||||
// The HTML-SDK tile uses the same hierarchy and hides its own upper menu until a floor is selected.
|
||||
await page.evaluate(async()=>{const p=window.nfPanel,card=document.createElement("nextfloor-card");card.setConfig({type:"custom:nextfloor-card",fill:true,room_buttons:true,controls:true});card.hass=p.hass;card.style.cssText="display:block;height:850px";document.body.append(card);await card.updateComplete;card.data.edit(structuredClone(window.topologyProject));p.style.display="none";window.topoHost=card;window.topoCard=card;await card.updateComplete;});
|
||||
await page.waitForFunction(()=>window.topoView()?.viewer&&window.topoView().shadowRoot.querySelector('[data-topology-kind="location"]'));
|
||||
await noTopMenu();await select("location","urbach");await select("branch","hq");await select("building","ras19");await noTopMenu();await select("floor","eg");
|
||||
await page.waitForFunction(()=>window.topoCard.shadowRoot.querySelectorAll(".nf-card-rooms button").length===2);
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector('.nf-topology-crumbs [data-topology-key="building:ras19"]').click());
|
||||
await select("outside","ras19","building");await noTopMenu();assert.deepEqual(await scene(),["outside-ras19"]);
|
||||
await page.evaluate(()=>window.topoView().shadowRoot.querySelector(".nf-thumb-house").click());await noTopMenu();
|
||||
await page.setViewport({width:390,height:844});
|
||||
await page.waitForFunction(()=>window.topoView().shadowRoot.querySelectorAll('[data-topology-kind="location"] img').length===2);
|
||||
|
||||
Reference in new issue
Block a user