-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Gui editor fixes #5416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gui editor fixes #5416
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,18 +6,24 @@ import { | |
| property, | ||
| CSSResult, | ||
| css, | ||
| query, | ||
| } from "lit-element"; | ||
| import "@polymer/paper-tabs"; | ||
|
|
||
| import { struct } from "../../common/structs/struct"; | ||
| import { HomeAssistant } from "../../../../types"; | ||
| import { LovelaceCardEditor } from "../../types"; | ||
| import { StackCardConfig } from "../../cards/types"; | ||
| import { fireEvent } from "../../../../common/dom/fire_event"; | ||
| import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event"; | ||
| import { LovelaceConfig } from "../../../../data/lovelace"; | ||
|
|
||
| import "../../../../components/entity/ha-entity-picker"; | ||
| import "../../../../components/ha-switch"; | ||
| import { | ||
| HuiCardEditor, | ||
| ConfigChangedEvent, | ||
| } from "../card-editor/hui-card-editor"; | ||
| import { GUIModeChangedEvent } from "../types"; | ||
|
|
||
| const conditionStruct = struct({ | ||
| entity: "string", | ||
|
|
@@ -36,7 +42,10 @@ export class HuiConditionalCardEditor extends LitElement | |
| @property() public hass?: HomeAssistant; | ||
| @property() public lovelace?: LovelaceConfig; | ||
| @property() private _config?: StackCardConfig; | ||
| @property() private _GUImode = true; | ||
| @property() private _guiModeAvailable? = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need the optional (undefined)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The event does not have to send it, so it could be undefined, should not happen...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah Gotcha |
||
| @property() private _cardTab: boolean = false; | ||
| @query("hui-card-editor") private _cardEditorEl?: HuiCardEditor; | ||
|
|
||
| public setConfig(config: StackCardConfig): void { | ||
| this._config = cardConfigStruct(config); | ||
|
|
@@ -69,6 +78,17 @@ export class HuiConditionalCardEditor extends LitElement | |
| ${this._config.card.type | ||
| ? html` | ||
| <div class="card-options"> | ||
| <mwc-button | ||
| @click=${this._toggleMode} | ||
| .disabled=${!this._guiModeAvailable} | ||
| class="gui-mode-button" | ||
| > | ||
| ${this.hass!.localize( | ||
| !this._cardEditorEl || this._GUImode | ||
| ? "ui.panel.lovelace.editor.edit_card.show_code_editor" | ||
| : "ui.panel.lovelace.editor.edit_card.show_visual_editor" | ||
| )} | ||
| </mwc-button> | ||
| <mwc-button @click=${this._handleReplaceCard} | ||
| >${this.hass!.localize( | ||
| "ui.panel.lovelace.editor.card.conditional.change_type" | ||
|
|
@@ -80,13 +100,14 @@ export class HuiConditionalCardEditor extends LitElement | |
| .value=${this._config.card} | ||
| .lovelace=${this.lovelace} | ||
| @config-changed=${this._handleCardChanged} | ||
| @GUImode-changed=${this._handleGUIModeChanged} | ||
| ></hui-card-editor> | ||
| ` | ||
| : html` | ||
| <hui-card-picker | ||
| .hass=${this.hass} | ||
| .lovelace=${this.lovelace} | ||
| @config-changed=${this._handleCardChanged} | ||
| @config-changed=${this._handleCardPicked} | ||
| ></hui-card-picker> | ||
| `} | ||
| </div> | ||
|
|
@@ -162,14 +183,44 @@ export class HuiConditionalCardEditor extends LitElement | |
| this._cardTab = parseInt((ev.target! as any).selected!, 10) === 1; | ||
| } | ||
|
|
||
| private _handleCardChanged(ev: CustomEvent): void { | ||
| private _toggleMode(): void { | ||
| this._cardEditorEl?.toggleMode(); | ||
| } | ||
|
|
||
| private _setMode(value: boolean): void { | ||
| this._GUImode = value; | ||
| if (this._cardEditorEl) { | ||
| this._cardEditorEl!.GUImode = value; | ||
| } | ||
| } | ||
|
|
||
| private _handleGUIModeChanged(ev: HASSDomEvent<GUIModeChangedEvent>): void { | ||
| ev.stopPropagation(); | ||
| this._GUImode = ev.detail.guiMode; | ||
| this._guiModeAvailable = ev.detail.guiModeAvailable; | ||
| } | ||
|
|
||
| private _handleCardPicked(ev: CustomEvent): void { | ||
| ev.stopPropagation(); | ||
| if (!this._config) { | ||
| return; | ||
| } | ||
| this._setMode(true); | ||
| this._guiModeAvailable = true; | ||
| this._config.card = ev.detail.config; | ||
| fireEvent(this, "config-changed", { config: this._config }); | ||
| } | ||
|
|
||
| private _handleCardChanged(ev: HASSDomEvent<ConfigChangedEvent>): void { | ||
| ev.stopPropagation(); | ||
| if (!this._config) { | ||
| return; | ||
| } | ||
| this._config.card = ev.detail.config; | ||
| this._guiModeAvailable = ev.detail.guiModeAvailable; | ||
| fireEvent(this, "config-changed", { config: this._config }); | ||
| } | ||
|
|
||
| private _handleReplaceCard(): void { | ||
| if (!this._config) { | ||
| return; | ||
|
|
@@ -267,6 +318,9 @@ export class HuiConditionalCardEditor extends LitElement | |
| justify-content: flex-end; | ||
| width: 100%; | ||
| } | ||
| .gui-mode-button { | ||
| margin-right: auto; | ||
| } | ||
| `; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here