Class: Ecoportal::API::V2::Page::Component

Inherits:
Common::Content::DoubleModel show all
Extended by:
Common::Content::StringDigest
Defined in:
lib/ecoportal/api/v2/page/component.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/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

Defined Under Namespace

Classes: Action, ActionField, ChartField, ChartFrField, ChecklistField, ChecklistItem, DateField, File, FilesField, GaugeField, GaugeStop, GeoCoordinates, GeoField, Image, ImagesField, LawField, NumberField, PeopleField, PeopleViewableField, PlainTextField, ReferenceField, RichTextField, SelectionField, SelectionOption, 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

#_key, #_parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::Content::StringDigest

hash_label

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, #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.

Returns:

  • (Boolean)

    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

#configure(*conf) ⇒ Object

Quick config helper

Parameters:

  • conf (Symbol, Array<Symbol>)
    • :required
    • :hide_view to hide in view mode
    • :hide_mobile to hide in mobile app
    • :hide_reports to hide in reports
    • :global to define a global binding


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ecoportal/api/v2/page/component.rb', line 138

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

#indexable_labelObject



127
128
129
# File 'lib/ecoportal/api/v2/page/component.rb', line 127

def indexable_label
  self.class.indexable_label(label)
end

#multi_section?Boolean

Returns whether or not the component has been attached to more than one section.

Returns:

  • (Boolean)

    whether or not the component has been attached to more than one section.



122
123
124
125
# File 'lib/ecoportal/api/v2/page/component.rb', line 122

def multi_section?
  secs = ooze.sections.select {|sec| sec.component?(id)}
  secs.length > 1
end

#oozeObject



96
97
98
# File 'lib/ecoportal/api/v2/page/component.rb', line 96

def ooze
  self._parent.ooze
end

#refObject



104
105
106
107
108
# File 'lib/ecoportal/api/v2/page/component.rb', line 104

def ref
  if digest = self.class.hash_label(label)
    [type, digest].join(".")
  end
end

#ref_backendObject



100
101
102
# File 'lib/ecoportal/api/v2/page/component.rb', line 100

def ref_backend
  refs.first
end

#sectionEcoportal::API::V2::Page::Section?

Looks up the section that this component belongs to.

Returns:



112
113
114
# File 'lib/ecoportal/api/v2/page/component.rb', line 112

def section
  ooze.sections.find {|sec| sec.component?(id)}
end