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

Inherits:
Ecoportal::API::V2::Page::Component show all
Defined in:
lib/ecoportal/api/v2/page/component/action_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_task(name) ⇒ Ecoportal::API::V2::Page::Component::Action

Adds a task with name short description



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 20

def add_task (name)
  task_doc = actions.items_class.new_doc
  actions.upsert!(task_doc) do |task|
    task.name = name
    if prev = previous_task(task)
      task.weight = prev.weight
    end
    yield(task) if block_given?
    fix_task_weights!
  end
end

#configure(*conf) ⇒ Object

Quick config helper

Parameters:

  • conf (Symbol, Array<Symbol>)
    • :requires required number of completed actions
      • :all
      • #Number


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 47

def configure(*conf)
  self.create_actions = true
  conf.each_with_object([]) do |cnf, unused|
    case cnf
    when Hash
      supported = [:requires]
      unless (rest = hash_except(cnf.dup, *supported)).empty?
        unused.push(rest)
      end
      if cnf.key?(:requires) then configure_required(cnf[:requires]) end
    else
      unused.push(cnf)
    end
  end.yield_self do |unused|
    super(*unused)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 14

def empty?
  actions.empty?
end

#ordered_tasksObject



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

def ordered_tasks
  actions.sort_by.with_index do |task, index|
    [task.weight, index]
  end
end

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



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

def to_s(delimiter: "\n")
  ordered_tasks.map(&:to_s).join(delimiter)
end