import * as classNames from "classnames"; import { observer } from "mobx-react"; import * as React from "react"; import { Link } from "react-router-dom"; import { Grid, Header, Icon, Item, SemanticICONS } from "semantic-ui-react"; import { DeviceImage } from "@client/components"; import * as p from "@client/pages"; import * as route from "@client/routePaths"; import { AppState, injectState } from "@client/state"; import { ISprinklersDevice } from "@common/httpApi"; import { ConnectionState as ConState, SprinklersDevice } from "@common/sprinklersRpc"; import { Route, RouteComponentProps, withRouter } from "react-router"; import { ProgramTable, RunSectionForm, SectionRunnerView, SectionTable } from "."; import "@client/styles/DeviceView"; const ConnectionState = observer(({ connectionState, className }: { connectionState: ConState, className?: string }) => { const connected = connectionState.isDeviceConnected; let connectionText: string; let iconName: SemanticICONS = "unlinkify"; let clazzName: string = "disconnected"; if (connected) { connectionText = "Connected"; iconName = "linkify"; clazzName = "connected"; } else if (connectionState.noPermission) { connectionText = "No permission for this device"; iconName = "ban"; } else if (connected === false) { connectionText = "Device Disconnected"; } else if (connectionState.clientToServer === false) { connectionText = "Disconnected from server"; } else { connectionText = "Unknown"; iconName = "question"; clazzName = "unknown"; } const classes = classNames("connectionState", clazzName, className); return (
  {connectionText}
); }); interface DeviceViewProps { deviceId: number; appState: AppState; inList?: boolean; } class DeviceView extends React.Component> { renderBody(iDevice: ISprinklersDevice, device: SprinklersDevice) { const { inList, appState: { uiStore, routerStore } } = this.props; const { connectionState, sectionRunner, sections } = device; if (!connectionState.isAvailable || inList) { return null; } return ( ); } render() { const { deviceId, inList, appState: { sprinklersRpc, userStore } } = this.props; const iDevice = userStore.findDevice(deviceId); let itemContent: React.ReactNode; if (!iDevice || !iDevice.deviceId) { // TODO: better and link back to devices list itemContent = You do not have access to this device; } else { const device = sprinklersRpc.getDevice(iDevice.deviceId); const { connectionState } = device; let header: React.ReactNode; if (inList) { // tslint:disable-line:prefer-conditional-expression header = Device {iDevice.name}; } else { header = Device {iDevice.name}; } itemContent = (
{header}
Raspberry Pi Grinklers Device {this.renderBody(iDevice, device)}
); } return {itemContent}; } } export default injectState(withRouter(observer(DeviceView)));