Farmbot-Web-App/frontend/controls/controls.tsx

99 lines
3.0 KiB
TypeScript
Raw Permalink Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import { connect } from "react-redux";
import { Peripherals } from "./peripherals";
2018-03-10 00:17:53 -07:00
import { Sensors } from "./sensors";
import { Row, Page, Col } from "../ui/index";
2017-06-29 12:54:02 -06:00
import { mapStateToProps } from "./state_to_props";
2017-09-19 07:25:18 -06:00
import { WebcamPanel } from "./webcam";
2018-07-24 12:49:40 -06:00
import { Props } from "./interfaces";
2018-07-31 18:48:43 -06:00
import { Move } from "./move/move";
import { BooleanSetting } from "../session_keys";
2018-07-19 23:48:32 -06:00
import { SensorReadings } from "./sensor_readings/sensor_readings";
2020-03-13 15:06:40 -06:00
import { isBotOnlineFromState } from "../devices/must_be_online";
2020-02-26 11:10:59 -07:00
import { hasSensors } from "../devices/components/firmware_hardware_support";
2017-06-29 12:54:02 -06:00
2018-07-24 12:49:40 -06:00
/** Controls page. */
2019-09-19 13:09:00 -06:00
export class RawControls extends React.Component<Props, {}> {
2018-07-24 12:49:40 -06:00
get arduinoBusy() {
return !!this.props.bot.hardware.informational_settings.busy;
}
2019-04-09 19:15:50 -06:00
get botOnline() {
2020-03-13 15:06:40 -06:00
return isBotOnlineFromState(this.props.bot);
2019-04-09 19:15:50 -06:00
}
2019-06-07 18:26:32 -06:00
get hideSensors() {
2020-02-26 11:10:59 -07:00
return this.props.getWebAppConfigVal(BooleanSetting.hide_sensors)
|| !hasSensors(this.props.firmwareHardware);
2019-06-07 18:26:32 -06:00
}
2018-07-24 12:49:40 -06:00
move = () => <Move
bot={this.props.bot}
2019-12-27 11:37:54 -07:00
env={this.props.env}
2018-07-24 12:49:40 -06:00
dispatch={this.props.dispatch}
arduinoBusy={this.arduinoBusy}
firmwareSettings={this.props.firmwareSettings}
2020-02-07 16:06:40 -07:00
firmwareHardware={this.props.firmwareHardware}
2018-07-24 12:49:40 -06:00
getWebAppConfigVal={this.props.getWebAppConfigVal} />
peripherals = () => <Peripherals
2020-02-18 12:21:09 -07:00
firmwareHardware={this.props.firmwareHardware}
2018-07-24 12:49:40 -06:00
bot={this.props.bot}
peripherals={this.props.peripherals}
dispatch={this.props.dispatch}
2019-04-11 21:17:18 -06:00
disabled={this.arduinoBusy || !this.botOnline} />
2018-07-24 12:49:40 -06:00
webcams = () => <WebcamPanel
feeds={this.props.feeds}
dispatch={this.props.dispatch} />
2019-06-07 18:26:32 -06:00
sensors = () => this.hideSensors
2019-06-14 16:59:11 -06:00
? <div id="hidden-sensors-widget" />
2019-06-07 18:26:32 -06:00
: <Sensors
2020-02-18 12:21:09 -07:00
firmwareHardware={this.props.firmwareHardware}
2019-06-07 18:26:32 -06:00
bot={this.props.bot}
sensors={this.props.sensors}
dispatch={this.props.dispatch}
disabled={this.arduinoBusy || !this.botOnline} />
2018-07-24 12:49:40 -06:00
2019-06-14 16:59:11 -06:00
sensorReadings = () => this.hideSensors
? <div id="hidden-sensor-history-widget" />
: <SensorReadings
2018-07-24 12:49:40 -06:00
sensorReadings={this.props.sensorReadings}
sensors={this.props.sensors}
2019-04-09 23:17:03 -06:00
timeSettings={this.props.timeSettings} />
2018-07-24 12:49:40 -06:00
2017-06-29 12:54:02 -06:00
render() {
2018-07-24 12:49:40 -06:00
const showWebcamWidget =
!this.props.getWebAppConfigVal(BooleanSetting.hide_webcam_widget);
2019-02-06 18:36:11 -07:00
return <Page className="controls-page">
{showWebcamWidget
?
<Row>
<Col xs={12} sm={6} md={5} mdOffset={1}>
2018-07-24 12:49:40 -06:00
<this.move />
<this.peripherals />
</Col>
<Col xs={12} sm={6}>
2018-07-24 12:49:40 -06:00
<this.webcams />
<this.sensors />
<this.sensorReadings />
</Col>
</Row>
:
<Row>
<Col xs={12} sm={6} md={5} mdOffset={1}>
2018-07-24 12:49:40 -06:00
<this.move />
</Col>
<Col xs={12} sm={5}>
2018-07-24 12:49:40 -06:00
<this.peripherals />
<this.sensors />
<this.sensorReadings />
</Col>
</Row>}
2017-08-28 05:44:37 -06:00
</Page>;
2017-06-29 12:54:02 -06:00
}
2017-07-03 12:19:07 -06:00
}
2019-09-19 13:09:00 -06:00
export const Controls = connect(mapStateToProps)(RawControls);