78 lines
2.6 KiB
TypeScript
Raw Normal View History

import * as classNames from "classnames";
2017-08-29 22:42:56 -06:00
import { observer } from "mobx-react";
import * as React from "react";
2017-10-13 16:11:37 -06:00
import { Grid, Header, Icon, Item } from "semantic-ui-react";
2017-10-14 01:51:22 -06:00
import { injectState, StateBase } from "@app/state";
import { SprinklersDevice } from "@common/sprinklers";
2017-09-10 17:06:11 -06:00
import { ProgramTable, RunSectionForm, SectionRunnerView, SectionTable } from ".";
2017-10-31 17:23:27 -06:00
import "./DeviceView.scss";
2017-10-13 16:11:37 -06:00
function ConnectionState({ connected, className }: { connected: boolean, className?: string }) {
2017-08-29 23:21:36 -06:00
const classes = classNames({
2017-10-31 17:23:27 -06:00
connectionState: true,
connected: connected, /* tslint:disable-line:object-literal-shorthand */
disconnected: !connected,
2017-10-13 16:11:37 -06:00
}, className);
2017-08-29 23:21:36 -06:00
return (
2017-10-13 16:11:37 -06:00
<div className={classes}>
2017-10-10 18:00:01 -06:00
<Icon name={connected ? "linkify" : "unlinkify"} />&nbsp;
2017-08-29 23:21:36 -06:00
{connected ? "Connected" : "Disconnected"}
2017-10-13 16:11:37 -06:00
</div>
2017-08-29 23:21:36 -06:00
);
2017-10-13 16:11:37 -06:00
}
2017-09-10 17:06:11 -06:00
interface DeviceViewProps {
deviceId: string;
2017-10-14 01:51:22 -06:00
state: StateBase;
2017-09-10 17:06:11 -06:00
}
class DeviceView extends React.Component<DeviceViewProps> {
2018-04-12 17:27:42 -06:00
device!: SprinklersDevice;
2017-09-10 17:06:11 -06:00
componentWillMount() {
this.updateDevice();
}
componentWillUpdate() {
this.updateDevice();
}
render() {
2017-09-10 17:06:11 -06:00
const { id, connected, sections, programs, sectionRunner } = this.device;
return (
<Item>
2017-09-10 17:06:11 -06:00
<Item.Image src={require("@app/images/raspberry_pi.png")} />
2017-10-31 17:23:27 -06:00
<Item.Content className="device">
<Header as="h1">
2017-10-13 16:11:37 -06:00
<div>Device <kbd>{id}</kbd></div>
2017-08-29 22:42:56 -06:00
<ConnectionState connected={connected} />
</Header>
<Item.Meta>
2017-10-31 17:23:27 -06:00
Raspberry Pi Grinklers Device
</Item.Meta>
2017-10-13 16:11:37 -06:00
<Grid>
<Grid.Column mobile={16} largeScreen={8}>
<SectionTable sections={sections} />
</Grid.Column>
<Grid.Column mobile={16} largeScreen={8}>
<RunSectionForm sections={sections} />
</Grid.Column>
</Grid>
2017-10-31 17:23:27 -06:00
<ProgramTable programs={programs} sections={sections} />
2017-10-10 18:00:01 -06:00
<SectionRunnerView sectionRunner={sectionRunner} sections={sections} />
</Item.Content>
</Item>
);
}
2017-09-10 17:06:11 -06:00
private updateDevice() {
const { state, deviceId } = this.props;
if (!this.device || this.device.id !== deviceId) {
this.device = state.sprinklersApi.getDevice(deviceId);
}
}
}
2017-09-10 12:30:23 -06:00
2017-09-10 17:06:11 -06:00
export default injectState(observer(DeviceView));