easy_flow 0.49.1 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/builds/easy_flow/canvas.js +1 -3
- data/app/controllers/easy_flow/manage/canvas_controller.rb +11 -2
- data/app/javascript/easy_flow/canvas/Canvas.jsx +2 -4
- data/app/javascript/easy_flow/canvas/Inspector.jsx +2 -1
- data/app/javascript/easy_flow/canvas/Joint.jsx +8 -6
- data/app/javascript/easy_flow/canvas/LeftToRight.jsx +105 -33
- data/app/javascript/easy_flow/canvas/RunView.jsx +1 -1
- data/app/javascript/easy_flow/canvas/StepCard.jsx +1 -4
- data/app/javascript/easy_flow/canvas/StepRows.jsx +56 -0
- data/app/javascript/easy_flow/canvas/graph.js +223 -0
- data/app/models/easy_flow/all_or_any.rb +2 -0
- data/app/models/easy_flow/canvas.rb +15 -3
- data/app/models/easy_flow/compare.rb +9 -0
- data/app/models/easy_flow/compare_two_values.rb +13 -0
- data/app/models/easy_flow/condition.rb +1 -0
- data/app/models/easy_flow/count.rb +8 -0
- data/app/models/easy_flow/data_step.rb +1 -0
- data/app/models/easy_flow/flow_step.rb +6 -0
- data/app/models/easy_flow/play_flows.rb +1 -0
- data/app/models/easy_flow/settings.rb +46 -6
- data/app/models/easy_flow/steps/checklist.rb +1 -0
- data/app/models/easy_flow/steps/file_upload.rb +1 -0
- data/app/models/easy_flow/steps/fill_in_the_blank.rb +1 -0
- data/app/models/easy_flow/steps/multiple_select.rb +1 -0
- data/app/models/easy_flow/steps/question.rb +5 -0
- data/app/models/easy_flow/switch.rb +2 -0
- data/app/models/easy_flow/wait.rb +8 -0
- data/lib/easy_flow/host.rb +12 -0
- data/lib/easy_flow/version.rb +1 -1
- data/the_local/agents/easy_flow-develop.md +3 -3
- data/the_local/agents/easy_flow-info.md +6 -4
- data/the_local/agents/easy_flow-install.md +3 -2
- metadata +3 -2
- data/app/javascript/easy_flow/canvas/reading.js +0 -52
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import Joint from "./Joint"
|
|
3
|
+
import { layOut } from "./graph"
|
|
4
|
+
|
|
5
|
+
const stack = { display: "flex", flexDirection: "column", gap: 14, padding: "64px 16px 24px" }
|
|
6
|
+
|
|
7
|
+
const box = { display: "flex", flexDirection: "column", gap: 10, padding: "8px 10px", borderRadius: 8 }
|
|
8
|
+
|
|
9
|
+
const connection = { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8, minHeight: 26, paddingLeft: 12, fontSize: 11 }
|
|
10
|
+
|
|
11
|
+
const byPlace = (places) => (a, b) => places[a.id].column - places[b.id].column || places[a.id].row - places[b.id].row
|
|
12
|
+
|
|
13
|
+
const nameOf = (node) => (node?.placeholder ? "nowhere yet" : node?.label)
|
|
14
|
+
|
|
15
|
+
const Row = ({ node, leaving, named, draw, joints }) => (
|
|
16
|
+
<div data-step-row={node.id}>
|
|
17
|
+
{draw(node)}
|
|
18
|
+
{leaving.map((link) => (
|
|
19
|
+
<Joint key={link.id} link={link} {...joints} alwaysShowInsertButtons shown
|
|
20
|
+
className="border-l border-gray-300 text-gray-500 dark:border-zinc-600 dark:text-gray-400" style={connection}>
|
|
21
|
+
<span>{[ link.label, "→", named.get(link.target) ].filter(Boolean).join(" ")}</span>
|
|
22
|
+
</Joint>
|
|
23
|
+
))}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const StepRows = ({ nodes, edges, draw, joints, children, style }) => {
|
|
28
|
+
const { places } = layOut(nodes, edges)
|
|
29
|
+
const named = new Map(nodes.map((node) => [ node.id, nameOf(node) ]))
|
|
30
|
+
const leaving = new Map(nodes.map((node) => [ node.id, [] ]))
|
|
31
|
+
edges.forEach((edge) => { if (leaving.has(edge.source) && named.has(edge.target)) leaving.get(edge.source).push(edge) })
|
|
32
|
+
const holders = new Map(nodes.flatMap((group) => (group.holds || []).map((id) => [ id, group.id ])))
|
|
33
|
+
const ordered = [ ...nodes ].sort(byPlace(places))
|
|
34
|
+
const inside = new Map()
|
|
35
|
+
ordered.filter((node) => holders.has(node.id)).forEach((node) => {
|
|
36
|
+
if (!inside.has(holders.get(node.id))) inside.set(holders.get(node.id), [])
|
|
37
|
+
inside.get(holders.get(node.id)).push(node)
|
|
38
|
+
})
|
|
39
|
+
const row = (node) => <Row key={node.id} node={node} leaving={leaving.get(node.id)} named={named} draw={draw} joints={joints} />
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div data-flow-rows style={{ ...stack, ...style }}>
|
|
43
|
+
{children}
|
|
44
|
+
{ordered.filter((node) => !holders.has(node.id)).map((node) => (node.holds
|
|
45
|
+
? (
|
|
46
|
+
<div key={node.id} data-group-box={node.id} className="border border-dashed border-gray-400 bg-white/60 dark:border-zinc-600 dark:bg-zinc-900/60" style={box}>
|
|
47
|
+
{row(node)}
|
|
48
|
+
{(inside.get(node.id) || []).map(row)}
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
: row(node)))}
|
|
52
|
+
</div>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default StepRows
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
const columnsOf = (ids, edges) => {
|
|
2
|
+
const columns = new Map(ids.map((id) => [ id, 0 ]))
|
|
3
|
+
const outgoing = new Map(ids.map((id) => [ id, [] ]))
|
|
4
|
+
const waiting = new Map(ids.map((id) => [ id, 0 ]))
|
|
5
|
+
edges.forEach((edge) => {
|
|
6
|
+
outgoing.get(edge.source).push(edge.target)
|
|
7
|
+
waiting.set(edge.target, waiting.get(edge.target) + 1)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const ready = ids.filter((id) => waiting.get(id) === 0)
|
|
11
|
+
for (let at = 0; at < ready.length; at++) {
|
|
12
|
+
const id = ready[at]
|
|
13
|
+
outgoing.get(id).forEach((target) => {
|
|
14
|
+
columns.set(target, Math.max(columns.get(target), columns.get(id) + 1))
|
|
15
|
+
waiting.set(target, waiting.get(target) - 1)
|
|
16
|
+
if (waiting.get(target) === 0) ready.push(target)
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return columns
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const outgoingOf = (ids, edges) => {
|
|
24
|
+
const outgoing = new Map(ids.map((id) => [ id, [] ]))
|
|
25
|
+
edges.forEach((edge) => outgoing.get(edge.source).push(edge))
|
|
26
|
+
return outgoing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const loopingBack = (ids, edges) => {
|
|
30
|
+
const outgoing = outgoingOf(ids, edges)
|
|
31
|
+
const entered = new Set(edges.map((edge) => edge.target))
|
|
32
|
+
const state = new Map()
|
|
33
|
+
const backward = new Set()
|
|
34
|
+
|
|
35
|
+
const walk = (root) => {
|
|
36
|
+
const stack = [ [ root, 0 ] ]
|
|
37
|
+
state.set(root, "open")
|
|
38
|
+
while (stack.length > 0) {
|
|
39
|
+
const top = stack[stack.length - 1]
|
|
40
|
+
const edge = outgoing.get(top[0])[top[1]++]
|
|
41
|
+
if (!edge) {
|
|
42
|
+
state.set(top[0], "done")
|
|
43
|
+
stack.pop()
|
|
44
|
+
} else if (state.get(edge.target) === "open") backward.add(edge)
|
|
45
|
+
else if (!state.has(edge.target)) {
|
|
46
|
+
state.set(edge.target, "open")
|
|
47
|
+
stack.push([ edge.target, 0 ])
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
ids.filter((id) => !entered.has(id)).forEach(walk)
|
|
53
|
+
ids.forEach((id) => { if (!state.has(id)) walk(id) })
|
|
54
|
+
|
|
55
|
+
return backward
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const rowsOf = (ids, forward, columns) => {
|
|
59
|
+
const stacks = []
|
|
60
|
+
ids.forEach((id) => (stacks[columns.get(id)] ||= []).push(id))
|
|
61
|
+
const outgoing = outgoingOf(ids, forward)
|
|
62
|
+
const exits = new Map()
|
|
63
|
+
outgoing.forEach((leaving) => leaving.forEach((edge, at) => exits.set(edge, (at + 1) / (leaving.length + 1))))
|
|
64
|
+
const incoming = new Map(ids.map((id) => [ id, [] ]))
|
|
65
|
+
forward.forEach((edge) => incoming.get(edge.target).push(edge))
|
|
66
|
+
const rows = new Map()
|
|
67
|
+
|
|
68
|
+
stacks.forEach((stack) => {
|
|
69
|
+
const keyOf = new Map(stack.map((id) => {
|
|
70
|
+
const from = incoming.get(id)
|
|
71
|
+
const total = from.reduce((sum, edge) => sum + rows.get(edge.source) + exits.get(edge), 0)
|
|
72
|
+
return [ id, from.length > 0 ? total / from.length : Infinity ]
|
|
73
|
+
}))
|
|
74
|
+
stack.sort((a, b) => (keyOf.get(a) === keyOf.get(b) ? 0 : keyOf.get(a) < keyOf.get(b) ? -1 : 1))
|
|
75
|
+
stack.forEach((id, row) => rows.set(id, row))
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return rows
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const CARD_WIDTH = 184
|
|
82
|
+
export const CARD_HEIGHT = 64
|
|
83
|
+
export const COLUMN_GAP = 64
|
|
84
|
+
export const ROW_GAP = 24
|
|
85
|
+
export const MARGIN = 40
|
|
86
|
+
export const EXIT = 40
|
|
87
|
+
export const CHANNEL_GAP = 14
|
|
88
|
+
|
|
89
|
+
const startsOf = (sizes, gap, from) => {
|
|
90
|
+
const starts = []
|
|
91
|
+
sizes.forEach((size, at) => { starts[at] = at === 0 ? from : starts[at - 1] + sizes[at - 1] + gap })
|
|
92
|
+
return starts
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const endOf = (starts, sizes) => (starts.length > 0 ? starts[starts.length - 1] + sizes[sizes.length - 1] : 0)
|
|
96
|
+
|
|
97
|
+
const deepestOf = (values) => {
|
|
98
|
+
const levels = [ values ]
|
|
99
|
+
for (let width = 1; width * 2 <= values.length; width *= 2) {
|
|
100
|
+
const below = levels[levels.length - 1]
|
|
101
|
+
levels.push(below.slice(0, values.length - width * 2 + 1).map((value, at) => Math.max(value, below[at + width])))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (from, to) => {
|
|
105
|
+
const level = Math.floor(Math.log2(to - from + 1))
|
|
106
|
+
return Math.max(levels[level][from], levels[level][to - (1 << level) + 1])
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const arrange = (ids, edges, sizeOf, room) => {
|
|
111
|
+
const backward = loopingBack(ids, edges)
|
|
112
|
+
const forward = edges.filter((edge) => !backward.has(edge))
|
|
113
|
+
const columns = columnsOf(ids, forward)
|
|
114
|
+
const rows = rowsOf(ids, forward, columns)
|
|
115
|
+
|
|
116
|
+
const columnWidths = []
|
|
117
|
+
const stacks = []
|
|
118
|
+
ids.forEach((id) => {
|
|
119
|
+
columnWidths[columns.get(id)] = Math.max(columnWidths[columns.get(id)] || 0, sizeOf(id).width)
|
|
120
|
+
;(stacks[columns.get(id)] ||= [])[rows.get(id)] = id
|
|
121
|
+
})
|
|
122
|
+
const skipping = (edge) => columns.get(edge.target) > columns.get(edge.source) + 1
|
|
123
|
+
const channelsOf = (taken) => {
|
|
124
|
+
const channels = new Map()
|
|
125
|
+
taken.forEach((edge) => { if (!channels.has(edge.target)) channels.set(edge.target, channels.size) })
|
|
126
|
+
return channels
|
|
127
|
+
}
|
|
128
|
+
const above = channelsOf(edges.filter((edge) => backward.has(edge)))
|
|
129
|
+
const below = channelsOf(forward.filter(skipping))
|
|
130
|
+
|
|
131
|
+
const lefts = startsOf(columnWidths, COLUMN_GAP, room.left)
|
|
132
|
+
const top = room.top + above.size * CHANNEL_GAP
|
|
133
|
+
const tops = new Map()
|
|
134
|
+
const bottoms = stacks.map((stack) => {
|
|
135
|
+
const heights = stack.map((id) => sizeOf(id).height)
|
|
136
|
+
startsOf(heights, ROW_GAP, top).forEach((y, at) => tops.set(stack[at], y))
|
|
137
|
+
return endOf(startsOf(heights, ROW_GAP, top), heights)
|
|
138
|
+
})
|
|
139
|
+
const lowestBetween = deepestOf(bottoms)
|
|
140
|
+
|
|
141
|
+
const places = Object.fromEntries(ids.map((id) => [ id, {
|
|
142
|
+
column: columns.get(id), row: rows.get(id),
|
|
143
|
+
x: lefts[columns.get(id)], y: tops.get(id), width: sizeOf(id).width, height: sizeOf(id).height
|
|
144
|
+
} ]))
|
|
145
|
+
|
|
146
|
+
const floors = new Map()
|
|
147
|
+
forward.filter(skipping).forEach((edge) => floors.set(edge.target,
|
|
148
|
+
Math.max(floors.get(edge.target) || 0, lowestBetween(columns.get(edge.source) + 1, columns.get(edge.target) - 1))))
|
|
149
|
+
|
|
150
|
+
const channelOf = (edge) => {
|
|
151
|
+
if (backward.has(edge)) return room.top + (above.size - 1 - above.get(edge.target)) * CHANNEL_GAP
|
|
152
|
+
if (skipping(edge)) return floors.get(edge.target) + (below.get(edge.target) + 1) * CHANNEL_GAP
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const arrivingAt = (id) => places[id].y + (sizeOf(id).arrives ?? places[id].height / 2)
|
|
157
|
+
const heading = (edge) => channelOf(edge) ?? arrivingAt(edge.target)
|
|
158
|
+
const leavingAt = new Map()
|
|
159
|
+
outgoingOf(ids, edges).forEach((leaving) => [ ...leaving ].sort((a, b) => heading(a) - heading(b))
|
|
160
|
+
.forEach((edge, at) => leavingAt.set(edge, (at + 1) / (leaving.length + 1))))
|
|
161
|
+
|
|
162
|
+
const routed = (edge) => {
|
|
163
|
+
const from = places[edge.source]
|
|
164
|
+
const to = places[edge.target]
|
|
165
|
+
const leaving = from.y + from.height * leavingAt.get(edge)
|
|
166
|
+
const arriving = arrivingAt(edge.target)
|
|
167
|
+
const turn = lefts[from.column] + columnWidths[from.column] + EXIT
|
|
168
|
+
const channel = channelOf(edge)
|
|
169
|
+
const start = [ [ from.x + from.width, leaving ], [ turn, leaving ] ]
|
|
170
|
+
const end = [ [ to.x - COLUMN_GAP + EXIT, arriving ], [ to.x, arriving ] ]
|
|
171
|
+
|
|
172
|
+
return { ...edge.drawn, points: channel === null ? [ ...start, [ turn, arriving ], end[1] ] : [ ...start, [ turn, channel ], [ end[0][0], channel ], ...end ] }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const links = edges.map(routed)
|
|
176
|
+
const corners = [ ...Object.values(places).map((card) => [ card.x + card.width, card.y + card.height ]), ...links.flatMap((each) => each.points) ]
|
|
177
|
+
const farthest = corners.reduce(([ right, low ], [ x, y ]) => [ Math.max(right, x), Math.max(low, y) ], [ 0, 0 ])
|
|
178
|
+
|
|
179
|
+
return { places, links, width: farthest[0] + room.right, height: farthest[1] + room.bottom }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const ENTRY = "\u0000entry"
|
|
183
|
+
const HEADER_HEIGHT = 24
|
|
184
|
+
const OUTSIDE = { left: COLUMN_GAP - EXIT + MARGIN / 2, top: MARGIN, right: MARGIN / 2, bottom: MARGIN }
|
|
185
|
+
const INSIDE = { left: 0, top: 8, right: 16, bottom: 12 }
|
|
186
|
+
|
|
187
|
+
export const layOut = (nodes, given, { heights = {} } = {}) => {
|
|
188
|
+
const drawn = new Set(nodes.map((node) => node.id))
|
|
189
|
+
const holders = new Map(nodes.flatMap((group) => (group.holds || []).filter((id) => drawn.has(id)).map((id) => [ id, group.id ])))
|
|
190
|
+
const levels = new Map([ [ null, { ids: [], edges: [] } ] ])
|
|
191
|
+
nodes.filter((node) => node.holds).forEach((group) => levels.set(group.id, { ids: [ ENTRY ], edges: [] }))
|
|
192
|
+
nodes.forEach((node) => levels.get(holders.get(node.id) ?? null).ids.push(node.id))
|
|
193
|
+
|
|
194
|
+
given.filter((edge) => drawn.has(edge.source) && drawn.has(edge.target)).forEach((edge) => {
|
|
195
|
+
const inside = holders.get(edge.target)
|
|
196
|
+
if (inside && inside === edge.source) levels.get(inside).edges.push({ source: ENTRY, target: edge.target, drawn: edge })
|
|
197
|
+
else if (inside && inside === holders.get(edge.source)) levels.get(inside).edges.push({ source: edge.source, target: edge.target, drawn: edge })
|
|
198
|
+
else levels.get(null).edges.push({ source: holders.get(edge.source) ?? edge.source, target: inside ?? edge.target, drawn: edge })
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
const cardSize = (id) => ({ width: CARD_WIDTH, height: heights[id] || CARD_HEIGHT })
|
|
202
|
+
const insides = new Map([ ...levels ].filter(([ group ]) => group).map(([ group, level ]) =>
|
|
203
|
+
[ group, arrange(level.ids, level.edges, (id) => (id === ENTRY ? { width: 0, height: CARD_HEIGHT } : cardSize(id)), INSIDE) ]))
|
|
204
|
+
const headerOf = (id) => heights[id] || HEADER_HEIGHT
|
|
205
|
+
const sizeOf = (id) => {
|
|
206
|
+
const inside = insides.get(id)
|
|
207
|
+
if (!inside) return cardSize(id)
|
|
208
|
+
return { width: inside.width, height: headerOf(id) + inside.height, arrives: headerOf(id) + inside.places[ENTRY].y + CARD_HEIGHT / 2 }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const outside = arrange(levels.get(null).ids, levels.get(null).edges, sizeOf, OUTSIDE)
|
|
212
|
+
const places = { ...outside.places }
|
|
213
|
+
const links = [ ...outside.links ]
|
|
214
|
+
insides.forEach((inside, group) => {
|
|
215
|
+
const box = outside.places[group]
|
|
216
|
+
const [ x, y ] = [ box.x, box.y + headerOf(group) ]
|
|
217
|
+
Object.entries(inside.places).filter(([ id ]) => id !== ENTRY)
|
|
218
|
+
.forEach(([ id, place ]) => { places[id] = { ...place, x: place.x + x, y: place.y + y } })
|
|
219
|
+
inside.links.forEach((each) => links.push({ ...each, points: each.points.map(([ px, py ]) => [ px + x, py + y ]) }))
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
return { places, links, width: outside.width, height: outside.height }
|
|
223
|
+
}
|
|
@@ -16,6 +16,8 @@ module EasyFlow
|
|
|
16
16
|
|
|
17
17
|
output :result, type: :boolean, values: [ true, false ]
|
|
18
18
|
|
|
19
|
+
summarizes_by { |node| Array(node.config["comparisons"]).size.then { |count| "#{node.config["join"]} #{count} #{"comparison".pluralize(count)}" } }
|
|
20
|
+
|
|
19
21
|
def route(node, state, times)
|
|
20
22
|
comparisons = Array(node.config["comparisons"])
|
|
21
23
|
return false if comparisons.empty?
|
|
@@ -20,13 +20,21 @@ module EasyFlow
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def drawn_step(node)
|
|
23
|
-
{ "id" => node.id, "type" => node.type, "type_name" => step_type_for(node)&.step_name, "label" => label_for(node), "summary" =>
|
|
23
|
+
{ "id" => node.id, "type" => node.type, "type_name" => step_type_for(node)&.step_name, "label" => label_for(node), "summary" => summary_of(node), "details" => drawn_by_type(node, :details_of).to_a, "links" => drawn_by_type(node, :links_of).to_a,
|
|
24
24
|
"config" => node.config.merge(kept_values(node)), "ports" => [], "ends_here" => ends_here?(node), "begins_here" => begins_here?(node),
|
|
25
25
|
"starts_a_flow" => starts_a_flow?(node), "holds" => holds(node), "opens" => opens(node), "loose" => loose?(node), "choices" => choices_for(node), "record_choices" => record_choices_for(node), "placeholder" => false, "picture_url" => picture_url(node), **placed[node.id] }
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def summary_of(node)
|
|
29
|
+
drawn_safely(node, :summary_of) { (@host&.summarizes?(node.type) ? @host : step_type_for(node))&.summary_of(node) }
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
def drawn_by_type(node, part)
|
|
29
|
-
step_type_for(node)&.public_send(part, node)
|
|
33
|
+
drawn_safely(node, part) { step_type_for(node)&.public_send(part, node) }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def drawn_safely(node, part)
|
|
37
|
+
yield
|
|
30
38
|
rescue StandardError => error
|
|
31
39
|
Rails.logger.error("EasyFlow could not draw step #{node.id}'s #{part}: #{error.class}: #{error.message}")
|
|
32
40
|
nil
|
|
@@ -171,7 +179,11 @@ module EasyFlow
|
|
|
171
179
|
|
|
172
180
|
def choices_for(node)
|
|
173
181
|
naming_steps(node).index_with { earlier_than(node) }.merge(naming_flows(node).index_with { offered_flows })
|
|
174
|
-
.merge(drawn_by(node)).merge(named_outputs_by(node))
|
|
182
|
+
.merge(drawn_by(node)).merge(named_outputs_by(node)).merge(worked_out_choices(node))
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def worked_out_choices(node)
|
|
186
|
+
drawn_safely(node, :options) { step_type_for(node)&.settings&.worked_out_choices(node.config) }.to_h.transform_keys(&:to_s)
|
|
175
187
|
end
|
|
176
188
|
|
|
177
189
|
def record_choices_for(node)
|
|
@@ -13,6 +13,15 @@ module EasyFlow
|
|
|
13
13
|
|
|
14
14
|
output :result, type: :boolean, values: [ true, false ]
|
|
15
15
|
|
|
16
|
+
summarizes_by { |node| [ node.config.values_at("step", "output").compact_blank.join("."), node.config["comparison"], Compare.amount_of(node.config["amount"]) ].compact_blank.join(" ") }
|
|
17
|
+
|
|
18
|
+
def self.amount_of(value)
|
|
19
|
+
number = Float(value.to_s, exception: false)
|
|
20
|
+
return value if number.nil?
|
|
21
|
+
|
|
22
|
+
number == number.round ? number.to_i.to_s : number.to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
16
25
|
def route(node, state, times)
|
|
17
26
|
number = Float(CompletedAt.value_of(state, times, *node.config.values_at("step", "output")).to_s, exception: false)
|
|
18
27
|
return false if number.nil?
|
|
@@ -15,6 +15,19 @@ module EasyFlow
|
|
|
15
15
|
|
|
16
16
|
output :result, type: :boolean, values: [ true, false ]
|
|
17
17
|
|
|
18
|
+
summarizes_by { |node| CompareTwoValues.summarized(node.config) }
|
|
19
|
+
|
|
20
|
+
def self.summarized(config)
|
|
21
|
+
[ config.values_at("step", "output").compact_blank.join("."), config["comparison"], compared_with(config) ].compact_blank.join(" ")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.compared_with(config)
|
|
25
|
+
amount = Compare.amount_of(config["amount"])
|
|
26
|
+
return amount if config["other_step"].blank?
|
|
27
|
+
|
|
28
|
+
[ config.values_at("other_step", "other_output").compact_blank.join("."), ("+ #{amount}" if amount.present?) ].compact.join(" ")
|
|
29
|
+
end
|
|
30
|
+
|
|
18
31
|
def route(node, state, times)
|
|
19
32
|
first = number(CompletedAt.value_of(state, times, *node.config.values_at("step", "output")))
|
|
20
33
|
second = node.config["other_step"].present? ? number(CompletedAt.value_of(state, times, *node.config.values_at("other_step", "other_output"))) : 0.0
|
|
@@ -12,6 +12,7 @@ module EasyFlow
|
|
|
12
12
|
output :result, type: :boolean, values: [ true, false ]
|
|
13
13
|
|
|
14
14
|
names_by { |node| node.config.values_at("step", "comparison", "answer").compact_blank.join(" ").presence }
|
|
15
|
+
summarizes_by { |node| [ node.config.values_at("step", "output").compact_blank.join("."), *node.config.values_at("comparison", "answer") ].compact_blank.join(" ") }
|
|
15
16
|
|
|
16
17
|
def route(node, state)
|
|
17
18
|
answer = state[node.config["step"]]
|
|
@@ -11,6 +11,14 @@ module EasyFlow
|
|
|
11
11
|
output :count, type: :integer
|
|
12
12
|
|
|
13
13
|
names_by { |node| [ "Count", *node.config.values_at("step", "answer") ].compact_blank.join(" ") }
|
|
14
|
+
summarizes_by { |node| Count.summarized(node.config) }
|
|
15
|
+
|
|
16
|
+
def self.summarized(config)
|
|
17
|
+
return if config["step"].blank?
|
|
18
|
+
|
|
19
|
+
counted = config.values_at("step", "output").compact_blank.join(".")
|
|
20
|
+
config["answer"].blank? ? "counts every answer to #{counted}" : "counts #{counted} is #{config["answer"]}"
|
|
21
|
+
end
|
|
14
22
|
|
|
15
23
|
def process(node, state)
|
|
16
24
|
visits(node, state).count { |answer| counted?(node, answer) }
|
|
@@ -9,6 +9,7 @@ module EasyFlow
|
|
|
9
9
|
|
|
10
10
|
setting(:values, type: :list, label: "Values it reports") { setting :name, type: :string, required: true }
|
|
11
11
|
outputs_named_by :values
|
|
12
|
+
summarizes_by { |node| Array(node.config["values"]).filter_map { |value| value["name"].presence }.then { |names| "reports #{names.join(", ")}" if names.any? } }
|
|
12
13
|
|
|
13
14
|
output :result, values: %w[passed failed]
|
|
14
15
|
output :reason
|
|
@@ -14,6 +14,12 @@ module EasyFlow
|
|
|
14
14
|
waits_until { |_node, _state| false }
|
|
15
15
|
|
|
16
16
|
names_by { |node| ChosenFlow.of(node).name }
|
|
17
|
+
summarizes_by { |node| FlowStep.steps_in(node)&.then { |count| "#{count} #{"step".pluralize(count)}" } }
|
|
18
|
+
|
|
19
|
+
def self.steps_in(node)
|
|
20
|
+
version = ChosenFlow.of(node).version
|
|
21
|
+
Array(version.definition.to_h["nodes"]).count { |step| %w[start terminal].exclude?(step["type"]) } if version
|
|
22
|
+
end
|
|
17
23
|
|
|
18
24
|
def self.endings_of(node)
|
|
19
25
|
version = ChosenFlow.of(node).version
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
module EasyFlow
|
|
2
2
|
class Settings
|
|
3
|
+
class OptionsUnavailable < StandardError
|
|
4
|
+
attr_reader :setting
|
|
5
|
+
|
|
6
|
+
def initialize(setting, cause)
|
|
7
|
+
@setting = setting
|
|
8
|
+
super("#{setting} options could not be worked out: #{cause.class}: #{cause.message}")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
3
12
|
attr_reader :fields, :labels, :explanations, :record_fields, :record_labels, :record_explanations, :record_choices, :record_outputs_of, :record_required, :drawn_from, :outputs_of
|
|
4
13
|
|
|
5
14
|
def initialize(fields: {}, labels: {}, explanations: {}, record_fields: {}, record_labels: {}, record_explanations: {}, record_choices: {}, record_outputs_of: {}, record_required: {}, choices: {},
|
|
@@ -24,7 +33,30 @@ module EasyFlow
|
|
|
24
33
|
end
|
|
25
34
|
|
|
26
35
|
def choices
|
|
27
|
-
@choices.transform_values { |offered|
|
|
36
|
+
@choices.transform_values { |offered| depends_on_settings?(offered) ? [] : worked_out(offered) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def choices_for(config)
|
|
40
|
+
choices.merge(worked_out_choices(config))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def worked_out_choices(config)
|
|
44
|
+
@choices.select { |_name, offered| depends_on_settings?(offered) }.to_h do |name, offered|
|
|
45
|
+
[ name, offered.call(config.to_h) ]
|
|
46
|
+
rescue StandardError => error
|
|
47
|
+
raise OptionsUnavailable.new(labels[name], error)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def strays(config)
|
|
52
|
+
worked_out_choices(config).filter_map do |name, offered|
|
|
53
|
+
chosen = config.to_h[name.to_s]
|
|
54
|
+
name.to_s if chosen.present? && values_of(offered).exclude?(chosen)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def cleared(config)
|
|
59
|
+
config.to_h.merge(strays(config).index_with(nil))
|
|
28
60
|
end
|
|
29
61
|
|
|
30
62
|
def kept_values(config)
|
|
@@ -66,17 +98,25 @@ module EasyFlow
|
|
|
66
98
|
end
|
|
67
99
|
|
|
68
100
|
def objections(config)
|
|
69
|
-
|
|
101
|
+
offered = choices_for(config)
|
|
102
|
+
config.to_h.flat_map { |name, value| objections_to(name.to_sym, value, offered) }.compact
|
|
70
103
|
end
|
|
71
104
|
|
|
72
105
|
private
|
|
73
106
|
|
|
74
|
-
def
|
|
75
|
-
|
|
107
|
+
def worked_out(offered)
|
|
108
|
+
offered.respond_to?(:call) ? offered.call : offered
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def depends_on_settings?(offered)
|
|
112
|
+
offered.respond_to?(:arity) && offered.arity == 1
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def objections_to(name, value, offered)
|
|
116
|
+
[ unoffered(name, value, offered[name]), over_limit(name, value), refused(name, value) ]
|
|
76
117
|
end
|
|
77
118
|
|
|
78
|
-
def unoffered(name, value)
|
|
79
|
-
offered = choices[name]
|
|
119
|
+
def unoffered(name, value, offered)
|
|
80
120
|
return unless offered
|
|
81
121
|
|
|
82
122
|
stray = Array(value).find { |chosen| values_of(offered).exclude?(chosen) }
|
|
@@ -14,6 +14,7 @@ module EasyFlow
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
names_by :question
|
|
17
|
+
summarizes_by { |node| Question.summarized(node.config) }
|
|
17
18
|
awaits_input
|
|
18
19
|
drawn_by "easy_flow/steps/ticking"
|
|
19
20
|
answer_check { |node, value| "Tick at least one to go on." if node.config["required"] && Array(value).compact_blank.empty? }
|
|
@@ -12,6 +12,7 @@ module EasyFlow
|
|
|
12
12
|
setting :required, type: :boolean
|
|
13
13
|
|
|
14
14
|
names_by :question
|
|
15
|
+
summarizes_by { |node| FileUpload.accepted_extensions(node).then { |extensions| "accepts #{extensions.join(", ")}" if extensions.any? } }
|
|
15
16
|
awaits_input
|
|
16
17
|
drawn_by "easy_flow/steps/uploading"
|
|
17
18
|
answer_check { |node, value| FileUpload.problem_with(node, value) }
|
|
@@ -20,6 +20,7 @@ module EasyFlow
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
names_by :question
|
|
23
|
+
summarizes_by { |node| Array(node.config["accepted_answers"]).size.then { |count| "accepts #{count} #{"answer".pluralize(count)}" } }
|
|
23
24
|
awaits_input
|
|
24
25
|
drawn_by "easy_flow/steps/typing"
|
|
25
26
|
answer_check { |node, value| "Type an answer to go on." if node.config["required"] && value.blank? }
|
|
@@ -16,6 +16,7 @@ module EasyFlow
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
names_by :question
|
|
19
|
+
summarizes_by { |node| Question.summarized(node.config) }
|
|
19
20
|
awaits_input
|
|
20
21
|
drawn_by "easy_flow/steps/ticking"
|
|
21
22
|
answer_check { |node, value| "Pick at least one answer to go on." if node.config["required"] && Array(value).compact_blank.empty? }
|
|
@@ -20,6 +20,7 @@ module EasyFlow
|
|
|
20
20
|
output :answer, type: :string, label: "Answer", values: ->(node) { Question.offered(node.config) }
|
|
21
21
|
|
|
22
22
|
names_by :question
|
|
23
|
+
summarizes_by { |node| Question.summarized(node.config) }
|
|
23
24
|
awaits_input
|
|
24
25
|
answer_check { |node, value| "Fill this in to go on." if node.config["required"] && value.blank? }
|
|
25
26
|
|
|
@@ -29,6 +30,10 @@ module EasyFlow
|
|
|
29
30
|
step.to_h["question"] || step.to_h["text"]
|
|
30
31
|
end
|
|
31
32
|
|
|
33
|
+
def self.summarized(step)
|
|
34
|
+
answers_of(step).size.then { |count| "#{count} #{"answer".pluralize(count)}" }
|
|
35
|
+
end
|
|
36
|
+
|
|
32
37
|
def self.answers_of(step)
|
|
33
38
|
Array(step.to_h["answers"] || step.to_h["options"])
|
|
34
39
|
end
|
|
@@ -10,6 +10,7 @@ module EasyFlow
|
|
|
10
10
|
setting :date, type: :string, label: "Date, as YYYY-MM-DD"
|
|
11
11
|
|
|
12
12
|
names_by { |node| Wait.named(node.config) }
|
|
13
|
+
summarizes_by { |node| Wait.summarized(node.config) }
|
|
13
14
|
|
|
14
15
|
waits_until { |node, _state, times| Wait.held_until(node, times)&.then { |held| held <= Time.current } || false }
|
|
15
16
|
|
|
@@ -20,6 +21,13 @@ module EasyFlow
|
|
|
20
21
|
"#{waited} after #{config["step"]}" if waited
|
|
21
22
|
end
|
|
22
23
|
|
|
24
|
+
def self.summarized(config)
|
|
25
|
+
until_then = config["date"].presence || config["time_of_day"].presence
|
|
26
|
+
return "waits until #{until_then}" if until_then
|
|
27
|
+
|
|
28
|
+
"waits #{config["minutes"]} #{"minute".pluralize(config["minutes"].to_i)}" if config["minutes"].present?
|
|
29
|
+
end
|
|
30
|
+
|
|
23
31
|
def self.held_until(node, times)
|
|
24
32
|
from = times[node.config["step"]]
|
|
25
33
|
return Time.zone.parse(node.config["date"]) if node.config["date"].present?
|
data/lib/easy_flow/host.rb
CHANGED
|
@@ -85,6 +85,18 @@ module EasyFlow
|
|
|
85
85
|
@step_groups || {}
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
def summaries=(summaries)
|
|
89
|
+
@summaries = summaries.to_h.transform_keys(&:to_s)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def summarizes?(step_type)
|
|
93
|
+
@summaries.to_h.key?(step_type.to_s)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def summary_of(node)
|
|
97
|
+
@summaries.to_h[node.type.to_s]&.call(node).presence
|
|
98
|
+
end
|
|
99
|
+
|
|
88
100
|
def explanation_for(step_type, setting)
|
|
89
101
|
@setting_explanations.to_h.dig(step_type.to_s, setting.to_s).presence
|
|
90
102
|
end
|
data/lib/easy_flow/version.rb
CHANGED