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

Inherits:
Ecoportal::API::V2::Page::Component show all
Defined in:
lib/ecoportal/api/v2/page/component/people_field.rb

Constant Summary

Constants included from Common::Content::StringDigest

Common::Content::StringDigest::MAX_HASH_LABEL

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 Ecoportal::API::V2::Page::Component

#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, new_doc, #ooze, #ref, #ref_backend, #replace, #replace_bindings, #section, #unattach!

Methods included from Common::Content::StringDigest

#hash_label, #indexable_label

Methods inherited from Common::Content::DoubleModel

#initialize, new_uuid

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

#as_update, #dirty?

Methods included from Common::Content::Includer

#include_missing

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel

Instance Method Details

#add(*ids) ⇒ Object

Attaches people



28
29
30
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 28

def add(*ids)
  people_ids << ids
end

#add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) ⇒ Object

Adds a field to the viewable_fields



38
39
40
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 38

def add_viewable(field_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
  viewable_fields.upsert!({'id' => field_id}, pos: pos, before: before, after: after)
end

#configure(*conf) ⇒ Object

Quick config helper

Parameters:

  • conf (Symbol, Array<Symbol>)
    • :snapshot to set mode to snapshot
    • :live to set mode to live
    • :me_button to display ME button
    • :permits to define the permissions
      • :all for entire page/all stages
      • :stages for all stages containing this field
      • :page for page only
      • :stage for only the stage containing this field when attached
      • :restructure
      • :configure
      • :can_permission
      • :create_actions
      • :admin_actions
      • :subscribed
      • :subscribed_to_tasks
    • requires: number to fine the number of required people to be attached


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 69

def configure(*conf) # rubocop:disable Metrics/AbcSize
  conf.each_with_object([]) do |cnf, unused|
    case cnf
    when :snapshot
      self.attach_mode  = 'snapshot'
    when :live
      self.attach_mode  = 'live'
    when :me_button
      self.is_me_button = true
    when :singular
      self.singular = true
    when Hash
      supported = %i[singular permits requires]
      unless (rest = hash_except!(cnf.dup, *supported)).empty?
        unused.push(rest)
      end

      self.singular = !!cnf[:singular] if cnf.key?(:singular)

      if cnf.key?(:permits)
        if (permits = cnf[:permits])
          self.attached_people_permissions_enabled = true
          configure_permits(*[permits].flatten.compact)
        else
          self.attached_people_permissions_enabled = false
        end
      end
      if cnf.key?(:requires)
        self.singular = false
        if (requires = cnf[:requires])
          self.required        = true
          self.requires_number = requires
        else
          self.required        = false
          self.requires_number = nil
        end
      end
    else
      unused.push(cnf)
    end
  end.then do |unused|
    super(*unused)
  end
end

#delete(*ids) ⇒ Object

Deletes people



33
34
35
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 33

def delete(*ids)
  people_ids.reject! {|id| ids.include?(id)}
end

#delete_viewable(field_id) ⇒ Object

Deletes a field from the viewable_fields



43
44
45
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 43

def delete_viewable(field_id)
  viewable_fields.delete!(field_id)
end

#empty?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 23

def empty?
  people_ids.empty?
end

#to_s(delimiter: "\n") ⇒ Object



47
48
49
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 47

def to_s(delimiter: "\n")
  people_ids.to_a.join(delimiter)
end