2017-06-20 08:45:25 -06:00
|
|
|
import * as classNames from "classnames";
|
2017-08-29 22:42:56 -06:00
|
|
|
import { observer } from "mobx-react";
|
2017-06-30 01:08:51 -06:00
|
|
|
import * as React from "react";
|
2017-10-13 16:11:37 -06:00
|
|
|
import { Grid, Header, Icon, Item } from "semantic-ui-react";
|
2017-06-20 08:45:25 -06:00
|
|
|
|
2017-10-14 01:51:22 -06:00
|
|
|
import { injectState, StateBase } from "@app/state";
|
2018-06-16 23:54:03 -06:00
|
|
|
import { ConnectionState as ConState, 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-06-20 08:45:25 -06:00
|
|
|
|
2018-06-17 01:04:30 -06:00
|
|
|
const ConnectionState = observer(({ connectionState, className }:
|
|
|
|
{ connectionState: ConState, className?: string }) => {
|
2018-06-16 23:54:03 -06:00
|
|
|
const connected = connectionState.isConnected;
|
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);
|
2018-06-16 23:54:03 -06:00
|
|
|
let connectionText: string;
|
|
|
|
if (connected) {
|
|
|
|
connectionText = "Connected";
|
|
|
|
} else if (connectionState.serverToBroker) {
|
|
|
|
connectionText = "Device Disconnected";
|
|
|
|
} else if (connectionState.clientToServer) {
|
|
|
|
connectionText = "Broker Disconnected";
|
|
|
|
} else {
|
|
|
|
connectionText = "Server Disconnected";
|
|
|
|
}
|
2017-08-29 23:21:36 -06:00
|
|
|
return (
|
2017-10-13 16:11:37 -06:00
|
|
|
<div className={classes}>
|
2018-06-16 23:54:03 -06:00
|
|
|
<Icon name={connected ? "linkify" : "unlinkify"}/>
|
|
|
|
{connectionText}
|
2017-10-13 16:11:37 -06:00
|
|
|
</div>
|
2017-08-29 23:21:36 -06:00
|
|
|
);
|
2018-06-17 01:04:30 -06:00
|
|
|
});
|
2017-06-20 08:45:25 -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();
|
|
|
|
}
|
|
|
|
|
2017-06-20 08:45:25 -06:00
|
|
|
render() {
|
2018-06-16 23:54:03 -06:00
|
|
|
const { id, connectionState, sections, programs, sectionRunner } = this.device;
|
2017-06-20 08:45:25 -06:00
|
|
|
return (
|
|
|
|
<Item>
|
2018-06-16 23:54:03 -06:00
|
|
|
<Item.Image src={require("@app/images/raspberry_pi.png")}/>
|
2017-10-31 17:23:27 -06:00
|
|
|
<Item.Content className="device">
|
2017-06-20 08:45:25 -06:00
|
|
|
<Header as="h1">
|
2017-10-13 16:11:37 -06:00
|
|
|
<div>Device <kbd>{id}</kbd></div>
|
2018-06-16 23:54:03 -06:00
|
|
|
<ConnectionState connectionState={connectionState}/>
|
2017-06-20 08:45:25 -06:00
|
|
|
</Header>
|
|
|
|
<Item.Meta>
|
2017-10-31 17:23:27 -06:00
|
|
|
Raspberry Pi Grinklers Device
|
2017-06-20 08:45:25 -06:00
|
|
|
</Item.Meta>
|
2018-06-17 01:04:30 -06:00
|
|
|
<Grid stackable>
|
|
|
|
<Grid.Column width="8">
|
2018-06-16 23:54:03 -06:00
|
|
|
<SectionTable sections={sections}/>
|
2017-10-13 16:11:37 -06:00
|
|
|
</Grid.Column>
|
2018-06-17 01:04:30 -06:00
|
|
|
<Grid.Column width="8">
|
2018-06-16 23:54:03 -06:00
|
|
|
<RunSectionForm sections={sections}/>
|
2017-10-13 16:11:37 -06:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
2018-06-16 23:54:03 -06:00
|
|
|
<ProgramTable programs={programs} sections={sections}/>
|
|
|
|
<SectionRunnerView sectionRunner={sectionRunner} sections={sections}/>
|
2017-06-20 08:45:25 -06:00
|
|
|
</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-06-20 08:53:50 -06:00
|
|
|
}
|
2017-09-10 12:30:23 -06:00
|
|
|
|
2017-09-10 17:06:11 -06:00
|
|
|
export default injectState(observer(DeviceView));
|