mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Add duplicate scene functionality (#9175)
This commit is contained in:
parent
cc0a120bf6
commit
ebf0bdc840
@ -39,6 +39,7 @@ export interface SceneEntity extends HassEntityBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SceneConfig {
|
export interface SceneConfig {
|
||||||
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
entities: SceneEntities;
|
entities: SceneEntities;
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
import { mdiContentSave } from "@mdi/js";
|
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
||||||
|
import "@material/mwc-list/mwc-list-item";
|
||||||
|
import {
|
||||||
|
mdiContentDuplicate,
|
||||||
|
mdiContentSave,
|
||||||
|
mdiDelete,
|
||||||
|
mdiDotsVertical,
|
||||||
|
} from "@mdi/js";
|
||||||
import "@polymer/paper-item/paper-icon-item";
|
import "@polymer/paper-item/paper-icon-item";
|
||||||
import "@polymer/paper-item/paper-item";
|
import "@polymer/paper-item/paper-item";
|
||||||
import "@polymer/paper-item/paper-item-body";
|
import "@polymer/paper-item/paper-item-body";
|
||||||
@ -48,6 +55,7 @@ import {
|
|||||||
SceneEntities,
|
SceneEntities,
|
||||||
SceneEntity,
|
SceneEntity,
|
||||||
SCENE_IGNORED_DOMAINS,
|
SCENE_IGNORED_DOMAINS,
|
||||||
|
showSceneEditor,
|
||||||
} from "../../../data/scene";
|
} from "../../../data/scene";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
@ -83,7 +91,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
|
|
||||||
@property() public route!: Route;
|
@property() public route!: Route;
|
||||||
|
|
||||||
@property() public sceneId?: string;
|
@property() public sceneId: string | null = null;
|
||||||
|
|
||||||
@property() public scenes!: SceneEntity[];
|
@property() public scenes!: SceneEntity[];
|
||||||
|
|
||||||
@ -198,19 +206,52 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
.backCallback=${() => this._backTapped()}
|
.backCallback=${() => this._backTapped()}
|
||||||
.tabs=${configSections.automation}
|
.tabs=${configSections.automation}
|
||||||
>
|
>
|
||||||
${!this.sceneId
|
<ha-button-menu
|
||||||
? ""
|
corner="BOTTOM_START"
|
||||||
: html`
|
slot="toolbar-icon"
|
||||||
<ha-icon-button
|
@action=${this._handleMenuAction}
|
||||||
class="warning"
|
activatable
|
||||||
slot="toolbar-icon"
|
>
|
||||||
title="${this.hass.localize(
|
<mwc-icon-button
|
||||||
"ui.panel.config.scene.picker.delete_scene"
|
slot="trigger"
|
||||||
)}"
|
.title=${this.hass.localize("ui.common.menu")}
|
||||||
icon="hass:delete"
|
.label=${this.hass.localize("ui.common.overflow_menu")}
|
||||||
@click=${this._deleteTapped}
|
><ha-svg-icon path=${mdiDotsVertical}></ha-svg-icon>
|
||||||
></ha-icon-button>
|
</mwc-icon-button>
|
||||||
`}
|
|
||||||
|
<mwc-list-item
|
||||||
|
.disabled=${!this.sceneId}
|
||||||
|
aria-label=${this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.duplicate_scene"
|
||||||
|
)}
|
||||||
|
graphic="icon"
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.duplicate_scene"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
|
<mwc-list-item
|
||||||
|
.disabled=${!this.sceneId}
|
||||||
|
aria-label=${this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.delete_scene"
|
||||||
|
)}
|
||||||
|
class=${classMap({ warning: Boolean(this.sceneId) })}
|
||||||
|
graphic="icon"
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.panel.config.scene.picker.delete_scene")}
|
||||||
|
<ha-svg-icon
|
||||||
|
class=${classMap({ warning: Boolean(this.sceneId) })}
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
>
|
||||||
|
</ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
</ha-button-menu>
|
||||||
${this._errors ? html` <div class="errors">${this._errors}</div> ` : ""}
|
${this._errors ? html` <div class="errors">${this._errors}</div> ` : ""}
|
||||||
${this.narrow ? html` <span slot="header">${name}</span> ` : ""}
|
${this.narrow ? html` <span slot="header">${name}</span> ` : ""}
|
||||||
<div
|
<div
|
||||||
@ -479,6 +520,17 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _handleMenuAction(ev: CustomEvent<ActionDetail>) {
|
||||||
|
switch (ev.detail.index) {
|
||||||
|
case 0:
|
||||||
|
this._duplicate();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this._deleteTapped();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async _setScene() {
|
private async _setScene() {
|
||||||
const scene = this.scenes.find(
|
const scene = this.scenes.find(
|
||||||
(entity: SceneEntity) => entity.attributes.id === this.sceneId
|
(entity: SceneEntity) => entity.attributes.id === this.sceneId
|
||||||
@ -683,6 +735,31 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
history.back();
|
history.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _duplicate() {
|
||||||
|
if (this._dirty) {
|
||||||
|
if (
|
||||||
|
!(await showConfirmationDialog(this, {
|
||||||
|
text: this.hass!.localize(
|
||||||
|
"ui.panel.config.scene.editor.unsaved_confirm"
|
||||||
|
),
|
||||||
|
confirmText: this.hass!.localize("ui.common.leave"),
|
||||||
|
dismissText: this.hass!.localize("ui.common.stay"),
|
||||||
|
}))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Wait for dialog to complete closing
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
}
|
||||||
|
showSceneEditor(this, {
|
||||||
|
...this._config,
|
||||||
|
id: undefined,
|
||||||
|
name: `${this._config?.name} (${this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.duplicate"
|
||||||
|
)})`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _calculateStates(): SceneEntities {
|
private _calculateStates(): SceneEntities {
|
||||||
const output: SceneEntities = {};
|
const output: SceneEntities = {};
|
||||||
this._entities.forEach((entityId) => {
|
this._entities.forEach((entityId) => {
|
||||||
|
@ -1680,6 +1680,8 @@
|
|||||||
"show_info_scene": "Show info about scene",
|
"show_info_scene": "Show info about scene",
|
||||||
"delete_scene": "Delete scene",
|
"delete_scene": "Delete scene",
|
||||||
"delete_confirm": "Are you sure you want to delete this scene?",
|
"delete_confirm": "Are you sure you want to delete this scene?",
|
||||||
|
"duplicate_scene": "Duplicate scene",
|
||||||
|
"duplicate": "Duplicate",
|
||||||
"headers": {
|
"headers": {
|
||||||
"name": "Name"
|
"name": "Name"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user