Farmbot-Web-App/frontend/devices/components/farmbot_os_settings.tsx

181 lines
6.6 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
2019-09-23 12:56:35 -06:00
import axios from "axios";
import { t } from "../../i18next_wrapper";
2018-01-11 23:18:26 -07:00
import { FarmbotOsProps, FarmbotOsState } from "../interfaces";
import { Widget, WidgetHeader, WidgetBody, Row, Col } from "../../ui";
2019-06-07 18:26:12 -06:00
import { save, edit } from "../../api/crud";
2019-04-09 19:15:50 -06:00
import { MustBeOnline, isBotOnline } from "../must_be_online";
2019-06-21 15:43:46 -06:00
import { Content } from "../../constants";
2017-06-29 12:54:02 -06:00
import { TimezoneSelector } from "../timezones/timezone_selector";
import { timezoneMismatch } from "../timezones/guess_timezone";
import { CameraSelection } from "./fbos_settings/camera_selection";
import { BoardType } from "./fbos_settings/board_type";
2018-01-11 23:18:26 -07:00
import { FarmbotOsRow } from "./fbos_settings/farmbot_os_row";
2017-11-09 09:45:11 -07:00
import { AutoUpdateRow } from "./fbos_settings/auto_update_row";
2017-11-09 10:42:06 -07:00
import { AutoSyncRow } from "./fbos_settings/auto_sync_row";
import { isUndefined } from "lodash";
import { PowerAndReset } from "./fbos_settings/power_and_reset";
import { SendDiagnosticReport } from "./send_diagnostic_report";
2019-09-19 09:03:31 -06:00
import { BootSequenceSelector } from "./fbos_settings/boot_sequence_selector";
2017-08-24 15:32:46 -06:00
export enum ColWidth {
label = 3,
description = 7,
button = 2
}
2018-01-11 23:18:26 -07:00
const OS_RELEASE_NOTES_URL =
"https://raw.githubusercontent.com/FarmBot/farmbot_os/staging/RELEASE_NOTES.md";
2017-06-29 12:54:02 -06:00
export class FarmbotOsSettings
2018-01-11 23:18:26 -07:00
extends React.Component<FarmbotOsProps, FarmbotOsState> {
2018-09-14 12:54:14 -06:00
state = { osReleaseNotesHeading: "", osReleaseNotes: "" };
2018-01-11 23:18:26 -07:00
componentDidMount() {
this.fetchReleaseNotes(OS_RELEASE_NOTES_URL,
(this.props.bot.hardware.informational_settings
.controller_version || "6").split(".")[0]);
}
fetchReleaseNotes = (url: string, osMajorVersion: string) => {
axios
2018-03-09 22:17:16 -07:00
.get<string>(url)
.then(resp => {
2018-09-14 12:54:14 -06:00
const osReleaseNotes = resp.data
2018-01-11 23:18:26 -07:00
.split("# v")
.filter(x => x.startsWith(osMajorVersion))[0]
2018-09-14 12:54:14 -06:00
.split("\n\n").slice(1).join("\n");
const osReleaseNotesHeading = "FarmBot OS v" + osMajorVersion;
this.setState({ osReleaseNotesHeading, osReleaseNotes });
2018-01-11 23:18:26 -07:00
})
.catch(() =>
this.setState({ osReleaseNotes: "Could not get release notes." }));
}
2017-08-24 15:32:46 -06:00
changeBot = (e: React.FormEvent<HTMLInputElement>) => {
2019-06-07 18:26:12 -06:00
const { deviceAccount, dispatch } = this.props;
dispatch(edit(deviceAccount, { name: e.currentTarget.value }));
2017-06-29 12:54:02 -06:00
}
updateBot = () => {
2019-06-07 18:26:12 -06:00
const { deviceAccount, dispatch } = this.props;
dispatch(save(deviceAccount.uuid));
2017-06-29 12:54:02 -06:00
}
handleTimezone = (timezone: string) => {
2019-06-07 18:26:12 -06:00
const { deviceAccount, dispatch } = this.props;
dispatch(edit(deviceAccount, { timezone }));
dispatch(save(deviceAccount.uuid));
2017-06-29 12:54:02 -06:00
}
maybeWarnTz = () => {
2019-06-07 18:26:12 -06:00
const wrongTZ = timezoneMismatch(this.props.deviceAccount.body.timezone);
2019-09-23 12:56:35 -06:00
return wrongTZ ? t(Content.DIFFERENT_TZ_WARNING) : "";
2017-06-29 12:54:02 -06:00
}
render() {
const { bot, sourceFbosConfig, botToMqttStatus } = this.props;
2019-04-09 20:31:25 -06:00
const { sync_status } = bot.hardware.informational_settings;
2019-04-09 19:15:50 -06:00
const botOnline = isBotOnline(sync_status, botToMqttStatus);
2017-06-29 12:54:02 -06:00
return <Widget className="device-widget">
2017-12-12 11:11:11 -07:00
<form onSubmit={(e) => e.preventDefault()}>
2019-06-21 15:43:46 -06:00
<WidgetHeader title="Device">
2017-06-29 12:54:02 -06:00
</WidgetHeader>
<WidgetBody>
<Row>
<Col xs={ColWidth.label}>
2017-06-29 12:54:02 -06:00
<label>
{t("NAME")}
</label>
</Col>
<Col xs={9}>
2017-06-30 10:07:30 -06:00
<input name="name"
2017-06-29 12:54:02 -06:00
onChange={this.changeBot}
onBlur={this.updateBot}
2019-06-07 18:26:12 -06:00
value={this.props.deviceAccount.body.name} />
2017-06-29 12:54:02 -06:00
</Col>
</Row>
2019-09-19 07:37:05 -06:00
<Row>
<Col xs={ColWidth.label}>
<label>
{t("BOOT SEQUENCE")}
</label>
</Col>
<Col xs={9}>
2019-09-19 13:09:00 -06:00
<BootSequenceSelector />
2019-09-19 07:37:05 -06:00
</Col>
</Row>
2017-06-29 12:54:02 -06:00
<Row>
<Col xs={ColWidth.label}>
2017-06-29 12:54:02 -06:00
<label>
{t("TIME ZONE")}
</label>
</Col>
<Col xs={ColWidth.description}>
2017-06-29 12:54:02 -06:00
<div className="note">
{this.maybeWarnTz()}
</div>
<div>
<TimezoneSelector
2019-06-07 18:26:12 -06:00
currentTimezone={this.props.deviceAccount.body.timezone}
2017-08-23 16:26:09 -06:00
onUpdate={this.handleTimezone} />
2017-06-29 12:54:02 -06:00
</div>
</Col>
</Row>
<MustBeOnline
2018-01-27 02:29:13 -07:00
syncStatus={sync_status}
2018-01-19 10:49:07 -07:00
networkState={this.props.botToMqttStatus}
lockOpen={process.env.NODE_ENV !== "production"
|| this.props.isValidFbosConfig}>
2018-01-11 23:18:26 -07:00
<FarmbotOsRow
2018-01-10 17:37:36 -07:00
bot={this.props.bot}
2018-09-14 12:54:14 -06:00
osReleaseNotesHeading={this.state.osReleaseNotesHeading}
2018-01-27 02:29:13 -07:00
osReleaseNotes={this.state.osReleaseNotes}
dispatch={this.props.dispatch}
sourceFbosConfig={sourceFbosConfig}
2018-11-26 20:39:35 -07:00
shouldDisplay={this.props.shouldDisplay}
2019-06-07 18:26:12 -06:00
botOnline={botOnline}
botToMqttLastSeen={new Date(this.props.botToMqttLastSeen).getTime()}
2019-06-07 18:26:12 -06:00
timeSettings={this.props.timeSettings}
deviceAccount={this.props.deviceAccount} />
2018-01-27 02:29:13 -07:00
<AutoUpdateRow
dispatch={this.props.dispatch}
sourceFbosConfig={sourceFbosConfig} />
{(location.host.includes("localhost")
|| !isUndefined(sourceFbosConfig("auto_sync").value)) &&
<AutoSyncRow
dispatch={this.props.dispatch}
sourceFbosConfig={sourceFbosConfig} />}
<CameraSelection
2018-11-01 11:17:18 -06:00
env={this.props.env}
botOnline={botOnline}
saveFarmwareEnv={this.props.saveFarmwareEnv}
shouldDisplay={this.props.shouldDisplay}
dispatch={this.props.dispatch} />
2018-01-27 02:29:13 -07:00
<BoardType
2019-04-09 20:31:25 -06:00
botOnline={botOnline}
bot={bot}
2019-07-12 14:39:40 -06:00
alerts={this.props.alerts}
2018-01-27 02:29:13 -07:00
dispatch={this.props.dispatch}
2018-03-13 19:32:19 -06:00
shouldDisplay={this.props.shouldDisplay}
2019-04-11 21:17:01 -06:00
timeSettings={this.props.timeSettings}
2018-01-27 02:29:13 -07:00
sourceFbosConfig={sourceFbosConfig} />
<PowerAndReset
2018-01-27 02:29:13 -07:00
controlPanelState={this.props.bot.controlPanelState}
dispatch={this.props.dispatch}
2018-03-07 22:08:00 -07:00
sourceFbosConfig={sourceFbosConfig}
shouldDisplay={this.props.shouldDisplay}
botOnline={botOnline} />
<SendDiagnosticReport
diagnostics={this.props.diagnostics}
expanded={this.props.bot.controlPanelState.diagnostic_dumps}
shouldDisplay={this.props.shouldDisplay}
2019-04-09 19:15:50 -06:00
botOnline={isBotOnline(sync_status, botToMqttStatus)}
dispatch={this.props.dispatch} />
2017-06-29 12:54:02 -06:00
</MustBeOnline>
</WidgetBody>
</form>
</Widget>;
}
}