quby-compiler 0.5.23 → 0.5.24

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6d745ba161d7dca63ed71bd68f0e0d3fcd22f217f730c1a06584bee9084d62c
4
- data.tar.gz: 4ac2be2cd51b3f9ad5e91e2c16f0654ea3fc52263ab93da3416cf3afcca745c0
3
+ metadata.gz: 4562dd43458813b4fcb9602d10ec82732aea08c22ca12dd1f0b0b934dd25282b
4
+ data.tar.gz: '041953ff8c41909b57b03f98fa20f14bb6094d4392b911cbc56a464b454ad6d1'
5
5
  SHA512:
6
- metadata.gz: 66cf125bda0986919c0d019d704cab0180eff8a075d0d16649eac654517df018585800d88629548bec29289a92d7f712c7c036680f8e64ea00f87de93a04bfea
7
- data.tar.gz: 7e639345f39abf65ab07353751cbfddd7db6ecab328eed8feaf0bfa239ebb3b18e3d5e7961a4e42a46932d1090db00c60c4c41c9eaac1fec875cab5601a55ec2
6
+ metadata.gz: 280c9f616bf3d451f82ccb35ab8eda3e5f1983b1a050171cebe12c4f59e334e61a4d58f51172ed69663733cb65bb7d44e1ef716d219e248745e6cc87ed5cce8e
7
+ data.tar.gz: 4c7ce2ae68ddd2c044dd24d02b7d29f7172b19a6424a8728328d3b79a352f97a0a5e9a9634928703670e27c14e7138d1fac2b76010a015fdf9a61acae1c0bd30
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.5.24
2
+
3
+ * frontend_v_2: Add dependsOnQuestions and DependsOnOptions to requires_answer validation.
4
+
1
5
  # 0.5.23
2
6
 
3
7
  * Validate check_all_option and uncheck_all_option exists.
@@ -10,8 +10,6 @@ module Quby
10
10
 
11
11
  MARKDOWN_ATTRIBUTES = %w(description title).freeze
12
12
 
13
- set_callback :after_dsl_enhance, :expand_depends_on_input_keys
14
-
15
13
  # Standard attributes
16
14
  attr_accessor :key
17
15
  validates :key, presence: true, 'quby/compiler/type': {is_a: Symbol}
@@ -183,7 +181,7 @@ module Quby
183
181
 
184
182
  # Require subquestions of required questions by default
185
183
  options[:required] = true if @parent&.validations&.first&.fetch(:type, nil) == :requires_answer
186
- @validations << {type: :requires_answer, explanation: options[:error_explanation]} if options[:required]
184
+ @validations << {type: :requires_answer, explanation: options[:error_explanation] } if options[:required]
187
185
 
188
186
  if @type == :float
189
187
  @validations << {type: :valid_float, explanation: options[:error_explanation]}
@@ -232,14 +230,6 @@ module Quby
232
230
  end
233
231
  # rubocop:enable AccessorMethodName
234
232
 
235
- def expand_depends_on_input_keys
236
- return unless @depends_on
237
- @depends_on = questionnaire.expand_input_keys(@depends_on)
238
- @extra_data[:"depends-on"] = @depends_on.to_json
239
- rescue => e
240
- raise e.class, "Question #{key} depends_on contains an error: #{e.message}"
241
- end
242
-
243
233
  def col_span
244
234
  options.length > 0 && type != :select ? options.length : @col_span
245
235
  end
@@ -68,7 +68,7 @@ module Quby
68
68
  description: question.description,
69
69
  presentation: question.presentation,
70
70
  hidden: question.hidden,
71
- depends_on: question.depends_on,
71
+ depends_on: expand_depends_on_input_keys(question),
72
72
  default_position: question.default_position,
73
73
  col_span: question.col_span,
74
74
  row_span: question.row_span,
@@ -366,6 +366,14 @@ module Quby
366
366
  exclude_end: range.exclude_end?
367
367
  }
368
368
  end
369
+
370
+ def expand_depends_on_input_keys(question)
371
+ return unless question.depends_on.present?
372
+
373
+ questionnaire.expand_input_keys(question.depends_on)
374
+ rescue => e
375
+ raise e.class, "Question #{question.key} depends_on contains an error: #{e.message}"
376
+ end
369
377
  end
370
378
  end
371
379
  end
@@ -90,7 +90,7 @@ module Quby
90
90
  {
91
91
  type: 'info',
92
92
  key: info_block.key,
93
- html: handle_html(info_block.html, type: :question_description, v1_markdown: false),
93
+ html: handle_html(info_block.html, type: :prose, v1_markdown: false),
94
94
  startOpen: info_block.start_open,
95
95
  items: info_block.items.map { panel_item(_1) }.compact
96
96
  }
@@ -289,15 +289,44 @@ module Quby
289
289
  @questionnaire.validations.map do |validation|
290
290
  validation.config.compact
291
291
  .transform_keys{ _1.to_s.camelize(:lower) }
292
- .tap do |validation_hsh|
292
+ .tap { |validation_hsh|
293
293
  # otherwise ruby will put a (?-mix around the regex, which js errors on.
294
294
  validation_hsh['matcher'] = validation_hsh['matcher'].source.to_s if validation_hsh['matcher']
295
295
  validation_hsh['type'] = 'minimum_date' if validation_hsh['type'] == :minimum && validation_hsh['subtype'] == :date
296
296
  validation_hsh['type'] = 'maximum_date' if validation_hsh['type'] == :maximum && validation_hsh['subtype'] == :date
297
- end.as_json
297
+ validation_hsh['dependsOnQuestions'] = depends_on(validation_hsh) if validation_hsh['type'] == :requires_answer
298
+ validation_hsh['dependsOnOptions'] = depends_on_options(validation_hsh) if validation_hsh['type'] == :requires_answer
299
+ }.compact.as_json
298
300
  end
299
301
  end
300
302
 
303
+ def depends_on(validation_hsh)
304
+ question = @questionnaire.question_hash[validation_hsh['fieldKey']]
305
+ return unless question.depends_on.present?
306
+
307
+ question.depends_on.select { @questionnaire.question_hash.key?(_1) }
308
+ end
309
+
310
+ def depends_on_options(validation_hsh)
311
+ question = @questionnaire.question_hash[validation_hsh['fieldKey']]
312
+ return unless question.depends_on.present?
313
+
314
+ question.depends_on
315
+ .map(&:to_s)
316
+ .reject { @questionnaire.question_hash.key?(_1) }
317
+ .map { |key|
318
+ question_key, option_key = key.split(/_(?=[^_]+$)/) # split on last _, works for all existing questionnaires.
319
+ if @questionnaire.question_hash.key?(question_key)
320
+ if @questionnaire.question_hash[question_key].options.any? { _1.key.to_s == option_key } # single_select
321
+ next [question_key, option_key]
322
+ elsif @questionnaire.question_hash[question_key].options.any? { _1.key.to_s == key } # multi_select
323
+ next [question_key, key]
324
+ end
325
+ end
326
+ raise "#{validation_hsh['fieldKey']} depends_on: can't find key '#{question_key}_#{option_key}'."
327
+ }.group_by(&:first).transform_values{ _1.map(&:last) }
328
+ end
329
+
301
330
  def handle_html(html, type: :simple, v1_markdown: true)
302
331
  if layout_version == :v2
303
332
  case type
@@ -1,5 +1,5 @@
1
1
  module Quby
2
2
  module Compiler
3
- VERSION = "0.5.23"
3
+ VERSION = "0.5.24"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quby-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.23
4
+ version: 0.5.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-24 00:00:00.000000000 Z
10
+ date: 2025-07-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activemodel
@@ -151,7 +151,6 @@ files:
151
151
  - lib/quby/compiler/dsl/charting/radar_chart_builder.rb
152
152
  - lib/quby/compiler/dsl/helpers.rb
153
153
  - lib/quby/compiler/dsl/info_block_builder.rb
154
- - lib/quby/compiler/dsl/merge(values(:v_1, :v_2), values(v_4).rb
155
154
  - lib/quby/compiler/dsl/panel_builder.rb
156
155
  - lib/quby/compiler/dsl/question_builder.rb
157
156
  - lib/quby/compiler/dsl/questionnaire_builder.rb
@@ -1,16 +0,0 @@
1
- merge(values(:v_1, :v_2), values(v_4).recode(1 => 3)).sum
2
-
3
-
4
-
5
- divide(value(:v_2), multiply(value(:v_1), value(:v_1)))
6
-
7
- w / l * l
8
-
9
-
10
- sexp_variable :key1 do
11
- foo = values(:v_1, :v_2)
12
- bar = recode(foo, 1 => 3)
13
- bla = merge(foo, bar)
14
- sum(bla)
15
-
16
- end