feat: add room name switches to 3D view and editor toolbars
This commit is contained in:
1 parent
7a9b2c0a38
commit
3f6cca056c
13 files changed
+695
-585
No files matched your search
@@ -50,6 +50,7 @@ export class NextFloorCard extends LitElement {
|
||||
_clean: { state: true },
|
||||
_night: { state: true },
|
||||
_orbit: { state: true },
|
||||
_roomNames: { state: true },
|
||||
};
|
||||
|
||||
declare hass: HomeAssistant;
|
||||
@@ -72,6 +73,7 @@ export class NextFloorCard extends LitElement {
|
||||
/** Kiosk: the night dimming is on, and the screensaver turn runs (after an idle return). */
|
||||
private declare _night: boolean;
|
||||
private declare _orbit: boolean;
|
||||
private declare _roomNames: boolean | null;
|
||||
|
||||
private readonly data = new BuildingController(this);
|
||||
private readonly kiosk = new KioskTimers({
|
||||
@@ -96,6 +98,7 @@ export class NextFloorCard extends LitElement {
|
||||
this._clean = false;
|
||||
this._night = false;
|
||||
this._orbit = false;
|
||||
this._roomNames = null;
|
||||
}
|
||||
|
||||
private view3d() {
|
||||
@@ -147,6 +150,7 @@ export class NextFloorCard extends LitElement {
|
||||
|
||||
setConfig(config: CardConfig): void {
|
||||
if (config.height !== undefined && !(config.height > 100)) throw new Error("height must be a number of pixels above 100");
|
||||
this._roomNames = null;
|
||||
this._own = config;
|
||||
this._config = withTemplate(config, this.data.building?.settings.card_templates as CardTemplates | undefined);
|
||||
this._floorId = undefined;
|
||||
@@ -353,7 +357,9 @@ export class NextFloorCard extends LitElement {
|
||||
.flows=${c?.flows ?? null}
|
||||
.holograms=${c?.holograms ?? null}
|
||||
.floorThumbs=${this.thumbs}
|
||||
.roomLabels=${c?.room_names !== false}
|
||||
.roomLabels=${this._roomNames ?? (c?.room_names !== false)}
|
||||
.roomNamesButton=${true}
|
||||
@room-names-change=${(e: CustomEvent<{ value: boolean }>) => (this._roomNames = e.detail.value)}
|
||||
.floorStack=${c?.floor_stack ?? "dim"}
|
||||
.panelOpen=${!!this._roomId && c?.room_panel !== false}
|
||||
.alerts=${c?.alerts !== false}
|
||||
|
||||
@@ -184,6 +184,7 @@ export class NfEditor extends LitElement {
|
||||
hass: { attribute: false },
|
||||
building: { attribute: false },
|
||||
narrow: { type: Boolean },
|
||||
roomLabels: { attribute: false },
|
||||
packs: { attribute: false },
|
||||
loadCardEditor: { attribute: false },
|
||||
_doc: { state: true },
|
||||
@@ -223,6 +224,8 @@ export class NfEditor extends LitElement {
|
||||
declare hass: HomeAssistant;
|
||||
declare building: Building;
|
||||
declare narrow: boolean;
|
||||
/** Show room names in the 3D preview; the host remembers this view preference. */
|
||||
declare roomLabels: boolean;
|
||||
/** Imported furniture packs (from the panel's controller). */
|
||||
declare packs: FurniturePack[] | undefined;
|
||||
/** Loads the card's settings dialog, for the card templates (set by the panel). */
|
||||
@@ -319,6 +322,7 @@ export class NfEditor extends LitElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.narrow = false;
|
||||
this.roomLabels = true;
|
||||
this._floorId = null;
|
||||
this._arcEdit = null;
|
||||
this._routeDraft = null;
|
||||
@@ -1067,7 +1071,7 @@ export class NfEditor extends LitElement {
|
||||
.selectedDevice=${this.sel.device}
|
||||
.quality=${"auto"}
|
||||
.floorThumbs=${false}
|
||||
.roomLabels=${true}
|
||||
.roomLabels=${this.roomLabels}
|
||||
.floorStack=${this.houseTool ? "stacked" : "single"}
|
||||
.panelOpen=${false}
|
||||
.alerts=${false}
|
||||
@@ -3184,6 +3188,10 @@ export class NfEditor extends LitElement {
|
||||
</button>`,
|
||||
)}
|
||||
</div>
|
||||
<button class="nf-chip nf-room-names-toggle" aria-pressed=${this.roomLabels} title=${this.t("room_names_toggle_hint")} @click=${() => {
|
||||
this.roomLabels = !this.roomLabels;
|
||||
this.dispatchEvent(new CustomEvent("room-names-change", { detail: { value: this.roomLabels }, bubbles: true, composed: true }));
|
||||
}}>${this.t("room_names_short")}</button>
|
||||
<div class="nf-seg">
|
||||
<button ?disabled=${!this._canUndo} @click=${() => this.undo()} title="Ctrl+Z">${this.t("undo")}</button>
|
||||
<button ?disabled=${!this._canRedo} @click=${() => this.redo()} title="Ctrl+Y">${this.t("redo")}</button>
|
||||
|
||||
@@ -157,6 +157,7 @@ export class NfView3d extends LitElement {
|
||||
_locked: { state: true },
|
||||
_now: { state: true },
|
||||
roomLabels: { attribute: false },
|
||||
roomNamesButton: { attribute: false },
|
||||
floorStack: { attribute: false },
|
||||
panelOpen: { attribute: false },
|
||||
alerts: { attribute: false },
|
||||
@@ -304,6 +305,8 @@ export class NfView3d extends LitElement {
|
||||
private clockTimer: ReturnType<typeof setInterval> | undefined;
|
||||
/** Room names in 3D (cards can switch them off). */
|
||||
declare roomLabels: boolean;
|
||||
/** Cards expose the room-name switch in their own 3D top bar. The designer has its toolbar switch. */
|
||||
declare roomNamesButton: boolean;
|
||||
/** Floors below an opened floor: dimmed, stacked (the house up to it) or hidden. */
|
||||
declare floorStack: FloorStack;
|
||||
private declare _thumbs: { floorId: string; url: string }[];
|
||||
@@ -490,6 +493,7 @@ export class NfView3d extends LitElement {
|
||||
}
|
||||
})();
|
||||
this.roomLabels = true;
|
||||
this.roomNamesButton = false;
|
||||
this.floorStack = "dim";
|
||||
this._low = false;
|
||||
this.panelOpen = false;
|
||||
@@ -2696,7 +2700,11 @@ export class NfView3d extends LitElement {
|
||||
const energy = !!e && !this.roomId && this.showEnergy && !!this.hass && !(e.consumption === null && e.grid === null && e.solar === null && e.battery === null);
|
||||
const climate = this.building?.floors.some((f) => f.rooms.some((r) => r.climate_card));
|
||||
const climateToggle = climate ? this.renderCardToggle() : nothing;
|
||||
if (!energy) return own.length || climateToggle !== nothing ? html`<div class="nf-energy" aria-live="off">${own}${climateToggle}</div>` : nothing;
|
||||
const roomNames = this.roomNamesButton ? html`<button class="nf-energy-item nf-flow-toggle nf-room-names-toggle" aria-pressed=${this.roomLabels} title=${translate(this.hass, "room_names_toggle_hint")} @click=${() => {
|
||||
this.roomLabels = !this.roomLabels;
|
||||
this.dispatchEvent(new CustomEvent("room-names-change", { detail: { value: this.roomLabels }, bubbles: true, composed: true }));
|
||||
}}><span>${translate(this.hass, "room_names_short")}</span><b aria-hidden="true">Aa</b></button>` : nothing;
|
||||
if (!energy) return own.length || climateToggle !== nothing || roomNames !== nothing ? html`<div class="nf-energy" aria-live="off">${roomNames}${own}${climateToggle}</div>` : nothing;
|
||||
const t = (k: Parameters<typeof translate>[1]) => translate(this.hass, k);
|
||||
const items: { cls: string; label: string; value: string }[] = [];
|
||||
if (e.solar !== null) items.push({ cls: "solar", label: t("energy_solar"), value: formatPower(this.hass, e.solar) });
|
||||
@@ -2713,6 +2721,7 @@ export class NfView3d extends LitElement {
|
||||
if (e.tariff) items.push({ cls: "tariff", label: t("energy_tariff"), value: `${formatNumber(this.hass, e.tariff.value, 3)} ${e.tariff.unit}`.trim() });
|
||||
if (this.building) for (const m of this.meterRows(this.building)) items.push({ cls: "meter", label: `${m.icon} ${m.label}`, value: m.value });
|
||||
return html`<div class="nf-energy" aria-live="off">
|
||||
${roomNames}
|
||||
${this.liveCardsOn && this._liveCards.some((c) => c.kind === "house") ? nothing : items.map((i) => html`<div class="nf-energy-item nf-energy-${i.cls}"><span>${i.label}</span><b>${i.value}</b></div>`)}
|
||||
${this.flows !== null
|
||||
? nothing
|
||||
@@ -3148,7 +3157,7 @@ export class NfView3d extends LitElement {
|
||||
.nf-person[hidden] {
|
||||
display: none;
|
||||
}
|
||||
.nf-no-room-names .nf-pin {
|
||||
.nf-no-room-names .nf-pin[data-room] {
|
||||
display: none !important;
|
||||
}
|
||||
/* tablet level: blur over the canvas and glowing shadows are expensive on weak GPUs */
|
||||
|
||||
@@ -769,6 +769,7 @@ const DE = {
|
||||
sill_boards_inside: "Nur innen",
|
||||
sill_boards_outside: "Nur außen",
|
||||
room_names_short: "Raumnamen",
|
||||
room_names_toggle_hint: "Raumnamen in der 3D-Ansicht ein- oder ausblenden",
|
||||
floor_stack_short_dim: "Abgedunkelt",
|
||||
floor_stack_short_stacked: "Gestapelt",
|
||||
floor_stack_short_single: "Einzeln",
|
||||
@@ -2811,6 +2812,7 @@ const EN: Record<Key, string> = {
|
||||
sill_boards_inside: "Inside only",
|
||||
sill_boards_outside: "Outside only",
|
||||
room_names_short: "Room names",
|
||||
room_names_toggle_hint: "Show or hide room names in the 3D view",
|
||||
floor_stack_short_dim: "Dimmed",
|
||||
floor_stack_short_stacked: "Stacked",
|
||||
floor_stack_short_single: "Alone",
|
||||
|
||||
@@ -381,6 +381,7 @@ export class NextFloorPanel extends LitElement {
|
||||
<h1>${NEXTFLOOR_MARK}NextFloor</h1>
|
||||
${this.isAdmin ? html`<div class="nf-seg" role="tablist">${tab("view", this.t("view"))}${tab("editor", this.t("editor"))}${tab("extensions", `✦ ${this.t("ext_tab")}`, "nf-tab-ext")}</div>` : nothing}
|
||||
<span class="nf-grow"></span>
|
||||
${this._mode === "view" && building?.floors.some((f) => f.rooms.length) ? html`<button class="nf-chip nf-room-names-toggle" aria-pressed=${this._prefs.roomNames} title=${this.t("room_names_toggle_hint")} @click=${() => this.setPref("roomNames", !this._prefs.roomNames)}>${this.t("room_names_short")}</button>` : nothing}
|
||||
${this.isAdmin && this.hass.symconRefresh ? html`<button class="nf-btn nf-reload-variables" ?disabled=${this._variablesLoading} aria-busy=${this._variablesLoading} @click=${() => void this.reloadVariables()}>↻ ${this.t(this._variablesLoading ? "symcon_variables_loading" : "symcon_variables_reload")}</button>` : nothing}
|
||||
${this._mode === "view" && building?.floors.some((f) => f.rooms.length) ? this.renderViewOptions() : nothing}
|
||||
${this._mode === "editor" && saveState !== "idle" ? html`<span class="nf-save nf-save-${saveState}">${this.t(saveLabel)}</span>` : nothing}
|
||||
@@ -439,6 +440,8 @@ export class NextFloorPanel extends LitElement {
|
||||
.hass=${this.hass}
|
||||
.building=${building}
|
||||
.narrow=${this.narrow}
|
||||
.roomLabels=${this._prefs.roomNames}
|
||||
@room-names-change=${(e: CustomEvent<{ value: boolean }>) => this.setPref("roomNames", e.detail.value)}
|
||||
.packs=${this.data.packs}
|
||||
.loadCardEditor=${loadCardEditor}
|
||||
@packs-changed=${() => void this.data.reloadPacks()}
|
||||
|
||||
@@ -25,6 +25,20 @@ try {
|
||||
await page.setViewport({ width: 1440, height: 1000 });
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/preview/index.html`, { waitUntil: "networkidle0" });
|
||||
await page.waitForFunction(() => window.nfPanel?.data.building?.floors.length);
|
||||
await page.evaluate(async () => {
|
||||
const p = window.nfPanel;
|
||||
p._floorId = p.data.building.floors[0].id;
|
||||
await p.updateComplete;
|
||||
const button = p.shadowRoot.querySelector(".nf-header .nf-room-names-toggle");
|
||||
if (!button) throw new Error("3D view needs a room-name switch directly in its header");
|
||||
if (!p._prefs.roomNames) button.click();
|
||||
await p.updateComplete;
|
||||
p.shadowRoot.querySelector(".nf-header .nf-room-names-toggle").click();
|
||||
await p.updateComplete;
|
||||
const view = p.shadowRoot.querySelector("nf-view3d");
|
||||
await view.updateComplete;
|
||||
if (view.roomLabels || localStorage.getItem("nextfloor.room_names") !== "0") throw new Error("3D room-name choice was not applied and remembered");
|
||||
});
|
||||
assert.equal(await page.evaluate(() => !!window.nfPanel.shadowRoot.querySelector(".nf-reload-variables")), false, "HA does not expose a Symcon-only button");
|
||||
await page.evaluate(async () => {
|
||||
const p = window.nfPanel;
|
||||
@@ -51,6 +65,30 @@ try {
|
||||
e.selectItem("room", e._doc.floors[0].rooms[0].id);
|
||||
await e.updateComplete;
|
||||
window.ed = e;
|
||||
if (e.roomLabels) throw new Error("Editor did not inherit the hidden room-name setting");
|
||||
const names = () => e.shadowRoot.querySelector(".nf-toolbar .nf-room-names-toggle");
|
||||
names().click();
|
||||
await e.updateComplete;
|
||||
await window.nfPanel.updateComplete;
|
||||
if (!e.roomLabels || localStorage.getItem("nextfloor.room_names") !== "1") throw new Error("Editor did not update the shared room-name choice");
|
||||
if (!e._split) [...e.shadowRoot.querySelectorAll(".nf-toolbar button")].find((b) => b.title === e.t("split_3d_hint")).click();
|
||||
await e.updateComplete;
|
||||
names().click();
|
||||
await e.updateComplete;
|
||||
const preview = e.shadowRoot.querySelector("nf-view3d");
|
||||
await preview.updateComplete;
|
||||
if (preview.roomLabels || !preview.shadowRoot.querySelector(".nf-stage.nf-no-room-names")) throw new Error("Editor switch did not hide names in its 3D preview");
|
||||
const labels = preview.shadowRoot.querySelector(".nf-labels") ?? preview.shadowRoot.querySelector(".nf-stage");
|
||||
const roomName = document.createElement("button"), note = document.createElement("button");
|
||||
roomName.className = note.className = "nf-pin";
|
||||
roomName.dataset.room = "fixture";
|
||||
note.classList.add("nf-note-pin");
|
||||
labels.append(roomName, note);
|
||||
if (getComputedStyle(roomName).display !== "none" || getComputedStyle(note).display === "none") throw new Error("Room-name switch also hid a note");
|
||||
roomName.remove(); note.remove();
|
||||
names().click();
|
||||
await e.updateComplete;
|
||||
await window.nfPanel.updateComplete;
|
||||
window.beforeReload = JSON.stringify(e._doc);
|
||||
});
|
||||
const wallState = () => page.evaluate(() => {
|
||||
@@ -324,6 +362,26 @@ try {
|
||||
assert.equal(await page.evaluate(() => window.helpPopup.shadowRoot.querySelector("dialog").open), false);
|
||||
await page.setViewport({ width: 1440, height: 1000 });
|
||||
await page.screenshot({ path: join(out, "symcon-dimmer-blind-controls.png") });
|
||||
await page.evaluate(async () => {
|
||||
const card = document.createElement("nextfloor-card");
|
||||
card.hass = window.nfPanel.hass;
|
||||
card.data.building = window.ed._doc;
|
||||
card.setConfig({ type: "custom:nextfloor-card", floor: window.ed._doc.floors[0].id, room_names: true, energy: false, floor_thumbs: false, height: 500 });
|
||||
card.style = "position:fixed;inset:0;z-index:2000;background:#202020";
|
||||
document.body.append(card);
|
||||
await card.updateComplete;
|
||||
const view = card.shadowRoot.querySelector("nf-view3d");
|
||||
await view.updateComplete;
|
||||
const button = () => view.shadowRoot.querySelector(".nf-room-names-toggle");
|
||||
if (!button()) throw new Error("Tile view needs a room-name switch without energy data");
|
||||
button().click();
|
||||
await card.updateComplete; await view.updateComplete;
|
||||
card.requestUpdate(); await card.updateComplete; await view.updateComplete;
|
||||
if (view.roomLabels || button().getAttribute("aria-pressed") !== "false") throw new Error("Tile room-name choice was lost after rendering");
|
||||
button().click(); await card.updateComplete; await view.updateComplete;
|
||||
if (!view.roomLabels) throw new Error("Tile names could not be restored");
|
||||
card.remove();
|
||||
});
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("OK: collapsible walls, variable reload, KNX temperature, numeric dimmer/position/slat tree bindings, off-state dimming and independent room/quick-menu commands");
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user