Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/panels/config/js/script/action_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import ActionEdit from "./action_edit";

export default class Action extends Component<any> {
public state: { yamlMode: boolean };
constructor() {
super();
private moveUp: (event: Event) => void;
private moveDown: (event: Event) => void;
constructor(props) {
super(props);

this.state = {
yamlMode: false,
};

this.onDelete = this.onDelete.bind(this);
this.switchYamlMode = this.switchYamlMode.bind(this);
this.moveUp = props.moveUp.bind(this, props.index);
this.moveDown = props.moveDown.bind(this, props.index);
}

public onDelete() {
Expand All @@ -38,6 +42,12 @@ export default class Action extends Component<any> {
<ha-card>
<div class="card-content">
<div class="card-menu" style="z-index: 3">
{props.index !== 0 && (
<paper-icon-button icon="hass:arrow-up" onTap={this.moveUp} />
)}
{props.index !== props.length - 1 && (
<paper-icon-button icon="hass:arrow-down" onTap={this.moveDown} />
)}
<paper-menu-button
no-animations
horizontal-align="right"
Expand Down
20 changes: 20 additions & 0 deletions src/panels/config/js/script/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default class Script extends Component<any> {

this.addAction = this.addAction.bind(this);
this.actionChanged = this.actionChanged.bind(this);
this.moveUp = this.moveUp.bind(this);
this.moveDown = this.moveDown.bind(this);
}

public addAction() {
Expand All @@ -32,14 +34,25 @@ export default class Script extends Component<any> {
this.props.onChange(script);
}

public moveUp(index: number) {
this.move(index, index - 1);
}

public moveDown(index: number) {
this.move(index, index + 1);
}

public render({ script, hass, localize }) {
return (
<div class="script">
{script.map((act, idx) => (
<ActionRow
index={idx}
length={script.length}
action={act}
onChange={this.actionChanged}
moveUp={this.moveUp}
moveDown={this.moveDown}
hass={hass}
localize={localize}
/>
Expand All @@ -54,4 +67,11 @@ export default class Script extends Component<any> {
</div>
);
}

private move(index: number, newIndex: number) {
const script = this.props.script.concat();
const action = script.splice(index, 1)[0];
script.splice(newIndex, 0, action);
this.props.onChange(script);
}
}