2018-08-01 18:20:50 -06:00
|
|
|
import { SequenceBodyItem, TaggedSequence } from "farmbot";
|
2018-04-23 20:33:53 -06:00
|
|
|
import { SelectSequence } from "./interfaces";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { edit, init, overwrite } from "../api/crud";
|
|
|
|
import { defensiveClone } from "../util";
|
2017-11-21 23:38:22 -07:00
|
|
|
import { push } from "../history";
|
|
|
|
import { urlFriendly } from "../util";
|
2018-04-23 20:33:53 -06:00
|
|
|
import { Actions } from "../constants";
|
2018-12-14 17:35:50 -07:00
|
|
|
import { setActiveSequenceByName } from "./set_active_sequence_by_name";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../i18next_wrapper";
|
2019-04-09 19:45:59 -06:00
|
|
|
import { isNumber } from "lodash";
|
2017-06-29 12:54:02 -06:00
|
|
|
|
|
|
|
export function pushStep(step: SequenceBodyItem,
|
|
|
|
dispatch: Function,
|
2019-04-09 19:45:59 -06:00
|
|
|
sequence: TaggedSequence,
|
|
|
|
index?: number | undefined) {
|
2017-08-28 05:49:13 -06:00
|
|
|
const next = defensiveClone(sequence);
|
2017-06-29 12:54:02 -06:00
|
|
|
next.body.body = next.body.body || [];
|
2019-04-09 19:45:59 -06:00
|
|
|
next.body.body.splice(isNumber(index) ? index : Infinity, 0, defensiveClone(step));
|
2017-06-29 12:54:02 -06:00
|
|
|
dispatch(overwrite(sequence, next.body));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function editCurrentSequence(dispatch: Function, seq: TaggedSequence,
|
|
|
|
update: Partial<typeof seq.body>) {
|
|
|
|
dispatch(edit(seq, update));
|
|
|
|
}
|
|
|
|
|
|
|
|
let count = 1;
|
2018-04-23 20:33:53 -06:00
|
|
|
|
2018-12-14 17:35:50 -07:00
|
|
|
export const copySequence = (payload: TaggedSequence) =>
|
|
|
|
(dispatch: Function) => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const copy = defensiveClone(payload);
|
2017-06-29 12:54:02 -06:00
|
|
|
copy.body.id = undefined;
|
2018-06-14 12:48:30 -06:00
|
|
|
copy.body.name = copy.body.name + t(" copy ") + (count++);
|
2018-10-31 14:13:47 -06:00
|
|
|
dispatch(init(copy.kind, copy.body));
|
2017-11-21 23:38:22 -07:00
|
|
|
push("/app/sequences/" + urlFriendly(copy.body.name));
|
2018-12-14 17:35:50 -07:00
|
|
|
setActiveSequenceByName();
|
2017-08-02 14:05:33 -06:00
|
|
|
};
|
2017-06-29 12:54:02 -06:00
|
|
|
|
|
|
|
export function selectSequence(uuid: string): SelectSequence {
|
|
|
|
return {
|
2018-04-23 20:33:53 -06:00
|
|
|
type: Actions.SELECT_SEQUENCE,
|
2017-06-29 12:54:02 -06:00
|
|
|
payload: uuid
|
|
|
|
};
|
|
|
|
}
|
2019-04-09 19:45:59 -06:00
|
|
|
|
|
|
|
export const unselectSequence = () => {
|
|
|
|
push("/app/sequences");
|
|
|
|
return { type: Actions.SELECT_SEQUENCE, payload: undefined };
|
|
|
|
};
|
2019-04-11 21:17:18 -06:00
|
|
|
|
|
|
|
export const closeCommandMenu = () => ({
|
|
|
|
type: Actions.SET_SEQUENCE_STEP_POSITION,
|
|
|
|
payload: undefined,
|
|
|
|
});
|