Class: Ecoportal::API::V2::Page::Component::ActionField
- Inherits:
-
Ecoportal::API::V2::Page::Component
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Component
- Ecoportal::API::V2::Page::Component::ActionField
- 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
Instance Method Summary collapse
-
#add_task(name) ⇒ Ecoportal::API::V2::Page::Component::Action
Adds a task with
name
short description. - #ordered_tasks ⇒ Object
Methods inherited from Ecoportal::API::V2::Page::Component
get_class, #indexable_label, new_doc, #ref, #section
Methods included from Common::Content::StringDigest
Methods inherited from Common::Content::DoubleModel
#_doc_key, #as_json, #as_update, #consolidate!, #dirty?, #doc, embeds_multiple, embeds_one, #initialize, #key, #key=, key?, new_uuid, #original_doc, pass_reader, pass_writer, passarray, passdate, passkey, passthrough, #pretty_print, #replace_doc, #reset!, #root, #to_json
Methods included from Common::Content::ClassHelpers
#instance_variable_name, #new_class, #resolve_class, #to_constant, #to_time, #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
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 15 def add_task (name) task_doc = Ecoportal::API::V2::Page::Component::Action.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 |
#ordered_tasks ⇒ Object
27 28 29 30 31 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 27 def ordered_tasks actions.each_with_index.sort_by do |task, index| (task.weight >= 9999) ? [index, index] : [task.weight, index] end.map(&:first) end |