Class: MetadataPresenter::Component
- Inherits:
-
Metadata
- Object
- Metadata
- MetadataPresenter::Component
show all
- 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
#autocomplete? ⇒ Boolean
49
50
51
|
# File 'app/models/metadata_presenter/component.rb', line 49
def autocomplete?
type == 'autocomplete'
end
|
#conditionals ⇒ Object
85
86
87
88
89
|
# File 'app/models/metadata_presenter/component.rb', line 85
def conditionals
Array(metadata['conditionals']).map do |conditional_metadata|
MetadataPresenter::Conditional.new(conditional_metadata)
end
end
|
#content? ⇒ Boolean
53
54
55
|
# File 'app/models/metadata_presenter/component.rb', line 53
def content?
type == 'content'
end
|
#find_item_by_uuid(uuid) ⇒ Object
65
66
67
|
# File 'app/models/metadata_presenter/component.rb', line 65
def find_item_by_uuid(uuid)
items.find { |item| item.uuid == uuid }
end
|
#humanised_title ⇒ Object
29
30
31
|
# File 'app/models/metadata_presenter/component.rb', line 29
def humanised_title
label || legend
end
|
#items ⇒ Object
33
34
35
36
37
|
# File 'app/models/metadata_presenter/component.rb', line 33
def items
Array(metadata.items).map do |item|
item_klass.new(item, editor: editor?)
end
end
|
#max_files ⇒ Object
81
82
83
|
# File 'app/models/metadata_presenter/component.rb', line 81
def max_files
metadata.max_files.presence || '0'
end
|
#multiupload? ⇒ Boolean
61
62
63
|
# File 'app/models/metadata_presenter/component.rb', line 61
def multiupload?
type == 'multiupload'
end
|
#supported_validations ⇒ Object
69
70
71
72
73
74
75
|
# File 'app/models/metadata_presenter/component.rb', line 69
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
45
46
47
|
# File 'app/models/metadata_presenter/component.rb', line 45
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.
19
20
21
22
23
|
# File 'app/models/metadata_presenter/component.rb', line 19
def to_json(*_args)
return super unless autocomplete?
JSON.parse(super).to_json(except: 'items')
end
|
#to_partial_path ⇒ Object
25
26
27
|
# File 'app/models/metadata_presenter/component.rb', line 25
def to_partial_path
"metadata_presenter/component/#{type}"
end
|
#upload? ⇒ Boolean
57
58
59
|
# File 'app/models/metadata_presenter/component.rb', line 57
def upload?
type == 'upload'
end
|
#validation_threshold ⇒ Object