Farmbot-Web-App/webpack/devices/devices.tsx

93 lines
3.1 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { connect } from "react-redux";
import { HardwareSettings } from "./components/hardware_settings";
import { FarmbotOsSettings } from "./components/farmbot_os_settings";
2017-07-04 07:20:51 -06:00
import { Page, Col, Row } from "../ui";
2017-06-29 12:54:02 -06:00
import { mapStateToProps } from "./state_to_props";
import { Props } from "./interfaces";
2017-09-25 12:37:24 -06:00
import * as moment from "moment";
2017-09-26 13:05:01 -06:00
import { ConnectivityPanel } from "./connectivity/index";
2017-09-27 21:41:34 -06:00
import {
botToMQTT, botToAPI, browserToMQTT, botToFirmware, browserToAPI
2017-09-27 21:41:34 -06:00
} from "./connectivity/status_checks";
import { Diagnosis, DiagnosisName } from "./connectivity/diagnosis";
2017-09-26 13:05:01 -06:00
import { StatusRowProps } from "./connectivity/connectivity_row";
import { refresh } from "../api/crud";
2017-09-25 12:37:24 -06:00
2017-06-29 12:54:02 -06:00
@connect(mapStateToProps)
export class Devices extends React.Component<Props, {}> {
state = { online: navigator.onLine };
/** A record of all the things we know about connectivity right now. */
get flags(): Record<DiagnosisName, StatusRowProps> {
2017-09-25 12:37:24 -06:00
const mqttConnected = this.props.bot.connectedToMQTT;
const lastSeen = this.props.deviceAccount.body.last_seen;
2017-09-27 20:27:56 -06:00
const timestamp = this.props.bot.hardware.user_env["LAST_CLIENT_CONNECTED"];
2017-09-27 21:41:34 -06:00
const fwVersion = this.props.bot.hardware
.informational_settings.firmware_version;
return {
userMQTT: browserToMQTT(mqttConnected),
userAPI: browserToAPI(this.props.connectivity),
2017-09-27 20:27:56 -06:00
botMQTT: botToMQTT(timestamp),
botAPI: botToAPI(lastSeen ? moment(lastSeen) : undefined, moment()),
botFirmware: botToFirmware(fwVersion),
};
}
/** Shuffle these around to change the ordering of the status table. */
get rowData(): StatusRowProps[] {
2017-09-27 21:41:34 -06:00
return [
this.flags.userAPI,
2017-09-27 21:41:34 -06:00
this.flags.userMQTT,
this.flags.botMQTT,
this.flags.botAPI,
this.flags.botFirmware,
2017-09-27 21:41:34 -06:00
];
2017-09-25 12:37:24 -06:00
}
2017-09-26 13:05:01 -06:00
refresh = () => {
this
.props
.dispatch(refresh(this.props.deviceAccount));
};
2017-06-29 12:54:02 -06:00
render() {
if (this.props.auth) {
return <Page className="devices">
2017-07-04 07:20:51 -06:00
<Row>
<Col xs={12} sm={6}>
<FarmbotOsSettings
account={this.props.deviceAccount}
dispatch={this.props.dispatch}
bot={this.props.bot}
2017-08-23 16:26:09 -06:00
auth={this.props.auth} />
2017-07-04 07:20:51 -06:00
</Col>
<Col xs={12} sm={6}>
<HardwareSettings
controlPanelState={this.props.bot.controlPanelState}
dispatch={this.props.dispatch}
2017-08-23 16:26:09 -06:00
bot={this.props.bot} />
2017-07-04 07:20:51 -06:00
</Col>
</Row>
2017-09-25 12:37:24 -06:00
<Row>
<Col xs={12} sm={6}>
2017-09-26 13:05:01 -06:00
<ConnectivityPanel
status={this.props.deviceAccount.specialStatus}
onRefresh={this.refresh}
rowData={this.rowData}>
<Diagnosis
userAPI={!!this.flags.userAPI}
userMQTT={!!this.flags.userMQTT.connectionStatus}
botMQTT={!!this.flags.botMQTT.connectionStatus}
botAPI={!!this.flags.botAPI.connectionStatus}
2017-09-27 21:41:34 -06:00
botFirmware={!!this.flags.botFirmware.connectionStatus} />
</ConnectivityPanel>
2017-09-25 12:37:24 -06:00
</Col>
</Row>
2017-06-29 12:54:02 -06:00
</Page>;
} else {
throw new Error("Log in first");
}
}
2017-07-04 07:20:51 -06:00
}