mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Add option to change the area card size for area dashboard (#26199)
This commit is contained in:
parent
1012245ef7
commit
0839528e22
@ -44,6 +44,10 @@ export class HaAreasFloorsDisplayEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
@property({ type: Boolean }) public required = false;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public actionsRenderer?: () =>
|
||||||
|
| TemplateResult<1>
|
||||||
|
| typeof nothing;
|
||||||
|
|
||||||
@property({ type: Boolean, attribute: "show-navigation-button" })
|
@property({ type: Boolean, attribute: "show-navigation-button" })
|
||||||
public showNavigationButton = false;
|
public showNavigationButton = false;
|
||||||
|
|
||||||
@ -109,6 +113,7 @@ export class HaAreasFloorsDisplayEditor extends LitElement {
|
|||||||
.items=${groupedAreasItems[floor.floor_id]}
|
.items=${groupedAreasItems[floor.floor_id]}
|
||||||
.value=${value}
|
.value=${value}
|
||||||
.floorId=${floor.floor_id}
|
.floorId=${floor.floor_id}
|
||||||
|
.actionsRenderer=${this.actionsRenderer}
|
||||||
@value-changed=${this._areaDisplayChanged}
|
@value-changed=${this._areaDisplayChanged}
|
||||||
.showNavigationButton=${this.showNavigationButton}
|
.showNavigationButton=${this.showNavigationButton}
|
||||||
></ha-items-display-editor>
|
></ha-items-display-editor>
|
||||||
|
@ -9,6 +9,7 @@ import { repeat } from "lit/directives/repeat";
|
|||||||
import { until } from "lit/directives/until";
|
import { until } from "lit/directives/until";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import { stopPropagation } from "../common/dom/stop_propagation";
|
||||||
import { orderCompare } from "../common/string/compare";
|
import { orderCompare } from "../common/string/compare";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-icon";
|
import "./ha-icon";
|
||||||
@ -141,14 +142,17 @@ export class HaItemDisplayEditor extends LitElement {
|
|||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
${this.actionsRenderer
|
|
||||||
? html`
|
|
||||||
<span slot="end"> ${this.actionsRenderer(item)} </span>
|
|
||||||
`
|
|
||||||
: nothing}
|
|
||||||
${this.showNavigationButton
|
${this.showNavigationButton
|
||||||
? html`<ha-icon-next slot="end"></ha-icon-next>`
|
? html`<ha-icon-next slot="end"></ha-icon-next>`
|
||||||
: nothing}
|
: nothing}
|
||||||
|
<div slot="end" class="separator"></div>
|
||||||
|
${this.actionsRenderer
|
||||||
|
? html`
|
||||||
|
<div slot="end" @click=${stopPropagation}>
|
||||||
|
${this.actionsRenderer(item)}
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.path=${isVisible ? mdiEye : mdiEyeOff}
|
.path=${isVisible ? mdiEye : mdiEyeOff}
|
||||||
slot="end"
|
slot="end"
|
||||||
@ -369,6 +373,12 @@ export class HaItemDisplayEditor extends LitElement {
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
margin: -8px;
|
margin: -8px;
|
||||||
}
|
}
|
||||||
|
.separator {
|
||||||
|
width: 1px;
|
||||||
|
background-color: var(--divider-color);
|
||||||
|
height: 21px;
|
||||||
|
margin: 0 -4px;
|
||||||
|
}
|
||||||
ha-md-list {
|
ha-md-list {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import type { AreasViewStrategyConfig } from "./areas-overview-view-strategy";
|
|||||||
import { computeAreaPath, getAreas } from "./helpers/areas-strategy-helper";
|
import { computeAreaPath, getAreas } from "./helpers/areas-strategy-helper";
|
||||||
|
|
||||||
interface AreaOptions {
|
interface AreaOptions {
|
||||||
|
card_size?: "small" | "large";
|
||||||
groups_options?: Record<string, EntitiesDisplay>;
|
groups_options?: Record<string, EntitiesDisplay>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ const UNASSIGNED_FLOOR = "__unassigned__";
|
|||||||
|
|
||||||
interface AreaOptions {
|
interface AreaOptions {
|
||||||
groups_options?: Record<string, EntitiesDisplay>;
|
groups_options?: Record<string, EntitiesDisplay>;
|
||||||
|
card_size?: "small" | "large";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AreasViewStrategyConfig {
|
export interface AreasViewStrategyConfig {
|
||||||
@ -100,7 +101,8 @@ export class AreasOverviewViewStrategy extends ReactiveElement {
|
|||||||
return {
|
return {
|
||||||
type: "area",
|
type: "area",
|
||||||
area: area.area_id,
|
area: area.area_id,
|
||||||
display_type: "compact",
|
display_type:
|
||||||
|
areaOptions.card_size === "large" ? "camera" : "compact",
|
||||||
sensor_classes: sensorClasses,
|
sensor_classes: sensorClasses,
|
||||||
exclude_entities: hiddenEntities,
|
exclude_entities: hiddenEntities,
|
||||||
features: filteredControls.length
|
features: filteredControls.length
|
||||||
|
@ -16,6 +16,10 @@ import {
|
|||||||
updateAreaRegistryEntry,
|
updateAreaRegistryEntry,
|
||||||
type AreaRegistryEntry,
|
type AreaRegistryEntry,
|
||||||
} from "../../../../../data/area_registry";
|
} from "../../../../../data/area_registry";
|
||||||
|
import {
|
||||||
|
haCardSizeLarge,
|
||||||
|
haCardSizeSmall,
|
||||||
|
} from "../../../../../resources/ha-icons";
|
||||||
import { buttonLinkStyle } from "../../../../../resources/styles";
|
import { buttonLinkStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import { showAreaRegistryDetailDialog } from "../../../../config/areas/show-dialog-area-registry-detail";
|
import { showAreaRegistryDetailDialog } from "../../../../config/areas/show-dialog-area-registry-detail";
|
||||||
@ -27,6 +31,7 @@ import {
|
|||||||
AREA_STRATEGY_GROUPS,
|
AREA_STRATEGY_GROUPS,
|
||||||
getAreaGroupedEntities,
|
getAreaGroupedEntities,
|
||||||
} from "../helpers/areas-strategy-helper";
|
} from "../helpers/areas-strategy-helper";
|
||||||
|
import type { DisplayItem } from "../../../../../components/ha-items-display-editor";
|
||||||
|
|
||||||
@customElement("hui-areas-dashboard-strategy-editor")
|
@customElement("hui-areas-dashboard-strategy-editor")
|
||||||
export class HuiAreasDashboardStrategyEditor
|
export class HuiAreasDashboardStrategyEditor
|
||||||
@ -140,11 +145,65 @@ export class HuiAreasDashboardStrategyEditor
|
|||||||
@value-changed=${this._areasFloorsDisplayChanged}
|
@value-changed=${this._areasFloorsDisplayChanged}
|
||||||
expanded
|
expanded
|
||||||
show-navigation-button
|
show-navigation-button
|
||||||
|
.actionsRenderer=${this._areasActionsButtonsRenderer}
|
||||||
@item-display-navigate-clicked=${this._handleAreaNavigate}
|
@item-display-navigate-clicked=${this._handleAreaNavigate}
|
||||||
></ha-areas-floors-display-editor>
|
></ha-areas-floors-display-editor>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _areasActionsButtonsRenderer = (item: DisplayItem) => {
|
||||||
|
const areaId = item.value;
|
||||||
|
const isHidden =
|
||||||
|
this._config?.areas_display?.hidden?.includes(areaId) || false;
|
||||||
|
const isLarge =
|
||||||
|
!isHidden && this._config?.areas_options?.[areaId]?.card_size === "large";
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass!.localize(
|
||||||
|
`ui.panel.lovelace.editor.strategy.areas.${isLarge ? "use_compact_card" : "use_large_card"}`
|
||||||
|
)}
|
||||||
|
@click=${this._toggleAreaLargeCard}
|
||||||
|
.area=${areaId}
|
||||||
|
.path=${isLarge ? haCardSizeLarge : haCardSizeSmall}
|
||||||
|
.disabled=${isHidden}
|
||||||
|
>
|
||||||
|
</ha-icon-button>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
private _toggleAreaLargeCard = (ev: Event) => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const area = (ev.currentTarget! as any).area as string;
|
||||||
|
const newConfig: AreasDashboardStrategyConfig = {
|
||||||
|
...this._config!,
|
||||||
|
areas_options: {
|
||||||
|
...this._config!.areas_options,
|
||||||
|
[area]: {
|
||||||
|
...this._config!.areas_options?.[area],
|
||||||
|
card_size:
|
||||||
|
this._config!.areas_options?.[area]?.card_size === "large"
|
||||||
|
? "small"
|
||||||
|
: "large",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newConfig.areas_options![area]!.card_size === "small") {
|
||||||
|
delete newConfig.areas_options![area].card_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(newConfig.areas_options![area]).length === 0) {
|
||||||
|
delete newConfig.areas_options![area];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(newConfig.areas_options!).length === 0) {
|
||||||
|
delete newConfig.areas_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "config-changed", { config: newConfig });
|
||||||
|
};
|
||||||
|
|
||||||
private _back(): void {
|
private _back(): void {
|
||||||
if (this._area) {
|
if (this._area) {
|
||||||
this._area = undefined;
|
this._area = undefined;
|
||||||
|
4
src/resources/ha-icons.ts
Normal file
4
src/resources/ha-icons.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export const haCardSizeSmall =
|
||||||
|
"M2 13C2 11.8954 2.89543 11 4 11H7C8.10457 11 9 11.8954 9 13V16C9 17.1046 8.10457 18 7 18H4C2.89543 18 2 17.1046 2 16V13Z M20 6C21.1046 6 22 6.89543 22 8V16C22 17.1046 21.1046 18 20 18H12C10.8954 18 10 17.1046 10 16V8C10 6.89543 10.8954 6 12 6H20Z M13 8C12.4477 8 12 8.44772 12 9V15C12 15.5523 12.4477 16 13 16H19C19.5523 16 20 15.5523 20 15V9C20 8.44772 19.5523 8 19 8H13Z";
|
||||||
|
export const haCardSizeLarge =
|
||||||
|
"M7 11C8.10457 11 9 11.8954 9 13V16C9 17.1046 8.10457 18 7 18H4C2.89543 18 2 17.1046 2 16V13C2 11.8954 2.89543 11 4 11H7Z M5 13C4.44772 13 4 13.4477 4 14V15C4 15.5523 4.44772 16 5 16H6C6.55228 16 7 15.5523 7 15V14C7 13.4477 6.55228 13 6 13H5Z M10 8C10 6.89543 10.8954 6 12 6H20C21.1046 6 22 6.89543 22 8V16C22 17.1046 21.1046 18 20 18H12C10.8954 18 10 17.1046 10 16V8Z";
|
@ -7954,7 +7954,9 @@
|
|||||||
},
|
},
|
||||||
"areas": {
|
"areas": {
|
||||||
"areas_display": "Areas to display",
|
"areas_display": "Areas to display",
|
||||||
"no_entities": "No entities in this group, the section will not be displayed"
|
"no_entities": "No entities in this group, the section will not be displayed",
|
||||||
|
"use_compact_card": "Use compact card",
|
||||||
|
"use_large_card": "Use large card"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"view": {
|
"view": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user