mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Add buttons to move entities (#3499)
This commit is contained in:
parent
c542b242fe
commit
6c109c15ef
@ -7,6 +7,7 @@ import {
|
|||||||
css,
|
css,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
|
import "@polymer/paper-icon-button/paper-icon-button";
|
||||||
|
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
@ -31,13 +32,29 @@ export class HuiEntityEditor extends LitElement {
|
|||||||
<div class="entities">
|
<div class="entities">
|
||||||
${this.entities.map((entityConf, index) => {
|
${this.entities.map((entityConf, index) => {
|
||||||
return html`
|
return html`
|
||||||
<ha-entity-picker
|
<div class="entity">
|
||||||
.hass="${this.hass}"
|
<ha-entity-picker
|
||||||
.value="${entityConf.entity}"
|
.hass="${this.hass}"
|
||||||
.index="${index}"
|
.value="${entityConf.entity}"
|
||||||
@change="${this._valueChanged}"
|
.index="${index}"
|
||||||
allow-custom-entity
|
@change="${this._valueChanged}"
|
||||||
></ha-entity-picker>
|
allow-custom-entity
|
||||||
|
></ha-entity-picker>
|
||||||
|
<paper-icon-button
|
||||||
|
title="Move entity down"
|
||||||
|
icon="hass:arrow-down"
|
||||||
|
.index="${index}"
|
||||||
|
@click="${this._entityDown}"
|
||||||
|
?disabled="${index === this.entities!.length - 1}"
|
||||||
|
></paper-icon-button>
|
||||||
|
<paper-icon-button
|
||||||
|
title="Move entity up"
|
||||||
|
icon="hass:arrow-up"
|
||||||
|
.index="${index}"
|
||||||
|
@click="${this._entityUp}"
|
||||||
|
?disabled="${index === 0}"
|
||||||
|
></paper-icon-button>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
})}
|
})}
|
||||||
<ha-entity-picker
|
<ha-entity-picker
|
||||||
@ -60,6 +77,30 @@ export class HuiEntityEditor extends LitElement {
|
|||||||
fireEvent(this, "entities-changed", { entities: newConfigEntities });
|
fireEvent(this, "entities-changed", { entities: newConfigEntities });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _entityUp(ev: Event): void {
|
||||||
|
const target = ev.target! as EditorTarget;
|
||||||
|
const newEntities = this.entities!.concat();
|
||||||
|
|
||||||
|
[newEntities[target.index! - 1], newEntities[target.index!]] = [
|
||||||
|
newEntities[target.index!],
|
||||||
|
newEntities[target.index! - 1],
|
||||||
|
];
|
||||||
|
|
||||||
|
fireEvent(this, "entities-changed", { entities: newEntities });
|
||||||
|
}
|
||||||
|
|
||||||
|
private _entityDown(ev: Event): void {
|
||||||
|
const target = ev.target! as EditorTarget;
|
||||||
|
const newEntities = this.entities!.concat();
|
||||||
|
|
||||||
|
[newEntities[target.index! + 1], newEntities[target.index!]] = [
|
||||||
|
newEntities[target.index!],
|
||||||
|
newEntities[target.index! + 1],
|
||||||
|
];
|
||||||
|
|
||||||
|
fireEvent(this, "entities-changed", { entities: newEntities });
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: Event): void {
|
private _valueChanged(ev: Event): void {
|
||||||
const target = ev.target! as EditorTarget;
|
const target = ev.target! as EditorTarget;
|
||||||
const newConfigEntities = this.entities!.concat();
|
const newConfigEntities = this.entities!.concat();
|
||||||
@ -81,6 +122,13 @@ export class HuiEntityEditor extends LitElement {
|
|||||||
.entities {
|
.entities {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
|
.entity {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
.entity ha-entity-picker {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user