Class: Ecoportal::API::V2::Page::Component
- Inherits:
-
Common::Content::DoubleModel
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Component
- Extended by:
- Common::Content::StringDigest
- Defined in:
- lib/ecoportal/api/v2/page/component.rb,
lib/ecoportal/api/v2/page/component/law.rb,
lib/ecoportal/api/v2/page/component/file.rb,
lib/ecoportal/api/v2/page/component/image.rb,
lib/ecoportal/api/v2/page/component/action.rb,
lib/ecoportal/api/v2/page/component/geo_field.rb,
lib/ecoportal/api/v2/page/component/law_field.rb,
lib/ecoportal/api/v2/page/component/tag_field.rb,
lib/ecoportal/api/v2/page/component/date_field.rb,
lib/ecoportal/api/v2/page/component/gauge_stop.rb,
lib/ecoportal/api/v2/page/component/chart_field.rb,
lib/ecoportal/api/v2/page/component/files_field.rb,
lib/ecoportal/api/v2/page/component/gauge_field.rb,
lib/ecoportal/api/v2/page/component/action_field.rb,
lib/ecoportal/api/v2/page/component/images_field.rb,
lib/ecoportal/api/v2/page/component/number_field.rb,
lib/ecoportal/api/v2/page/component/people_field.rb,
lib/ecoportal/api/v2/page/component/chart_fr_field.rb,
lib/ecoportal/api/v2/page/component/checklist_item.rb,
lib/ecoportal/api/v2/page/component/checklist_field.rb,
lib/ecoportal/api/v2/page/component/geo_coordinates.rb,
lib/ecoportal/api/v2/page/component/reference_field.rb,
lib/ecoportal/api/v2/page/component/rich_text_field.rb,
lib/ecoportal/api/v2/page/component/selection_field.rb,
lib/ecoportal/api/v2/page/component/signature_field.rb,
lib/ecoportal/api/v2/page/component/plain_text_field.rb,
lib/ecoportal/api/v2/page/component/selection_option.rb,
lib/ecoportal/api/v2/page/component/chart_field/serie.rb,
lib/ecoportal/api/v2/page/component/selection_options.rb,
lib/ecoportal/api/v2/page/component/chart_field/config.rb,
lib/ecoportal/api/v2/page/component/chart_field/sankey.rb,
lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb,
lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb,
lib/ecoportal/api/v2/page/component/chart_field/frequency.rb,
lib/ecoportal/api/v2/page/component/chart_field/indicator.rb,
lib/ecoportal/api/v2/page/component/people_viewable_field.rb,
lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb,
lib/ecoportal/api/v2/page/component/chart_field/series_config.rb
Direct Known Subclasses
ActionField, ChartField, ChartFrField, ChecklistField, DateField, FilesField, GaugeField, GeoField, ImagesField, LawField, NumberField, PeopleField, PlainTextField, ReferenceField, RichTextField, SelectionField, SignatureField, TagField
Defined Under Namespace
Classes: Action, ActionField, ChartField, ChartFrField, ChecklistField, ChecklistItem, DateField, File, FilesField, GaugeField, GaugeStop, GeoCoordinates, GeoField, Image, ImagesField, Law, LawField, NumberField, PeopleField, PeopleViewableField, PlainTextField, ReferenceField, RichTextField, SelectionField, SelectionOption, SelectionOptions, SignatureField, TagField
Constant Summary
Constants included from Common::Content::StringDigest
Common::Content::StringDigest::MAX_HASH_LABEL
Constants inherited from Common::Content::DoubleModel
Common::Content::DoubleModel::NOT_USED
Constants included from Common::Content::ClassHelpers
Common::Content::ClassHelpers::NOT_USED
Instance Attribute Summary
Attributes inherited from Common::Content::DoubleModel
Class Method Summary collapse
Instance Method Summary collapse
-
#attached? ⇒ Boolean
Whether or not this field is attached to any section.
-
#bindings ⇒ Array<Ecoportal::API::V2::Page::Force::Binding] the force bindings if any.
Array<Ecoportal::API::V2::Page::Force::Binding] the force bindings if any.
-
#bindings? ⇒ Boolean
trueif the component is bound to any force,falseotherwise. -
#configure(*conf) ⇒ Object
Quick config helper.
- #delete! ⇒ Object
-
#forces ⇒ Array<Ecoportal::API::V2::Page::Force] the forces this component is bound to if any.
Array<Ecoportal::API::V2::Page::Force] the forces this component is bound to if any.
- #indexable_label(any_length: false) ⇒ Object
- #move(section:, before: nil, after: nil, side: nil) ⇒ Object
-
#multi_section? ⇒ Boolean
Whether or not the component has been attached to more than one section.
- #ooze ⇒ Object
- #ref(any_length: false) ⇒ Object
- #ref_backend ⇒ Object
-
#section ⇒ Ecoportal::API::V2::Page::Section?
Looks up the section that this component belongs to.
-
#unattach! ⇒ Object
Unattaches the field from any section.
Methods included from Common::Content::StringDigest
Methods inherited from Common::Content::DoubleModel
#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_many, embeds_one, enforce!, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passboolean, passdate, passforced, passkey, passthrough, #print_pretty, #replace_doc, #reset!, #root, #to_json
Methods included from Common::Content::ClassHelpers
#inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #uid, #used_param?
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel
Class Method Details
.get_class(doc) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 41 def get_class(doc) if doc.is_a?(Hash) case doc["type"] when "tag_field" tag_field_class when "geo" geo_field_class when "select" selection_field_class when "date" date_field_class when "number" number_field_class when "gauge" gauge_field_class when "plain_text" plain_text_field_class when "rich_text" rich_text_field_class when "people" people_field_class when "checklist" checklist_field_class when "page_action","checklist_task" action_field_class when "file" files_field_class when "image_gallery" images_field_class when "signature" signature_field_class when "cross_reference" reference_field_class when "law" law_field_class when "chart" chart_field_class when "frequency_rate_chart" chart_fr_field_class else self end end end |
.new_doc(type: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 28 def new_doc(type: nil) { "id" => new_uuid }.tap do |base_doc| if type base_doc.merge!({"type" => type}) if klass = get_class(base_doc) base_doc.merge!(klass.new_doc || {}) end end end end |
Instance Method Details
#attached? ⇒ Boolean
Returns whether or not this field is attached to any section.
117 118 119 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 117 def attached? !!section end |
#bindings ⇒ Array<Ecoportal::API::V2::Page::Force::Binding] the force bindings if any.
Returns Array<Ecoportal::API::V2::Page::Force::Binding] the force bindings if any.
138 139 140 141 142 143 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 138 def bindings ooze.forces.each_with_object([]) do |force, out| out.push(*force.bindings.get_by_reference(self)) end out end |
#bindings? ⇒ Boolean
Returns true if the component is bound to any force, false otherwise.
153 154 155 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 153 def bindings? forces.count > 0 end |
#configure(*conf) ⇒ Object
Quick config helper
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 179 def configure(*conf) conf.each_with_object([]) do |cnf, unused| case cnf when :required self.required = true when :hide_view self.hide_view = true when :hide_mobile self.hidden_on_mobile = true when :hide_reports self.hidden_on_reports = true when Hash if cnf.key?(:global) self.global_binding = cnf[:global] end else unused.push(cnf) end end.tap do |unused| raise "Unsupported configuration options '#{unused}' for #{self.class}" unless unused.empty? end end |
#delete! ⇒ Object
157 158 159 160 161 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 157 def delete! bindings.each {|b| b.delete!} self.unattach! self._parent.delete!(self) end |
#forces ⇒ Array<Ecoportal::API::V2::Page::Force] the forces this component is bound to if any.
Returns Array<Ecoportal::API::V2::Page::Force] the forces this component is bound to if any.
146 147 148 149 150 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 146 def forces ooze.forces.select do |force| force.bindings.reference?(self) end end |
#indexable_label(any_length: false) ⇒ Object
168 169 170 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 168 def indexable_label(any_length: false) self.class.indexable_label(label, any_length: any_length) end |
#move(section:, before: nil, after: nil, side: nil) ⇒ Object
163 164 165 166 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 163 def move(section:, before: nil, after: nil, side: nil) self.unattach! section.add_component(self, before: before, after: after, side: side) end |
#multi_section? ⇒ Boolean
Returns whether or not the component has been attached to more than one section.
132 133 134 135 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 132 def multi_section? secs = ooze.sections.select {|sec| sec.component?(id)} secs.length > 1 end |
#ooze ⇒ Object
96 97 98 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 96 def ooze self._parent.ooze end |
#ref(any_length: false) ⇒ Object
104 105 106 107 108 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 104 def ref(any_length: false) if digest = self.class.hash_label(label, any_length: any_length) [type, digest].join(".") end end |
#ref_backend ⇒ Object
100 101 102 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 100 def ref_backend refs.first end |
#section ⇒ Ecoportal::API::V2::Page::Section?
Looks up the section that this component belongs to.
112 113 114 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 112 def section ooze.sections.find {|sec| sec.component?(id)} end |
#unattach! ⇒ Object
please make sure to reattach or delete! the field before save
Unattaches the field from any section
123 124 125 126 127 128 129 |
# File 'lib/ecoportal/api/v2/page/component.rb', line 123 def unattach! ooze.sections.select do |sec| sec.component?(id) end.each do |sec| sec.remove_component!(self) end end |