import * as React from "react"; import axios from "axios"; import { t } from "../../i18next_wrapper"; import { FarmbotOsProps, FarmbotOsState } from "../interfaces"; import { Widget, WidgetHeader, WidgetBody, Row, Col } from "../../ui"; import { save, edit } from "../../api/crud"; import { MustBeOnline, isBotOnline } from "../must_be_online"; import { Content } from "../../constants"; 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"; import { FarmbotOsRow } from "./fbos_settings/farmbot_os_row"; import { AutoUpdateRow } from "./fbos_settings/auto_update_row"; 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"; import { BootSequenceSelector } from "./fbos_settings/boot_sequence_selector"; export enum ColWidth { label = 3, description = 7, button = 2 } const OS_RELEASE_NOTES_URL = "https://raw.githubusercontent.com/FarmBot/farmbot_os/staging/RELEASE_NOTES.md"; export class FarmbotOsSettings extends React.Component { state = { osReleaseNotesHeading: "", osReleaseNotes: "" }; componentDidMount() { this.fetchReleaseNotes(OS_RELEASE_NOTES_URL, (this.props.bot.hardware.informational_settings .controller_version || "6").split(".")[0]); } fetchReleaseNotes = (url: string, osMajorVersion: string) => { axios .get(url) .then(resp => { const osReleaseNotes = resp.data .split("# v") .filter(x => x.startsWith(osMajorVersion))[0] .split("\n\n").slice(1).join("\n"); const osReleaseNotesHeading = "FarmBot OS v" + osMajorVersion; this.setState({ osReleaseNotesHeading, osReleaseNotes }); }) .catch(() => this.setState({ osReleaseNotes: "Could not get release notes." })); } changeBot = (e: React.FormEvent) => { const { deviceAccount, dispatch } = this.props; dispatch(edit(deviceAccount, { name: e.currentTarget.value })); } updateBot = () => { const { deviceAccount, dispatch } = this.props; dispatch(save(deviceAccount.uuid)); } handleTimezone = (timezone: string) => { const { deviceAccount, dispatch } = this.props; dispatch(edit(deviceAccount, { timezone })); dispatch(save(deviceAccount.uuid)); } maybeWarnTz = () => { const wrongTZ = timezoneMismatch(this.props.deviceAccount.body.timezone); return wrongTZ ? t(Content.DIFFERENT_TZ_WARNING) : ""; } render() { const { bot, sourceFbosConfig, botToMqttStatus } = this.props; const { sync_status } = bot.hardware.informational_settings; const botOnline = isBotOnline(sync_status, botToMqttStatus); return
e.preventDefault()}>
{this.maybeWarnTz()}
{(location.host.includes("localhost") || !isUndefined(sourceFbosConfig("auto_sync").value)) && }
; } }