module Ecoportal module API class V2 class Page class Component < Common::Content::DoubleModel extend Ecoportal::API::Common::Content::StringDigest class_resolver :tag_field_class, "Ecoportal::API::V2::Page::Component::TagField" class_resolver :geo_field_class, "Ecoportal::API::V2::Page::Component::GeoField" class_resolver :selection_field_class, "Ecoportal::API::V2::Page::Component::SelectionField" class_resolver :date_field_class, "Ecoportal::API::V2::Page::Component::DateField" class_resolver :number_field_class, "Ecoportal::API::V2::Page::Component::NumberField" class_resolver :gauge_field_class, "Ecoportal::API::V2::Page::Component::GaugeField" class_resolver :plain_text_field_class, "Ecoportal::API::V2::Page::Component::PlainTextField" class_resolver :rich_text_field_class, "Ecoportal::API::V2::Page::Component::RichTextField" class_resolver :people_field_class, "Ecoportal::API::V2::Page::Component::PeopleField" class_resolver :checklist_field_class, "Ecoportal::API::V2::Page::Component::ChecklistField" class_resolver :action_field_class, "Ecoportal::API::V2::Page::Component::ActionField" class_resolver :files_field_class, "Ecoportal::API::V2::Page::Component::FilesField" class_resolver :images_field_class, "Ecoportal::API::V2::Page::Component::ImagesField" class_resolver :signature_field_class, "Ecoportal::API::V2::Page::Component::SignatureField" class_resolver :reference_field_class, "Ecoportal::API::V2::Page::Component::ReferenceField" class_resolver :law_field_class, "Ecoportal::API::V2::Page::Component::LawField" class_resolver :chart_field_class, "Ecoportal::API::V2::Page::Component::ChartField" class_resolver :chart_fr_field_class, "Ecoportal::API::V2::Page::Component::ChartFrField" class << self 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 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 end passkey :id passforced :patch_ver, default: 1 passboolean :undeletable passthrough :type, :label, :tooltip, :global_binding passboolean :hidden, :deindex, :required passthrough :accent passboolean :hide_view, :hidden_on_reports, :hidden_on_mobile passarray :refs def ooze self._parent.ooze end def ref_backend refs.first end def ref if digest = self.class.hash_label(label) [type, digest].join(".") end end # Looks up the section that this component belongs to. # @return [Ecoportal::API::V2::Page::Section, nil] the section where this field is attached to. def section root.sections.find {|sec| sec.component?(id)} end # @return [Boolean] whether or not this field is attached to any section. def attached? !!section end # @return [Boolean] whether or not the component has been attached to more than one section. def multi_section? secs = ooze.sections.select {|sec| sec.component?(id)} secs.length > 1 end def indexable_label self.class.indexable_label(label) end # Quick config helper # @param conf [Symbol, Array] # - `: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 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 end end end end end require 'ecoportal/api/v2/page/component/tag_field' require 'ecoportal/api/v2/page/component/geo_field' require 'ecoportal/api/v2/page/component/selection_field' require 'ecoportal/api/v2/page/component/date_field' require 'ecoportal/api/v2/page/component/number_field' require 'ecoportal/api/v2/page/component/gauge_field' require 'ecoportal/api/v2/page/component/plain_text_field' require 'ecoportal/api/v2/page/component/rich_text_field' require 'ecoportal/api/v2/page/component/people_field' require 'ecoportal/api/v2/page/component/checklist_field' require 'ecoportal/api/v2/page/component/action_field' require 'ecoportal/api/v2/page/component/files_field' require 'ecoportal/api/v2/page/component/images_field' require 'ecoportal/api/v2/page/component/signature_field' require 'ecoportal/api/v2/page/component/reference_field' require 'ecoportal/api/v2/page/component/law_field' require 'ecoportal/api/v2/page/component/chart_field' require 'ecoportal/api/v2/page/component/chart_fr_field'