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

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

#_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, read_only!, read_only?, #read_only?, #replace_doc, #reset!, #resolved_doc_key, #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

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
# File 'lib/ecoportal/api/v2/page/component/people_field.rb', line 69

def configure(*conf)
  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 = [:singular, :permits, :requires]
      unless (rest = hash_except(cnf.dup, *supported)).empty?
        unused.push(rest)
      end

      if cnf.key?(:singular) then self.singular = !!cnf[:singular] end
      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.yield_self 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