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";
|
2018-06-29 18:16:06 -06:00
|
|
|
import { Grid, Header, Icon, Item, SemanticICONS } from "semantic-ui-react";
|
2017-06-20 08:45:25 -06:00
|
|
|
|
2018-07-02 15:22:59 -06:00
|
|
|
import { AppState, injectState } from "@app/state";
|
2018-07-01 02:00:17 -06:00
|
|
|
import { ConnectionState as ConState } from "@common/sprinklersRpc";
|
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,
|
2018-06-29 18:16:06 -06:00
|
|
|
connected: connected === true,
|
|
|
|
disconnected: connected === false,
|
|
|
|
unknown: connected === null,
|
2017-10-13 16:11:37 -06:00
|
|
|
}, className);
|
2018-06-16 23:54:03 -06:00
|
|
|
let connectionText: string;
|
2018-06-29 18:16:06 -06:00
|
|
|
let iconName: SemanticICONS = "unlinkify";
|
2018-06-16 23:54:03 -06:00
|
|
|
if (connected) {
|
|
|
|
connectionText = "Connected";
|
2018-06-29 18:16:06 -06:00
|
|
|
iconName = "linkify";
|
|
|
|
} else if (connected === null) {
|
|
|
|
connectionText = "Unknown";
|
|
|
|
iconName = "question";
|
|
|
|
} else if (connectionState.noPermission) {
|
|
|
|
connectionText = "No permission for this device";
|
|
|
|
iconName = "ban";
|
2018-06-16 23:54:03 -06:00
|
|
|
} 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-29 18:16:06 -06:00
|
|
|
<Icon name={iconName}/>
|
2018-06-16 23:54:03 -06:00
|
|
|
{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;
|
2018-07-02 15:22:59 -06:00
|
|
|
appState: AppState;
|
2017-09-10 17:06:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
class DeviceView extends React.Component<DeviceViewProps> {
|
2017-06-20 08:45:25 -06:00
|
|
|
render() {
|
2018-07-02 15:22:59 -06:00
|
|
|
const { uiStore, sprinklersRpc } = this.props.appState;
|
|
|
|
const device = sprinklersRpc.getDevice(this.props.deviceId);
|
2018-06-29 21:30:55 -06:00
|
|
|
const { id, connectionState, sections, programs, sectionRunner } = device;
|
|
|
|
const deviceBody = connectionState.isAvailable && (
|
|
|
|
<React.Fragment>
|
|
|
|
<SectionRunnerView sectionRunner={sectionRunner} sections={sections}/>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Column mobile="16" tablet="16" computer="8">
|
|
|
|
<SectionTable sections={sections}/>
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column mobile="16" tablet="16" computer="8">
|
|
|
|
<RunSectionForm device={device} uiStore={uiStore}/>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
|
|
|
<ProgramTable programs={programs} sections={sections}/>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
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-29 21:30:55 -06:00
|
|
|
{deviceBody}
|
2017-06-20 08:45:25 -06:00
|
|
|
</Item.Content>
|
|
|
|
</Item>
|
|
|
|
);
|
|
|
|
}
|
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));
|