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'
}.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
48
49
50
|
# File 'app/models/metadata_presenter/component.rb', line 48
def autocomplete?
type == 'autocomplete'
end
|
#content? ⇒ Boolean
52
53
54
|
# File 'app/models/metadata_presenter/component.rb', line 52
def content?
type == 'content'
end
|
#find_item_by_uuid(uuid) ⇒ Object
60
61
62
|
# File 'app/models/metadata_presenter/component.rb', line 60
def find_item_by_uuid(uuid)
items.find { |item| item.uuid == uuid }
end
|
#humanised_title ⇒ Object
28
29
30
|
# File 'app/models/metadata_presenter/component.rb', line 28
def humanised_title
label || legend
end
|
#items ⇒ Object
32
33
34
35
36
|
# File 'app/models/metadata_presenter/component.rb', line 32
def items
Array(metadata.items).map do |item|
item_klass.new(item, editor: editor?)
end
end
|
#supported_validations ⇒ Object
64
65
66
67
68
69
70
|
# File 'app/models/metadata_presenter/component.rb', line 64
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
44
45
46
|
# File 'app/models/metadata_presenter/component.rb', line 44
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.
18
19
20
21
22
|
# File 'app/models/metadata_presenter/component.rb', line 18
def to_json(*_args)
return super unless autocomplete?
JSON.parse(super).to_json(except: 'items')
end
|
#to_partial_path ⇒ Object
24
25
26
|
# File 'app/models/metadata_presenter/component.rb', line 24
def to_partial_path
"metadata_presenter/component/#{type}"
end
|
#upload? ⇒ Boolean
56
57
58
|
# File 'app/models/metadata_presenter/component.rb', line 56
def upload?
type == 'upload'
end
|
#validation_threshold ⇒ Object