feat: add branch overviews scoped outdoor plans and complete room moves

This commit is contained in:
jhartworks committed 2026-11-19 15:12:11 +01:00
1 parent 382d6e04f2
commit 16eddacebf
35 files changed
+2598 -2116

No files matched your search

@@ -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>`;