import * as React from "react";
import { computed } from "mobx";
import DevTools from "mobx-react-devtools";
import { observer } from "mobx-react";
import { SprinklersDevice, Section, Program, Duration, Schedule } from "./sprinklers";
import { Item, Table, Header, Segment, Form, Input, DropdownItemProps } from "semantic-ui-react";
import FontAwesome = require("react-fontawesome");
import * as classNames from "classnames";
import "semantic-ui-css/semantic.css";
import "font-awesome/css/font-awesome.css";
import "app/style/app.css";
/* tslint:disable:object-literal-sort-keys */
@observer
class SectionTable extends React.PureComponent<{ sections: Section[] }, void> {
private static renderRow(section: Section, index: number) {
if (!section) {
return null;
}
const { name, state } = section;
return (
{"" + (index + 1)}
{name}
{state ?
( Irrigating)
: "Not irrigating"}
);
}
public render() {
return (
Sections
#
Name
State
{
this.props.sections.map(SectionTable.renderRow)
}
);
}
}
class DurationInput extends React.Component<{
duration: Duration,
onDurationChange?: (newDuration: Duration) => void;
}, void> {
public render() {
const duration = this.props.duration;
const editing = this.props.onDurationChange != null;
return ;
}
private onMinutesChange = (e, { value }) => {
this.props.onDurationChange(new Duration(Number(value), this.props.duration.seconds));
}
private onSecondsChange = (e, { value }) => {
let newSeconds = Number(value);
let newMinutes = this.props.duration.minutes;
if (newSeconds >= 60) {
newMinutes++;
newSeconds = 0;
}
if (newSeconds < 0) {
newMinutes = Math.max(0, newMinutes - 1);
newSeconds = 59;
}
this.props.onDurationChange(new Duration(newMinutes, newSeconds));
}
}
@observer
class RunSectionForm extends React.Component<{ sections: Section[] }, { duration: Duration }> {
public componentWillMount() {
this.setState({
duration: new Duration(1, 1),
});
}
public render() {
return
this.setState({ duration: newDuration })} />
;
}
@computed
private get sectionOptions(): DropdownItemProps[] {
return this.props.sections.map((s, i) => ({
text: s ? s.name : null,
value: i,
}));
}
}
@observer
class ScheduleView extends React.PureComponent<{ schedule: Schedule }, void> {
public render() {
return (
{JSON.stringify(this.props.schedule)}
);
}
}
@observer
class ProgramTable extends React.PureComponent<{ programs: Program[] }, void> {
private static renderRow(program: Program, i: number) {
if (!program) {
return null;
}
const { name, running, enabled, schedule, sequence } = program;
return [
{"" + (i + 1)}
{name}
{running ? "Running" : "Not running"}
{enabled ? "Enabled" : "Not enabled"}
,
{sequence.map((item) =>
(- Section {item.section + 1 + ""} for
{item.duration.minutes}M {item.duration.seconds}S
))}
,
];
}
public render() {
return (
Programs
#
Name
Running?
Enabled?
{
Array.prototype.concat.apply([], this.props.programs.map(ProgramTable.renderRow))
}
);
}
}
const ConnectionState = ({ connected }: { connected: boolean }) =>
{connected ? "Connected" : "Disconnected"}
;
@observer
class DeviceView extends React.PureComponent<{ device: SprinklersDevice }, void> {
public render() {
const { id, connected, sections, programs } = this.props.device;
return (
-
("app/images/raspberry_pi.png")} />
);
}
}
@observer
export default class App extends React.PureComponent<{ device: SprinklersDevice }, any> {
public render() {
return
;
}
}