diff --git a/app/components/ProgramSequenceView.tsx b/app/components/ProgramSequenceView.tsx
index ece2ab3..96c0760 100644
--- a/app/components/ProgramSequenceView.tsx
+++ b/app/components/ProgramSequenceView.tsx
@@ -1,9 +1,8 @@
import classNames = require("classnames");
import { observer } from "mobx-react";
import * as React from "react";
-import * as ReactDOM from "react-dom";
-import { SortableContainer, SortableElement, SortableHandle, SortEnd, arrayMove } from "react-sortable-hoc";
-import { Form, Icon, List } from "semantic-ui-react";
+import { SortableContainer, SortableElement, SortableHandle, SortEnd } from "react-sortable-hoc";
+import { Button, Form, Icon, List } from "semantic-ui-react";
import { DurationView, SectionChooser } from "@app/components/index";
import { Duration } from "@common/Duration";
@@ -11,21 +10,31 @@ import { ProgramItem, Section } from "@common/sprinklersRpc";
import "@app/styles/ProgramSequenceView";
-const Handle = SortableHandle(() => );
+type ItemChangeHandler = (index: number, newItem: ProgramItem) => void;
+type ItemRemoveHandler = (index: number) => void;
+
+const Handle = SortableHandle(() => );
@observer
class ProgramSequenceItem extends React.Component<{
- sequenceItem: ProgramItem, sections: Section[], onChange?: (newItem: ProgramItem) => void,
+ sequenceItem: ProgramItem,
+ idx: number,
+ sections: Section[],
+ editing: boolean,
+ onChange: ItemChangeHandler,
+ onRemove: ItemRemoveHandler,
}> {
renderContent() {
- const { sequenceItem, sections } = this.props;
- const editing = this.props.onChange != null;
+ const { editing, sequenceItem, sections } = this.props;
const section = sections[sequenceItem.section];
const duration = Duration.fromSeconds(sequenceItem.duration);
if (editing) {
return (
+
{editing ? : }
@@ -60,44 +69,43 @@ class ProgramSequenceItem extends React.Component<{
}
private onSectionChange = (newSection: Section) => {
- if (!this.props.onChange) {
- return;
- }
- this.props.onChange(new ProgramItem({
+ this.props.onChange(this.props.idx, new ProgramItem({
...this.props.sequenceItem, section: newSection.id,
}));
}
private onDurationChange = (newDuration: Duration) => {
- if (!this.props.onChange) {
- return;
- }
- this.props.onChange(new ProgramItem({
+ this.props.onChange(this.props.idx, new ProgramItem({
...this.props.sequenceItem, duration: newDuration.toSeconds(),
}));
}
+
+ private onRemove = () => {
+ this.props.onRemove(this.props.idx);
+ }
}
const ProgramSequenceItemD = SortableElement(ProgramSequenceItem);
-type ItemChangeHandler = (newItem: ProgramItem, index: number) => void;
-
-const ProgramSequenceList = SortableContainer(observer(({ className, list, sections, onChange }: {
+const ProgramSequenceList = SortableContainer(observer((props: {
className: string,
list: ProgramItem[],
sections: Section[],
- onChange?: ItemChangeHandler,
+ editing: boolean,
+ onChange: ItemChangeHandler,
+ onRemove: ItemRemoveHandler,
}) => {
+ const { className, list, sections, ...rest } = props;
const listItems = list.map((item, index) => {
- const onChangeHandler = onChange ? (newItem: ProgramItem) => onChange(newItem, index) : undefined;
const key = `item-${index}`;
return (
);
});
@@ -112,23 +120,28 @@ class ProgramSequenceView extends React.Component<{
const { sequence, sections } = this.props;
const editing = this.props.editing || false;
const className = classNames("programSequence", { editing });
- const onChange = editing ? this.changeItem : undefined;
return (
);
}
- private changeItem: ItemChangeHandler = (newItem, index) => {
+ private changeItem: ItemChangeHandler = (index, newItem) => {
this.props.sequence[index] = newItem;
}
+ private removeItem: ItemRemoveHandler = (index) => {
+ this.props.sequence.splice(index, 1);
+ }
+
private onSortEnd = ({oldIndex, newIndex}: SortEnd) => {
const { sequence: array } = this.props;
if (newIndex >= array.length) {
diff --git a/app/components/ProgramTable.tsx b/app/components/ProgramTable.tsx
index 29361a0..1b2f82d 100644
--- a/app/components/ProgramTable.tsx
+++ b/app/components/ProgramTable.tsx
@@ -2,7 +2,7 @@ import { observer } from "mobx-react";
import { RouterStore } from "mobx-react-router";
import * as React from "react";
import { Link } from "react-router-dom";
-import { Button, ButtonProps, Table } from "semantic-ui-react";
+import { Button, ButtonProps, Icon, Table } from "semantic-ui-react";
import { ProgramSequenceView, ScheduleView } from "@app/components";
import * as rp from "@app/routePaths";
@@ -20,9 +20,16 @@ class ProgramRows extends React.Component<{
const { name, running, enabled, schedule, sequence } = program;
- const buttonStyle: ButtonProps = { size: "small", compact: true };
+ const buttonStyle: ButtonProps = { size: "small", compact: false };
const detailUrl = rp.program(device.id, program.id);
+ const stopStartButton = (
+
+ );
+
const mainRow = (
{"" + program.id}
@@ -32,13 +39,13 @@ class ProgramRows extends React.Component<{
{running ? "Running" : "Not running"}
-
+ {stopStartButton}
diff --git a/app/components/RunSectionForm.tsx b/app/components/RunSectionForm.tsx
index 2cefeff..c97ac20 100644
--- a/app/components/RunSectionForm.tsx
+++ b/app/components/RunSectionForm.tsx
@@ -1,6 +1,6 @@
import { observer } from "mobx-react";
import * as React from "react";
-import { Form, Header, Segment } from "semantic-ui-react";
+import { Form, Header, Icon, Segment } from "semantic-ui-react";
import { DurationView, SectionChooser } from "@app/components";
import { UiStore } from "@app/state";
@@ -47,6 +47,7 @@ export default class RunSectionForm extends React.Component<{
onClick={this.run}
disabled={!this.isValid}
>
+
Run
diff --git a/app/components/SectionRunnerView.tsx b/app/components/SectionRunnerView.tsx
index e2a5d82..6057a97 100644
--- a/app/components/SectionRunnerView.tsx
+++ b/app/components/SectionRunnerView.tsx
@@ -21,7 +21,7 @@ function PausedState({ paused, togglePaused }: PausedStateProps) {
"sectionRunner--pausedState-unpaused": !paused,
});
return (
-