qube_rails 0.2.0 → 0.3.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/CHANGELOG.md +321 -0
- data/README.md +406 -76
- data/app/assets/javascripts/qube_rails/question.js +469 -43
- data/app/assets/stylesheets/qube_rails.css +1349 -912
- data/app/controllers/qube_rails/connections_controller.rb +42 -9
- data/app/controllers/qube_rails/questions_controller.rb +39 -7
- data/app/controllers/qube_rails/runs_controller.rb +4 -3
- data/app/controllers/qube_rails/storyboard_controller.rb +1 -1
- data/app/models/qube_rails/connection.rb +131 -9
- data/app/models/qube_rails/quickbooks_record.rb +22 -0
- data/app/models/qube_rails/run.rb +28 -10
- data/app/views/qube_rails/_error.html.erb +2 -2
- data/app/views/qube_rails/_manage_connection.html.erb +19 -0
- data/app/views/qube_rails/_question.html.erb +4 -1
- data/app/views/qube_rails/question/_choice.html.erb +34 -11
- data/app/views/qube_rails/question/_disclosure.html.erb +7 -0
- 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 +12 -4
- data/app/views/qube_rails/question/_inline_search.html.erb +12 -0
- data/app/views/qube_rails/question/_pick.html.erb +29 -6
- data/app/views/qube_rails/question/_picks.html.erb +2 -1
- data/app/views/qube_rails/question/_question.html.erb +31 -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 +6 -3
- 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/app/views/qube_rails/storyboard/show.html.erb +4 -3
- data/config/locales/en.yml +30 -1
- data/config/routes.rb +2 -0
- data/db/migrate/20261031000000_add_qube_connection_type_and_run_headline.rb +12 -0
- data/db/migrate/20261124000000_add_qube_company_file_change.rb +17 -0
- data/lib/generators/qube_rails/templates/connection_events.rb.tt +17 -1
- data/lib/generators/qube_rails/templates/initializer.rb.tt +12 -4
- data/lib/qube_rails/configuration.rb +5 -2
- data/lib/qube_rails/connection_events.rb +70 -7
- data/lib/qube_rails/engine.rb +1 -0
- data/lib/qube_rails/link_check.rb +274 -0
- data/lib/qube_rails/operation.rb +116 -32
- data/lib/qube_rails/question_view.rb +293 -35
- data/lib/qube_rails/request.rb +2 -0
- 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 +9 -11
- data/lib/qube_rails/storyboard/choose.json +10 -7
- data/lib/qube_rails/storyboard/enum_select.json +5 -4
- data/lib/qube_rails/storyboard/missing_record.json +11 -14
- data/lib/qube_rails/storyboard/name_clash.json +51 -21
- data/lib/qube_rails/storyboard/near_match.json +18 -15
- data/lib/qube_rails/storyboard/number_boolean.json +5 -4
- data/lib/qube_rails/storyboard/record_search.json +15 -16
- data/lib/qube_rails/storyboard/refusal.json +15 -18
- data/lib/qube_rails/storyboard/rows.json +45 -31
- data/lib/qube_rails/storyboard.rb +28 -7
- data/lib/qube_rails/sync_status.rb +16 -3
- data/lib/qube_rails/version.rb +1 -1
- data/lib/qube_rails/view_helpers.rb +4 -2
- data/lib/qube_rails.rb +11 -2
- metadata +10 -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
|
|
@@ -33,42 +40,151 @@ module QubeRails
|
|
|
33
40
|
arrange
|
|
34
41
|
end
|
|
35
42
|
|
|
36
|
-
# The choices by where they show: picks (option rows),
|
|
37
|
-
#
|
|
38
|
-
#
|
|
43
|
+
# The choices by where they show: picks (option rows), the search boxes under offered records
|
|
44
|
+
# (searches), declines beside them (alongside), forms (a section each, "or" between), forms
|
|
45
|
+
# behind "or <its label>…" (disclosed), then exits (a footer row, cancel last). plain? when
|
|
46
|
+
# there's neither a pick nor a form: one row, the first choice primary.
|
|
47
|
+
# The picks are the offered records, a slot per search box for its picked match (hidden until
|
|
48
|
+
# the script fills it), then the rest.
|
|
39
49
|
def picks
|
|
40
|
-
choices.select { |c| c.kind == :pick }
|
|
50
|
+
offered = choices.select { |c| c.kind == :pick && c.role == "pick" }
|
|
51
|
+
offered + searches.map { |c| PickedView.new(c) } + choices.select { |c| c.kind == :pick && c.role != "pick" }
|
|
41
52
|
end
|
|
42
53
|
|
|
43
54
|
def forms
|
|
44
|
-
choices.select { |c| c.kind == :form }
|
|
55
|
+
choices.select { |c| c.kind == :form && !searches.include?(c) && !disclosed.include?(c) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# With records offered, a search is a box under them; its picked match becomes a row.
|
|
59
|
+
def searches
|
|
60
|
+
@searches || []
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# A decline beside offered records with no row of its own ("None of them: add it again"): a
|
|
64
|
+
# button just under them, weighing the same.
|
|
65
|
+
def alongside
|
|
66
|
+
@alongside || []
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# The forms after a promoted row (a name clash's rename), each behind "or <its label>…".
|
|
70
|
+
def disclosed
|
|
71
|
+
@disclosed || []
|
|
45
72
|
end
|
|
46
73
|
|
|
47
74
|
def exits
|
|
48
|
-
choices.select { |c| c.kind == :exit }
|
|
75
|
+
choices.select { |c| c.kind == :exit && !alongside.include?(c) }.partition { |c| !c.cancel? }.flatten
|
|
49
76
|
end
|
|
50
77
|
|
|
51
78
|
def plain?
|
|
52
79
|
picks.empty? && forms.empty?
|
|
53
80
|
end
|
|
54
81
|
|
|
82
|
+
# The one form whose button row also holds the exits (cancel left, the rest beside its
|
|
83
|
+
# submit): a question with no picks, one form, and exits without descriptions. Else nil, and
|
|
84
|
+
# the exits have a footer row of their own.
|
|
85
|
+
def joined_form
|
|
86
|
+
return nil unless picks.empty? && forms.size == 1 && exits.none?(&:description)
|
|
87
|
+
|
|
88
|
+
forms.first
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# How many records QuBe Sync offers.
|
|
92
|
+
def offered_count
|
|
93
|
+
choices.count { |c| c.kind == :pick && c.role == "pick" }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Whether an "or" goes before form n: another form before it, or the picks.
|
|
97
|
+
def divided?(_choice, n)
|
|
98
|
+
n.positive? || picks.any?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# A label as it reads after "or": its first letter lowercased.
|
|
102
|
+
def mid_sentence(label)
|
|
103
|
+
text = label.to_s
|
|
104
|
+
text.empty? ? "" : text[0].downcase + text[1..-1]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Whether QuBe Sync said each choice's role (prompt.choices[].role): then the picks are the
|
|
108
|
+
# records it offers (option rows, no heading).
|
|
109
|
+
def roles?
|
|
110
|
+
choices.any?(&:role)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def matches?
|
|
114
|
+
offered_count.positive?
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# One of the engine's own words for this question (question.<key> in the locale files). The one
|
|
118
|
+
# place they're looked up, so a later QuBe Sync can send them with the prompt.
|
|
119
|
+
def ui_text(key, **options)
|
|
120
|
+
QubeRails.t("question.#{key}", **options)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# The id of the refusal's message, which the refused choice's fields point at (aria-describedby).
|
|
124
|
+
def error_id
|
|
125
|
+
"qube-error-#{token}"
|
|
126
|
+
end
|
|
127
|
+
|
|
55
128
|
private
|
|
56
129
|
|
|
57
|
-
# Kinds and button styles. With
|
|
58
|
-
#
|
|
59
|
-
#
|
|
130
|
+
# Kinds and button styles. With roles: the offered records are picks, the first the one
|
|
131
|
+
# primary action; a search is a form; decline and cancel are exits; an answer shows by its
|
|
132
|
+
# shape. Without roles, every choice by its shape. Offered records beside a decline weigh the
|
|
133
|
+
# same as it; a promoted row (a name clash's "Use the existing record") leads, the forms after
|
|
134
|
+
# it behind "or <its label>…".
|
|
60
135
|
def arrange
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
136
|
+
roles = roles?
|
|
137
|
+
@choices.each { |c| c.arrange(roles ? kind_by_role(c) : c.kind, nil) }
|
|
138
|
+
promoted = promote_rows
|
|
139
|
+
offered = @choices.select { |c| c.kind == :pick && c.role == "pick" }
|
|
140
|
+
all_forms = @choices.select { |c| c.kind == :form }
|
|
141
|
+
plain = @choices.none? { |c| c.kind == :pick } && all_forms.empty?
|
|
142
|
+
promoted_first = promoted.first
|
|
143
|
+
primary = offered.first || promoted_first ||
|
|
144
|
+
(plain ? @choices.find { |c| !c.cancel? } : all_forms.find { |c| c.role != "search" } || all_forms.first)
|
|
145
|
+
level = offered.any? && @choices.any? { |c| c.role == "decline" }
|
|
65
146
|
@choices.each do |choice|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
elsif choice.
|
|
147
|
+
kind = choice.kind
|
|
148
|
+
style = if kind == :pick then (offered.include?(choice) || promoted.include?(choice) ? button_style(choice, primary) : nil)
|
|
149
|
+
elsif choice.equal?(primary) || (kind == :form && promoted_first) then :primary
|
|
150
|
+
elsif choice.cancel? then :ghost
|
|
69
151
|
else :secondary
|
|
70
152
|
end
|
|
71
|
-
choice.
|
|
153
|
+
if level && choice.role == "decline"
|
|
154
|
+
kind = :pick if choice.row?
|
|
155
|
+
style = :secondary
|
|
156
|
+
elsif level && offered.include?(choice)
|
|
157
|
+
style = :secondary
|
|
158
|
+
end
|
|
159
|
+
choice.arrange(kind, style)
|
|
160
|
+
end
|
|
161
|
+
@alongside = level ? @choices.select { |c| c.role == "decline" && c.kind == :exit } : []
|
|
162
|
+
@searches = offered.any? ? @choices.select { |c| c.kind == :form && c.role == "search" } : []
|
|
163
|
+
@searches.each { |c| c.fields.each(&:inline!) }
|
|
164
|
+
@disclosed = promoted_first ? @choices.select { |c| c.kind == :form && c.role != "search" } : []
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def kind_by_role(choice)
|
|
168
|
+
case choice.role
|
|
169
|
+
when "pick" then :pick
|
|
170
|
+
when "search" then :form
|
|
171
|
+
when "decline", "cancel" then :exit
|
|
172
|
+
else choice.fields.any? ? :form : :exit
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def button_style(choice, primary)
|
|
177
|
+
choice.equal?(primary) ? :primary : :secondary
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# With no picks but a form, a plain choice before the first form (a name clash's "Use the
|
|
181
|
+
# existing record") is an option row too. Returns those.
|
|
182
|
+
def promote_rows
|
|
183
|
+
return [] if @choices.any? { |c| c.kind == :pick }
|
|
184
|
+
return [] unless (first_form = @choices.index { |c| c.kind == :form })
|
|
185
|
+
|
|
186
|
+
@choices.first(first_form).reject { |c| c.cancel? || %w[decline cancel].include?(c.role) }.each do |c|
|
|
187
|
+
c.arrange(:pick, nil)
|
|
72
188
|
end
|
|
73
189
|
end
|
|
74
190
|
end
|
|
@@ -79,20 +195,45 @@ module QubeRails
|
|
|
79
195
|
# One of a select's options.
|
|
80
196
|
OptionView = Struct.new(:value, :label)
|
|
81
197
|
|
|
198
|
+
# One fact of a record a choice is about ("Balance", "1,250.00"): label and value side by side.
|
|
199
|
+
FactView = Struct.new(:label, :value)
|
|
200
|
+
|
|
82
201
|
# One thing the user can pick: a form of its own, posting choice=<id> and data[...] for its
|
|
83
202
|
# fields to the question's action_url.
|
|
84
203
|
class ChoiceView
|
|
85
|
-
|
|
204
|
+
ROLES = %w[pick search decline cancel answer].freeze
|
|
205
|
+
|
|
206
|
+
attr_reader :id, :label, :title, :action, :detail, :lines, :facts, :description, :fields, :index, :action_url,
|
|
207
|
+
:kind, :style, :role
|
|
208
|
+
|
|
209
|
+
# A text's parts (QuBe Sync joins them with " · "), each but the last ending in its " ·", so a
|
|
210
|
+
# line breaks between parts and never starts with the separator. The detail's by default.
|
|
211
|
+
def detail_parts(text = detail)
|
|
212
|
+
parts = text.to_s.split(" · ")
|
|
213
|
+
parts.each_with_index.map { |part, i| i < parts.size - 1 ? "#{part} ·" : part }
|
|
214
|
+
end
|
|
86
215
|
|
|
87
216
|
def initialize(choice, index, question)
|
|
88
217
|
@id = choice["id"].to_s
|
|
218
|
+
# QuBe Sync's role for it, nil when the prompt has none; one this version doesn't know is answer.
|
|
219
|
+
@role = (ROLES.include?(choice["role"]) ? choice["role"] : "answer") if choice.key?("role")
|
|
89
220
|
@label = choice["label"].to_s
|
|
221
|
+
# A choice about one record can say what it is as a row: title in place of its label, action
|
|
222
|
+
# as its button, lines and facts in place of detail.
|
|
223
|
+
@title = presence(choice["title"])
|
|
224
|
+
@action = presence(choice["action"])
|
|
90
225
|
@detail = presence(choice["detail"])
|
|
226
|
+
@lines = Array(choice["lines"]).map { |line| presence(line) }.compact
|
|
227
|
+
@facts = Array(choice["facts"]).select { |f| f.is_a?(Hash) }.map do |f|
|
|
228
|
+
FactView.new(presence(f["label"]), presence(f["value"]))
|
|
229
|
+
end.select { |f| f.label && f.value }
|
|
91
230
|
@description = presence(choice["description"])
|
|
92
231
|
@index = index
|
|
93
232
|
@action_url = question.action_url
|
|
233
|
+
@token = question.token
|
|
234
|
+
@refused = question.refused_choice == @id
|
|
94
235
|
@fields = Array(choice["fields"]).select { |f| f.is_a?(Hash) }.map do |field|
|
|
95
|
-
FieldView.from_prompt(field, question, index)
|
|
236
|
+
FieldView.from_prompt(field, question, index, refused: @refused)
|
|
96
237
|
end
|
|
97
238
|
@kind = if fields.any? then :form
|
|
98
239
|
elsif @id.match?(/:\d+\z/) then :pick
|
|
@@ -102,7 +243,8 @@ module QubeRails
|
|
|
102
243
|
|
|
103
244
|
# kind is :pick (an option row: an item of a choose list, id "<option>:<n>", no fields), :form
|
|
104
245
|
# (a choice with fields) or :exit (none, cancel and the like). style is its button's: :primary,
|
|
105
|
-
# :secondary or :ghost (cancel)
|
|
246
|
+
# :secondary or :ghost (cancel); for a pick nil, or with roles its "Use this one" button's.
|
|
247
|
+
# Set by the QuestionView.
|
|
106
248
|
def arrange(kind, style)
|
|
107
249
|
@kind = kind
|
|
108
250
|
@style = style
|
|
@@ -112,16 +254,63 @@ module QubeRails
|
|
|
112
254
|
def button_piece
|
|
113
255
|
case style
|
|
114
256
|
when :primary then :button
|
|
115
|
-
when :ghost then
|
|
257
|
+
when :ghost then :button_ghost # no host class unless ui_classes has one: the engine's ghost look
|
|
116
258
|
else :button_secondary
|
|
117
259
|
end
|
|
118
260
|
end
|
|
119
261
|
|
|
120
|
-
# A choice that
|
|
121
|
-
def
|
|
122
|
-
id == "cancel"
|
|
262
|
+
# A choice that ends the request: its role cancel, or without roles its id.
|
|
263
|
+
def cancel?
|
|
264
|
+
role ? role == "cancel" : id == "cancel"
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
alias secondary? cancel?
|
|
268
|
+
|
|
269
|
+
# Its form's id: an exit's button in another form's row names it (the form attribute).
|
|
270
|
+
def form_id
|
|
271
|
+
"qube-#{@token}-choice-#{index}"
|
|
123
272
|
end
|
|
124
273
|
|
|
274
|
+
# The id of an offered record's name, which its button is described by.
|
|
275
|
+
def label_id
|
|
276
|
+
"qube-#{@token}-pick-#{index}#{"-picked" if slot?}"
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Whether one of its fields is a rows field (which needs the behaviour script).
|
|
280
|
+
def rows?
|
|
281
|
+
fields.any? { |f| f.type == "rows" }
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
# A search's submit ("Use this one"): hidden until a match is picked, which the script shows.
|
|
285
|
+
def waits_for_pick?
|
|
286
|
+
role == "search" && fields.any? { |f| f.type == "search" }
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Whether QuBe Sync just refused this choice's answer (a 422): its fields are marked invalid.
|
|
290
|
+
def refused?
|
|
291
|
+
@refused
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Whether it says what it is as a row of its own (title, action, lines or facts).
|
|
295
|
+
def row?
|
|
296
|
+
!title.nil? || !action.nil? || lines.any? || facts.any?
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# The hidden data[...] inputs its pick's form posts (a picked match's value).
|
|
300
|
+
def data
|
|
301
|
+
{}
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
# Whether it's a slot the script fills (a search box's picked match), hidden until then.
|
|
305
|
+
def slot?
|
|
306
|
+
false
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
protected
|
|
310
|
+
|
|
311
|
+
# The question's token, for a picked row made from this search.
|
|
312
|
+
attr_reader :token
|
|
313
|
+
|
|
125
314
|
private
|
|
126
315
|
|
|
127
316
|
def presence(value)
|
|
@@ -130,6 +319,34 @@ module QubeRails
|
|
|
130
319
|
end
|
|
131
320
|
end
|
|
132
321
|
|
|
322
|
+
# The row a search box under offered records shows its picked match in: an option row whose
|
|
323
|
+
# "Use this one" answers the search's choice with the match. Rendered empty and hidden; the
|
|
324
|
+
# script fills it (a second pick replaces the first).
|
|
325
|
+
class PickedView < ChoiceView
|
|
326
|
+
def initialize(search)
|
|
327
|
+
@search = search
|
|
328
|
+
@id = search.id
|
|
329
|
+
@role = search.role
|
|
330
|
+
@label = ""
|
|
331
|
+
@lines = []
|
|
332
|
+
@facts = []
|
|
333
|
+
@fields = []
|
|
334
|
+
@index = search.index
|
|
335
|
+
@token = search.token
|
|
336
|
+
@action_url = search.action_url
|
|
337
|
+
@kind = :pick
|
|
338
|
+
@style = :secondary
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def data
|
|
342
|
+
@search.fields.select { |f| f.type == "search" }.map { |f| [f.input_name, ""] }.to_h
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def slot?
|
|
346
|
+
true
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
133
350
|
# One input: a choice's field, or a field of a rows field's row.
|
|
134
351
|
# type is "text", "number", "boolean", "select", "search" or "rows"; partial is the piece that
|
|
135
352
|
# renders it (qube_rails/question/fields/_<type>).
|
|
@@ -137,20 +354,24 @@ module QubeRails
|
|
|
137
354
|
TYPES = %w[text number boolean select search rows].freeze
|
|
138
355
|
|
|
139
356
|
attr_reader :name, :input_name, :dom_id, :type, :label, :required, :options, :kind,
|
|
140
|
-
:search_url, :search_field, :row_key, :when, :rows, :context, :disabled
|
|
357
|
+
:search_url, :search_field, :row_key, :when, :rows, :context, :disabled, :value,
|
|
358
|
+
:error_id
|
|
141
359
|
|
|
142
|
-
# A choice's field, as QuBe Sync sends it
|
|
143
|
-
|
|
360
|
+
# A choice's field, as QuBe Sync sends it; refused: its choice's answer was just refused, so
|
|
361
|
+
# it's marked invalid and holds what was typed.
|
|
362
|
+
def self.from_prompt(field, question, choice_index, refused: false)
|
|
144
363
|
name = field["name"].to_s
|
|
145
364
|
input_name = "data[#{name}]"
|
|
146
365
|
type = type_of(field, record_type: "search")
|
|
147
366
|
rows = if type == "rows"
|
|
148
|
-
RowsView.new(field, input_name: input_name, search_url: question.search_url)
|
|
367
|
+
RowsView.new(field, input_name: input_name, search_url: question.search_url, question: question)
|
|
149
368
|
end
|
|
150
369
|
new(name: name, input_name: input_name, dom_id: "qube-#{question.token}-#{choice_index}-#{name}",
|
|
151
370
|
type: type, label: field["label"] || name, required: field["required"] == true,
|
|
152
371
|
options: options_of(field), kind: field["kind"], search_url: question.search_url,
|
|
153
|
-
search_field: name, rows: rows
|
|
372
|
+
search_field: name, rows: rows,
|
|
373
|
+
value: (refused && type != "rows" ? question.refused_values.to_h[name] : nil),
|
|
374
|
+
error_id: (refused ? question.error_id : nil))
|
|
154
375
|
end
|
|
155
376
|
|
|
156
377
|
# What a prompt field shows as: a record a search, an enum a select, else by its type.
|
|
@@ -173,7 +394,7 @@ module QubeRails
|
|
|
173
394
|
# their label.
|
|
174
395
|
def initialize(name:, type:, label:, input_name: nil, dom_id: nil, required: false, options: [], kind: nil,
|
|
175
396
|
search_url: nil, search_field: nil, row_key: nil, when_values: nil, rows: nil,
|
|
176
|
-
context: :choice, disabled: false)
|
|
397
|
+
context: :choice, disabled: false, value: nil, error_id: nil, optional: nil)
|
|
177
398
|
raise ArgumentError, "QuBe Sync: no field type #{type.inspect}" unless TYPES.include?(type)
|
|
178
399
|
|
|
179
400
|
@name = name
|
|
@@ -191,6 +412,43 @@ module QubeRails
|
|
|
191
412
|
@rows = rows
|
|
192
413
|
@context = context
|
|
193
414
|
@disabled = disabled
|
|
415
|
+
@value = value
|
|
416
|
+
@error_id = error_id
|
|
417
|
+
@optional = optional.nil? ? !required : optional
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# A search box under offered records: never required (its pick is a row of its own), and it
|
|
421
|
+
# says "Search QuickBooks…".
|
|
422
|
+
def inline!
|
|
423
|
+
@inline = true
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def inline?
|
|
427
|
+
@inline == true
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def required
|
|
431
|
+
@required && !inline?
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
def placeholder
|
|
435
|
+
inline? ? QubeRails.t("question.search_quickbooks") : nil
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
# Whether it may be left empty: its label says "(optional)". A rows cell's column decides it,
|
|
439
|
+
# though a hidden cell isn't required in the markup yet.
|
|
440
|
+
def optional?
|
|
441
|
+
@optional && !%w[boolean rows].include?(type)
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
# Whether it's in a refused answer: aria-invalid, described by the refusal.
|
|
445
|
+
def invalid?
|
|
446
|
+
!error_id.nil?
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
# The aria attributes that say so.
|
|
450
|
+
def aria_invalid
|
|
451
|
+
invalid? ? { "aria-invalid": "true", "aria-describedby": error_id } : {}
|
|
194
452
|
end
|
|
195
453
|
|
|
196
454
|
def partial
|
data/lib/qube_rails/request.rb
CHANGED
|
@@ -28,6 +28,8 @@ module QubeRails
|
|
|
28
28
|
"qube_id): the customer finishes onboarding first"
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
connection.wait_for_link_check!(record, name) if connection.is_a?(QubeRails::Connection)
|
|
32
|
+
|
|
31
33
|
row, params_error = claim(record, connection)
|
|
32
34
|
raise params_error if params_error
|
|
33
35
|
return retry_queue(row) if row.reused?
|
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
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "A lost answer",
|
|
3
|
-
"note": "
|
|
3
|
+
"note": "QuickBooks never answered the add, so it isn't known whether the invoice went in. Your user picks the invoice that matches, adds it again, or cancels.",
|
|
4
4
|
"prompt": {
|
|
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
|
},
|