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";
|
2019-10-09 15:04:23 -06:00
|
|
|
import { FarmbotOsProps, FarmbotOsState, Feature } from "../interfaces";
|
2019-08-23 13:33:50 -06:00
|
|
|
import { Widget, WidgetHeader, WidgetBody, Row, Col } from "../../ui";
|
2019-06-07 18:26:12 -06:00
|
|
|
import { save, edit } from "../../api/crud";
|
2020-02-15 11:29:31 -07:00
|
|
|
import { isBotOnline } from "../must_be_online";
|
2020-02-18 12:21:09 -07:00
|
|
|
import { Content, DeviceSetting } from "../../constants";
|
2017-06-29 12:54:02 -06:00
|
|
|
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-12-01 21:32:26 -07:00
|
|
|
import { PowerAndReset } from "./fbos_settings/power_and_reset";
|
2019-09-19 09:03:31 -06:00
|
|
|
import { BootSequenceSelector } from "./fbos_settings/boot_sequence_selector";
|
2020-02-15 11:30:23 -07:00
|
|
|
import { ExternalUrl } from "../../external_urls";
|
2020-02-18 12:21:09 -07:00
|
|
|
import { Highlight } from "./maybe_highlight";
|
2020-02-26 13:08:49 -07:00
|
|
|
import { OtaTimeSelectorRow } from "./fbos_settings/ota_time_selector";
|
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
|
|
|
|
}
|
|
|
|
|
2017-06-29 12:54:02 -06:00
|
|
|
export class FarmbotOsSettings
|
2018-01-11 23:18:26 -07:00
|
|
|
extends React.Component<FarmbotOsProps, FarmbotOsState> {
|
2019-10-30 12:25:56 -06:00
|
|
|
state: FarmbotOsState = { allOsReleaseNotes: "" };
|
2018-01-11 23:18:26 -07:00
|
|
|
|
|
|
|
componentDidMount() {
|
2020-02-15 11:30:23 -07:00
|
|
|
this.fetchReleaseNotes(ExternalUrl.osReleaseNotes);
|
2018-01-11 23:18:26 -07:00
|
|
|
}
|
|
|
|
|
2019-10-30 12:25:56 -06:00
|
|
|
get osMajorVersion() {
|
|
|
|
return (this.props.bot.hardware.informational_settings
|
|
|
|
.controller_version || "6").split(".")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchReleaseNotes = (url: string) => {
|
2018-01-11 23:18:26 -07:00
|
|
|
axios
|
2018-03-09 22:17:16 -07:00
|
|
|
.get<string>(url)
|
2019-10-30 12:25:56 -06:00
|
|
|
.then(resp => this.setState({ allOsReleaseNotes: resp.data }))
|
|
|
|
.catch(() => this.setState({ allOsReleaseNotes: "" }));
|
|
|
|
}
|
|
|
|
|
|
|
|
get osReleaseNotes() {
|
|
|
|
const notes = (this.state.allOsReleaseNotes
|
|
|
|
.split("# v")
|
|
|
|
.filter(x => x.startsWith(this.osMajorVersion))[0] || "")
|
|
|
|
.split("\n\n").slice(1).join("\n") || t("Could not get release notes.");
|
|
|
|
const heading = "FarmBot OS v" + this.osMajorVersion;
|
|
|
|
return { heading, notes };
|
2018-01-11 23:18:26 -07:00
|
|
|
}
|
2017-08-24 15:32:46 -06:00
|
|
|
|
2019-08-23 13:33:50 -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
|
|
|
}
|
|
|
|
|
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);
|
2019-09-23 12:56:35 -06:00
|
|
|
return wrongTZ ? t(Content.DIFFERENT_TZ_WARNING) : "";
|
2017-06-29 12:54:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-08-23 13:33:50 -06:00
|
|
|
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>
|
2020-02-18 12:21:09 -07:00
|
|
|
<Highlight settingName={DeviceSetting.name}>
|
|
|
|
<Col xs={ColWidth.label}>
|
|
|
|
<label>
|
|
|
|
{t(DeviceSetting.name)}
|
|
|
|
</label>
|
|
|
|
</Col>
|
|
|
|
<Col xs={9}>
|
|
|
|
<input name="name"
|
|
|
|
onChange={this.changeBot}
|
|
|
|
onBlur={this.updateBot}
|
|
|
|
value={this.props.deviceAccount.body.name} />
|
|
|
|
</Col>
|
|
|
|
</Highlight>
|
2017-06-29 12:54:02 -06:00
|
|
|
</Row>
|
|
|
|
<Row>
|
2020-02-18 12:21:09 -07:00
|
|
|
<Highlight settingName={DeviceSetting.timezone}>
|
|
|
|
<Col xs={ColWidth.label}>
|
|
|
|
<label>
|
|
|
|
{t("TIME ZONE")}
|
|
|
|
</label>
|
|
|
|
</Col>
|
|
|
|
<Col xs={ColWidth.description}>
|
|
|
|
<div className="note">
|
|
|
|
{this.maybeWarnTz()}
|
|
|
|
</div>
|
2020-02-28 09:34:28 -07:00
|
|
|
<TimezoneSelector
|
|
|
|
currentTimezone={this.props.deviceAccount.body.timezone}
|
|
|
|
onUpdate={this.handleTimezone} />
|
2020-02-18 12:21:09 -07:00
|
|
|
</Col>
|
|
|
|
</Highlight>
|
2017-06-29 12:54:02 -06:00
|
|
|
</Row>
|
2020-02-15 11:29:31 -07:00
|
|
|
<CameraSelection
|
|
|
|
env={this.props.env}
|
|
|
|
botOnline={botOnline}
|
|
|
|
saveFarmwareEnv={this.props.saveFarmwareEnv}
|
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
|
|
|
dispatch={this.props.dispatch} />
|
|
|
|
<BoardType
|
|
|
|
botOnline={botOnline}
|
|
|
|
bot={bot}
|
|
|
|
alerts={this.props.alerts}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
|
|
|
timeSettings={this.props.timeSettings}
|
|
|
|
sourceFbosConfig={sourceFbosConfig} />
|
2020-02-26 13:08:49 -07:00
|
|
|
<OtaTimeSelectorRow
|
|
|
|
timeSettings={this.props.timeSettings}
|
2020-02-15 11:29:31 -07:00
|
|
|
device={this.props.deviceAccount}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
sourceFbosConfig={sourceFbosConfig} />
|
2020-02-26 13:08:49 -07:00
|
|
|
<AutoUpdateRow
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
sourceFbosConfig={sourceFbosConfig} />
|
2020-02-15 11:29:31 -07:00
|
|
|
<FarmbotOsRow
|
|
|
|
bot={this.props.bot}
|
|
|
|
osReleaseNotesHeading={this.osReleaseNotes.heading}
|
|
|
|
osReleaseNotes={this.osReleaseNotes.notes}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
sourceFbosConfig={sourceFbosConfig}
|
|
|
|
shouldDisplay={this.props.shouldDisplay}
|
|
|
|
botOnline={botOnline}
|
|
|
|
botToMqttLastSeen={new Date(this.props.botToMqttLastSeen).getTime()}
|
|
|
|
timeSettings={this.props.timeSettings}
|
|
|
|
deviceAccount={this.props.deviceAccount} />
|
|
|
|
<AutoSyncRow
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
sourceFbosConfig={sourceFbosConfig} />
|
|
|
|
{this.props.shouldDisplay(Feature.boot_sequence) &&
|
|
|
|
<BootSequenceSelector />}
|
|
|
|
<PowerAndReset
|
|
|
|
controlPanelState={this.props.bot.controlPanelState}
|
|
|
|
dispatch={this.props.dispatch}
|
|
|
|
sourceFbosConfig={sourceFbosConfig}
|
|
|
|
botOnline={botOnline} />
|
2017-06-29 12:54:02 -06:00
|
|
|
</WidgetBody>
|
|
|
|
</form>
|
|
|
|
</Widget>;
|
|
|
|
}
|
|
|
|
}
|