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

Inherits:
Common::Content::DoubleModel show all
Defined in:
lib/ecoportal/api/v2/page.rb,
lib/ecoportal/api/v2/page/force.rb,
lib/ecoportal/api/v2/page/stage.rb,
lib/ecoportal/api/v2/page/forces.rb,
lib/ecoportal/api/v2/page/permit.rb,
lib/ecoportal/api/v2/page/stages.rb,
lib/ecoportal/api/v2/page/section.rb,
lib/ecoportal/api/v2/page/sections.rb,
lib/ecoportal/api/v2/page/component.rb,
lib/ecoportal/api/v2/page/components.rb,
lib/ecoportal/api/v2/page/force/helper.rb,
lib/ecoportal/api/v2/page/component/law.rb,
lib/ecoportal/api/v2/page/force/binding.rb,
lib/ecoportal/api/v2/page/mould_counter.rb,
lib/ecoportal/api/v2/page/component/file.rb,
lib/ecoportal/api/v2/page/force/bindings.rb,
lib/ecoportal/api/v2/page/component/image.rb,
lib/ecoportal/api/v2/page/component/action.rb,
lib/ecoportal/api/v2/page/permission_flags.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/actions_field.rb,
lib/ecoportal/api/v2/page/component/mailbox_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,
lib/ecoportal/api/v2/page/component/contractor_entities_field.rb

Direct Known Subclasses

Ecoportal::API::V2::Pages::PageStage

Defined Under Namespace

Classes: Component, Components, Force, Forces, MouldCounter, PermissionFlags, Permit, Section, Sections, Stage, Stages

Constant Summary collapse

ALLOWED_KEYS =
%w[
  id external_id patch_ver name template_id
  base_tags tags
  time_zone created_at updated_at
  components sections stages
  permits mould_counter mould
  state task_priority
  votes_enabled upvotes downvotes
  forces force_errors subtags
  tasks
].freeze

Constants included from Common::Content::DoubleModel::Diffable

Common::Content::DoubleModel::Diffable::DIFF_CLASS

Constants included from Common::Content::DoubleModel::Base

Common::Content::DoubleModel::Base::NOT_USED

Instance Attribute Summary

Attributes included from Common::Content::DoubleModel::Parented

#_parent, #_parent_key

Instance Method Summary collapse

Methods inherited from Common::Content::DoubleModel

new_uuid

Methods included from Common::Content::DoubleModel::Diffable

#dirty?

Methods included from Common::Content::Includer

#include_missing

Constructor Details

#initialize(doc = [], parent: self, key: nil) ⇒ Page

Returns a new instance of Page.



36
37
38
39
# File 'lib/ecoportal/api/v2/page.rb', line 36

def initialize(doc = [], parent: self, key: nil)
  doc = _doc_bug_fix(doc)
  super
end

Instance Method Details

#as_updateObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ecoportal/api/v2/page.rb', line 45

def as_update
  super.tap do |hash|
    next unless hash

    hash['data'].select! do |key, _value|
      ALLOWED_KEYS.include?(key)
    end

    return nil if (hash['data'].keys - ['patch_ver']).empty?
  end
end

#oozeObject



41
42
43
# File 'lib/ecoportal/api/v2/page.rb', line 41

def ooze
  self
end

#stages?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ecoportal/api/v2/page.rb', line 57

def stages?
  doc['stages'] && stages.count.positive?
end

#validateString

Returns with feedback, if for this page instance, there are any of:

  1. components multi-section (fields belonging to more than one section).

Returns:

  • (String)

    with feedback, if for this page instance, there are any of:

    1. components multi-section (fields belonging to more than one section)


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ecoportal/api/v2/page.rb', line 63

def validate
  multi = components.multi_section
  return true unless multi.length.positive?

  msg = ''
  msg << 'There are fields attached to more than one section:'
  msg << "\n  • "
  msg << multi.map(&:label).join("\n  • ")
  msg << "\n"
  msg
end