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-23 19:20:41 -06:00
|
|
|
import * as p from "@app/pages";
|
|
|
|
import * as rp from "@app/routePaths";
|
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";
|
2018-07-23 19:20:41 -06:00
|
|
|
import { Route, RouteComponentProps, withRouter } from "react-router";
|
2017-09-10 17:06:11 -06:00
|
|
|
import { ProgramTable, RunSectionForm, SectionRunnerView, SectionTable } from ".";
|
2018-07-25 15:55:35 -06:00
|
|
|
|
|
|
|
import "@app/styles/DeviceView";
|
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-07-13 00:04:59 -06:00
|
|
|
const connected = connectionState.isDeviceConnected;
|
2018-06-16 23:54:03 -06:00
|
|
|
let connectionText: string;
|
2018-06-29 18:16:06 -06:00
|
|
|
let iconName: SemanticICONS = "unlinkify";
|
2018-07-13 00:04:59 -06:00
|
|
|
let clazzName: string = "disconnected";
|
2018-06-16 23:54:03 -06:00
|
|
|
if (connected) {
|
|
|
|
connectionText = "Connected";
|
2018-06-29 18:16:06 -06:00
|
|
|
iconName = "linkify";
|
2018-07-13 00:04:59 -06:00
|
|
|
clazzName = "connected";
|
|
|
|
} else if (connected === false) {
|
|
|
|
connectionText = "Device Disconnected";
|
2018-06-29 18:16:06 -06:00
|
|
|
} else if (connectionState.noPermission) {
|
|
|
|
connectionText = "No permission for this device";
|
|
|
|
iconName = "ban";
|
2018-07-13 00:04:59 -06:00
|
|
|
} else if (connectionState.clientToServer === false) {
|
|
|
|
connectionText = "Disconnected from server";
|
2018-06-16 23:54:03 -06:00
|
|
|
} else {
|
2018-07-13 00:04:59 -06:00
|
|
|
connectionText = "Unknown";
|
|
|
|
iconName = "question";
|
|
|
|
clazzName = "unknown";
|
2018-06-16 23:54:03 -06:00
|
|
|
}
|
2018-07-13 00:04:59 -06:00
|
|
|
const classes = classNames("connectionState", clazzName, className);
|
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
|
|
|
}
|
|
|
|
|
2018-07-23 19:20:41 -06:00
|
|
|
class DeviceView extends React.Component<DeviceViewProps & RouteComponentProps<any>> {
|
2017-06-20 08:45:25 -06:00
|
|
|
render() {
|
2018-07-22 14:50:08 -06:00
|
|
|
const { uiStore, sprinklersRpc, routerStore } = this.props.appState;
|
2018-07-02 15:22:59 -06:00
|
|
|
const device = sprinklersRpc.getDevice(this.props.deviceId);
|
2018-07-22 14:50:08 -06:00
|
|
|
const { id, connectionState, sections, sectionRunner } = device;
|
2018-06-29 21:30:55 -06:00
|
|
|
const deviceBody = connectionState.isAvailable && (
|
|
|
|
<React.Fragment>
|
|
|
|
<Grid>
|
2018-07-24 12:55:43 -06:00
|
|
|
<Grid.Column mobile="16" tablet="16" computer="16" largeScreen="6">
|
|
|
|
<SectionRunnerView sectionRunner={sectionRunner} sections={sections}/>
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column mobile="16" tablet="9" computer="9" largeScreen="6">
|
2018-06-29 21:30:55 -06:00
|
|
|
<SectionTable sections={sections}/>
|
|
|
|
</Grid.Column>
|
2018-07-24 12:55:43 -06:00
|
|
|
<Grid.Column mobile="16" tablet="7" computer="7" largeScreen="4">
|
2018-06-29 21:30:55 -06:00
|
|
|
<RunSectionForm device={device} uiStore={uiStore}/>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid>
|
2018-07-22 14:50:08 -06:00
|
|
|
<ProgramTable device={device} routerStore={routerStore}/>
|
2018-07-23 19:20:41 -06:00
|
|
|
<Route path={rp.program(":deviceId", ":programId")} component={p.ProgramPage}/>
|
2018-06-29 21:30:55 -06:00
|
|
|
</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
|
|
|
|
2018-07-23 19:20:41 -06:00
|
|
|
export default injectState(withRouter(observer(DeviceView)));
|