qube_rails 0.2.0 → 0.2.1
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/CHANGELOG.md +216 -0
- data/README.md +242 -69
- data/app/assets/javascripts/qube_rails/question.js +425 -38
- data/app/assets/stylesheets/qube_rails.css +1201 -907
- data/app/controllers/qube_rails/connections_controller.rb +23 -6
- data/app/controllers/qube_rails/questions_controller.rb +39 -7
- data/app/controllers/qube_rails/runs_controller.rb +4 -3
- data/app/models/qube_rails/connection.rb +22 -2
- data/app/models/qube_rails/run.rb +28 -10
- data/app/views/qube_rails/_error.html.erb +2 -2
- data/app/views/qube_rails/_question.html.erb +4 -1
- data/app/views/qube_rails/question/_choice.html.erb +36 -11
- data/app/views/qube_rails/question/_exit_button.html.erb +8 -0
- data/app/views/qube_rails/question/_field.html.erb +4 -3
- data/app/views/qube_rails/question/_footer.html.erb +19 -5
- data/app/views/qube_rails/question/_pick.html.erb +8 -3
- data/app/views/qube_rails/question/_picks.html.erb +4 -2
- data/app/views/qube_rails/question/_question.html.erb +22 -7
- data/app/views/qube_rails/question/_submit.html.erb +9 -0
- data/app/views/qube_rails/question/fields/_boolean.html.erb +2 -2
- data/app/views/qube_rails/question/fields/_number.html.erb +2 -2
- data/app/views/qube_rails/question/fields/_rows.html.erb +17 -4
- data/app/views/qube_rails/question/fields/_search.html.erb +3 -1
- data/app/views/qube_rails/question/fields/_select.html.erb +6 -5
- data/app/views/qube_rails/question/fields/_text.html.erb +2 -2
- data/app/views/qube_rails/question/rows/_segmented.html.erb +3 -1
- data/app/views/qube_rails/run_status/_detail.html.erb +5 -1
- data/app/views/qube_rails/run_status/_status.html.erb +5 -2
- data/config/locales/en.yml +23 -1
- data/db/migrate/20261031000000_add_qube_connection_type_and_run_headline.rb +12 -0
- data/lib/generators/qube_rails/templates/initializer.rb.tt +12 -4
- data/lib/qube_rails/configuration.rb +3 -2
- data/lib/qube_rails/connection_events.rb +3 -0
- data/lib/qube_rails/operation.rb +115 -32
- data/lib/qube_rails/question_view.rb +235 -29
- data/lib/qube_rails/rows_view.rb +18 -5
- data/lib/qube_rails/run_status_view.rb +12 -7
- data/lib/qube_rails/storyboard/ask_about_add.json +8 -10
- data/lib/qube_rails/storyboard/choose.json +8 -5
- data/lib/qube_rails/storyboard/enum_select.json +4 -3
- data/lib/qube_rails/storyboard/missing_record.json +10 -13
- data/lib/qube_rails/storyboard/name_clash.json +10 -18
- data/lib/qube_rails/storyboard/near_match.json +12 -14
- data/lib/qube_rails/storyboard/number_boolean.json +4 -3
- data/lib/qube_rails/storyboard/record_search.json +14 -15
- data/lib/qube_rails/storyboard/refusal.json +10 -18
- data/lib/qube_rails/storyboard/rows.json +11 -14
- data/lib/qube_rails/storyboard.rb +8 -3
- data/lib/qube_rails/sync_status.rb +4 -2
- data/lib/qube_rails/version.rb +1 -1
- data/lib/qube_rails/view_helpers.rb +4 -2
- data/lib/qube_rails.rb +2 -2
- metadata +5 -2
|
@@ -6,22 +6,29 @@ module QubeRails
|
|
|
6
6
|
# The open question of a run, as the question partials render it: the override contract, kept
|
|
7
7
|
# stable across versions (README, "Styling"). Built from the prompt QuBe Sync sent.
|
|
8
8
|
class QuestionView
|
|
9
|
-
attr_reader :prompt, :message, :details, :choices, :token, :action_url, :search_url, :error
|
|
9
|
+
attr_reader :prompt, :message, :details, :choices, :token, :action_url, :search_url, :error,
|
|
10
|
+
:refused_choice, :refused_values
|
|
10
11
|
|
|
11
12
|
# The question run is asking, or nil when it isn't asking. urls answers question_path(run):
|
|
12
|
-
# the engine's route proxy (qube_rails) in a view.
|
|
13
|
-
|
|
13
|
+
# the engine's route proxy (qube_rails) in a view. refusal is flash[:qube_rails_refusal] (a
|
|
14
|
+
# 422 for one of its choices: token, choice, message, values), used when it's this question's.
|
|
15
|
+
def self.from_run(run, urls, error: nil, refusal: nil)
|
|
14
16
|
prompt = run && run.open_question
|
|
15
17
|
return nil unless prompt
|
|
16
18
|
|
|
17
19
|
action = urls.question_path(run)
|
|
18
|
-
new(prompt, action_url: action, search_url: "#{action}/search", error: error)
|
|
20
|
+
new(prompt, action_url: action, search_url: "#{action}/search", error: error, refusal: refusal)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
def initialize(prompt, action_url:, search_url:, error: nil)
|
|
23
|
+
def initialize(prompt, action_url:, search_url:, error: nil, refusal: nil)
|
|
22
24
|
@prompt = prompt
|
|
23
25
|
@message = prompt["message"].to_s
|
|
24
26
|
@token = prompt["token"].to_s
|
|
27
|
+
if refusal.is_a?(Hash) && refusal["token"].to_s == @token
|
|
28
|
+
error ||= refusal["message"]
|
|
29
|
+
@refused_choice = refusal["choice"].to_s
|
|
30
|
+
@refused_values = refusal["values"].is_a?(Hash) ? refusal["values"] : {}
|
|
31
|
+
end
|
|
25
32
|
@details = Array(prompt["details"]).select { |row| row.is_a?(Hash) }
|
|
26
33
|
.map { |row| DetailView.new(row["label"], row["value"]) }
|
|
27
34
|
@action_url = action_url
|
|
@@ -34,43 +41,183 @@ module QubeRails
|
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
# The choices by where they show: picks (option rows), forms (a section each, "or" between),
|
|
37
|
-
# then exits (a footer row). plain? when there's neither a pick nor a form: one
|
|
38
|
-
# choice primary.
|
|
44
|
+
# then exits (a footer row, cancel last). plain? when there's neither a pick nor a form: one
|
|
45
|
+
# row, the first choice primary.
|
|
39
46
|
def picks
|
|
40
47
|
choices.select { |c| c.kind == :pick }
|
|
41
48
|
end
|
|
42
49
|
|
|
50
|
+
# The forms shown as sections. In a chain (chain?) the search ones are its search branch.
|
|
43
51
|
def forms
|
|
44
52
|
choices.select { |c| c.kind == :form }
|
|
45
53
|
end
|
|
46
54
|
|
|
47
55
|
def exits
|
|
48
|
-
choices.select { |c| c.kind == :exit }
|
|
56
|
+
choices.select { |c| c.kind == :exit }.partition { |c| !c.cancel? }.flatten
|
|
49
57
|
end
|
|
50
58
|
|
|
51
59
|
def plain?
|
|
52
60
|
picks.empty? && forms.empty?
|
|
53
61
|
end
|
|
54
62
|
|
|
63
|
+
# The one form whose button row also holds the exits (cancel left, the rest beside its
|
|
64
|
+
# submit): a question with no picks, one form, and exits without descriptions; in a chain, its
|
|
65
|
+
# one search. Else nil, and the exits have a footer row of their own.
|
|
66
|
+
def joined_form
|
|
67
|
+
candidates = if chain? then forms.select { |c| c.role == "search" }
|
|
68
|
+
elsif picks.empty? then forms
|
|
69
|
+
else []
|
|
70
|
+
end
|
|
71
|
+
return nil unless candidates.size == 1 && exits.none?(&:description)
|
|
72
|
+
|
|
73
|
+
candidates.first
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# The exits a joined form's row holds: in a chain, decline and cancel (the search's branch).
|
|
77
|
+
def joined_exits
|
|
78
|
+
chain? ? exits.select { |c| %w[decline cancel].include?(c.role) } : exits
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Offered records with a search: a chain, shown a branch at a time. The offered records come
|
|
82
|
+
# first with "Not this one" / "None of these", which swaps them for the search (README, "Choices").
|
|
83
|
+
def chain?
|
|
84
|
+
matches? && choices.any? { |c| c.role == "search" }
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The branch a chain shows as the page loads: :search when its search's answer was just
|
|
88
|
+
# refused, else :offered. nil when it isn't a chain.
|
|
89
|
+
def branch
|
|
90
|
+
return nil unless chain?
|
|
91
|
+
|
|
92
|
+
choices.any? { |c| c.role == "search" && c.id == refused_choice } ? :search : :offered
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# The branch a piece of a chain belongs to ("offered" or "search", its data-qube-branch-part):
|
|
96
|
+
# a search form, or the picks (:picks), another form, or the footer (:footer) when the search's
|
|
97
|
+
# row holds the exits. nil outside a chain, and for what both branches show.
|
|
98
|
+
def branch_part(piece)
|
|
99
|
+
return nil unless chain?
|
|
100
|
+
|
|
101
|
+
case piece
|
|
102
|
+
when :picks then "offered"
|
|
103
|
+
when :footer then joined_form ? "offered" : nil
|
|
104
|
+
when ChoiceView
|
|
105
|
+
return nil unless piece.kind == :form
|
|
106
|
+
|
|
107
|
+
piece.role == "search" ? "search" : "offered"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Whether that part is on show as the page loads.
|
|
112
|
+
def shown_part?(part)
|
|
113
|
+
part.nil? || part == branch.to_s
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# The count "None of these" and its way back say ("Not this one" for one).
|
|
117
|
+
def offered_count
|
|
118
|
+
picks.count { |c| c.role == "pick" }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Whether an "or" goes before form n: another form before it in its branch, or the picks.
|
|
122
|
+
def divided?(choice, n)
|
|
123
|
+
return n.positive? || picks.any? unless chain?
|
|
124
|
+
|
|
125
|
+
part = branch_part(choice)
|
|
126
|
+
forms.first(n).any? { |c| branch_part(c) == part } || (part == "offered" && picks.any?)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Whether QuBe Sync said each choice's role (prompt.choices[].role): then the picks are the
|
|
130
|
+
# records it offers (option rows, no heading).
|
|
131
|
+
def roles?
|
|
132
|
+
choices.any?(&:role)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def matches?
|
|
136
|
+
picks.any? { |c| c.role == "pick" }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# One of the engine's own words for this question (question.<key> in the locale files). The one
|
|
140
|
+
# place they're looked up, so a later QuBe Sync can send them with the prompt.
|
|
141
|
+
def ui_text(key, **options)
|
|
142
|
+
QubeRails.t("question.#{key}", **options)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# The id of the refusal's message, which the refused choice's fields point at (aria-describedby).
|
|
146
|
+
def error_id
|
|
147
|
+
"qube-error-#{token}"
|
|
148
|
+
end
|
|
149
|
+
|
|
55
150
|
private
|
|
56
151
|
|
|
57
|
-
# Kinds and button styles. With no picks but a form, a plain choice before the first form
|
|
58
|
-
# (name clash's "Use the existing record") is an option row too. One filled button at most:
|
|
59
|
-
# the first form's submit, or in a plain question the first choice.
|
|
60
152
|
def arrange
|
|
61
|
-
|
|
62
|
-
|
|
153
|
+
roles? ? arrange_by_role : arrange_by_shape
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# By role: the offered records are picks, the first the one primary action; a search is a form,
|
|
157
|
+
# secondary; decline and cancel are exits. An answer shows by its shape, as without roles.
|
|
158
|
+
def arrange_by_role
|
|
159
|
+
@choices.each do |c|
|
|
160
|
+
kind = case c.role
|
|
161
|
+
when "pick" then :pick
|
|
162
|
+
when "search" then :form
|
|
163
|
+
when "decline", "cancel" then :exit
|
|
164
|
+
else c.fields.any? ? :form : :exit
|
|
165
|
+
end
|
|
166
|
+
c.arrange(kind, nil)
|
|
167
|
+
end
|
|
168
|
+
promote_rows
|
|
169
|
+
offered = @choices.select { |c| c.role == "pick" }
|
|
170
|
+
all_forms = @choices.select { |c| c.kind == :form }
|
|
171
|
+
plain = picks.empty? && all_forms.empty?
|
|
172
|
+
primary = offered.first || (plain ? @choices.find { |c| !c.cancel? } : all_forms.find { |c| c.role != "search" } || all_forms.first)
|
|
173
|
+
@choices.each do |choice|
|
|
174
|
+
style = if choice.kind == :pick then (offered.include?(choice) ? button_style(choice, primary) : promoted_style(choice))
|
|
175
|
+
elsif choice.equal?(primary) || (choice.role == "search" && chain?) then :primary
|
|
176
|
+
elsif choice.cancel? then :ghost
|
|
177
|
+
else :secondary
|
|
178
|
+
end
|
|
179
|
+
choice.arrange(choice.kind, style)
|
|
63
180
|
end
|
|
64
|
-
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# A choice promoted to an option row ends in a secondary "Use this one", as an offered
|
|
184
|
+
# record's does, not a bare link beside the form's filled button.
|
|
185
|
+
def promoted_style(choice)
|
|
186
|
+
Array(@promoted).include?(choice) ? :secondary : nil
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def button_style(choice, primary)
|
|
190
|
+
choice.equal?(primary) ? :primary : :secondary
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Kinds and button styles from each choice's shape (a prompt without roles). One filled button
|
|
194
|
+
# at most: the first form's submit, or in a plain question the first choice.
|
|
195
|
+
def arrange_by_shape
|
|
196
|
+
promote_rows
|
|
197
|
+
primary = plain? ? @choices.find { |c| !c.cancel? } : forms.first
|
|
65
198
|
@choices.each do |choice|
|
|
66
|
-
style = if choice.kind == :pick then
|
|
199
|
+
style = if choice.kind == :pick then promoted_style(choice)
|
|
67
200
|
elsif choice.equal?(primary) then :primary
|
|
68
|
-
elsif choice.
|
|
201
|
+
elsif choice.cancel? then :ghost
|
|
69
202
|
else :secondary
|
|
70
203
|
end
|
|
71
204
|
choice.arrange(choice.kind, style)
|
|
72
205
|
end
|
|
73
206
|
end
|
|
207
|
+
|
|
208
|
+
# With no picks but a form, a plain choice before the first form (name clash's "Use the
|
|
209
|
+
# existing record") is an option row too.
|
|
210
|
+
def promote_rows
|
|
211
|
+
return if @choices.any? { |c| c.kind == :pick }
|
|
212
|
+
return unless (first_form = @choices.index { |c| c.kind == :form })
|
|
213
|
+
|
|
214
|
+
@choices.first(first_form).each do |c|
|
|
215
|
+
next if c.cancel? || %w[decline cancel].include?(c.role)
|
|
216
|
+
|
|
217
|
+
c.arrange(:pick, nil)
|
|
218
|
+
(@promoted ||= []) << c
|
|
219
|
+
end
|
|
220
|
+
end
|
|
74
221
|
end
|
|
75
222
|
|
|
76
223
|
# One label and value row of what the question is about.
|
|
@@ -82,17 +229,30 @@ module QubeRails
|
|
|
82
229
|
# One thing the user can pick: a form of its own, posting choice=<id> and data[...] for its
|
|
83
230
|
# fields to the question's action_url.
|
|
84
231
|
class ChoiceView
|
|
85
|
-
|
|
232
|
+
ROLES = %w[pick search decline cancel answer].freeze
|
|
233
|
+
|
|
234
|
+
attr_reader :id, :label, :detail, :description, :fields, :index, :action_url, :kind, :style, :role
|
|
235
|
+
|
|
236
|
+
# The detail's parts (QuBe Sync joins them with " · "), each but the last ending in its " ·",
|
|
237
|
+
# so a line breaks between parts and never starts with the separator.
|
|
238
|
+
def detail_parts
|
|
239
|
+
parts = detail.to_s.split(" · ")
|
|
240
|
+
parts.each_with_index.map { |part, i| i < parts.size - 1 ? "#{part} ·" : part }
|
|
241
|
+
end
|
|
86
242
|
|
|
87
243
|
def initialize(choice, index, question)
|
|
88
244
|
@id = choice["id"].to_s
|
|
245
|
+
# QuBe Sync's role for it, nil when the prompt has none; one this version doesn't know is answer.
|
|
246
|
+
@role = (ROLES.include?(choice["role"]) ? choice["role"] : "answer") if choice.key?("role")
|
|
89
247
|
@label = choice["label"].to_s
|
|
90
248
|
@detail = presence(choice["detail"])
|
|
91
249
|
@description = presence(choice["description"])
|
|
92
250
|
@index = index
|
|
93
251
|
@action_url = question.action_url
|
|
252
|
+
@token = question.token
|
|
253
|
+
@refused = question.refused_choice == @id
|
|
94
254
|
@fields = Array(choice["fields"]).select { |f| f.is_a?(Hash) }.map do |field|
|
|
95
|
-
FieldView.from_prompt(field, question, index)
|
|
255
|
+
FieldView.from_prompt(field, question, index, refused: @refused)
|
|
96
256
|
end
|
|
97
257
|
@kind = if fields.any? then :form
|
|
98
258
|
elsif @id.match?(/:\d+\z/) then :pick
|
|
@@ -102,7 +262,8 @@ module QubeRails
|
|
|
102
262
|
|
|
103
263
|
# kind is :pick (an option row: an item of a choose list, id "<option>:<n>", no fields), :form
|
|
104
264
|
# (a choice with fields) or :exit (none, cancel and the like). style is its button's: :primary,
|
|
105
|
-
# :secondary or :ghost (cancel)
|
|
265
|
+
# :secondary or :ghost (cancel); for a pick nil, or with roles its "Use this one" button's.
|
|
266
|
+
# Set by the QuestionView.
|
|
106
267
|
def arrange(kind, style)
|
|
107
268
|
@kind = kind
|
|
108
269
|
@style = style
|
|
@@ -112,14 +273,36 @@ module QubeRails
|
|
|
112
273
|
def button_piece
|
|
113
274
|
case style
|
|
114
275
|
when :primary then :button
|
|
115
|
-
when :ghost then
|
|
276
|
+
when :ghost then :button_ghost # no host class unless ui_classes has one: the engine's ghost look
|
|
116
277
|
else :button_secondary
|
|
117
278
|
end
|
|
118
279
|
end
|
|
119
280
|
|
|
120
|
-
# A choice that
|
|
121
|
-
def
|
|
122
|
-
id == "cancel"
|
|
281
|
+
# A choice that ends the request: its role cancel, or without roles its id.
|
|
282
|
+
def cancel?
|
|
283
|
+
role ? role == "cancel" : id == "cancel"
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
alias secondary? cancel?
|
|
287
|
+
|
|
288
|
+
# Its form's id: an exit's button in another form's row names it (the form attribute).
|
|
289
|
+
def form_id
|
|
290
|
+
"qube-#{@token}-choice-#{index}"
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# Whether one of its fields is a rows field (which needs the behaviour script).
|
|
294
|
+
def rows?
|
|
295
|
+
fields.any? { |f| f.type == "rows" }
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# A search's submit ("Use this one"): hidden until a match is picked, which the script shows.
|
|
299
|
+
def waits_for_pick?
|
|
300
|
+
role == "search" && fields.any? { |f| f.type == "search" }
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Whether QuBe Sync just refused this choice's answer (a 422): its fields are marked invalid.
|
|
304
|
+
def refused?
|
|
305
|
+
@refused
|
|
123
306
|
end
|
|
124
307
|
|
|
125
308
|
private
|
|
@@ -137,20 +320,24 @@ module QubeRails
|
|
|
137
320
|
TYPES = %w[text number boolean select search rows].freeze
|
|
138
321
|
|
|
139
322
|
attr_reader :name, :input_name, :dom_id, :type, :label, :required, :options, :kind,
|
|
140
|
-
:search_url, :search_field, :row_key, :when, :rows, :context, :disabled
|
|
323
|
+
:search_url, :search_field, :row_key, :when, :rows, :context, :disabled, :value,
|
|
324
|
+
:error_id
|
|
141
325
|
|
|
142
|
-
# A choice's field, as QuBe Sync sends it
|
|
143
|
-
|
|
326
|
+
# A choice's field, as QuBe Sync sends it; refused: its choice's answer was just refused, so
|
|
327
|
+
# it's marked invalid and holds what was typed.
|
|
328
|
+
def self.from_prompt(field, question, choice_index, refused: false)
|
|
144
329
|
name = field["name"].to_s
|
|
145
330
|
input_name = "data[#{name}]"
|
|
146
331
|
type = type_of(field, record_type: "search")
|
|
147
332
|
rows = if type == "rows"
|
|
148
|
-
RowsView.new(field, input_name: input_name, search_url: question.search_url)
|
|
333
|
+
RowsView.new(field, input_name: input_name, search_url: question.search_url, question: question)
|
|
149
334
|
end
|
|
150
335
|
new(name: name, input_name: input_name, dom_id: "qube-#{question.token}-#{choice_index}-#{name}",
|
|
151
336
|
type: type, label: field["label"] || name, required: field["required"] == true,
|
|
152
337
|
options: options_of(field), kind: field["kind"], search_url: question.search_url,
|
|
153
|
-
search_field: name, rows: rows
|
|
338
|
+
search_field: name, rows: rows,
|
|
339
|
+
value: (refused && type != "rows" ? question.refused_values.to_h[name] : nil),
|
|
340
|
+
error_id: (refused ? question.error_id : nil))
|
|
154
341
|
end
|
|
155
342
|
|
|
156
343
|
# What a prompt field shows as: a record a search, an enum a select, else by its type.
|
|
@@ -173,7 +360,7 @@ module QubeRails
|
|
|
173
360
|
# their label.
|
|
174
361
|
def initialize(name:, type:, label:, input_name: nil, dom_id: nil, required: false, options: [], kind: nil,
|
|
175
362
|
search_url: nil, search_field: nil, row_key: nil, when_values: nil, rows: nil,
|
|
176
|
-
context: :choice, disabled: false)
|
|
363
|
+
context: :choice, disabled: false, value: nil, error_id: nil, optional: nil)
|
|
177
364
|
raise ArgumentError, "QuBe Sync: no field type #{type.inspect}" unless TYPES.include?(type)
|
|
178
365
|
|
|
179
366
|
@name = name
|
|
@@ -191,6 +378,25 @@ module QubeRails
|
|
|
191
378
|
@rows = rows
|
|
192
379
|
@context = context
|
|
193
380
|
@disabled = disabled
|
|
381
|
+
@value = value
|
|
382
|
+
@error_id = error_id
|
|
383
|
+
@optional = optional.nil? ? !required : optional
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Whether it may be left empty: its label says "(optional)". A rows cell's column decides it,
|
|
387
|
+
# though a hidden cell isn't required in the markup yet.
|
|
388
|
+
def optional?
|
|
389
|
+
@optional && !%w[boolean rows].include?(type)
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# Whether it's in a refused answer: aria-invalid, described by the refusal.
|
|
393
|
+
def invalid?
|
|
394
|
+
!error_id.nil?
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# The aria attributes that say so.
|
|
398
|
+
def aria_invalid
|
|
399
|
+
invalid? ? { "aria-invalid": "true", "aria-describedby": error_id } : {}
|
|
194
400
|
end
|
|
195
401
|
|
|
196
402
|
def partial
|
data/lib/qube_rails/rows_view.rb
CHANGED
|
@@ -10,7 +10,8 @@ module QubeRails
|
|
|
10
10
|
class RowsView
|
|
11
11
|
attr_reader :name, :label, :input_name, :search_url, :columns, :rows
|
|
12
12
|
|
|
13
|
-
def initialize(field, input_name:, search_url:)
|
|
13
|
+
def initialize(field, input_name:, search_url:, question: nil)
|
|
14
|
+
@question = question
|
|
14
15
|
@name = field["name"].to_s
|
|
15
16
|
@label = (field["label"] || @name).to_s
|
|
16
17
|
@input_name = input_name
|
|
@@ -22,16 +23,22 @@ module QubeRails
|
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
|
|
26
|
+
# The question's words (QuestionView#ui_text), else the locale files'.
|
|
27
|
+
def ui_text(key, **options)
|
|
28
|
+
@question ? @question.ui_text(key, **options) : QubeRails.t("question.#{key}", **options)
|
|
29
|
+
end
|
|
30
|
+
|
|
25
31
|
# A column's control for one row (context :cell). Shown or not, it isn't required in the
|
|
26
32
|
# markup while hidden (the script sets required as it shows it).
|
|
27
|
-
def cell_field(column, row_key, row_index, shown)
|
|
33
|
+
def cell_field(column, row_key, row_index, shown, value = nil)
|
|
28
34
|
col = column["name"].to_s
|
|
29
35
|
FieldView.new(name: col, type: FieldView.type_of(column, record_type: "search"),
|
|
30
36
|
label: column["label"] || col, input_name: "#{input_name}[#{row_key}][#{col}]",
|
|
31
37
|
dom_id: "qube-#{input_name.gsub(/[^A-Za-z0-9]+/, "-")}#{row_index}-#{col}".squeeze("-"),
|
|
32
38
|
required: column["required"] == true && shown, options: FieldView.options_of(column),
|
|
33
39
|
kind: column["kind"], search_url: search_url, search_field: "#{name}.#{col}",
|
|
34
|
-
row_key: row_key, when_values: when_of(column), context: :cell, disabled: !shown
|
|
40
|
+
row_key: row_key, when_values: when_of(column), context: :cell, disabled: !shown,
|
|
41
|
+
value: value, optional: column["required"] != true)
|
|
35
42
|
end
|
|
36
43
|
|
|
37
44
|
def when_of(column)
|
|
@@ -72,6 +79,11 @@ module QubeRails
|
|
|
72
79
|
@values = row["values"].is_a?(Hash) ? row["values"] : {}
|
|
73
80
|
@index = index
|
|
74
81
|
asks = Array(row["columns"]).map(&:to_s)
|
|
82
|
+
# A column's default (one of its enum values) starts chosen in a row that asks it.
|
|
83
|
+
@defaults = declared.each_with_object({}) do |column, acc|
|
|
84
|
+
col = column["name"].to_s
|
|
85
|
+
acc[col] = column["default"] if asks.include?(col) && !column["default"].nil?
|
|
86
|
+
end
|
|
75
87
|
@cells = declared.filter_map do |column|
|
|
76
88
|
col = column["name"].to_s
|
|
77
89
|
when_values = rows.when_of(column)
|
|
@@ -79,7 +91,7 @@ module QubeRails
|
|
|
79
91
|
required = column["required"] == true
|
|
80
92
|
label = (column["label"] || col).to_s
|
|
81
93
|
if asks.include?(col)
|
|
82
|
-
CellView.new(column: col, label: label, field: rows.cell_field(column, @key, index, shown),
|
|
94
|
+
CellView.new(column: col, label: label, field: rows.cell_field(column, @key, index, shown, @defaults[col]),
|
|
83
95
|
when_values: when_values, shown: shown, required: required)
|
|
84
96
|
elsif !@values[col].to_s.empty?
|
|
85
97
|
CellView.new(column: col, label: label, preset: preset_text(column, @values[col]), when_values: when_values,
|
|
@@ -105,7 +117,8 @@ module QubeRails
|
|
|
105
117
|
|
|
106
118
|
# Before the user picks anything, a column shows when its "when" holds for the row's values.
|
|
107
119
|
def applies?(when_values)
|
|
108
|
-
|
|
120
|
+
chosen = @defaults.merge(values)
|
|
121
|
+
when_values.all? { |col, allowed| Array(allowed).include?(chosen[col]) }
|
|
109
122
|
end
|
|
110
123
|
|
|
111
124
|
# A value the row already has, shown as its enum label when it has one.
|
|
@@ -6,10 +6,11 @@ module QubeRails
|
|
|
6
6
|
# :sending, :needs_answer, :in_quickbooks, :done, :failed, :cancelled); state the latest run's
|
|
7
7
|
# ("starting", "running", "awaiting_input", "completed", "failed" or "cancelled"), or nil.
|
|
8
8
|
# summary is a few words for the pill; reason, why it failed or was cancelled, as a sentence
|
|
9
|
-
# below it; detail, what to do about a failure
|
|
9
|
+
# below it; detail, what to do about a failure (its hint); headline, an ended run's sentence
|
|
10
|
+
# for what happened (QuBe Sync's, shown as it is), when no reason says it.
|
|
10
11
|
class RunStatusView
|
|
11
12
|
attr_reader :status, :state, :summary, :reason, :detail, :quiet_text, :retry_url, :redeliver_url, :error, :stall,
|
|
12
|
-
:stall_text
|
|
13
|
+
:stall_text, :headline, :with_errors
|
|
13
14
|
|
|
14
15
|
# The stall reasons with words of their own (status.stalled.<reason>); any other is "other".
|
|
15
16
|
STALL_REASONS = %w[not_checking_in quickbooks_unavailable].freeze
|
|
@@ -26,11 +27,13 @@ module QubeRails
|
|
|
26
27
|
connection ||= run && run.connection
|
|
27
28
|
stall = sync.status == :sending ? stall_of(connection) : nil
|
|
28
29
|
stuck = run && !stall ? run.looks_stuck? : false
|
|
30
|
+
headline = run && run.ended? && !reason && !run.headline.to_s.strip.empty? ? run.headline.strip : nil
|
|
29
31
|
new(status: sync.status, state: state,
|
|
30
32
|
summary: stall ? QubeRails.t("status.waiting_for_quickbooks") : sync.summary_text, reason: reason, detail: detail,
|
|
31
33
|
quiet_text: stuck ? QubeRails.t("status.quiet") : nil,
|
|
32
|
-
retry_url: sync.unconfirmed? ? urls.retry_start_path(run) : nil,
|
|
33
|
-
redeliver_url: stuck ? urls.redeliver_path(run) : nil, error: error, stall: stall
|
|
34
|
+
retry_url: sync.unconfirmed? || run&.realtime_required? ? urls.retry_start_path(run) : nil,
|
|
35
|
+
redeliver_url: stuck ? urls.redeliver_path(run) : nil, error: error, stall: stall, headline: headline,
|
|
36
|
+
with_errors: run ? run.with_errors? : false)
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
# A stalled connection's reason as a Symbol (:other when it gives none), or nil.
|
|
@@ -42,7 +45,7 @@ module QubeRails
|
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
def initialize(status:, state: nil, summary: nil, reason: nil, detail: nil, quiet_text: nil, retry_url: nil,
|
|
45
|
-
redeliver_url: nil, error: nil, stall: nil)
|
|
48
|
+
redeliver_url: nil, error: nil, stall: nil, headline: nil, with_errors: false)
|
|
46
49
|
@status = status.to_sym
|
|
47
50
|
@state = state
|
|
48
51
|
@summary = summary
|
|
@@ -53,6 +56,8 @@ module QubeRails
|
|
|
53
56
|
@redeliver_url = redeliver_url
|
|
54
57
|
@error = error
|
|
55
58
|
@stall = stall
|
|
59
|
+
@headline = headline
|
|
60
|
+
@with_errors = with_errors
|
|
56
61
|
@stall_text = stall && QubeRails.t("status.stalled.#{STALL_REASONS.include?(stall.to_s) ? stall : "other"}")
|
|
57
62
|
end
|
|
58
63
|
|
|
@@ -64,8 +69,8 @@ module QubeRails
|
|
|
64
69
|
# The qube- classes on the status element: qube-sync-<status>, qube-run-<state>, and
|
|
65
70
|
# qube-connection-stalled while it waits on a stalled connection.
|
|
66
71
|
def css_class
|
|
67
|
-
["qube-run-status", "qube-sync-#{status}", state && "qube-run-#{state}", stall && "qube-connection-stalled"
|
|
68
|
-
|
|
72
|
+
["qube-run-status", "qube-sync-#{status}", state && "qube-run-#{state}", stall && "qube-connection-stalled",
|
|
73
|
+
(with_errors ? "qube-run-with-errors" : nil)].compact.join(" ")
|
|
69
74
|
end
|
|
70
75
|
end
|
|
71
76
|
end
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"id": "add_transaction / ask_about_add",
|
|
6
6
|
"kind": "decision",
|
|
7
7
|
"token": "Xh6rV8wBt4QjC6eE",
|
|
8
|
-
"message": "QuickBooks
|
|
8
|
+
"message": "QuickBooks never answered when the invoice was added, so it isn't known whether it went in.",
|
|
9
9
|
"data": {
|
|
10
10
|
"operation": "invoice",
|
|
11
11
|
"why": "lost_answer",
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"not_found": null
|
|
15
15
|
},
|
|
16
16
|
"details": [
|
|
17
|
-
{
|
|
18
|
-
"label": "Adding",
|
|
19
|
-
"value": "Invoice"
|
|
20
|
-
},
|
|
21
17
|
{
|
|
22
18
|
"label": "Number",
|
|
23
19
|
"value": "1042"
|
|
@@ -31,28 +27,30 @@
|
|
|
31
27
|
"value": "Riverbend Electric"
|
|
32
28
|
}
|
|
33
29
|
],
|
|
34
|
-
"options": [],
|
|
35
30
|
"choices": [
|
|
36
31
|
{
|
|
37
32
|
"id": "use_existing:1",
|
|
38
33
|
"label": "1042",
|
|
39
34
|
"description": null,
|
|
40
35
|
"detail": "2026-10-20 · Riverbend Electric · 1250.00",
|
|
41
|
-
"fields": []
|
|
36
|
+
"fields": [],
|
|
37
|
+
"role": "pick"
|
|
42
38
|
},
|
|
43
39
|
{
|
|
44
40
|
"id": "add_again",
|
|
45
41
|
"label": "None of them: add it again",
|
|
46
42
|
"description": null,
|
|
47
43
|
"detail": null,
|
|
48
|
-
"fields": []
|
|
44
|
+
"fields": [],
|
|
45
|
+
"role": "decline"
|
|
49
46
|
},
|
|
50
47
|
{
|
|
51
48
|
"id": "cancel",
|
|
52
|
-
"label": "Cancel",
|
|
49
|
+
"label": "Cancel adding the invoice",
|
|
53
50
|
"description": null,
|
|
54
51
|
"detail": null,
|
|
55
|
-
"fields": []
|
|
52
|
+
"fields": [],
|
|
53
|
+
"role": "cancel"
|
|
56
54
|
}
|
|
57
55
|
]
|
|
58
56
|
},
|
|
@@ -15,35 +15,38 @@
|
|
|
15
15
|
"value": "1042"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
|
-
"options": [],
|
|
19
18
|
"choices": [
|
|
20
19
|
{
|
|
21
20
|
"id": "use:1",
|
|
22
21
|
"label": "1042",
|
|
23
22
|
"description": null,
|
|
24
23
|
"detail": "2026-10-20 · Riverbend Electric · 1250.00",
|
|
25
|
-
"fields": []
|
|
24
|
+
"fields": [],
|
|
25
|
+
"role": "pick"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"id": "use:2",
|
|
29
29
|
"label": "1042-B",
|
|
30
30
|
"description": null,
|
|
31
31
|
"detail": "2026-10-21 · Riverbend Electric · 310.50",
|
|
32
|
-
"fields": []
|
|
32
|
+
"fields": [],
|
|
33
|
+
"role": "pick"
|
|
33
34
|
},
|
|
34
35
|
{
|
|
35
36
|
"id": "none",
|
|
36
37
|
"label": "None of these",
|
|
37
38
|
"description": null,
|
|
38
39
|
"detail": null,
|
|
39
|
-
"fields": []
|
|
40
|
+
"fields": [],
|
|
41
|
+
"role": "decline"
|
|
40
42
|
},
|
|
41
43
|
{
|
|
42
44
|
"id": "cancel",
|
|
43
45
|
"label": "Cancel",
|
|
44
46
|
"description": null,
|
|
45
47
|
"detail": null,
|
|
46
|
-
"fields": []
|
|
48
|
+
"fields": [],
|
|
49
|
+
"role": "cancel"
|
|
47
50
|
}
|
|
48
51
|
]
|
|
49
52
|
},
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"value": "SO-2207"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
|
-
"options": [],
|
|
17
16
|
"choices": [
|
|
18
17
|
{
|
|
19
18
|
"id": "route",
|
|
@@ -41,14 +40,16 @@
|
|
|
41
40
|
}
|
|
42
41
|
]
|
|
43
42
|
}
|
|
44
|
-
]
|
|
43
|
+
],
|
|
44
|
+
"role": "answer"
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
"id": "cancel",
|
|
48
48
|
"label": "Cancel",
|
|
49
49
|
"description": null,
|
|
50
50
|
"detail": null,
|
|
51
|
-
"fields": []
|
|
51
|
+
"fields": [],
|
|
52
|
+
"role": "cancel"
|
|
52
53
|
}
|
|
53
54
|
]
|
|
54
55
|
},
|