Comitt of all things done before I forgot about it. beginnings of a restructuring, I think...
This commit is contained in:
@@ -32,6 +32,9 @@ const ICONS = {
|
||||
YAML: mdiCodeJson,
|
||||
};
|
||||
|
||||
import { TreeNode} from "./script-graph";
|
||||
import { Action } from "./types";
|
||||
|
||||
const OPTIONS = [
|
||||
"condition",
|
||||
"delay",
|
||||
@@ -44,10 +47,14 @@ const OPTIONS = [
|
||||
"choose",
|
||||
];
|
||||
|
||||
interface NodeHandler {
|
||||
(action, selected: any[], select, update): TreeNode;
|
||||
}
|
||||
|
||||
const SPECIAL = {
|
||||
condition: (action, selected, select, update) => {
|
||||
return {
|
||||
icon: ICONS["choose"],
|
||||
icon: ICONS["condition"],
|
||||
clickCallback: () => select([1], action, update),
|
||||
children: [
|
||||
{
|
||||
@@ -164,13 +171,16 @@ const SPECIAL = {
|
||||
|
||||
};
|
||||
|
||||
interface NoAction {
|
||||
}
|
||||
|
||||
export class ActionHandler {
|
||||
_actions = [];
|
||||
_actions: (Action | NoAction)[] = [];
|
||||
updateCallback = null;
|
||||
selectCallback = null;
|
||||
selected = [];
|
||||
selected: number[] = [];
|
||||
|
||||
constructor(actions = []) {
|
||||
constructor(actions: (Action | NoAction)[] = []) {
|
||||
this._actions = actions;
|
||||
}
|
||||
|
||||
@@ -184,10 +194,10 @@ export class ActionHandler {
|
||||
}
|
||||
|
||||
get graph() {
|
||||
return this.actions.map((_, idx) => this._make_graph_node(idx));
|
||||
return this.actions.map((action, idx) => this._make_graph_node(idx, action));
|
||||
}
|
||||
|
||||
_update_action(idx, action) {
|
||||
_update_action(idx: number, action) {
|
||||
if(action === null)
|
||||
this.actions.splice(idx, 1);
|
||||
else
|
||||
@@ -196,21 +206,20 @@ export class ActionHandler {
|
||||
this.updateCallback(this.actions);
|
||||
}
|
||||
|
||||
_add_action(idx) {
|
||||
_add_action(idx: number) {
|
||||
this.actions.splice(idx, 0, {});
|
||||
if (this.updateCallback)
|
||||
this.updateCallback(this.actions);
|
||||
this._select_node([idx], {}, (a) =>this._update_action(idx, a));
|
||||
}
|
||||
|
||||
_select_node(idx, action, update=null) {
|
||||
this.selected = idx;
|
||||
_select_node(path: number[], action, update=null) {
|
||||
this.selected = path;
|
||||
if (this.selectCallback)
|
||||
this.selectCallback(idx, action, update);
|
||||
this.selectCallback(path, action, update);
|
||||
}
|
||||
|
||||
_make_graph_node(idx) {
|
||||
const action = this.actions[idx] || {};
|
||||
_make_graph_node(idx: number, action): TreeNode {
|
||||
let _type = "yaml";
|
||||
if (Object.keys(action).length === 0)
|
||||
_type = "new";
|
||||
@@ -218,7 +227,7 @@ export class ActionHandler {
|
||||
_type = OPTIONS.find((option) => option in action) || "YAML";
|
||||
|
||||
const selected = this.selected.length >= 1 && this.selected[0] == idx;
|
||||
let node = {};
|
||||
let node: TreeNode = {icon: ""};
|
||||
|
||||
if (_type in SPECIAL) {
|
||||
node = SPECIAL[_type](
|
||||
|
||||
Reference in New Issue
Block a user