mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Add ability to edit panel view cards (#5257)
* Add ability to edit panel view cards * Localize and fix some styling
This commit is contained in:
parent
eed3263c70
commit
1950656bd5
@ -32,6 +32,8 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ type: Boolean, reflect: true })
|
||||||
public isPanel = false;
|
public isPanel = false;
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public editMode = false;
|
||||||
@property() protected _config?: IframeCardConfig;
|
@property() protected _config?: IframeCardConfig;
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
@ -88,6 +90,10 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([ispanel][editMode]) ha-card {
|
||||||
|
height: calc(100% - 51px);
|
||||||
|
}
|
||||||
|
|
||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true })
|
@property({ type: Boolean, reflect: true })
|
||||||
public isPanel = false;
|
public isPanel = false;
|
||||||
|
@property({ type: Boolean, reflect: true })
|
||||||
|
public editMode = false;
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
private _config?: MapCardConfig;
|
private _config?: MapCardConfig;
|
||||||
@ -460,6 +462,10 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([ispanel][editMode]) ha-card {
|
||||||
|
height: calc(100% - 51px);
|
||||||
|
}
|
||||||
|
|
||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@ -701,6 +701,8 @@ class HUIRoot extends LitElement {
|
|||||||
if (viewConfig.panel && viewConfig.cards && viewConfig.cards.length > 0) {
|
if (viewConfig.panel && viewConfig.cards && viewConfig.cards.length > 0) {
|
||||||
view = document.createElement("hui-panel-view");
|
view = document.createElement("hui-panel-view");
|
||||||
view.config = viewConfig;
|
view.config = viewConfig;
|
||||||
|
view.lovelace = this.lovelace;
|
||||||
|
view.index = viewIndex;
|
||||||
} else {
|
} else {
|
||||||
view = document.createElement("hui-view");
|
view = document.createElement("hui-view");
|
||||||
view.lovelace = this.lovelace;
|
view.lovelace = this.lovelace;
|
||||||
|
@ -33,6 +33,7 @@ export interface LovelaceBadge extends HTMLElement {
|
|||||||
export interface LovelaceCard extends HTMLElement {
|
export interface LovelaceCard extends HTMLElement {
|
||||||
hass?: HomeAssistant;
|
hass?: HomeAssistant;
|
||||||
isPanel?: boolean;
|
isPanel?: boolean;
|
||||||
|
editMode?: boolean;
|
||||||
getCardSize(): number;
|
getCardSize(): number;
|
||||||
setConfig(config: LovelaceCardConfig): void;
|
setConfig(config: LovelaceCardConfig): void;
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,18 @@ import {
|
|||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
|
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LovelaceCard } from "../types";
|
import { LovelaceCard, Lovelace } from "../types";
|
||||||
import { createCardElement } from "../create-element/create-card-element";
|
import { createCardElement } from "../create-element/create-card-element";
|
||||||
import { LovelaceViewConfig } from "../../../data/lovelace";
|
import { LovelaceViewConfig } from "../../../data/lovelace";
|
||||||
|
|
||||||
|
let editCodeLoaded = false;
|
||||||
|
|
||||||
@customElement("hui-panel-view")
|
@customElement("hui-panel-view")
|
||||||
export class HUIPanelView extends UpdatingElement {
|
export class HUIPanelView extends UpdatingElement {
|
||||||
@property() public hass?: HomeAssistant;
|
@property() public hass?: HomeAssistant;
|
||||||
|
@property() public lovelace?: Lovelace;
|
||||||
@property() public config?: LovelaceViewConfig;
|
@property() public config?: LovelaceViewConfig;
|
||||||
|
@property({ type: Number }) public index!: number;
|
||||||
|
|
||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
protected firstUpdated(changedProperties: PropertyValues): void {
|
||||||
super.firstUpdated(changedProperties);
|
super.firstUpdated(changedProperties);
|
||||||
@ -26,11 +30,25 @@ export class HUIPanelView extends UpdatingElement {
|
|||||||
super.update(changedProperties);
|
super.update(changedProperties);
|
||||||
|
|
||||||
const hass = this.hass!;
|
const hass = this.hass!;
|
||||||
|
const lovelace = this.lovelace!;
|
||||||
const hassChanged = changedProperties.has("hass");
|
const hassChanged = changedProperties.has("hass");
|
||||||
const oldHass = changedProperties.get("hass") as this["hass"] | undefined;
|
const oldHass = changedProperties.get("hass") as this["hass"] | undefined;
|
||||||
const configChanged = changedProperties.has("config");
|
const configChanged = changedProperties.has("config");
|
||||||
|
|
||||||
if (configChanged) {
|
if (lovelace.editMode && !editCodeLoaded) {
|
||||||
|
editCodeLoaded = true;
|
||||||
|
import(/* webpackChunkName: "hui-view-editable" */ "./hui-view-editable");
|
||||||
|
}
|
||||||
|
|
||||||
|
let editModeChanged = false;
|
||||||
|
|
||||||
|
if (changedProperties.has("lovelace")) {
|
||||||
|
const oldLovelace = changedProperties.get("lovelace") as Lovelace;
|
||||||
|
editModeChanged =
|
||||||
|
!oldLovelace || lovelace.editMode !== oldLovelace.editMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editModeChanged || configChanged) {
|
||||||
this._createCard();
|
this._createCard();
|
||||||
} else if (hassChanged) {
|
} else if (hassChanged) {
|
||||||
(this.lastChild! as LovelaceCard).hass = this.hass;
|
(this.lastChild! as LovelaceCard).hass = this.hass;
|
||||||
@ -48,14 +66,37 @@ export class HUIPanelView extends UpdatingElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createCard(): void {
|
private _createCard(): void {
|
||||||
if (this.lastChild) {
|
while (this.lastChild) {
|
||||||
this.removeChild(this.lastChild);
|
this.removeChild(this.lastChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
const card: LovelaceCard = createCardElement(this.config!.cards![0]);
|
const card: LovelaceCard = createCardElement(this.config!.cards![0]);
|
||||||
card.hass = this.hass;
|
card.hass = this.hass;
|
||||||
card.isPanel = true;
|
card.isPanel = true;
|
||||||
this.appendChild(card);
|
|
||||||
|
if (!this.lovelace!.editMode) {
|
||||||
|
this.appendChild(card);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const wrapper = document.createElement("hui-card-options");
|
||||||
|
wrapper.hass = this.hass;
|
||||||
|
wrapper.lovelace = this.lovelace;
|
||||||
|
wrapper.path = [this.index, 0];
|
||||||
|
card.editMode = true;
|
||||||
|
wrapper.appendChild(card);
|
||||||
|
this.appendChild(wrapper);
|
||||||
|
if (this.config!.cards!.length > 1) {
|
||||||
|
const warning = document.createElement("hui-warning");
|
||||||
|
warning.setAttribute(
|
||||||
|
"style",
|
||||||
|
"position: absolute; top: 0; width: 100%; box-sizing: border-box;"
|
||||||
|
);
|
||||||
|
warning.innerText = this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.editor.view.panel_mode.warning_multiple_cards"
|
||||||
|
);
|
||||||
|
this.appendChild(warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +298,7 @@ export class HUIView extends LitElement {
|
|||||||
wrapper.hass = this.hass;
|
wrapper.hass = this.hass;
|
||||||
wrapper.lovelace = this.lovelace;
|
wrapper.lovelace = this.lovelace;
|
||||||
wrapper.path = [this.index!, cardIndex];
|
wrapper.path = [this.index!, cardIndex];
|
||||||
|
element.editMode = true;
|
||||||
wrapper.appendChild(element);
|
wrapper.appendChild(element);
|
||||||
elementsToAppend.push(wrapper);
|
elementsToAppend.push(wrapper);
|
||||||
});
|
});
|
||||||
|
@ -2137,7 +2137,8 @@
|
|||||||
"view": {
|
"view": {
|
||||||
"panel_mode": {
|
"panel_mode": {
|
||||||
"title": "Panel Mode?",
|
"title": "Panel Mode?",
|
||||||
"description": "This renders the first card at full width; other cards in this view will not be rendered."
|
"description": "This renders the first card at full width; other cards in this view will not be rendered.",
|
||||||
|
"warning_multiple_cards": "This view contains more than one card, but a panel view can only show 1 card."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2393,11 +2394,6 @@
|
|||||||
"tabs": {
|
"tabs": {
|
||||||
"info": {
|
"info": {
|
||||||
"title": "Info",
|
"title": "Info",
|
||||||
"remove": "Remove",
|
|
||||||
"set": "Set",
|
|
||||||
"default_ui": "{action} {name} as default page on this device",
|
|
||||||
"lovelace_ui": "Go to the Lovelace UI",
|
|
||||||
"states_ui": "Go to the states UI",
|
|
||||||
"home_assistant_logo": "Home Assistant logo",
|
"home_assistant_logo": "Home Assistant logo",
|
||||||
"path_configuration": "Path to configuration.yaml: {path}",
|
"path_configuration": "Path to configuration.yaml: {path}",
|
||||||
"developed_by": "Developed by a bunch of awesome people.",
|
"developed_by": "Developed by a bunch of awesome people.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user