easy_flow 0.32.1 → 0.34.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 -1
- data/app/controllers/concerns/easy_flow/manage/draws_canvas.rb +5 -2
- data/app/controllers/easy_flow/flows_controller.rb +3 -0
- data/app/controllers/easy_flow/manage/canvas_controller.rb +26 -12
- data/app/controllers/easy_flow/manage/flows_controller.rb +1 -0
- data/app/javascript/easy_flow/canvas/Canvas.jsx +15 -8
- data/app/javascript/easy_flow/canvas/Connector.jsx +5 -5
- data/app/javascript/easy_flow/canvas/ConnectorLayer.jsx +3 -3
- data/app/javascript/easy_flow/canvas/Panel.jsx +19 -4
- data/app/javascript/easy_flow/canvas/StepCard.jsx +15 -4
- data/app/javascript/easy_flow/canvas/TypePicker.jsx +2 -2
- data/app/javascript/easy_flow/canvas/changes.js +6 -0
- data/app/javascript/easy_flow/canvas/flowSender.js +10 -1
- data/app/javascript/easy_flow/canvas/useFlow.js +3 -2
- data/app/models/easy_flow/canvas.rb +23 -13
- data/app/models/easy_flow/change.rb +11 -1
- data/app/models/easy_flow/data_step.rb +33 -0
- data/app/models/easy_flow/definition.rb +5 -0
- data/app/models/easy_flow/document.rb +11 -0
- data/app/models/easy_flow/inputs.rb +24 -0
- data/app/models/easy_flow/progress/kept.rb +4 -0
- data/app/models/easy_flow/progress/loose.rb +4 -0
- data/app/models/easy_flow/read_data.rb +11 -0
- data/app/models/easy_flow/runner.rb +9 -1
- data/app/models/easy_flow/step_type/declaration.rb +5 -1
- data/app/models/easy_flow/step_type.rb +3 -2
- data/app/models/easy_flow/unconnected_steps.rb +44 -0
- data/app/models/easy_flow/write_data.rb +11 -0
- data/app/views/easy_flow/flows/refused.html.erb +3 -0
- data/app/views/easy_flow/manage/flows/show.html.erb +5 -1
- data/lib/easy_flow/engine.rb +2 -0
- data/lib/easy_flow/host.rb +17 -3
- data/lib/easy_flow/version.rb +1 -1
- data/lib/easy_flow.rb +1 -1
- data/the_local/agents/easy_flow-develop.md +30 -3
- data/the_local/agents/easy_flow-info.md +11 -1
- data/the_local/agents/easy_flow-install.md +23 -5
- data/the_local/interface.yml +6 -0
- metadata +7 -1
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
module EasyFlow
|
|
2
2
|
module Change
|
|
3
3
|
PHRASING = { "added" => "Added", "updated" => "Updated", "removed" => "Removed",
|
|
4
|
-
"moved" => "Moved", "connected" => "Connected", "disconnected" => "Disconnected", "returned" => "Returned to"
|
|
4
|
+
"moved" => "Moved", "connected" => "Connected", "disconnected" => "Disconnected", "returned" => "Returned to",
|
|
5
|
+
"removed_unconnected" => "Removed unconnected" }.freeze
|
|
6
|
+
|
|
7
|
+
def self.listed(changes)
|
|
8
|
+
changes.chunk_while { |earlier, later| saves_to_one_step?(earlier, later) }.map { |saves| phrase(saves.last) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.saves_to_one_step?(earlier, later)
|
|
12
|
+
earlier["action"] == "updated" && later["action"] == "updated" && earlier["steps"] == later["steps"]
|
|
13
|
+
end
|
|
5
14
|
|
|
6
15
|
def self.phrase(change)
|
|
7
16
|
named = Array(change["named"]).compact_blank.map { |name| "“#{name}”" }
|
|
8
17
|
verb = PHRASING.fetch(change["action"], change["action"])
|
|
9
18
|
|
|
19
|
+
return "#{verb} #{named.join(', ')}" if named.any? && change["action"] == "removed_unconnected"
|
|
10
20
|
return "#{verb} #{named.join(' → ')}" if named.any?
|
|
11
21
|
return "#{verb} #{change['detail']}" if change["detail"].present?
|
|
12
22
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module EasyFlow
|
|
2
|
+
module DataStep
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
include Inputs
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
names_by :data
|
|
8
|
+
needs_a_saved_run "Data can only be read or written in a flow that saves its runs."
|
|
9
|
+
|
|
10
|
+
setting(:values, type: :list, label: "Values it reports") { setting :name, type: :string, required: true }
|
|
11
|
+
outputs_named_by :values
|
|
12
|
+
|
|
13
|
+
output :result, values: %w[passed failed]
|
|
14
|
+
output :reason
|
|
15
|
+
output :answer
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def process(node, state)
|
|
19
|
+
raise ArgumentError, "#{node.config["data"]} is not offered by this step" unless self.class.step_type.settings.choices[:data].include?(node.config["data"])
|
|
20
|
+
|
|
21
|
+
answer = ActiveRecord::Base.transaction(requires_new: true) do
|
|
22
|
+
EasyFlow.data_source.carry_out(node.config["data"], Inputs.values_of(node, state))
|
|
23
|
+
end.as_json
|
|
24
|
+
(answer.is_a?(Hash) ? answer : { "answer" => answer }).merge("result" => "passed")
|
|
25
|
+
rescue => error
|
|
26
|
+
{ "result" => "failed", "reason" => error.message }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def route(node, state)
|
|
30
|
+
state.dig(node.id, "result")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -61,6 +61,11 @@ module EasyFlow
|
|
|
61
61
|
update!(undo_history: edit_history.undoable, changes_since_version: [], undone_changes: [])
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
def remove_unconnected(steps)
|
|
65
|
+
create_version
|
|
66
|
+
edit_history.record(Document.new(document).without(steps), :removed_unconnected, steps, document)
|
|
67
|
+
end
|
|
68
|
+
|
|
64
69
|
def returning_to(version)
|
|
65
70
|
{ "action" => "returned", "steps" => [], "named" => [],
|
|
66
71
|
"detail" => "version #{version.number}", "before" => document }
|
|
@@ -47,6 +47,12 @@ module EasyFlow
|
|
|
47
47
|
found
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
def unconnected
|
|
51
|
+
return [] unless entry
|
|
52
|
+
|
|
53
|
+
nodes.map(&:id).uniq - reachable - beginnings
|
|
54
|
+
end
|
|
55
|
+
|
|
50
56
|
def to_h
|
|
51
57
|
@document
|
|
52
58
|
end
|
|
@@ -103,6 +109,11 @@ module EasyFlow
|
|
|
103
109
|
edges: (raw_edges - incoming - outgoing) + bridges(incoming, outgoing))
|
|
104
110
|
end
|
|
105
111
|
|
|
112
|
+
def without(ids)
|
|
113
|
+
Document.new(@document.merge("nodes" => raw_nodes.reject { |node| ids.include?(node["id"]) },
|
|
114
|
+
"edges" => raw_edges.reject { |edge| ids.include?(edge["from"]) || ids.include?(edge["to"]) }), registry: @registry)
|
|
115
|
+
end
|
|
116
|
+
|
|
106
117
|
private
|
|
107
118
|
|
|
108
119
|
def bridges(incoming, outgoing)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module EasyFlow
|
|
2
|
+
module Inputs
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
setting :inputs, type: :list do
|
|
7
|
+
setting :name, type: :string, required: true
|
|
8
|
+
setting :value, type: :string
|
|
9
|
+
setting :step, type: :previous_step, label: "Earlier step"
|
|
10
|
+
setting :output, outputs_of: :step, label: "Earlier step's output"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.values_of(node, state)
|
|
15
|
+
Array(node.config["inputs"]).to_h { |input| [ input["name"], input["step"].present? ? latest_output(input, state) : input["value"] ] }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.latest_output(input, state)
|
|
19
|
+
latest_visit = state.keys.select { |key| key.split("@").first == input["step"] }.max_by { |key| key.split("@")[1].to_i }
|
|
20
|
+
CompletedAt.value_of(state, {}, latest_visit, input["output"])
|
|
21
|
+
end
|
|
22
|
+
private_class_method :latest_output
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -29,13 +29,17 @@ module EasyFlow
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def run(progress)
|
|
32
|
-
while (node = @digest.next_step(named(progress.recorded), named(progress.completed_at))) && goes_on?(node, named(progress.recorded), CompletedAt.latest(named(progress.completed_at)))
|
|
32
|
+
while (node = @digest.next_step(named(progress.recorded), named(progress.completed_at))) && goes_on?(node, named(progress.recorded), CompletedAt.latest(named(progress.completed_at))) && (progress.saved? || refusal_of(node).nil?)
|
|
33
33
|
progress.record(node.id, result_of(@digest.step(node.id), named(progress.recorded)))
|
|
34
34
|
end
|
|
35
35
|
progress.start_inner(node) if node && starts_a_flow?(node)
|
|
36
36
|
progress.ended unless node
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
def unsaved_refusal(state, times: {})
|
|
40
|
+
refusal_of(@digest.next_step(named(state), named(times)))
|
|
41
|
+
end
|
|
42
|
+
|
|
39
43
|
def fills_in_next?(state)
|
|
40
44
|
node = @digest.next_step(named(state))
|
|
41
45
|
node.present? && decided?(node, state)
|
|
@@ -59,6 +63,10 @@ module EasyFlow
|
|
|
59
63
|
|
|
60
64
|
private
|
|
61
65
|
|
|
66
|
+
def refusal_of(node)
|
|
67
|
+
@registry.fetch(node.type).unsaved_refusal if node && @registry.registered?(node.type)
|
|
68
|
+
end
|
|
69
|
+
|
|
62
70
|
def starts_a_flow?(node)
|
|
63
71
|
@registry.registered?(node.type) && @registry.fetch(node.type).starts_a_flow?
|
|
64
72
|
end
|
|
@@ -59,6 +59,10 @@ module EasyFlow
|
|
|
59
59
|
@answer_labelling = labelling
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
def needs_a_saved_run(refusal)
|
|
63
|
+
@unsaved_refusal = refusal
|
|
64
|
+
end
|
|
65
|
+
|
|
62
66
|
def comes_back_while(&return_rule)
|
|
63
67
|
@return_rule = return_rule
|
|
64
68
|
end
|
|
@@ -151,7 +155,7 @@ module EasyFlow
|
|
|
151
155
|
StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
|
|
152
156
|
ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, plays_the_picked_flow: @plays_the_picked_flow, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
|
|
153
157
|
display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming,
|
|
154
|
-
outputs: @declared_outputs, outputs_named_by: @outputs_named_by, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness, return_rule: @return_rule)
|
|
158
|
+
outputs: @declared_outputs, outputs_named_by: @outputs_named_by, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness, return_rule: @return_rule, unsaved_refusal: @unsaved_refusal)
|
|
155
159
|
end
|
|
156
160
|
|
|
157
161
|
def settings
|
|
@@ -4,11 +4,11 @@ module EasyFlow
|
|
|
4
4
|
Declaration.new(id).tap { |decl| decl.instance_eval(&declaration) }.to_step_type
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
attr_reader :id, :step_name, :settings, :naming_field, :naming, :outputs, :drawn_by
|
|
7
|
+
attr_reader :id, :step_name, :settings, :naming_field, :naming, :outputs, :drawn_by, :unsaved_refusal
|
|
8
8
|
|
|
9
9
|
def initialize(id:, step_name:, settings:, awaits_input:, behaviour:, routing:,
|
|
10
10
|
ends_here: false, begins_here: false, starts_a_flow: false, plays_the_picked_flow: false, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
|
|
11
|
-
naming_field: nil, naming: nil, outputs: [], outputs_named_by: nil, answer_check: nil, answer_labelling: nil, readiness: nil, return_rule: nil)
|
|
11
|
+
naming_field: nil, naming: nil, outputs: [], outputs_named_by: nil, answer_check: nil, answer_labelling: nil, readiness: nil, return_rule: nil, unsaved_refusal: nil)
|
|
12
12
|
@id = id
|
|
13
13
|
@step_name = step_name
|
|
14
14
|
@settings = settings
|
|
@@ -31,6 +31,7 @@ module EasyFlow
|
|
|
31
31
|
@answer_labelling = answer_labelling
|
|
32
32
|
@readiness = readiness
|
|
33
33
|
@return_rule = return_rule
|
|
34
|
+
@unsaved_refusal = unsaved_refusal
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def display_of(node, run = nil)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module EasyFlow
|
|
2
|
+
class UnconnectedSteps
|
|
3
|
+
def initialize(document, flow: nil, registry: EasyFlow.registry)
|
|
4
|
+
@document = document
|
|
5
|
+
@flow = flow
|
|
6
|
+
@registry = registry
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def ids
|
|
10
|
+
@document.unconnected
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def named
|
|
14
|
+
ids.map { |id| { "id" => id, "label" => Name.of(@document.node(id), @registry) } }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def accepted?(named_steps)
|
|
18
|
+
Array(named_steps).map(&:to_s).sort == ids.map(&:to_s).sort
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def objections
|
|
22
|
+
Validator.new(staying, registry: @registry, flow: @flow).violations + readers
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def readers
|
|
28
|
+
staying.nodes.select { |node| entries_naming(node).intersect?(ids) }
|
|
29
|
+
.map { |node| Violation.new(node: node.id, problem: :reading_an_unconnected_step) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def entries_naming(node)
|
|
33
|
+
return [] unless @registry.registered?(node.type)
|
|
34
|
+
|
|
35
|
+
@registry.fetch(node.type).settings.record_fields.flat_map do |list, holds|
|
|
36
|
+
Array(node.config[list.to_s]).flat_map { |entry| entry.to_h.values_at(*holds.select { |_name, type| type == :previous_step }.keys.map(&:to_s)) }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def staying
|
|
41
|
+
@document.without(ids)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
<%= ui_button(label: "Back to #{@parent.title.presence || @parent.slug}", href: flow_routes.manage_flow_path(@parent), variant: :secondary) %>
|
|
21
21
|
<% end %>
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
<% if @back_link %>
|
|
24
|
+
<%= ui_button(label: @back_link.label, href: @back_link.address, variant: :secondary) %>
|
|
25
|
+
<% else %>
|
|
26
|
+
<%= ui_button(label: "All flows", href: flow_routes.manage_flows_path, variant: :secondary) %>
|
|
27
|
+
<% end %>
|
|
24
28
|
</div>
|
|
25
29
|
</header>
|
|
26
30
|
|
data/lib/easy_flow/engine.rb
CHANGED
|
@@ -29,6 +29,8 @@ module EasyFlow
|
|
|
29
29
|
EasyFlow::CompareTwoValues.register
|
|
30
30
|
EasyFlow::AllOrAny.register
|
|
31
31
|
EasyFlow::Count.register
|
|
32
|
+
EasyFlow::ReadData.register
|
|
33
|
+
EasyFlow::WriteData.register
|
|
32
34
|
EasyFlow::Wait.register
|
|
33
35
|
EasyFlow::FlowStep.register
|
|
34
36
|
EasyFlow::PlayFlows.register
|
data/lib/easy_flow/host.rb
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
module EasyFlow
|
|
2
2
|
class Host
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
BackLink = Data.define(:label, :address)
|
|
4
|
+
|
|
5
|
+
attr_reader :name, :back_link
|
|
6
|
+
attr_writer :layout, :admin_layout, :offers, :allowed_answers, :always_show_insert_buttons, :hide_step_type_codes
|
|
7
|
+
attr_accessor :admin_authentication_method, :visitor_authorization_method, :refusal_method, :owner_method, :finds_flows_across_owners, :publish_note
|
|
6
8
|
|
|
7
9
|
def initialize(name)
|
|
8
10
|
@name = name.to_s
|
|
9
11
|
end
|
|
10
12
|
|
|
13
|
+
def back_link=(link)
|
|
14
|
+
@back_link = link && BackLink.new(**link)
|
|
15
|
+
end
|
|
16
|
+
|
|
11
17
|
def layout
|
|
12
18
|
@layout || "easy_flow/application"
|
|
13
19
|
end
|
|
@@ -28,6 +34,14 @@ module EasyFlow
|
|
|
28
34
|
@allowed_answers&.call(step, answers)
|
|
29
35
|
end
|
|
30
36
|
|
|
37
|
+
def always_show_insert_buttons?
|
|
38
|
+
@always_show_insert_buttons.present?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def hide_step_type_codes?
|
|
42
|
+
@hide_step_type_codes.present?
|
|
43
|
+
end
|
|
44
|
+
|
|
31
45
|
def offers?(step_type)
|
|
32
46
|
@offers.nil? || @offers.map(&:to_s).include?(step_type.to_s)
|
|
33
47
|
end
|
data/lib/easy_flow/version.rb
CHANGED
data/lib/easy_flow.rb
CHANGED
|
@@ -9,7 +9,7 @@ This local follows the steps below exactly and invents none. Where a step names
|
|
|
9
9
|
|
|
10
10
|
## What easy_flow is
|
|
11
11
|
|
|
12
|
-
A Rails engine for flows an admin draws on a canvas and a visitor runs one step at a time. Each step is an instance of a step type. The engine ships
|
|
12
|
+
A Rails engine for flows an admin draws on a canvas and a visitor runs one step at a time. Each step is an instance of a step type. The engine ships seventeen: start (`:start`), end (`:terminal`, whose one setting is the output an admin writes for a flow that ends there), question (`:question`, a question with a list of answers of which the visitor picks one, which the admin can mark required so a blank answer is refused), checklist (`:checklist`, a question with a list of answers of which the visitor ticks any number, which the admin can mark required so a visitor who ticks nothing is refused), Multiple select (`:multiple_select`, a question with a category and a list of answers, each with a value, a label and a weight, of which the visitor ticks any number, recording the list of ticked values, which the admin can mark required so a visitor who ticks nothing is refused with `Pick at least one answer to go on.`), Fill in the blank (`:fill_in_the_blank`, a question with a category and a list of accepted answers, each with a value, which the visitor answers by typing into a text box, recording the text exactly as typed, whose accepted answers are never sent to the visitor's page, which the admin can mark required so a visitor who types nothing or only spaces is refused with `Type an answer to go on.`; easy_flow records the answer and does not mark it right or wrong), File upload (`:file_upload`, a question the visitor answers by choosing one file from a file upload control labelled with the question text, with an admin setting listing the accepted file types as comma-separated extensions such as `.pdf, .png`, which limits the visitor's file picker to those types and is shown under the control as `Accepts` followed by the list as the admin wrote it, such as `Accepts .pdf, .png`, which the admin can mark required so a visitor who chooses no file is refused, and whose recorded answer is the reference the host's file store returned for the file), five that pick a branch from earlier answers with no code — condition (`:condition`, is or is not a chosen value, where the admin must pick one of the earlier step's outputs and the answer is read from that output when the earlier step recorded several and whole otherwise, so a Condition cannot be completed on a step whose type declares no output), switch (`:switch`, follows the connection labelled with the answer), compare (`:compare`, reads the answer as a number, from the output the admin picks when the earlier step recorded several, and checks it by more than, less than, at least or at most against an amount) and Compare two values (`:compare_two_values`, reads the answers of two earlier steps the admin picks as numbers, reading each from the output the admin picks when that step recorded several, and checks the first by more than, less than, at least, at most or equal to against the second plus an amount the admin may give, a blank amount adding nothing, checking the first against the amount alone when the admin leaves the second step empty, following its `true` or `false` connection, and following `false` when either answer is missing, is an array or is not a number) and All of or Any of (`:all_or_any`, holds a list of comparisons the admin enters and a `Must hold` setting of `all of` or `any of`, where each comparison asks for the same things as a Compare two values step, a step, its output, a comparison, an amount, and an optional second step and its output, and is checked the same way, a comparison with no second step checking the first answer against the amount alone, following its `true` connection when every comparison holds for `all of` or at least one holds for `any of`, and its `false` connection otherwise, including when it holds no comparisons, a comparison whose answer is missing, is an array or is not a number counting as not holding) — Count (`:count`, which acts without the visitor and records a whole number, how many visits to an earlier step the admin picks the run has recorded, counting only visits that gave the answer the admin picks or every visit when the admin picks none, reading that answer from the output the admin picks when the earlier step recorded several, named on the canvas `Count` followed by the earlier step's id and the answer, such as `Count tests failed`, and recording a new count under its own visit key each time a loop reaches it, so a compare step after it can end a loop once the count reaches an amount), Read data and Write data (`:read_data` and `:write_data`, which ask the app to carry out one thing from what it says can be read or written, with named inputs, and follow a `passed` or `failed` connection; `easy_flow-install` sets what the app offers), Wait (`:wait`, which holds the run until a time worked out from an earlier step the admin picks as `Counting from`; see "Hold a run until a time"), and Flow (`:flow_step`, names another flow of the same host and the number of one of its versions, with one connection for each different output that version's End steps write, and named on the canvas by that flow's title and the version number, such as `Intake, version 2`). On a compare, Compare two values or Count step, and in each comparison of an All of or Any of step, once the admin picks an earlier step, the admin must also pick which of that step's outputs to read: until then the step's card shows `missing setting: output`, `missing setting: other_output` for a Compare two values step's second step, or `missing setting: comparisons <n> output` and `missing setting: comparisons <n> other_output` for the comparison at position `n` counting from 1, and saving the flow as a new version and publishing it are refused. When a stored run stops at a Flow step, a run of the named flow is started on the named version, and the first run waits on the Flow step. When the second run ends with an output, that output is recorded in the first run at the Flow step, and the first run moves on along the connection labelled with that output. When the second run ends with no output, nothing is recorded and the first run stays waiting at the Flow step. On a question and on a checklist the admin can give each answer info, a longer explanation the visitor opens with an info button beside that answer. An admin may connect a step back to an earlier one, so a flow can ask the same question more than once, and each visit's answer is kept. The time each step visit was completed is kept together with its recorded value; see "Read when steps were completed". A File upload step takes a file only in a flow the admin set to save each step. In a flow set to save on finish or to save nothing, a visitor who chooses a file is shown `A file can only be uploaded in a flow that saves its runs.` and cannot go on with it. Before writing a step type to ask for one answer or several, to take a file, to branch on an answer or a number, to branch on how two earlier answers compare, to branch on whether all or any of several comparisons hold, to branch on when an earlier step was completed, to count the visits to an earlier step, or to hold a run until a time, ask the developer whether an admin placing one of the built-in types on the canvas is enough. None of condition, switch, compare, Compare two values or All of or Any of reads a checklist's answer, so branching on what a visitor ticked takes a step type of the app's own that defines `route`. Use this local when the app needs a step type of its own, needs a host's flows on its own pages with its own behaviour when a visitor finishes, needs a visitor's earlier answers to decide which answers a later step offers, or needs to read what a visitor answered. It assumes easy_flow is already installed and a host is declared; if not, hand off to `easy_flow-install` first.
|
|
13
13
|
|
|
14
14
|
## Interface
|
|
15
15
|
|
|
@@ -17,6 +17,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
|
|
|
17
17
|
- `EasyFlow.step` — declares and registers a step type in one call from a block of the same words, for a type small enough not to need its own class.
|
|
18
18
|
- `labels_answer_by` — a word in a step type's declaration giving the label a run's recorded answer to a step of that type is shown by, on the completion page and from `EasyFlow::QuestionRunner#choice_label`.
|
|
19
19
|
- `outputs_named_by` — a word in a step type's declaration adding one output for each entry an admin enters in one of the type's list settings, named by that entry, so the admin decides the names of the values the step records.
|
|
20
|
+
- `EasyFlow::Inputs` — a module a step type's class includes, after `EasyFlow::Step`, to declare the list of named inputs an admin fills in, each a fixed value or an output of an earlier step. `EasyFlow::Inputs.values_of(node, state)` returns those values as a hash with string keys, reading a step reached more than once at its latest visit.
|
|
20
21
|
- `host.allowed_answers=` — set on a host to a lambda given a step and the answers recorded so far, returning the answers that step may take in this run: several narrows the answers shown, one is recorded without showing the step, and none records a blank and skips it.
|
|
21
22
|
- `EasyFlow::FlowsController` — the visitor controller; the app subclasses it to serve one host's flows from its own routes and to change what happens at the start, on each step and at the finish.
|
|
22
23
|
- `hosted_by` — class method on a `FlowsController` subclass naming the host whose flows it serves.
|
|
@@ -78,7 +79,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
|
|
|
78
79
|
```
|
|
79
80
|
|
|
80
81
|
A step whose type is not registered is neither shown nor run as that type.
|
|
81
|
-
4. Ask the developer which hosts' admins should be able to add the type. A registered type is in a host's palette, the step types an admin can add on that host's canvas, only when the host names no list of offered step types or its list includes the type's id. A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in none. When a host that names a list should offer the new type, add the type's id to that host's list through `easy_flow-install`. Leaving a type off a host's list only keeps admins from adding it there, and a step of that type already in one of the host's flows is still drawn and run.
|
|
82
|
+
4. Ask the developer which hosts' admins should be able to add the type. A registered type is in a host's palette, the step types an admin can add on that host's canvas, only when the host names no list of offered step types or its list includes the type's id. A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in none. When a host that names a list should offer the new type, add the type's id to that host's list through `easy_flow-install`. Leaving a type off a host's list only keeps admins from adding it there, and a step of that type already in one of the host's flows is still drawn and run, and still opens with all its settings and can be saved.
|
|
82
83
|
5. Use these words to declare the type. Each is called once at class level (or inside the `EasyFlow.step` block):
|
|
83
84
|
- `step_name "<label>"` — the name admins see on the canvas. Defaults to the id.
|
|
84
85
|
- `setting :name, type:, label:, options:, required:, optional:, limit:, check:, from:, outputs_of:, kept_on:, attribute:` — a field the admin fills in on the canvas. `type` is one of `:string`, `:integer`, `:float`, `:boolean`, `:select`, `:multi_select`, `:previous_step`, `:from_step`, `:list`, `:flow`, or boot raises `EasyFlow::UnknownFieldType`. A `:select` or `:multi_select` must pass `options:`, or boot raises the same error. `options:` is either an array of strings, or a lambda taking no arguments that returns one; the lambda is called each time the canvas is opened and each time an admin saves the step's settings, so the options follow the app's data without a restart (`options: -> { Region.order(:name).pluck(:code) }`). A saved setting whose value is no longer among the options is refused the next time the admin saves that step. When the options come from the app's records, ask the developer which records, which column is stored as the value, and whether the list must differ by account or host, since the lambda is passed nothing and the same list is offered everywhere the type is used. A `:list` must take a block of `setting` calls describing one entry. `:previous_step` lets the admin pick an earlier step, and is required unless declared with `optional: true`. Ask the developer whether a step of the type may be left without that earlier step, and when it may, declare `optional: true` and handle a blank value in the type's code. `outputs_of: :<setting>` offers the outputs of the step chosen in that setting, and `from: :<setting>` offers the values of the output chosen in that setting; either one makes the type `:from_step`. A required setting left blank shows `missing setting: <name>` on the step's card, and saving the flow as a new version and publishing it are refused until the admin fills it in. An `outputs_of:` setting left blank is flagged and refused the same way once the setting it reads names a step, whether or not it is declared `required:`. Inside a `:list` entry, a blank required setting, or a blank `outputs_of:` setting whose step is picked, shows `missing setting: <list> <n> <name>` for the entry at position `n` counting from 1. `optional:` has no effect inside a `:list` entry, where a `:previous_step` is required only when declared `required: true`. `:flow` lets the admin pick one of the flows the admin's list shows on the same host, offered by title, and is stored in `node.config` as that flow's id as a string. A `:flow` setting is not checked on save against the flows offered, so code that reads it looks the flow up through the host and handles a blank or unknown id. `limit:` is the most values a `:multi_select` takes. `check:` is a lambda given the value that returns an error message, or `nil` when the value is acceptable. `label:` defaults to the name humanized. `kept_on:` and `attribute:` keep the setting's value on one of the app's own records instead of in the flow; see "Keep a setting on one of the app's records".
|
|
@@ -279,6 +280,31 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
|
|
|
279
280
|
- The app calls `run.advance` where the event is handled, such as a webhook or a job. See "Read a run and its answers". This needs a stored run, so it only applies to a flow the admin set to save each step.
|
|
280
281
|
9. Restart the server, open a flow on the canvas of each host that should offer the type, and check the type is in the palette, its settings show, and a preview walks through it. On a host that names a list of offered step types without the type's id, check the type is not in the palette. For a type that declares `starts_a_flow`, check the step is marked `Runs a flow`, that once a flow is picked in its settings clicking the step goes to that flow's page, that the `Back to` button on that page returns to the flow the step is in, and that its `Settings` button opens its settings. Also check that the step shows `missing flow` while no flow is picked, `unrunnable version` while the version number names no live or replaced version, `circular` while it names the flow it sits in, and that publishing is refused until each is fixed. For a type that declares `chooses_flow`, set the settings the block reads and check that clicking the step goes to the flow the block names, that a type with no `names_by` is named on the canvas by that flow's title and version, and that a run stopping at the step starts a run of that flow on that version. For a type that declares `chooses_flow_from_run`, start a stored run whose owner or answers the block reads, walk it to the step, and check `run.waiting_on` is a run of the flow and version the block names, and that a run for which the block names no flow raises `EasyFlow::InnerFlowError`.
|
|
281
282
|
|
|
283
|
+
### Take named inputs at a step type of the app's own
|
|
284
|
+
|
|
285
|
+
1. Include `EasyFlow::Inputs` after `EasyFlow::Step`, and read the values in `process`:
|
|
286
|
+
|
|
287
|
+
```ruby
|
|
288
|
+
class FlowSteps::Script
|
|
289
|
+
include EasyFlow::Step
|
|
290
|
+
include EasyFlow::Inputs
|
|
291
|
+
|
|
292
|
+
step_name "Script"
|
|
293
|
+
|
|
294
|
+
def process(node, state)
|
|
295
|
+
ScriptRunner.call(EasyFlow::Inputs.values_of(node, state))
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
2. What then holds:
|
|
301
|
+
- The step's settings on the canvas hold an `inputs` list, and each entry takes a name, a fixed value, an earlier step and that step's output.
|
|
302
|
+
- An entry that names an earlier step reads that step's output, at its latest visit when a loop reached it more than once. Any other entry gives its fixed value.
|
|
303
|
+
- `state` in `process` still holds every visit under its own key, so a step type that adds up every visit keeps working.
|
|
304
|
+
- An earlier step that recorded a plain value gives that value for whichever output the entry names.
|
|
305
|
+
- `process` is not given completion times, so an entry naming "Hour completed", "Weekday completed" or "Minutes since 1970 when completed" gives nothing.
|
|
306
|
+
3. Publish a flow set to save each step with a loop back to a question before the step, answer it twice, and check the step reads the second answer.
|
|
307
|
+
|
|
282
308
|
### Keep a setting on one of the app's records
|
|
283
309
|
|
|
284
310
|
Use this when an admin should edit a value that belongs to one of the app's own records, such as a customer's name, from a step's settings on the canvas, and the flow should not hold a copy of it.
|
|
@@ -536,7 +562,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
|
|
|
536
562
|
## Conventions
|
|
537
563
|
|
|
538
564
|
- A step type's id comes from its class name or the id passed to `EasyFlow.step`, and it is stored in flow documents, so renaming the class or id breaks every flow that uses it.
|
|
539
|
-
- Never give a step type one of the built-in ids: `start`, `terminal`, `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `wait`, `flow_step`.
|
|
565
|
+
- Never give a step type one of the built-in ids: `start`, `terminal`, `question`, `checklist`, `multiple_select`, `fill_in_the_blank`, `file_upload`, `condition`, `switch`, `compare`, `compare_two_values`, `all_or_any`, `count`, `read_data`, `write_data`, `wait`, `flow_step`.
|
|
540
566
|
- Register class-based step types inside `to_prepare`. A type registered anywhere else is lost on code reload in development.
|
|
541
567
|
- Registering a type does not put it in the palette of a host that names a list of offered step types without the type's id. Which step types a host offers is set through `easy_flow-install`, not here.
|
|
542
568
|
- A type that declares `ends_here` is in every host's palette, and a type that declares `begins_here` is in no host's palette.
|
|
@@ -555,6 +581,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
|
|
|
555
581
|
- A flow holding a `starts_a_flow` step whose `flow` names no existing flow, or whose `version` names no live or replaced version of it, or whose `flow` leads back to the flow the step sits in directly or through other flows, cannot be saved as a version or published, and these checks cannot be turned off.
|
|
556
582
|
- On the canvas, clicking a step of a `starts_a_flow` type whose `flow` setting names a flow goes to that flow's page, which has a `Back to` button to the flow the step is in, and the step's settings open from its `Settings` button.
|
|
557
583
|
- A `:previous_step` setting is required unless declared `optional: true`, and an `outputs_of:` setting must be filled once the step it reads is picked, or the flow cannot be saved as a version or published.
|
|
584
|
+
- Only the canvas's Create version and Publish requests remove unconnected steps, and only when the request's `remove_unconnected` names exactly the steps unconnected at that moment. `Definition#publish`, `Definition#create_version` and `Validator#violations` never remove one, and `violations` lists each as `unreachable`, so app code that checks `violations` before publishing goes on refusing such a flow. A request that names none is answered with status 422, the refusal in `error`, and the steps in `unconnected`.
|
|
558
585
|
- A type that routes declares the values its output takes, or the canvas offers no connections to label.
|
|
559
586
|
- An output named by `outputs_named_by` takes its name from an entry's `name`, lists no values, and is never a connection leaving the step.
|
|
560
587
|
- A run starts only on a version its own flow has published and not retired or withdrawn, and any other version raises `ActiveRecord::RecordInvalid`.
|
|
@@ -31,6 +31,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
|
|
|
31
31
|
- To branch a flow on several comparisons at once, such as whether a reading is above one amount and a second reading is below another, no code is needed: an admin places an All of or Any of step on the canvas and lists the comparisons.
|
|
32
32
|
- To branch a flow on when a step was completed, such as the hour of the day or the weekday, or on how many minutes passed between two steps being completed, no code is needed: an admin places a Compare or Compare two values step on the canvas and picks one of the completion time outputs.
|
|
33
33
|
- To hold a run for a number of minutes after a step was completed, until the next time of day after it, or until a date, no code is needed: an admin places a Wait step on the canvas.
|
|
34
|
+
- To read from or write to the app inside a flow, no step type is needed: the app says what can be read and written and how, and an admin places a Read data or Write data step on the canvas.
|
|
34
35
|
- To make a visitor answer a question or tick something on a checklist before going on, no code is needed: an admin marks that step as required on the canvas.
|
|
35
36
|
- To let a visitor tick several answers on one step, no code is needed: an admin places a checklist step on the canvas.
|
|
36
37
|
- To explain an answer to the visitor, no code is needed: an admin fills in that answer's info on a question or checklist step.
|
|
@@ -44,6 +45,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
|
|
|
44
45
|
- **Flow** — one guided path, found by its slug within its host. It holds a working document the admin edits and a list of versions.
|
|
45
46
|
- **Document** — the flow's content: its steps (nodes), the connections between them (edges), a headline and a slug.
|
|
46
47
|
- **Version** — a numbered snapshot of the document. A version is a draft until it is published, and a flow has at most one live version at a time. Publishing another version makes the one that was live superseded. A version can also be retired or withdrawn, and a retired or withdrawn version cannot be published again.
|
|
48
|
+
- **Unconnected step** — a step on the canvas the flow does not reach from its start, left to the side until an admin connects it. It stays in the working document through every edit. Create version and Publish warn with each such step's name, and only an admin accepting that warning removes them. Accepting saves a draft version with the steps in it first, which an admin can return to from the history, then creates or publishes the next version without them. A second start step is not counted, and a problem on a step that stays still blocks.
|
|
47
49
|
- **Published version** — a version that is live or superseded, which is any version that has been published and not taken out of service.
|
|
48
50
|
- **Removing a flow** — an admin deleting a flow from the admin's list of flows. It deletes the flow's versions and its runs with it. A run of another flow that one of those runs had started is kept, and no longer records a run that started it. A flow is not removed while a run of it is the inner run that a run of another flow is stopped at a Flow step waiting on. The admin is then told "This flow cannot be removed while" followed by the waiting flow's title, or its slug when it has no title, and "waits on one of its runs".
|
|
49
51
|
- **Canvas** — the admin screen where steps are added, configured, moved, removed and connected, with undo and redo. Publishing happens there.
|
|
@@ -74,6 +76,8 @@ easy_flow declares no commands of its own for this local. Its surface is split b
|
|
|
74
76
|
- **Compare** — a built-in branching step that reads an earlier step's answer as a number and checks it against an amount by more than, less than, at least or at most, then follows the true or the false connection. The admin picks which of the earlier step's outputs to read, as described under chosen output. An answer that is missing or is not a number decides false.
|
|
75
77
|
- **Compare two values** — a built-in branching step that reads two earlier steps' answers as numbers and checks the first against the second by more than, less than, at least, at most or equal to, then follows the true or the false connection. For each side the admin picks which of that step's outputs to read, as described under chosen output. An optional amount is added to the second answer before the check, so "more than" with an amount of 5 is true only when the first answer exceeds the second by more than 5, and a blank amount adds nothing. The second step may be left empty, and the first answer is then checked against the amount alone, or against 0 when the amount is blank too. When either answer is missing or is not a number, the step decides false.
|
|
76
78
|
- **All of or Any of** — a built-in branching step that holds a list of comparisons and a "Must hold" setting of "all of" or "any of", then follows the true or the false connection. Each comparison names an earlier step and which of its outputs to read, then more than, less than, at least, at most or equal to, then an amount, a second step with its output, or both. A comparison with a second step holds the same way a Compare two values step would decide, adding the amount to the second answer, and one with no second step checks the first answer against the amount alone. "All of" decides true only when every comparison holds, and "any of" when at least one does. A comparison whose answer is missing or is not a number does not hold, and a step with no comparisons decides false.
|
|
79
|
+
- **Read data and Write data** — built-in steps that ask the app to carry out one thing from its list of what a flow can read or write, in a nested transaction, then follow the `passed` or the `failed` connection. The step records `result`, `reason` on a failure, and the app's answer: a hash as named outputs, anything else as `answer`. The admin lists the answer's names under "Values it reports" so later steps can pick them. Both need a flow that keeps every answer as it is given. In a flow that keeps nothing or keeps the run only once it finishes, the visitor is told "Data can only be read or written in a flow that saves its runs." when the run reaches the step and cannot go on, and the app is not called.
|
|
80
|
+
- **Input** — a named value a Read data or Write data step passes to the app, either a fixed value or an output of an earlier step. A step reached more than once gives its most recent output.
|
|
77
81
|
- **Completion time** — the time a step was completed, kept for every visit beside the value that visit recorded. Every step that records a value has one, including steps that act on their own and waiting steps, not only steps a visitor answers. A stored run saves it with the run. A flow that carries its answers in the page carries each completion time in the page too, gives a value sent without a time the time it arrived, and drops a time it cannot read. A run stored when such a flow finishes keeps the completion times of the visits on its path. Going back discards the last visit's completion time with its value.
|
|
78
82
|
- **Completion time outputs** — three outputs every step that records a value offers beside its own: "Hour completed", the hour from 0 to 23 in the app's time zone, "Weekday completed", from 1 for Monday to 7 for Sunday, and "Minutes since 1970 when completed", the whole minutes since the start of 1 January 1970 in UTC. Each is read from the completion time of the latest visit to that step, and a step with no completion time has none of them. Compare, Compare two values and All of or Any of read them, so Compare two values with "more than" and an amount of 30 on two steps' minutes is true when the first step was completed more than 30 minutes after the second. Condition and Count list them among a step's outputs but do not read the time when one is picked.
|
|
79
83
|
- **Wait** — a built-in waiting step that holds a run until a time. The admin picks the earlier step it counts from and gives a number of minutes after it, a time of day as HH:MM, or a date as YYYY-MM-DD. A date holds the run until the start of that day in the app's time zone and wins over the other two, and it holds even when the earlier step has no completion time. Otherwise a time of day holds the run until the next time that time of day comes after the earlier step's completion time, the same day when it is still to come and the next day when it is not, and it wins over minutes. With neither, the run is held for the minutes after the earlier step's completion time, and blank minutes hold it not at all. While the earlier step has no completion time and no date is set, the run stays held. It is counted from the completion time of the latest visit to that step. Like any waiting step, once its time has come the run moves past it the next time the visitor's page is loaded or the app moves the run on.
|
|
@@ -93,7 +97,13 @@ easy_flow declares no commands of its own for this local. Its surface is split b
|
|
|
93
97
|
- **Host** — a named part of the app that owns a set of flows. A host sets the visitor layout and the admin layout, how admins are authenticated, how visitors are authorized, how a refusal is answered, and optionally which step types it offers and which answers it allows a step in a run. Flows are always looked up through a host, so one host never sees another's flows.
|
|
94
98
|
- **Offered step types** — the list of step types a host names for its admins to add. A host that names no list offers every registered step type. The list only narrows the palette.
|
|
95
99
|
- **Allowed answers** — a rule a host may carry that looks at a step and the answers given so far in a run and names the answer values that step allows. When it names nothing for a step, the step offers every answer. When it names several, a question or checklist offers only those. When it names exactly one, the step records that answer without being shown, and when it names none, the step is passed over and records a blank answer. This holds in a stored run, a run moved on outside a visitor's request, a flow that carries its answers in the page, and an admin's preview. Going back skips the steps the host filled in and returns to the last step the visitor was shown.
|
|
96
|
-
- **
|
|
100
|
+
- **Always-visible insert buttons** — a setting a host may turn on, `always_show_insert_buttons`, that shows each connection's button for inserting a step on its canvas without the pointer over the connection, with the connection's label moved to the right of the line. It is off by default, and with it off the button shows only with the pointer over the connection.
|
|
101
|
+
- **Hidden step type codes** — a setting a host may turn on, `hide_step_type_codes`, that hides step type code names on its canvas. The add menu lists each step type by its name alone, and a step's box shows its step type's name in place of the code name, with a step that has no name of its own headed by its step type's name. It is off by default, and with it off the add menu and step boxes show the code names. The settings panel shows a step's id and code name either way.
|
|
102
|
+
- **Publish note** — a setting a host may set, `publish_note`, whose sentence is shown directly under the Publish button in its flow panel. With none set, the panel shows no note.
|
|
103
|
+
- **Back link** — a setting a host may set, `back_link`, holding a label and an address, that shows a button with that label and address in its builder header in place of `All flows`. With none set, the header shows `All flows`.
|
|
104
|
+
- **Flow panel** — the panel the `This flow` button opens on the canvas, on every host. It shows Create version and Publish above its lists of problems and changes. Several saves to the same step in a row show as one line in the changes list, named by the step's latest name. A save, a move and any other change each keep their own line, and the history of versions still lists every change a version captured.
|
|
105
|
+
- **Picture mark** — the words `Has a picture` on the box of a step with a picture on the canvas, on every host.
|
|
106
|
+
- **Palette** — the step types an admin can add on a host's canvas. It never holds the start step, always holds the end step, and otherwise holds the step types the host offers. A step already in a flow whose type the host does not offer is still drawn and run, and still opens with all its settings and can be saved.
|
|
97
107
|
- **Run** — one visitor's pass through a flow. A run may belong to one of the app's own records, its owner, which the app sets. A run is pinned to the version it started on, so publishing a new version does not change a run already under way. A run starts on the live version unless the app chooses another of the flow's published versions. A run is refused when the chosen version is a draft, is retired or withdrawn, or belongs to another flow. It records each visit, and going back discards the last visit on the path.
|
|
98
108
|
- **Stored run** and **carried answers** — the two ways a visitor's progress is held. A stored run is saved by the app and found again by its id. A flow that keeps nothing carries the answers given so far, and their completion times, in the page itself and sends them along with each step.
|
|
99
109
|
- **Visit entry** — what a stored run keeps for one visit: the value the step recorded and the step's completion time, held together as one entry. Reading a run's answers gives each visit's value, and reading its completion times gives each visit's time. A run stored before entries existed holds bare values, and the engine's migration wraps each one in an entry with no completion time, and running that migration back unwraps them.
|