Class: MetadataPresenter::Page
- Inherits:
-
Metadata
show all
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/metadata_presenter/page.rb
Constant Summary
collapse
- NOT_EDITABLE =
i[
_uuid
_id
_type
add_component
].freeze
- QUESTION_PAGES =
%w[page.singlequestion page.multiplequestions].freeze
- USES_HEADING =
%w[
page.content
page.checkanswers
page.confirmation
page.multiplequestions
page.exit
].freeze
- END_OF_ROUTE_PAGES =
%w[
page.checkanswers
page.confirmation
page.exit
].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?, #to_json, #type, #uuid
Instance Method Details
#all_components ⇒ Object
37
38
39
|
# File 'app/models/metadata_presenter/page.rb', line 37
def all_components
[components, ].flatten.compact
end
|
#assign_autocomplete_items(items) ⇒ Object
112
113
114
115
116
117
|
# File 'app/models/metadata_presenter/page.rb', line 112
def assign_autocomplete_items(items)
component_uuids = items.keys
components.each do |component|
component.items = items[component.uuid] if component.uuid.in?(component_uuids)
end
end
|
#autocomplete_component_present? ⇒ Boolean
108
109
110
|
# File 'app/models/metadata_presenter/page.rb', line 108
def autocomplete_component_present?
components.any?(&:autocomplete?)
end
|
#components ⇒ Object
41
42
43
44
|
# File 'app/models/metadata_presenter/page.rb', line 41
def components
@components ||=
to_components(metadata.components, collection: :components)
end
|
#content_components ⇒ Object
54
55
56
|
# File 'app/models/metadata_presenter/page.rb', line 54
def content_components
all_components.select(&:content?)
end
|
#editable_attributes ⇒ Object
29
30
31
|
# File 'app/models/metadata_presenter/page.rb', line 29
def editable_attributes
to_h.reject { |k, _| k.in?(NOT_EDITABLE) }
end
|
#end_of_route? ⇒ Boolean
100
101
102
|
# File 'app/models/metadata_presenter/page.rb', line 100
def end_of_route?
type.in?(END_OF_ROUTE_PAGES)
end
|
46
47
48
|
# File 'app/models/metadata_presenter/page.rb', line 46
def
to_components(metadata., collection: :extra_components)
end
|
#find_component_by_uuid(uuid) ⇒ Object
33
34
35
|
# File 'app/models/metadata_presenter/page.rb', line 33
def find_component_by_uuid(uuid)
all_components.find { |component| component.uuid == uuid }
end
|
50
51
52
|
# File 'app/models/metadata_presenter/page.rb', line 50
def input_components
all_components.reject(&:content?)
end
|
#multiple_questions? ⇒ Boolean
104
105
106
|
# File 'app/models/metadata_presenter/page.rb', line 104
def multiple_questions?
type == 'page.multiplequestions'
end
|
#question_page? ⇒ Boolean
90
91
92
|
# File 'app/models/metadata_presenter/page.rb', line 90
def question_page?
type.in?(QUESTION_PAGES)
end
|
#standalone? ⇒ Boolean
86
87
88
|
# File 'app/models/metadata_presenter/page.rb', line 86
def standalone?
type == 'page.standalone'
end
|
#supported_components_by_type(type) ⇒ Object
58
59
60
61
62
63
64
|
# File 'app/models/metadata_presenter/page.rb', line 58
def supported_components_by_type(type)
supported = supported_components(raw_type)[type]
all_components.select do |component|
supported.include?(component.type)
end
end
|
#supported_content_components ⇒ Object
78
79
80
|
# File 'app/models/metadata_presenter/page.rb', line 78
def supported_content_components
supported_components(raw_type)[:content]
end
|
74
75
76
|
# File 'app/models/metadata_presenter/page.rb', line 74
def supported_input_components
supported_components(raw_type)[:input]
end
|
#template ⇒ Object
70
71
72
|
# File 'app/models/metadata_presenter/page.rb', line 70
def template
"metadata_presenter/#{type.gsub('.', '/')}"
end
|
#title ⇒ Object
94
95
96
97
98
|
# File 'app/models/metadata_presenter/page.rb', line 94
def title
return heading if heading?
components.first.humanised_title
end
|
#to_partial_path ⇒ Object
66
67
68
|
# File 'app/models/metadata_presenter/page.rb', line 66
def to_partial_path
type.gsub('.', '/')
end
|
#upload_components ⇒ Object
82
83
84
|
# File 'app/models/metadata_presenter/page.rb', line 82
def upload_components
components.select(&:upload?)
end
|