mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add "Clear" button to template editor + confirmation dialog (#17020)
This commit is contained in:
parent
68fb98454f
commit
b40a3224fc
@ -10,6 +10,7 @@ import {
|
|||||||
RenderTemplateResult,
|
RenderTemplateResult,
|
||||||
subscribeRenderTemplate,
|
subscribeRenderTemplate,
|
||||||
} from "../../../data/ws-templates";
|
} from "../../../data/ws-templates";
|
||||||
|
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { documentationUrl } from "../../../util/documentation-url";
|
import { documentationUrl } from "../../../util/documentation-url";
|
||||||
@ -142,6 +143,9 @@ class HaPanelDevTemplate extends LitElement {
|
|||||||
"ui.panel.developer-tools.tabs.templates.reset"
|
"ui.panel.developer-tools.tabs.templates.reset"
|
||||||
)}
|
)}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
|
<mwc-button @click=${this._clear}>
|
||||||
|
${this.hass.localize("ui.common.clear")}
|
||||||
|
</mwc-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="render-pane">
|
<div class="render-pane">
|
||||||
@ -378,11 +382,42 @@ class HaPanelDevTemplate extends LitElement {
|
|||||||
localStorage["panel-dev-template-template"] = this._template;
|
localStorage["panel-dev-template-template"] = this._template;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _restoreDemo() {
|
private async _restoreDemo() {
|
||||||
|
if (
|
||||||
|
!(await showConfirmationDialog(this, {
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.developer-tools.tabs.templates.confirm_reset"
|
||||||
|
),
|
||||||
|
warning: true,
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._template = DEMO_TEMPLATE;
|
this._template = DEMO_TEMPLATE;
|
||||||
this._subscribeTemplate();
|
this._subscribeTemplate();
|
||||||
delete localStorage["panel-dev-template-template"];
|
delete localStorage["panel-dev-template-template"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _clear() {
|
||||||
|
if (
|
||||||
|
!(await showConfirmationDialog(this, {
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.developer-tools.tabs.templates.confirm_clear"
|
||||||
|
),
|
||||||
|
warning: true,
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._unsubscribeTemplate();
|
||||||
|
this._template = "";
|
||||||
|
// Reset to empty result. Setting to 'undefined' results in a different visual
|
||||||
|
// behaviour compared to manually emptying the template input box.
|
||||||
|
this._templateResult = {
|
||||||
|
result: "",
|
||||||
|
listeners: { all: false, entities: [], domains: [], time: false },
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -5348,6 +5348,8 @@
|
|||||||
"description": "Templates are rendered using the Jinja2 template engine with some Home Assistant specific extensions.",
|
"description": "Templates are rendered using the Jinja2 template engine with some Home Assistant specific extensions.",
|
||||||
"editor": "Template editor",
|
"editor": "Template editor",
|
||||||
"reset": "Reset to demo template",
|
"reset": "Reset to demo template",
|
||||||
|
"confirm_reset": "Do you want to reset your current template back to the demo template?",
|
||||||
|
"confirm_clear": "Do you want to clear your current template?",
|
||||||
"result_type": "Result type",
|
"result_type": "Result type",
|
||||||
"jinja_documentation": "Jinja2 template documentation",
|
"jinja_documentation": "Jinja2 template documentation",
|
||||||
"template_extensions": "Home Assistant template extensions",
|
"template_extensions": "Home Assistant template extensions",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user