pull/1648/head
Rick Carlino 2019-12-26 10:25:03 -06:00
parent cd20fcf943
commit 79690a90a2
4 changed files with 94 additions and 5 deletions

View File

@ -293,6 +293,9 @@ export namespace ToolTips {
For example, you can mark a plant as "planted" during a seeding
sequence or delete a weed after removing it.`);
export const REBOOT =
trim(`Power cycle FarmBot's onboard computer or microcontroller.`);
export const SET_SERVO_ANGLE =
trim(`Move a servo to the provided angle.`);

View File

@ -105,11 +105,11 @@ export function StepButtonCluster(props: StepButtonProps) {
color="brown">
{t("EMERGENCY LOCK")}
</StepButton>,
// <StepButton {...commonStepProps}
// step={{ kind: "reboot", args: { package: "farmbot_os" } }}
// color="brown">
// {t("REBOOT")}
// </StepButton>,
<StepButton {...commonStepProps}
step={{ kind: "reboot", args: { package: "farmbot_os" } }}
color="brown">
{t("REBOOT")}
</StepButton>,
<StepButton{...commonStepProps}
step={{
kind: "find_home",

View File

@ -32,6 +32,7 @@ import { TileMoveHome } from "./tile_move_home";
import { t } from "../../i18next_wrapper";
import { TileAssertion } from "./tile_assertion";
import { TileEmergencyStop } from "./tile_emergency_stop";
import { TileReboot } from "./tile_reboot";
interface MoveParams {
step: Step;
@ -155,6 +156,7 @@ export function renderCeleryNode(props: StepParams) {
case "calibrate": return <TileCalibrate {...props} />;
case "home": return <TileMoveHome {...props} />;
case "reboot":
return <TileReboot {...props} />;
case "check_updates":
case "factory_reset":
return <TileFirmwareAction {...props} />;

View File

@ -0,0 +1,84 @@
import * as React from "react";
import { StepParams } from "../interfaces";
import { ToolTips } from "../../constants";
import { StepWrapper, StepHeader, StepContent } from "../step_ui/index";
import { t } from "../../i18next_wrapper";
import { Row, Col } from "../../ui";
import { ALLOWED_PACKAGES, SequenceBodyItem, Reboot } from "farmbot";
import { editStep } from "../../api/crud";
type StringMap = Record<string, string>;
interface MultiChoiceRadioProps<T extends StringMap> {
uuid: string;
choices: T;
currentChoice: keyof T;
onChange(key: keyof T): void;
}
const MultiChoiceRadio =
<T extends StringMap>(props: MultiChoiceRadioProps<T>) => {
const choices = Object.keys(props.choices);
return <Row>
<Col xs={12}>
<div className="bottom-content">
<div className="channel-fields">
<form>
{choices.map((choice, i) =>
<div key={`${props.uuid} ${i}`} style={{ display: "inline" }}>
<label>
<input type="radio"
value={choice}
onChange={() => props.onChange(choice)}
checked={props.currentChoice === choice} />
{t(props.choices[choice])}
</label>
</div>)}
</form>
</div>
</div>
</Col>
</Row>;
};
const PACKAGE_CHOICES: Record<ALLOWED_PACKAGES, string> = {
"arduino_firmware": "Just the Arduino",
"farmbot_os": "Entire system"
};
function assertReboot(x: SequenceBodyItem): asserts x is Reboot {
if (x.kind !== "reboot") {
throw new Error("Impossible");
}
}
export function TileReboot(props: StepParams) {
const { dispatch, currentStep, index, currentSequence } = props;
const className = "set-zero-step";
assertReboot(currentStep);
return <StepWrapper>
<StepHeader
className={className}
helpText={ToolTips.REBOOT}
currentSequence={currentSequence}
currentStep={currentStep}
dispatch={dispatch}
index={index}
confirmStepDeletion={props.confirmStepDeletion} />
<StepContent className={className}>
<MultiChoiceRadio
uuid={currentSequence.uuid + index}
choices={PACKAGE_CHOICES}
currentChoice={currentStep.args.package as ALLOWED_PACKAGES}
onChange={pkg => dispatch(editStep({
step: currentStep,
index,
sequence: currentSequence,
executor(step) {
assertReboot(step);
step.args.package = pkg;
},
}))} />
</StepContent>
</StepWrapper>;
}