quby-compiler 0.6.10 → 0.6.11
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 +19 -4
- data/lib/quby/compiler/dsl/question_builder.rb +3 -1
- data/lib/quby/compiler/dsl/questionnaire_builder.rb +10 -0
- data/lib/quby/compiler/dsl/questions/option_set_multi_select_question_builder.rb +16 -0
- data/lib/quby/compiler/dsl/sexp_variable_builder.rb +44 -0
- data/lib/quby/compiler/entities/question.rb +1 -0
- data/lib/quby/compiler/entities/questionnaire.rb +9 -0
- data/lib/quby/compiler/entities/questions/option_set_multi_select_question.rb +24 -0
- data/lib/quby/compiler/entities/sexp_variable.rb +47 -1
- data/lib/quby/compiler/entities/sexp_variables.rb +54 -4
- data/lib/quby/compiler/outputs/locale_serializer.rb +2 -1
- data/lib/quby/compiler/outputs/quby_frontend_v1_serializer.rb +4 -0
- data/lib/quby/compiler/outputs/quby_frontend_v2_serializer.rb +7 -0
- data/lib/quby/compiler/outputs/roqua_serializer.rb +3 -0
- data/lib/quby/compiler/services/definition_validator.rb +11 -0
- data/lib/quby/compiler/services/quby_proxy.rb +1 -1
- data/lib/quby/compiler/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eaf83764fb2a549594b3309d88e25e13d0346a57dc709debd68715241b192ae4
|
|
4
|
+
data.tar.gz: 66ea5c81240fc00eb264743ae72785a99f96bc1d1ce6d876d178ef793fe059a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b1ddb5ba6ac6d18d317b7b163000b6ea498cf097ce9140422a08debeb27b828f9e42a31bcfeac209a604b39d8709d3e2c1b5a556efc482ec6e1d973caeaa8a45
|
|
7
|
+
data.tar.gz: 45d62ba99ee721eff43252f8e1bc79e904ac5029301b73a5836e1dd4c05aa87d4bf4b96d65fc0667cf3abc5b91f5d516bbd23f628f0b68dcaf9b7693f5c3a0ce
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Unreleased
|
|
2
2
|
|
|
3
|
+
# 0.6.11
|
|
4
|
+
|
|
5
|
+
* dsl + quby1.json + quby2.json: Add question type `option_set_multi_select` with an `option_set_key`. Its options are given at
|
|
6
|
+
render time as an option set; the answer is an array of the selected option keys. Quby 2 layout only.
|
|
7
|
+
* dsl + quby2.json: Add `option_set_available(key)` to s-expressions, true when the option set is given and has options.
|
|
8
|
+
* dsl + quby2.json: Add `translation key, text` to declare a translation that isn't tied to a question or panel.
|
|
9
|
+
* dsl + quby2.json: Add translation to s-expressions. It reads such a translation key and fills its
|
|
10
|
+
`{{-placeholder-}}`s with s-expressions; the result is empty when any replacement is missing.
|
|
11
|
+
* dsl_quby2.json: Add `textvar_value key` to s-expressions, reading the value of a textvar.
|
|
12
|
+
* dsl_quby2.json: Add `parse_date value` and `format_date value, format: :auto_past` to
|
|
13
|
+
s-expressions, reading a string as an iso8601 date and writing it out for display. Formats are
|
|
14
|
+
`:auto_past`, the shortest form that still says which moment it is, `:day_month_year`, the date
|
|
15
|
+
in full, and `:day_month_year_time`, the date and time in full. Dates can only be used through format_date, a sexp_variable can't have type date
|
|
16
|
+
itself.
|
|
17
|
+
|
|
3
18
|
# 0.6.10
|
|
4
19
|
|
|
5
20
|
* dsl + quby2.json: Add min/max to s-expressions.
|
|
@@ -10,13 +25,13 @@
|
|
|
10
25
|
|
|
11
26
|
# 0.6.8
|
|
12
27
|
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
28
|
+
* dsl + quby2.json: Add count_selected to s-expressions.
|
|
29
|
+
* dsl + quby2.json: Add cond, true and false to s-expressions. cond evaluates the body of the first clause whose test is true; each body must have the same type.
|
|
30
|
+
* dsl + quby2.json: single_select_label variables (also via cond) must be declared `type: :quest_i18n_key` and are serialized with that type.
|
|
16
31
|
|
|
17
32
|
# 0.6.7
|
|
18
33
|
|
|
19
|
-
*
|
|
34
|
+
* dsl + quby2.json: Add single_select_label to s-expressions.
|
|
20
35
|
|
|
21
36
|
# 0.6.6
|
|
22
37
|
|
|
@@ -8,6 +8,7 @@ require 'quby/compiler/dsl/questions/date_question_builder'
|
|
|
8
8
|
require 'quby/compiler/dsl/questions/deprecated_question_builder'
|
|
9
9
|
require 'quby/compiler/dsl/questions/float_question_builder'
|
|
10
10
|
require 'quby/compiler/dsl/questions/integer_question_builder'
|
|
11
|
+
require 'quby/compiler/dsl/questions/option_set_multi_select_question_builder'
|
|
11
12
|
require 'quby/compiler/dsl/questions/radio_question_builder'
|
|
12
13
|
require 'quby/compiler/dsl/questions/select_question_builder'
|
|
13
14
|
require 'quby/compiler/dsl/questions/string_question_builder'
|
|
@@ -28,7 +29,8 @@ module Quby
|
|
|
28
29
|
'select' => Questions::SelectQuestionBuilder,
|
|
29
30
|
'check_box' => Questions::CheckboxQuestionBuilder,
|
|
30
31
|
'date' => Questions::DateQuestionBuilder,
|
|
31
|
-
'hidden' => Questions::DeprecatedQuestionBuilder
|
|
32
|
+
'hidden' => Questions::DeprecatedQuestionBuilder,
|
|
33
|
+
'option_set_multi_select' => Questions::OptionSetMultiSelectQuestionBuilder
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
def self.build(key, **options, &block)
|
|
@@ -234,6 +234,16 @@ module Quby
|
|
|
234
234
|
end
|
|
235
235
|
end
|
|
236
236
|
|
|
237
|
+
# A translation that isn't tied to a question or panel, for use in sexp_variables:
|
|
238
|
+
#
|
|
239
|
+
# translation :score_summary, "Je hebt {{-count-}} van de {{-total-}} vragen beantwoord."
|
|
240
|
+
#
|
|
241
|
+
# The `{{-...-}}` placeholders are filled in when the translation is displayed, with the
|
|
242
|
+
# replacements given to the `translation` call in the sexp_variable that refers to this key.
|
|
243
|
+
def translation(key, text)
|
|
244
|
+
@questionnaire.add_translation(key, text)
|
|
245
|
+
end
|
|
246
|
+
|
|
237
247
|
def sexp_variable(key, type: :number, &block)
|
|
238
248
|
@questionnaire.add_sexp_variable(key, SexpVariableBuilder.new(key, type:, &block).build)
|
|
239
249
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Quby
|
|
4
|
+
module Compiler
|
|
5
|
+
module DSL
|
|
6
|
+
module Questions
|
|
7
|
+
class OptionSetMultiSelectQuestionBuilder < Base
|
|
8
|
+
def initialize(key, **options, &block)
|
|
9
|
+
super
|
|
10
|
+
@question = Entities::Questions::OptionSetMultiSelectQuestion.new(key, options)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -19,10 +19,54 @@ module Quby::Compiler
|
|
|
19
19
|
Entities::SexpVariables::StringValue.new(op: :string_value, key: key)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
# The value of a textvar, filled in by the protocol or by a question that sets it.
|
|
23
|
+
# Takes the full textvar key, so including the questionnaire key in front of it, the same way
|
|
24
|
+
# a question's `sets_textvar` does.
|
|
25
|
+
def textvar_value(key)
|
|
26
|
+
Entities::SexpVariables::TextvarValue.new(key: key)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Reads a string as an iso8601 date or datetime, so that `format_date` can show it:
|
|
30
|
+
#
|
|
31
|
+
# format_date(parse_date(textvar_value(:rq_mylist_last_filled_out)))
|
|
32
|
+
#
|
|
33
|
+
# The result is empty when the string isn't an iso8601 date.
|
|
34
|
+
def parse_date(value)
|
|
35
|
+
Entities::SexpVariables::ParseDate.new(value: value)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Writes a date out for display, in the language the questionnaire is being filled out in.
|
|
39
|
+
#
|
|
40
|
+
# `:auto_past` picks the shortest form that still says which moment it is: a time for today,
|
|
41
|
+
# "gisteren 15:30" for yesterday, a weekday with a time up to five days back, a day and month
|
|
42
|
+
# up to ten months back, and a day, month and year ("15 oktober 2025") before that. It is
|
|
43
|
+
# meant for dates in the past, dates in the future get that last form too.
|
|
44
|
+
# `:day_month_year` always writes the date out in full: "15 oktober 2025".
|
|
45
|
+
# `:day_month_year_time` always writes the date and the time out in full: "15 oktober 2025 om 15:30".
|
|
46
|
+
def format_date(value, format: :auto_past)
|
|
47
|
+
Entities::SexpVariables::FormatDate.new(value: value, format: format)
|
|
48
|
+
end
|
|
49
|
+
|
|
22
50
|
def single_select_label(key)
|
|
23
51
|
Entities::SexpVariables::SingleSelectLabel.new(op: :single_select_label, key: key)
|
|
24
52
|
end
|
|
25
53
|
|
|
54
|
+
# The key of a translation defined with the questionnaire's `translation` DSL method, with a
|
|
55
|
+
# calculation for each `{{-replacement-}}` placeholder in it:
|
|
56
|
+
#
|
|
57
|
+
# translation(:score_summary, count: count_selected(:v_5), total: 10)
|
|
58
|
+
#
|
|
59
|
+
# Replacements can't be quest_i18n_keys themselves; numbers and booleans are shown as strings.
|
|
60
|
+
def translation(key, **replacements)
|
|
61
|
+
Entities::SexpVariables::Translation.new(op: :translation, key: key,
|
|
62
|
+
replacements: replacements.transform_values { wrap_scalars(_1) })
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Whether the option set (used by option_set_multi_select questions) is given and has options.
|
|
66
|
+
def option_set_available(option_set_key)
|
|
67
|
+
Entities::SexpVariables::OptionSetAvailable.new(key: option_set_key)
|
|
68
|
+
end
|
|
69
|
+
|
|
26
70
|
def count_selected(key)
|
|
27
71
|
Entities::SexpVariables::CountSelected.new(key: key)
|
|
28
72
|
end
|
|
@@ -342,6 +342,7 @@ require 'quby/compiler/entities/questions/date_question'
|
|
|
342
342
|
require 'quby/compiler/entities/questions/deprecated_question'
|
|
343
343
|
require 'quby/compiler/entities/questions/float_question'
|
|
344
344
|
require 'quby/compiler/entities/questions/integer_question'
|
|
345
|
+
require 'quby/compiler/entities/questions/option_set_multi_select_question'
|
|
345
346
|
require 'quby/compiler/entities/questions/radio_question'
|
|
346
347
|
require 'quby/compiler/entities/questions/select_question'
|
|
347
348
|
require 'quby/compiler/entities/questions/string_question'
|
|
@@ -54,6 +54,7 @@ module Quby
|
|
|
54
54
|
@check_score_keys_consistency = true
|
|
55
55
|
@lookup_tables = {}
|
|
56
56
|
@sexp_variables = {}
|
|
57
|
+
@extra_translations = {}
|
|
57
58
|
@extra_visibility_rules = []
|
|
58
59
|
@versions = []
|
|
59
60
|
@editable_from_version = nil
|
|
@@ -111,6 +112,8 @@ module Quby
|
|
|
111
112
|
attr_accessor :outcome_tables
|
|
112
113
|
attr_accessor :score_schemas
|
|
113
114
|
attr_accessor :sexp_variables
|
|
115
|
+
# Translations declared in the definition with the `translation` DSL method, key => text.
|
|
116
|
+
attr_accessor :extra_translations
|
|
114
117
|
attr_reader :extra_visibility_rules
|
|
115
118
|
attr_accessor :lookup_tables
|
|
116
119
|
attr_accessor :anonymous_conditions
|
|
@@ -384,6 +387,12 @@ module Quby
|
|
|
384
387
|
sexp_variables[key] = sexp_variable
|
|
385
388
|
end
|
|
386
389
|
|
|
390
|
+
def add_translation(key, text)
|
|
391
|
+
fail(ArgumentError, "Translation '#{key}' already defined") if extra_translations.key?(key.to_s)
|
|
392
|
+
|
|
393
|
+
extra_translations[key.to_s] = text
|
|
394
|
+
end
|
|
395
|
+
|
|
387
396
|
def add_outcome_table(outcome_table_options)
|
|
388
397
|
outcome_tables << OutcomeTable.new(**outcome_table_options, questionnaire: self)
|
|
389
398
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Quby
|
|
4
|
+
module Compiler
|
|
5
|
+
module Entities
|
|
6
|
+
module Questions
|
|
7
|
+
# Multi select question whose options are not part of the questionnaire definition.
|
|
8
|
+
# They are given at render time (by roqua) as a named option set: [{key:, label:}, ..].
|
|
9
|
+
# The answer is an array of the selected option keys.
|
|
10
|
+
class OptionSetMultiSelectQuestion < Question
|
|
11
|
+
# key of the option set to show the options of.
|
|
12
|
+
attr_accessor :option_set_key
|
|
13
|
+
|
|
14
|
+
validates :option_set_key, presence: true, 'quby/compiler/type': {is_a: Symbol}
|
|
15
|
+
|
|
16
|
+
def initialize(key, options = {})
|
|
17
|
+
super
|
|
18
|
+
@option_set_key = options[:option_set_key]&.to_sym
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -12,6 +12,10 @@ module Quby::Compiler::Entities
|
|
|
12
12
|
|
|
13
13
|
# Called by DefinitionValidator.
|
|
14
14
|
def validate(questionnaire, calculation: self.calculation)
|
|
15
|
+
if type == :date
|
|
16
|
+
fail "sexp_variable #{key} has type date, which can't be shown; wrap it in format_date for a string."
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
validate_node(calculation, questionnaire:, type:)
|
|
16
20
|
end
|
|
17
21
|
|
|
@@ -31,12 +35,23 @@ module Quby::Compiler::Entities
|
|
|
31
35
|
when SexpVariables::StringValue
|
|
32
36
|
validate_question_exist(questionnaire, node)
|
|
33
37
|
validate_value_is_string(questionnaire, node)
|
|
38
|
+
when SexpVariables::TextvarValue
|
|
39
|
+
validate_textvar_exist(questionnaire, node)
|
|
40
|
+
when SexpVariables::ParseDate
|
|
41
|
+
validate_node(node.value, questionnaire:, type: :string)
|
|
42
|
+
when SexpVariables::FormatDate
|
|
43
|
+
validate_node(node.value, questionnaire:, type: :date)
|
|
34
44
|
when SexpVariables::SingleSelectLabel
|
|
35
45
|
validate_question_exist(questionnaire, node)
|
|
36
46
|
validate_value_is_single_select(questionnaire, node)
|
|
37
47
|
when SexpVariables::CountSelected
|
|
38
48
|
validate_question_exist(questionnaire, node)
|
|
39
49
|
validate_value_is_multi_select(questionnaire, node)
|
|
50
|
+
when SexpVariables::Translation
|
|
51
|
+
validate_translation_exists(questionnaire, node)
|
|
52
|
+
node.replacements.each_value do |replacement|
|
|
53
|
+
validate_replacement(replacement, questionnaire:)
|
|
54
|
+
end
|
|
40
55
|
when SexpVariables::NumberReducer
|
|
41
56
|
node.values.each do |value|
|
|
42
57
|
validate_node(value, questionnaire:, type: :number)
|
|
@@ -63,6 +78,26 @@ module Quby::Compiler::Entities
|
|
|
63
78
|
fail "sexp_variable #{key} has invalid type #{node.class} for expected type #{type}."
|
|
64
79
|
end
|
|
65
80
|
|
|
81
|
+
def validate_translation_exists(questionnaire, sexp)
|
|
82
|
+
return if questionnaire.extra_translations.key?(sexp.key.to_s)
|
|
83
|
+
|
|
84
|
+
fail "sexp_variable #{key} uses translation #{sexp.key}, which is not defined with `translation`."
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Replacements have no declared type, their own type determines how they are rendered.
|
|
88
|
+
def validate_replacement(replacement, questionnaire:)
|
|
89
|
+
type = node_type(replacement)
|
|
90
|
+
if type == :quest_i18n_key
|
|
91
|
+
fail "sexp_variable #{key} uses a quest_i18n_key as a translation replacement, which is not supported."
|
|
92
|
+
end
|
|
93
|
+
if type == :date
|
|
94
|
+
fail "sexp_variable #{key} uses a date as a translation replacement, which is not " \
|
|
95
|
+
"supported. Wrap it in format_date for a string."
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
validate_node(replacement, questionnaire:, type:)
|
|
99
|
+
end
|
|
100
|
+
|
|
66
101
|
def validate_question_exist(questionnaire, sexp)
|
|
67
102
|
return if questionnaire.question_hash.key?(sexp.key)
|
|
68
103
|
|
|
@@ -91,11 +126,20 @@ module Quby::Compiler::Entities
|
|
|
91
126
|
|
|
92
127
|
def validate_value_is_multi_select(questionnaire, sexp)
|
|
93
128
|
question = questionnaire.question_hash[sexp.key]
|
|
94
|
-
|
|
129
|
+
case question
|
|
130
|
+
when Questions::CheckboxQuestion, Questions::OptionSetMultiSelectQuestion
|
|
131
|
+
return
|
|
132
|
+
end
|
|
95
133
|
|
|
96
134
|
fail "sexp_variable #{key} uses non-multi-select question #{sexp.key} for count_selected."
|
|
97
135
|
end
|
|
98
136
|
|
|
137
|
+
def validate_textvar_exist(questionnaire, sexp)
|
|
138
|
+
return if questionnaire.textvars.key?(sexp.key)
|
|
139
|
+
|
|
140
|
+
fail "sexp_variable #{key} uses nonexistent textvar #{sexp.key}."
|
|
141
|
+
end
|
|
142
|
+
|
|
99
143
|
def validate_value_is_string(questionnaire, sexp)
|
|
100
144
|
question = questionnaire.question_hash[sexp.key]
|
|
101
145
|
case question
|
|
@@ -118,6 +162,8 @@ module Quby::Compiler::Entities
|
|
|
118
162
|
:string
|
|
119
163
|
when SexpVariables::QuestI18nKeyType
|
|
120
164
|
:quest_i18n_key
|
|
165
|
+
when SexpVariables::DateType
|
|
166
|
+
:date
|
|
121
167
|
end
|
|
122
168
|
end
|
|
123
169
|
end
|
|
@@ -16,15 +16,23 @@ module Quby::Compiler::Entities
|
|
|
16
16
|
class Comparer < Base; end
|
|
17
17
|
class True < Base; end
|
|
18
18
|
class False < Base; end
|
|
19
|
+
class OptionSetAvailable < Base; end
|
|
19
20
|
|
|
20
21
|
class StringValue < Base; end
|
|
22
|
+
class TextvarValue < Base; end
|
|
21
23
|
class SingleSelectLabel < Base; end
|
|
24
|
+
class Translation < Base; end
|
|
25
|
+
|
|
26
|
+
class ParseDate < Base; end
|
|
27
|
+
class FormatDate < Base; end
|
|
22
28
|
|
|
23
29
|
NumericType = Number | NumberReducer | NumberMethod | NumberValue | CountSelected | Cond
|
|
24
|
-
BooleanType = BooleanReducer | Comparer | True | False | Cond
|
|
25
|
-
StringType = StringValue | Cond
|
|
26
|
-
QuestI18nKeyType = SingleSelectLabel | Cond
|
|
27
|
-
|
|
30
|
+
BooleanType = BooleanReducer | Comparer | True | False | OptionSetAvailable | Cond
|
|
31
|
+
StringType = StringValue | TextvarValue | FormatDate | Cond
|
|
32
|
+
QuestI18nKeyType = SingleSelectLabel | Translation | Cond
|
|
33
|
+
# Dates exist only to be fed to format_date, a sexp_variable can't have this type itself.
|
|
34
|
+
DateType = ParseDate | Cond
|
|
35
|
+
AllTypes = NumericType | BooleanType | StringType | QuestI18nKeyType | DateType
|
|
28
36
|
|
|
29
37
|
class NumberValue
|
|
30
38
|
attribute :op, Quby::Types::Symbol.enum(:number_value)
|
|
@@ -36,12 +44,47 @@ module Quby::Compiler::Entities
|
|
|
36
44
|
attribute :key, Quby::Types::Symbol
|
|
37
45
|
end
|
|
38
46
|
|
|
47
|
+
# value of a textvar, as filled in by the protocol or by a question that sets it.
|
|
48
|
+
# The key is the full textvar key, so including the questionnaire key in front of it.
|
|
49
|
+
class TextvarValue
|
|
50
|
+
attribute :op, Quby::Types::Symbol.default(:textvar_value).enum(:textvar_value)
|
|
51
|
+
attribute :key, Quby::Types::Symbol
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# reads a string as an iso8601 date or datetime, so that format_date can show it.
|
|
55
|
+
# The result is empty when the string isn't one.
|
|
56
|
+
class ParseDate
|
|
57
|
+
attribute :op, Quby::Types::Symbol.default(:parse_date).enum(:parse_date)
|
|
58
|
+
attribute :value, StringType
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# returning a String: a date written out for display, in the language the questionnaire is
|
|
62
|
+
# being filled out in.
|
|
63
|
+
# `auto_past` picks the shortest form that still says which moment it is: a time for today,
|
|
64
|
+
# "gisteren 15:30", "maandag 15:30", "15 oktober", "15 oktober 2018"
|
|
65
|
+
# `day_month_year` always writes the date out in full: "15 oktober 2025".
|
|
66
|
+
# `day_month_year_time` always writes the date and the time out in full: "15 oktober 2025 om 15:30".
|
|
67
|
+
class FormatDate
|
|
68
|
+
attribute :op, Quby::Types::Symbol.default(:format_date).enum(:format_date)
|
|
69
|
+
attribute :value, DateType
|
|
70
|
+
attribute :format, Quby::Types::Symbol.default(:auto_past).enum(:auto_past, :day_month_year, :day_month_year_time)
|
|
71
|
+
end
|
|
72
|
+
|
|
39
73
|
# label of the selected option of a single-select (radio, scale, select) question.
|
|
40
74
|
class SingleSelectLabel
|
|
41
75
|
attribute :op, Quby::Types::Symbol.enum(:single_select_label)
|
|
42
76
|
attribute :key, Quby::Types::Symbol
|
|
43
77
|
end
|
|
44
78
|
|
|
79
|
+
# key of a translation defined with the `translation` DSL method, along with the values for the
|
|
80
|
+
# `{{-replacement-}}` placeholders in it. Placeholders are filled in when the translation is displayed.
|
|
81
|
+
class Translation
|
|
82
|
+
attribute :op, Quby::Types::Symbol.default(:translation).enum(:translation)
|
|
83
|
+
attribute :key, Quby::Types::Symbol
|
|
84
|
+
# SexpVariable#validate rejects quest_i18n_key replacements, those would need translating first.
|
|
85
|
+
attribute :replacements, Quby::Types::Hash.map(Quby::Types::Symbol, AllTypes)
|
|
86
|
+
end
|
|
87
|
+
|
|
45
88
|
# returning a Boolean: always true. Used as the default case of a cond.
|
|
46
89
|
class True
|
|
47
90
|
attribute :op, Quby::Types::Symbol.default(:true).enum(:true)
|
|
@@ -52,6 +95,13 @@ module Quby::Compiler::Entities
|
|
|
52
95
|
attribute :op, Quby::Types::Symbol.default(:false).enum(:false)
|
|
53
96
|
end
|
|
54
97
|
|
|
98
|
+
# returning a Boolean: whether the option set with this key was given at render time and has options.
|
|
99
|
+
class OptionSetAvailable
|
|
100
|
+
attribute :op, Quby::Types::Symbol.default(:option_set_available).enum(:option_set_available)
|
|
101
|
+
# key of the option set
|
|
102
|
+
attribute :key, Quby::Types::Symbol
|
|
103
|
+
end
|
|
104
|
+
|
|
55
105
|
# number of selected options of a multi-select (check_box) question.
|
|
56
106
|
class CountSelected
|
|
57
107
|
attribute :op, Quby::Types::Symbol.default(:count_selected).enum(:count_selected)
|
|
@@ -18,6 +18,7 @@ module Quby
|
|
|
18
18
|
footer: @quby_frontend_v2_serializer.footer,
|
|
19
19
|
**panel_locale_values,
|
|
20
20
|
**validations_locale_values,
|
|
21
|
+
**@questionnaire.extra_translations,
|
|
21
22
|
}.compact
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -81,7 +82,7 @@ module Quby
|
|
|
81
82
|
options_locale_values(question: question)
|
|
82
83
|
when :integer, :float
|
|
83
84
|
{"#{question.key}.unit" => question.unit}
|
|
84
|
-
when :string, :textarea, :date, :country_select
|
|
85
|
+
when :string, :textarea, :date, :country_select, :option_set_multi_select
|
|
85
86
|
{}
|
|
86
87
|
else
|
|
87
88
|
raise "Unknown question as #{as_type} for locale serialization"
|
|
@@ -131,6 +131,10 @@ module Quby
|
|
|
131
131
|
unit: question.unit,
|
|
132
132
|
size: question.size,
|
|
133
133
|
)
|
|
134
|
+
when Quby::Compiler::Entities::Questions::OptionSetMultiSelectQuestion
|
|
135
|
+
base_options.merge(
|
|
136
|
+
option_set_key: question.option_set_key
|
|
137
|
+
)
|
|
134
138
|
when Quby::Compiler::Entities::Questions::RadioQuestion
|
|
135
139
|
base_options.merge(
|
|
136
140
|
options: options_as_json(question)
|
|
@@ -163,6 +163,13 @@ module Quby
|
|
|
163
163
|
}.compact
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
+
def option_set_multi_select_question(question)
|
|
167
|
+
{
|
|
168
|
+
**base_question(question),
|
|
169
|
+
optionSetKey: question.option_set_key,
|
|
170
|
+
}.compact
|
|
171
|
+
end
|
|
172
|
+
|
|
166
173
|
def radio_question(question)
|
|
167
174
|
{
|
|
168
175
|
**base_question(question),
|
|
@@ -7,6 +7,7 @@ module Quby
|
|
|
7
7
|
date: 'date_parts',
|
|
8
8
|
float: 'float',
|
|
9
9
|
integer: 'integer',
|
|
10
|
+
option_set_multi_select: 'option_set_multi_select',
|
|
10
11
|
radio: 'single_select',
|
|
11
12
|
scale: 'single_select',
|
|
12
13
|
select: 'single_select',
|
|
@@ -199,6 +200,7 @@ module Quby
|
|
|
199
200
|
# parent_option_key [nil/string] question defined under option
|
|
200
201
|
# title_question_key [nil/string]
|
|
201
202
|
# date_parts [nil/{..}]
|
|
203
|
+
# option_set_key [nil/string] option_set_multi_select only, options are given per measurement sequence.
|
|
202
204
|
# options: [nil/{..}]
|
|
203
205
|
def questions
|
|
204
206
|
questionnaire.sorted_questions.reject{_1.type == :hidden}.map { |question|
|
|
@@ -216,6 +218,7 @@ module Quby
|
|
|
216
218
|
parent_option_key: question.parent_option_key,
|
|
217
219
|
title_question_key: question.title_question&.key,
|
|
218
220
|
date_parts: date_parts_for(question),
|
|
221
|
+
option_set_key: question.try(:option_set_key),
|
|
219
222
|
options: options_for(question)
|
|
220
223
|
}.compact
|
|
221
224
|
}
|
|
@@ -31,6 +31,7 @@ module Quby
|
|
|
31
31
|
validate_checkbox_options(questionnaire)
|
|
32
32
|
validate_visiblity_rules(questionnaire)
|
|
33
33
|
validate_quby2_unsupported_features(questionnaire)
|
|
34
|
+
validate_quby2_only_features(questionnaire)
|
|
34
35
|
validate_locales(questionnaire:, definition:)
|
|
35
36
|
# Some compilation errors are Exceptions (pure syntax errors) and some StandardErrors (NameErrors)
|
|
36
37
|
rescue Exception => exception # rubocop:disable Lint/RescueException
|
|
@@ -471,6 +472,16 @@ scores_schema tables to the resulting seed."
|
|
|
471
472
|
end
|
|
472
473
|
end
|
|
473
474
|
|
|
475
|
+
def validate_quby2_only_features(questionnaire)
|
|
476
|
+
return if questionnaire.layout_version == :v2
|
|
477
|
+
|
|
478
|
+
questionnaire.question_hash.each_value do |question|
|
|
479
|
+
if question.type == :option_set_multi_select
|
|
480
|
+
fail "Question #{question.key} of type option_set_multi_select is only supported for Quby 2 layout."
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
474
485
|
def validate_quby2_unsupported_features(questionnaire)
|
|
475
486
|
return unless questionnaire.layout_version == :v2
|
|
476
487
|
|
|
@@ -63,7 +63,7 @@ module Quby
|
|
|
63
63
|
subquestion(question, question_titles, d_qtypes, vars, question.title_question, nil, nil)
|
|
64
64
|
end
|
|
65
65
|
update_hidden_questions_for(question, for_checkbox: true)
|
|
66
|
-
when :textarea
|
|
66
|
+
when :textarea, :option_set_multi_select
|
|
67
67
|
d_qtypes[question.key.to_s] = { type: :text_field }
|
|
68
68
|
when :string, :integer, :float
|
|
69
69
|
handle_textfield(question, d_qtypes)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quby-compiler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marten Veldthuis
|
|
@@ -220,6 +220,7 @@ files:
|
|
|
220
220
|
- lib/quby/compiler/dsl/questions/deprecated_question_builder.rb
|
|
221
221
|
- lib/quby/compiler/dsl/questions/float_question_builder.rb
|
|
222
222
|
- lib/quby/compiler/dsl/questions/integer_question_builder.rb
|
|
223
|
+
- lib/quby/compiler/dsl/questions/option_set_multi_select_question_builder.rb
|
|
223
224
|
- lib/quby/compiler/dsl/questions/radio_question_builder.rb
|
|
224
225
|
- lib/quby/compiler/dsl/questions/select_question_builder.rb
|
|
225
226
|
- lib/quby/compiler/dsl/questions/string_question_builder.rb
|
|
@@ -257,6 +258,7 @@ files:
|
|
|
257
258
|
- lib/quby/compiler/entities/questions/deprecated_question.rb
|
|
258
259
|
- lib/quby/compiler/entities/questions/float_question.rb
|
|
259
260
|
- lib/quby/compiler/entities/questions/integer_question.rb
|
|
261
|
+
- lib/quby/compiler/entities/questions/option_set_multi_select_question.rb
|
|
260
262
|
- lib/quby/compiler/entities/questions/radio_question.rb
|
|
261
263
|
- lib/quby/compiler/entities/questions/select_question.rb
|
|
262
264
|
- lib/quby/compiler/entities/questions/string_question.rb
|