mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Change take control of blueprint UX (#21254)
* Change take control of blueprint UX * Add margin to ha-alert --------- Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
This commit is contained in:
parent
09accb3071
commit
9a2051a679
@ -20,14 +20,6 @@ export class HaBlueprintAutomationEditor extends HaBlueprintGenericEditor {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
|
||||||
? html`<ha-alert alert-type="warning">
|
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.read_only")}
|
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.migrate")}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
${this.stateObj?.state === "off"
|
${this.stateObj?.state === "off"
|
||||||
? html`
|
? html`
|
||||||
<ha-alert alert-type="info">
|
<ha-alert alert-type="info">
|
||||||
|
@ -81,9 +81,9 @@ declare global {
|
|||||||
unsub?: UnsubscribeFunc;
|
unsub?: UnsubscribeFunc;
|
||||||
};
|
};
|
||||||
"ui-mode-not-available": Error;
|
"ui-mode-not-available": Error;
|
||||||
duplicate: undefined;
|
|
||||||
"move-down": undefined;
|
"move-down": undefined;
|
||||||
"move-up": undefined;
|
"move-up": undefined;
|
||||||
|
duplicate: undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +116,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _validationErrors?: (string | TemplateResult)[];
|
@state() private _validationErrors?: (string | TemplateResult)[];
|
||||||
|
|
||||||
|
@state() private _blueprintConfig?: BlueprintAutomationConfig;
|
||||||
|
|
||||||
private _configSubscriptions: Record<
|
private _configSubscriptions: Record<
|
||||||
string,
|
string,
|
||||||
(config?: AutomationConfig) => void
|
(config?: AutomationConfig) => void
|
||||||
@ -200,7 +202,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<ha-list-item
|
<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._promptAutomationAlias}
|
@click=${this._promptAutomationAlias}
|
||||||
.disabled=${!this.automationId || this._mode === "yaml"}
|
.disabled=${this._readOnly ||
|
||||||
|
!this.automationId ||
|
||||||
|
this._mode === "yaml"}
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
||||||
@ -224,7 +228,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
<ha-list-item
|
<ha-list-item
|
||||||
.disabled=${!this._readOnly && !this.automationId}
|
.disabled=${this._blueprintConfig ||
|
||||||
|
(!this._readOnly && !this.automationId)}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._duplicate}
|
@click=${this._duplicate}
|
||||||
>
|
>
|
||||||
@ -244,7 +249,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<ha-list-item
|
<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._takeControl}
|
@click=${this._takeControl}
|
||||||
.disabled=${this._readOnly || this._mode === "yaml"}
|
.disabled=${this._readOnly}
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.take_control"
|
"ui.panel.config.automation.editor.take_control"
|
||||||
@ -337,6 +342,32 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
</ha-alert>`
|
</ha-alert>`
|
||||||
: ""}
|
: ""}
|
||||||
|
${this._blueprintConfig
|
||||||
|
? html`<ha-alert alert-type="info">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.confirm_take_control"
|
||||||
|
)}
|
||||||
|
<div slot="action" style="display: flex;">
|
||||||
|
<mwc-button @click=${this._takeControlSave}
|
||||||
|
>${this.hass.localize("ui.common.yes")}</mwc-button
|
||||||
|
>
|
||||||
|
<mwc-button @click=${this._revertBlueprint}
|
||||||
|
>${this.hass.localize("ui.common.no")}</mwc-button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</ha-alert>`
|
||||||
|
: this._readOnly
|
||||||
|
? html`<ha-alert alert-type="warning" dismissable
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.read_only"
|
||||||
|
)}
|
||||||
|
<mwc-button slot="action" @click=${this._duplicate}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.migrate"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-alert>`
|
||||||
|
: nothing}
|
||||||
${this._mode === "gui"
|
${this._mode === "gui"
|
||||||
? html`
|
? html`
|
||||||
<div
|
<div
|
||||||
@ -354,7 +385,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.config=${this._config}
|
.config=${this._config}
|
||||||
.disabled=${Boolean(this._readOnly)}
|
.disabled=${Boolean(this._readOnly)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@duplicate=${this._duplicate}
|
|
||||||
></blueprint-automation-editor>
|
></blueprint-automation-editor>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
@ -366,25 +396,12 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.config=${this._config}
|
.config=${this._config}
|
||||||
.disabled=${Boolean(this._readOnly)}
|
.disabled=${Boolean(this._readOnly)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@duplicate=${this._duplicate}
|
|
||||||
></manual-automation-editor>
|
></manual-automation-editor>
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: this._mode === "yaml"
|
: this._mode === "yaml"
|
||||||
? html` ${this._readOnly
|
? html`${stateObj?.state === "off"
|
||||||
? html`<ha-alert alert-type="warning">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.read_only"
|
|
||||||
)}
|
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.migrate"
|
|
||||||
)}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
${stateObj?.state === "off"
|
|
||||||
? html`
|
? html`
|
||||||
<ha-alert alert-type="info">
|
<ha-alert alert-type="info">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
@ -409,7 +426,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
</div>
|
</div>
|
||||||
<ha-fab
|
<ha-fab
|
||||||
slot="fab"
|
slot="fab"
|
||||||
class=${classMap({ dirty: this._dirty })}
|
class=${classMap({ dirty: !this._readOnly && this._dirty })}
|
||||||
.label=${this.hass.localize("ui.panel.config.automation.editor.save")}
|
.label=${this.hass.localize("ui.panel.config.automation.editor.save")}
|
||||||
extended
|
extended
|
||||||
@click=${this._saveAutomation}
|
@click=${this._saveAutomation}
|
||||||
@ -651,20 +668,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
private async _takeControl() {
|
private async _takeControl() {
|
||||||
const config = this._config as BlueprintAutomationConfig;
|
const config = this._config as BlueprintAutomationConfig;
|
||||||
|
|
||||||
const confirmation = await showConfirmationDialog(this, {
|
|
||||||
title: this.hass!.localize(
|
|
||||||
"ui.panel.config.automation.editor.take_control_confirmation.title"
|
|
||||||
),
|
|
||||||
text: this.hass!.localize(
|
|
||||||
"ui.panel.config.automation.editor.take_control_confirmation.text"
|
|
||||||
),
|
|
||||||
confirmText: this.hass!.localize(
|
|
||||||
"ui.panel.config.automation.editor.take_control_confirmation.action"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!confirmation) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await substituteBlueprint(
|
const result = await substituteBlueprint(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -675,18 +678,38 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
...normalizeAutomationConfig(result.substituted_config),
|
...normalizeAutomationConfig(result.substituted_config),
|
||||||
|
id: config.id,
|
||||||
alias: config.alias,
|
alias: config.alias,
|
||||||
description: config.description,
|
description: config.description,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._blueprintConfig = config;
|
||||||
this._config = newConfig;
|
this._config = newConfig;
|
||||||
this._dirty = true;
|
if (this._mode === "yaml") {
|
||||||
|
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
|
||||||
|
}
|
||||||
|
this._readOnly = true;
|
||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._errors = err.message;
|
this._errors = err.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _revertBlueprint() {
|
||||||
|
this._config = this._blueprintConfig;
|
||||||
|
if (this._mode === "yaml") {
|
||||||
|
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
|
||||||
|
}
|
||||||
|
this._blueprintConfig = undefined;
|
||||||
|
this._readOnly = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _takeControlSave() {
|
||||||
|
this._readOnly = false;
|
||||||
|
this._dirty = true;
|
||||||
|
this._blueprintConfig = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private async _duplicate() {
|
private async _duplicate() {
|
||||||
const result = this._readOnly
|
const result = this._readOnly
|
||||||
? await showConfirmationDialog(this, {
|
? await showConfirmationDialog(this, {
|
||||||
@ -819,10 +842,12 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
manual-automation-editor,
|
manual-automation-editor,
|
||||||
blueprint-automation-editor {
|
blueprint-automation-editor,
|
||||||
|
:not(.yaml-mode) > ha-alert {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
max-width: 1040px;
|
max-width: 1040px;
|
||||||
padding: 28px 20px 0;
|
padding: 28px 20px 0;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
ha-yaml-editor {
|
ha-yaml-editor {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
|
@ -38,14 +38,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
|
||||||
? html`<ha-alert alert-type="warning">
|
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.read_only")}
|
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.migrate")}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
${this.stateObj?.state === "off"
|
${this.stateObj?.state === "off"
|
||||||
? html`
|
? html`
|
||||||
<ha-alert alert-type="info">
|
<ha-alert alert-type="info">
|
||||||
@ -238,10 +230,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _duplicate() {
|
|
||||||
fireEvent(this, "duplicate");
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@ -280,12 +268,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
}
|
}
|
||||||
ha-alert.re-order {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { nestedArrayMove } from "../../../common/util/array-move";
|
import { nestedArrayMove } from "../../../common/util/array-move";
|
||||||
import "../../../components/ha-alert";
|
|
||||||
import "../../../components/ha-blueprint-picker";
|
import "../../../components/ha-blueprint-picker";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
@ -126,14 +125,14 @@ export abstract class HaBlueprintGenericEditor extends LitElement {
|
|||||||
);
|
);
|
||||||
const expanded = !section.collapsed || anyRequired;
|
const expanded = !section.collapsed || anyRequired;
|
||||||
|
|
||||||
return html` <ha-expansion-panel
|
return html`<ha-expansion-panel
|
||||||
outlined
|
outlined
|
||||||
.expanded=${expanded}
|
.expanded=${expanded}
|
||||||
.noCollapse=${anyRequired}
|
.noCollapse=${anyRequired}
|
||||||
>
|
>
|
||||||
<div slot="header" role="heading" aria-level="3" class="section-header">
|
<div slot="header" role="heading" aria-level="3" class="section-header">
|
||||||
${section?.icon
|
${section?.icon
|
||||||
? html` <ha-icon
|
? html`<ha-icon
|
||||||
class="section-header"
|
class="section-header"
|
||||||
.icon=${section.icon}
|
.icon=${section.icon}
|
||||||
></ha-icon>`
|
></ha-icon>`
|
||||||
@ -261,10 +260,6 @@ export abstract class HaBlueprintGenericEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _duplicate() {
|
|
||||||
fireEvent(this, "duplicate");
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@ -318,14 +313,6 @@ export abstract class HaBlueprintGenericEditor extends LitElement {
|
|||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
ha-alert {
|
|
||||||
margin-bottom: 16px;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
ha-alert.re-order {
|
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
div.section-header {
|
div.section-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
@ -333,6 +320,10 @@ export abstract class HaBlueprintGenericEditor extends LitElement {
|
|||||||
ha-icon.section-header {
|
ha-icon.section-header {
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
}
|
}
|
||||||
|
ha-alert {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import { html, nothing } from "lit";
|
import { html, nothing } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import "../../../components/ha-alert";
|
|
||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import { fetchBlueprints } from "../../../data/blueprint";
|
import { fetchBlueprints } from "../../../data/blueprint";
|
||||||
import { BlueprintScriptConfig } from "../../../data/script";
|
import { BlueprintScriptConfig } from "../../../data/script";
|
||||||
@ -17,14 +16,6 @@ export class HaBlueprintScriptEditor extends HaBlueprintGenericEditor {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
|
||||||
? html`<ha-alert alert-type="warning">
|
|
||||||
${this.hass.localize("ui.panel.config.script.editor.read_only")}
|
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
|
||||||
${this.hass.localize("ui.panel.config.script.editor.migrate")}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
${this.config.description
|
${this.config.description
|
||||||
? html`<ha-markdown
|
? html`<ha-markdown
|
||||||
class="description"
|
class="description"
|
||||||
|
@ -99,6 +99,8 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _validationErrors?: (string | TemplateResult)[];
|
@state() private _validationErrors?: (string | TemplateResult)[];
|
||||||
|
|
||||||
|
@state() private _blueprintConfig?: BlueprintScriptConfig;
|
||||||
|
|
||||||
protected render(): TemplateResult | typeof nothing {
|
protected render(): TemplateResult | typeof nothing {
|
||||||
if (!this._config) {
|
if (!this._config) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@ -216,7 +218,8 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
|
|
||||||
<ha-list-item
|
<ha-list-item
|
||||||
.disabled=${!this._readOnly && !this.scriptId}
|
.disabled=${this._blueprintConfig ||
|
||||||
|
(!this._readOnly && !this.scriptId)}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._duplicate}
|
@click=${this._duplicate}
|
||||||
>
|
>
|
||||||
@ -236,7 +239,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<ha-list-item
|
<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._takeControl}
|
@click=${this._takeControl}
|
||||||
.disabled=${this._readOnly || this._mode === "yaml"}
|
.disabled=${this._readOnly}
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.script.editor.take_control"
|
"ui.panel.config.script.editor.take_control"
|
||||||
@ -312,6 +315,32 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
: nothing}
|
: nothing}
|
||||||
</ha-alert>`
|
</ha-alert>`
|
||||||
: ""}
|
: ""}
|
||||||
|
${this._blueprintConfig
|
||||||
|
? html`<ha-alert alert-type="info">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.script.editor.confirm_take_control"
|
||||||
|
)}
|
||||||
|
<div slot="action" style="display: flex;">
|
||||||
|
<mwc-button @click=${this._takeControlSave}
|
||||||
|
>${this.hass.localize("ui.common.yes")}</mwc-button
|
||||||
|
>
|
||||||
|
<mwc-button @click=${this._revertBlueprint}
|
||||||
|
>${this.hass.localize("ui.common.no")}</mwc-button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</ha-alert>`
|
||||||
|
: this._readOnly
|
||||||
|
? html`<ha-alert alert-type="warning" dismissable
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.script.editor.read_only"
|
||||||
|
)}
|
||||||
|
<mwc-button slot="action" @click=${this._duplicate}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.script.editor.migrate"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-alert>`
|
||||||
|
: nothing}
|
||||||
${this._mode === "gui"
|
${this._mode === "gui"
|
||||||
? html`
|
? html`
|
||||||
<div
|
<div
|
||||||
@ -328,7 +357,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.config=${this._config}
|
.config=${this._config}
|
||||||
.disabled=${this._readOnly}
|
.disabled=${this._readOnly}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@duplicate=${this._duplicate}
|
|
||||||
></blueprint-script-editor>
|
></blueprint-script-editor>
|
||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
@ -339,31 +367,18 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.config=${this._config}
|
.config=${this._config}
|
||||||
.disabled=${this._readOnly}
|
.disabled=${this._readOnly}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
@duplicate=${this._duplicate}
|
|
||||||
></manual-script-editor>
|
></manual-script-editor>
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: this._mode === "yaml"
|
: this._mode === "yaml"
|
||||||
? html` ${this._readOnly
|
? html`<ha-yaml-editor
|
||||||
? html`<ha-alert alert-type="warning">
|
copyClipboard
|
||||||
${this.hass.localize(
|
.hass=${this.hass}
|
||||||
"ui.panel.config.script.editor.read_only"
|
.defaultValue=${this._preprocessYaml()}
|
||||||
)}
|
.readOnly=${this._readOnly}
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
@value-changed=${this._yamlChanged}
|
||||||
${this.hass.localize(
|
></ha-yaml-editor>`
|
||||||
"ui.panel.config.script.editor.migrate"
|
|
||||||
)}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
<ha-yaml-editor
|
|
||||||
copyClipboard
|
|
||||||
.hass=${this.hass}
|
|
||||||
.defaultValue=${this._preprocessYaml()}
|
|
||||||
.readOnly=${this._readOnly}
|
|
||||||
@value-changed=${this._yamlChanged}
|
|
||||||
></ha-yaml-editor>`
|
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
<ha-fab
|
<ha-fab
|
||||||
@ -625,20 +640,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
private async _takeControl() {
|
private async _takeControl() {
|
||||||
const config = this._config as BlueprintScriptConfig;
|
const config = this._config as BlueprintScriptConfig;
|
||||||
|
|
||||||
const confirmation = await showConfirmationDialog(this, {
|
|
||||||
title: this.hass!.localize(
|
|
||||||
"ui.panel.config.script.editor.take_control_confirmation.title"
|
|
||||||
),
|
|
||||||
text: this.hass!.localize(
|
|
||||||
"ui.panel.config.script.editor.take_control_confirmation.text"
|
|
||||||
),
|
|
||||||
confirmText: this.hass!.localize(
|
|
||||||
"ui.panel.config.script.editor.take_control_confirmation.action"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!confirmation) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await substituteBlueprint(
|
const result = await substituteBlueprint(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -653,14 +654,33 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
description: config.description,
|
description: config.description,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._blueprintConfig = config;
|
||||||
this._config = newConfig;
|
this._config = newConfig;
|
||||||
this._dirty = true;
|
if (this._mode === "yaml") {
|
||||||
|
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
|
||||||
|
}
|
||||||
|
this._readOnly = true;
|
||||||
this._errors = undefined;
|
this._errors = undefined;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._errors = err.message;
|
this._errors = err.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _revertBlueprint() {
|
||||||
|
this._config = this._blueprintConfig;
|
||||||
|
if (this._mode === "yaml") {
|
||||||
|
this.renderRoot.querySelector("ha-yaml-editor")?.setValue(this._config);
|
||||||
|
}
|
||||||
|
this._blueprintConfig = undefined;
|
||||||
|
this._readOnly = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _takeControlSave() {
|
||||||
|
this._readOnly = false;
|
||||||
|
this._dirty = true;
|
||||||
|
this._blueprintConfig = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private async _duplicate() {
|
private async _duplicate() {
|
||||||
const result = this._readOnly
|
const result = this._readOnly
|
||||||
? await showConfirmationDialog(this, {
|
? await showConfirmationDialog(this, {
|
||||||
@ -812,10 +832,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
.config-container,
|
.config-container,
|
||||||
manual-script-editor,
|
manual-script-editor,
|
||||||
blueprint-script-editor {
|
blueprint-script-editor,
|
||||||
|
:not(.yaml-mode) > ha-alert {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
max-width: 1040px;
|
max-width: 1040px;
|
||||||
padding: 28px 20px 0;
|
padding: 28px 20px 0;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
.config-container ha-alert {
|
.config-container ha-alert {
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
|
@ -60,14 +60,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
|
||||||
? html`<ha-alert alert-type="warning">
|
|
||||||
${this.hass.localize("ui.panel.config.script.editor.read_only")}
|
|
||||||
<mwc-button slot="action" @click=${this._duplicate}>
|
|
||||||
${this.hass.localize("ui.panel.config.script.editor.migrate")}
|
|
||||||
</mwc-button>
|
|
||||||
</ha-alert>`
|
|
||||||
: nothing}
|
|
||||||
${this.config.description
|
${this.config.description
|
||||||
? html`<ha-markdown
|
? html`<ha-markdown
|
||||||
class="description"
|
class="description"
|
||||||
@ -170,10 +162,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _duplicate() {
|
|
||||||
fireEvent(this, "duplicate");
|
|
||||||
}
|
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@ -205,12 +193,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
.header a {
|
.header a {
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
ha-alert.re-order {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
border-radius: var(--ha-card-border-radius, 12px);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2771,11 +2771,7 @@
|
|||||||
"migrate": "Migrate",
|
"migrate": "Migrate",
|
||||||
"duplicate": "[%key:ui::common::duplicate%]",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"take_control": "Take control",
|
"take_control": "Take control",
|
||||||
"take_control_confirmation": {
|
"confirm_take_control": "Your are viewing a preview of the automation config, do you want to take control?",
|
||||||
"title": "Take control of automation?",
|
|
||||||
"text": "This automation is based on a blueprint. You are about to take control, which will separate it from the blueprint and give you the ability to fully edit the automation. Would you like to proceed?",
|
|
||||||
"action": "Take control"
|
|
||||||
},
|
|
||||||
"run": "[%key:ui::panel::config::automation::editor::actions::run%]",
|
"run": "[%key:ui::panel::config::automation::editor::actions::run%]",
|
||||||
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
||||||
"show_trace": "Traces",
|
"show_trace": "Traces",
|
||||||
@ -3648,11 +3644,7 @@
|
|||||||
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
||||||
"change_mode": "[%key:ui::panel::config::automation::editor::change_mode%]",
|
"change_mode": "[%key:ui::panel::config::automation::editor::change_mode%]",
|
||||||
"take_control": "[%key:ui::panel::config::automation::editor::take_control%]",
|
"take_control": "[%key:ui::panel::config::automation::editor::take_control%]",
|
||||||
"take_control_confirmation": {
|
"confirm_take_control": "Your are viewing a preview of the script config, do you want to take control?",
|
||||||
"title": "Take control of script?",
|
|
||||||
"text": "This script is based on a blueprint. You are about to take control, which will separate it from the blueprint and give you the ability to fully edit the script. Would you like to proceed?",
|
|
||||||
"action": "[%key:ui::panel::config::automation::editor::take_control_confirmation::action%]"
|
|
||||||
},
|
|
||||||
"read_only": "This script cannot be edited from the UI, because it is not stored in the ''scripts.yaml'' file.",
|
"read_only": "This script cannot be edited from the UI, because it is not stored in the ''scripts.yaml'' file.",
|
||||||
"unavailable": "Script is unavailable",
|
"unavailable": "Script is unavailable",
|
||||||
"migrate": "Migrate",
|
"migrate": "Migrate",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user