2017-06-29 12:54:02 -06:00
|
|
|
import * as React from "react";
|
2018-01-11 23:18:26 -07:00
|
|
|
import { FarmbotOsProps, FarmbotOsState } from "../interfaces";
|
2019-04-09 20:09:57 -06:00
|
|
|
import { Widget, WidgetHeader, WidgetBody, Row, Col, SaveBtn } 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";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { ToolTips, Content } from "../../constants";
|
|
|
|
import { TimezoneSelector } from "../timezones/timezone_selector";
|
|
|
|
import { timezoneMismatch } from "../timezones/guess_timezone";
|
2017-12-07 21:05:22 -07:00
|
|
|
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";
|
2017-11-09 12:05:20 -07:00
|
|
|
import { isUndefined } from "lodash";
|
2017-12-01 21:32:26 -07:00
|
|
|
import { PowerAndReset } from "./fbos_settings/power_and_reset";
|
2018-06-18 15:12:00 -06:00
|
|
|
import { SendDiagnosticReport } from "./send_diagnostic_report";
|
2018-01-11 23:18:26 -07:00
|
|
|
import axios from "axios";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2017-08-24 15:32:46 -06:00
|
|
|
|
2017-12-07 21:05:22 -07: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
|
|
|
|
2017-06-30 10:07:30 -06:00
|
|
|
changeBot = (e: React.ChangeEvent<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
|
|
|
}
|
|
|
|
|
2018-03-13 16:37:24 -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);
|
2017-06-29 12:54:02 -06:00
|
|
|
if (wrongTZ) {
|
2018-07-01 00:42:37 -06:00
|
|
|
return t(Content.DIFFERENT_TZ_WARNING);
|
2017-06-29 12:54:02 -06:00
|
|
|
} else {
|
2017-07-02 19:06:43 -06:00
|
|
|
return "";
|
2017-06-29 12:54:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-06-07 18:26:12 -06:00
|
|
|
const { bot, deviceAccount, 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()}>
|
2017-06-29 12:54:02 -06:00
|
|
|
<WidgetHeader title="Device" helpText={ToolTips.OS_SETTINGS}>
|
|
|
|
<SaveBtn
|
2019-06-07 18:26:12 -06:00
|
|
|
status={deviceAccount.specialStatus}
|
2017-08-15 14:21:41 -06:00
|
|
|
onClick={this.updateBot} />
|
2017-06-29 12:54:02 -06:00
|
|
|
</WidgetHeader>
|
|
|
|
<WidgetBody>
|
|
|
|
<Row>
|
2017-12-07 21:05:22 -07:00
|
|
|
<Col xs={ColWidth.label}>
|
2017-06-29 12:54:02 -06:00
|
|
|
<label>
|
|
|
|
{t("NAME")}
|
|
|
|
</label>
|
|
|
|
</Col>
|
2017-12-07 21:05:22 -07:00
|
|
|
<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}
|
2019-06-07 18:26:12 -06:00
|
|
|
value={this.props.deviceAccount.body.name} />
|
2017-06-29 12:54:02 -06:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<Row>
|
2017-12-07 21:05:22 -07:00
|
|
|
<Col xs={ColWidth.label}>
|
2017-06-29 12:54:02 -06:00
|
|
|
<label>
|
|
|
|
{t("TIME ZONE")}
|
|
|
|
</label>
|
|
|
|
</Col>
|
2017-12-07 21:05:22 -07:00
|
|
|
<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}
|
2018-03-10 02:42:15 -07:00
|
|
|
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}
|
2018-03-10 02:42:15 -07:00
|
|
|
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={this.props.botToMqttLastSeen}
|
|
|
|
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} />}
|
2018-03-10 02:42:15 -07:00
|
|
|
<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}
|
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} />
|
2017-12-01 21:32:26 -07:00
|
|
|
<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}
|
2018-03-10 02:42:15 -07:00
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
|
|
|
botOnline={botOnline} />
|
2018-06-18 15:12:00 -06:00
|
|
|
<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)}
|
2018-06-18 15:12:00 -06:00
|
|
|
dispatch={this.props.dispatch} />
|
2017-06-29 12:54:02 -06:00
|
|
|
</MustBeOnline>
|
|
|
|
</WidgetBody>
|
|
|
|
</form>
|
|
|
|
</Widget>;
|
|
|
|
}
|
|
|
|
}
|