diff --git a/web/src/automation/StateManager/ScriptRepeat.tsx b/web/src/automation/StateManager/ScriptRepeat.tsx new file mode 100644 index 0000000..803b856 --- /dev/null +++ b/web/src/automation/StateManager/ScriptRepeat.tsx @@ -0,0 +1,36 @@ +import InputNumber from "../../components/InputNumber"; +import InputText from "../../components/InputText"; +import { RepeatScript } from "../types/script"; +import { BaseState } from "./BaseState"; + + +export default class ScriptRepeatState extends BaseState { + defaultState = () => ({ + alias: "Repeat", + repeat: { + count: 1, + sequence: [], + } + }) + isReady(state: RepeatScript): boolean { + return state.alias !== '' && + state?.repeat?.sequence.length > 0 + } + renderOptionList(state: RepeatScript): JSX.Element { + return
+ this.setState({...state, alias})} + /> + this.setState({...state, repeat: {...state.repeat, count}})} + /> +
+ {JSON.stringify(state?.repeat?.sequence)} +
+
+ } +} \ No newline at end of file diff --git a/web/src/automation/StateManager/ScriptWait.tsx b/web/src/automation/StateManager/ScriptWait.tsx new file mode 100644 index 0000000..446995e --- /dev/null +++ b/web/src/automation/StateManager/ScriptWait.tsx @@ -0,0 +1,44 @@ +import InputBoolean from "../../components/InputBoolean"; +import InputNumber from "../../components/InputNumber"; +import InputText from "../../components/InputText"; +import { WaitScript } from "../types/script"; +import { BaseState } from "./BaseState"; + + +export default class ScriptWaitState extends BaseState { + defaultState = () => ({ + alias: "Wait", + wait_template: "", + timeout: 0, + continue_on_timeout: false, + }) + isReady(state: WaitScript): boolean { + return state.alias !== '' && + state.wait_template !== "" + } + renderOptionList(state: WaitScript): JSX.Element { + return
+ this.setState({...state, alias})} + /> + this.setState({...state, wait_template})} + /> + this.setState({...state, timeout})} + /> + this.setState({...state, continue_on_timeout})} + /> +
+ } +} \ No newline at end of file diff --git a/web/src/automation/StateManager/getBaseState.ts b/web/src/automation/StateManager/getBaseState.ts index 577f035..88982db 100644 --- a/web/src/automation/StateManager/getBaseState.ts +++ b/web/src/automation/StateManager/getBaseState.ts @@ -1,16 +1,22 @@ -import { AutomationNode, AutomationNodeType, NodeSubType } from "../types" -import { BaseState } from "./BaseState" +import { AutomationNodeType, NodeSubType } from "../types" +import ScriptRepeatState from "./ScriptRepeat" import ScriptCallServiceState from "./ScriptService" +import ScriptWaitState from "./ScriptWait" export const getBaseState = ( node_type: T, node_subtype: NodeSubType ) : any => { + console.log(node_subtype) if ( node_type === 'action') { switch (node_subtype) { case 'Service': return ScriptCallServiceState + case "Repeat": + return ScriptRepeatState; + case "Wait": + return ScriptWaitState; } } throw new Error(`Invalid or Not implemented node type ${node_type} -> ${node_subtype}`) diff --git a/web/src/components/InputBoolean.tsx b/web/src/components/InputBoolean.tsx new file mode 100644 index 0000000..c73165e --- /dev/null +++ b/web/src/components/InputBoolean.tsx @@ -0,0 +1,26 @@ +import InputWrapper from "./InputWrapper"; + +export interface Props { + label: string; + value: boolean; + onChange: (v: boolean) => void; +} +export default function InputBoolean({ + label, + value=false, + onChange, +}: Props) { + return + { + e.preventDefault() + onChange(!value) + }}> + {value ? '✔️' : ' '} + + +} \ No newline at end of file diff --git a/web/src/components/InputNumber.tsx b/web/src/components/InputNumber.tsx new file mode 100644 index 0000000..88d873b --- /dev/null +++ b/web/src/components/InputNumber.tsx @@ -0,0 +1,25 @@ +import { useToolTip } from "../tooltip/context"; +import InputWrapper from "./InputWrapper"; + +export interface Props { + label: string; + value: number; + onChange: (v: number) => void; +} +export default function InputNumber({ + label, + value=0, + onChange, +}: Props) { + const tooltip = useToolTip(); + return + { + e.preventDefault(); + onChange(Number(e.target.value)) + }} + /> + +} \ No newline at end of file diff --git a/web/src/components/InputWrapper.tsx b/web/src/components/InputWrapper.tsx index d3ff57b..4ec2a0e 100644 --- a/web/src/components/InputWrapper.tsx +++ b/web/src/components/InputWrapper.tsx @@ -1,11 +1,12 @@ -import { PropsWithChildren } from "react"; +import { CSSProperties, PropsWithChildren } from "react"; export interface Props { label: string; + style?: CSSProperties; } -export default function InputWrapper({label, children}: PropsWithChildren) { - return
+export default function InputWrapper({label, children, style={}}: PropsWithChildren) { + return
{children}
diff --git a/web/src/styles/common.scss b/web/src/styles/common.scss index 1a34a50..d873451 100644 --- a/web/src/styles/common.scss +++ b/web/src/styles/common.scss @@ -95,3 +95,26 @@ input { margin: 0; cursor: text; } +input[type="number"]::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + opacity: 0; +} +span.checkbox { + height: 16px; + width: 16px; + font-size: 12px; + cursor: pointer; + border: 1px $primary-accent solid; + align-content: center; + text-align: center; + justify-content: center; + display: flex; + background-color: $primary; + color: $primary-accent; + overflow: hidden; + + &:hover { + background-color: $secondary; + color: $secondary-accent; + } +}