Class: MetadataPresenter::Component
- Inherits:
-
Metadata
- Object
- Metadata
- MetadataPresenter::Component
show all
- Includes:
- Comparable
- Defined in:
- app/models/metadata_presenter/component.rb
Constant Summary
collapse
- VALIDATION_BUNDLES =
{
'date' => 'date',
'number' => 'number',
'text' => 'string',
'textarea' => 'string',
'multiupload' => 'file'
}.freeze
- VALIDATION_STRING_LENGTH_THRESHOLD =
Used for max_length and max_word validations. Threshold percentage at which the remaining count is shown
75
- SUPPORTS_BRANCHING =
%w[radios checkboxes].freeze
Instance Attribute Summary
Attributes inherited from Metadata
#metadata
Instance Method Summary
collapse
Methods inherited from Metadata
#==, #editor?, #id, #initialize, #method_missing, #respond_to_missing?, #type, #uuid
Instance Method Details
#<=>(other) ⇒ Object
16
17
18
19
20
21
|
# File 'app/models/metadata_presenter/component.rb', line 16
def <=>(other)
return nil unless other.is_a?(MetadataPresenter::Component)
return 0 unless order && other.order
order <=> other.order
end
|
#autocomplete? ⇒ Boolean
58
59
60
|
# File 'app/models/metadata_presenter/component.rb', line 58
def autocomplete?
type == 'autocomplete'
end
|
#conditionals ⇒ Object
94
95
96
97
98
|
# File 'app/models/metadata_presenter/component.rb', line 94
def conditionals
Array(metadata['conditionals']).map do |conditional_metadata|
MetadataPresenter::Conditional.new(conditional_metadata)
end
end
|
#content? ⇒ Boolean
62
63
64
|
# File 'app/models/metadata_presenter/component.rb', line 62
def content?
type == 'content'
end
|
#find_item_by_uuid(uuid) ⇒ Object
74
75
76
|
# File 'app/models/metadata_presenter/component.rb', line 74
def find_item_by_uuid(uuid)
items.find { |item| item.uuid == uuid }
end
|
#humanised_title ⇒ Object
38
39
40
|
# File 'app/models/metadata_presenter/component.rb', line 38
def humanised_title
label || legend
end
|
#items ⇒ Object
42
43
44
45
46
|
# File 'app/models/metadata_presenter/component.rb', line 42
def items
Array(metadata.items).map do |item|
item_klass.new(item, editor: editor?)
end
end
|
#max_files ⇒ Object
90
91
92
|
# File 'app/models/metadata_presenter/component.rb', line 90
def max_files
metadata.max_files.presence || '0'
end
|
#multiupload? ⇒ Boolean
70
71
72
|
# File 'app/models/metadata_presenter/component.rb', line 70
def multiupload?
type == 'multiupload'
end
|
#supported_validations ⇒ Object
78
79
80
81
82
83
84
|
# File 'app/models/metadata_presenter/component.rb', line 78
def supported_validations
return [] if validation_bundle_key.nil?
JSON::Validator.schema_for_uri(validation_bundle_key)
.schema['properties']['validation']['properties']
.keys
end
|
#supports_branching? ⇒ Boolean
54
55
56
|
# File 'app/models/metadata_presenter/component.rb', line 54
def supports_branching?
type.in?(SUPPORTS_BRANCHING)
end
|
#to_json(*_args) ⇒ Object
Overriding here because autocomplete component’s items property is non interactable in the Editor therefore it does not need to exist in the data-fb-content-data attribute on the page. The data-fb-content-data attribute is what is used to update user interactable elements such as the component question or page section heading etc.
28
29
30
31
32
|
# File 'app/models/metadata_presenter/component.rb', line 28
def to_json(*_args)
return super unless autocomplete?
JSON.parse(super).to_json(except: 'items')
end
|
#to_partial_path ⇒ Object
34
35
36
|
# File 'app/models/metadata_presenter/component.rb', line 34
def to_partial_path
"metadata_presenter/component/#{type}"
end
|
#upload? ⇒ Boolean
66
67
68
|
# File 'app/models/metadata_presenter/component.rb', line 66
def upload?
type == 'upload'
end
|
#validation_threshold ⇒ Object