fix: separate hierarchy management from selected building editing
This commit is contained in:
1 parent
bffc4d0acc
commit
382d6e04f2
18 files changed
+2103
-1648
No files matched your search
@@ -0,0 +1,75 @@
|
||||
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 { tokens } from "../../styles.ts";
|
||||
import { hint } from "./fields.ts";
|
||||
import type { EditorScope } from "./editor-context.ts";
|
||||
|
||||
/** Metadata only. Picking a row never reassigns floors or creates a storey. */
|
||||
class HierarchyManager extends LitElement {
|
||||
static properties = { doc:{attribute:false}, admin:{type:Boolean}, suggestedName:{attribute:false},
|
||||
locationId:{state:true}, branchId:{state:true}, buildingId:{state:true} };
|
||||
declare doc: Building;
|
||||
declare admin: boolean;
|
||||
declare suggestedName: string;
|
||||
private declare locationId: string;
|
||||
private declare branchId: string;
|
||||
private declare buildingId: string;
|
||||
constructor(){super();this.admin=false;this.suggestedName="Gebäude 1";this.locationId="";this.branchId="";this.buildingId="";}
|
||||
|
||||
protected willUpdate(_changed:PropertyValues){
|
||||
const t=this.doc?.topology;if(!t)return;
|
||||
if(!t.locations.some((l)=>l.id===this.locationId))this.locationId=t.locations[0]?.id??"";
|
||||
const branches=t.branches.filter((n)=>n.location_id===this.locationId);
|
||||
if(!branches.some((n)=>n.id===this.branchId))this.branchId=branches[0]?.id??"";
|
||||
const buildings=t.buildings.filter((g)=>g.branch_id===this.branchId);
|
||||
if(!buildings.some((g)=>g.id===this.buildingId))this.buildingId=buildings[0]?.id??"";
|
||||
}
|
||||
private edit(change:(b:Building,t:PlanTopology)=>void){
|
||||
if(!this.admin||!this.doc?.topology)return;
|
||||
const next=structuredClone(this.doc);change(next,next.topology!);this.publish(next);
|
||||
}
|
||||
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 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>`;
|
||||
}
|
||||
render(){
|
||||
const t=this.doc?.topology;
|
||||
if(!t)return html`<div class="setup">${hint("Vorhandene Etagen werden einem ersten Ort, einer Niederlassung und einem Gebäude zugeordnet. Geometrie, Raumverknüpfungen und Benutzerrechte bleiben erhalten.")}
|
||||
<button class="setup-button" ?disabled=${!this.admin} @click=${()=>{const b=structuredClone(this.doc);enableTopology(b,this.suggestedName);this.publish(b);}}>Hierarchie einrichten</button></div>`;
|
||||
const l=t.locations.find((l)=>l.id===this.locationId),n=t.branches.find((n)=>n.id===this.branchId),g=t.buildings.find((g)=>g.id===this.buildingId);
|
||||
return html`<div class="help">${hint("Hier pflegst du Ort, Niederlassung und Gebäude. Die Listen wechseln nur die Auswahl. Etagen legst du anschließend oben im Editor im gewählten Gebäude an. Räume und ihre Symcon-Bereichskategorie bearbeitest du rechts auf der ausgewählten Etage.")}</div>
|
||||
<div class="columns">
|
||||
<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="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>
|
||||
<section aria-label="Niederlassungen"><h3>Niederlassungen</h3><div class="items">${t.branches.filter((s)=>s.location_id===this.locationId).map((s)=>html`<button class="pick" data-branch=${s.id} aria-pressed=${s.id===this.branchId} @click=${()=>{this.branchId=s.id;this.buildingId="";}}>${s.name}</button>`)}</div>
|
||||
<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>
|
||||
</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>
|
||||
<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>
|
||||
</div>`:nothing}
|
||||
</section>
|
||||
</div>`;
|
||||
}
|
||||
static styles=[tokens,css`
|
||||
:host{display:block;font:13px/1.4 system-ui;color:var(--nf-text)}button,input,select{box-sizing:border-box;font:inherit;color:inherit;background:var(--nf-fill,#ffffff08);border:1px solid var(--nf-line);border-radius:8px;padding:8px 10px;min-width:0}button{cursor:pointer}button:disabled,input:disabled,select:disabled{opacity:.45;cursor:default}button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--nf-accent);outline-offset:2px}.columns{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}.help{margin-bottom:8px}section{min-width:0;border:1px solid var(--nf-line);border-radius:12px;padding:12px}h3{font-size:14px;margin:0 0 10px}.items{display:grid;align-content:start;gap:5px;min-height:100px;max-height:240px;overflow:auto;margin-bottom:10px}.pick{text-align:left;display:flex;justify-content:space-between;gap:8px;overflow-wrap:anywhere}.pick[aria-pressed=true]{border-color:var(--nf-accent);background:color-mix(in srgb,var(--nf-accent) 15%,transparent)}small{white-space:nowrap;color:var(--nf-muted)}.details{display:grid;gap:10px;margin-top:18px;padding-top:12px;border-top:1px solid var(--nf-line)}label{display:grid;gap:5px;font-size:12px;color:var(--nf-muted)}input,select{width:100%;color:var(--nf-text)}.delete{color:var(--nf-muted)}.primary{border-color:var(--nf-accent)}.setup{display:flex;gap:10px;align-items:center}@media(max-width:720px){.columns{grid-template-columns:1fr}.items{min-height:0;max-height:140px}.details{margin-top:10px}section{padding:10px}}
|
||||
`];
|
||||
}
|
||||
if(!customElements.get("nf-hierarchy-manager"))customElements.define("nf-hierarchy-manager",HierarchyManager);
|
||||
Reference in new issue
Block a user