Class: Ecoportal::API::V2::Page::Component::ImagesField

Inherits:
Ecoportal::API::V2::Page::Component show all
Defined in:
lib/ecoportal/api/v2/page/component/images_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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ecoportal::API::V2::Page::Component

#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, #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

Class Method Details

.new_docObject



9
10
11
12
13
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 9

def new_doc
  {
    "layout" => "third"
  }
end

Instance Method Details

#add_image(upload_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 24

def add_image(upload_id, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
  image_doc = images.items_class.new_doc
  images.upsert!(image_doc, pos: pos, before: before, after: after) do |image|
    image.upload_id  = upload_id
    if prev = previous_image(image)
      image.weight = prev.weight
    end
    yield(image) if block_given?
    fix_image_positions!
  end
end

#configure(*conf) ⇒ Object

Quick config helper

Parameters:

  • conf (Symbol, Array<Symbol>)
    • :strech to make the image fit the full size of the image field
    • :popup to set to enable disable poupup on click
    • :layout_button to offer layout options to user
    • :layout with the following available values
      • :three_crop to specify 3 across by cutting the image to equalize size
      • :three to specify 3 across
      • :two to specify 2 across
      • :one to specify Full width (1 Across)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 56

def configure(*conf)
  conf.each_with_object([]) do |cnf, unused|
    case cnf
    when :strech
      self.strech = true
    when :popup
      self.no_popup = false
    when :layout_button
      self.hide_options = false
    when Hash
      supported = [:layout_button, :layout]
      unless (rest = hash_except(cnf.dup, *supported)).empty?
        unused.push(rest)
      end

      if cnf.key?(:layout_button) then self.hide_options = !cnf[:layout_button] end
      if cnf.key?(:layout) then configure_layour cnf[:layout] end
    else
      unused.push(cnf)
    end
  end.yield_self do |unused|
    super(*unused)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 20

def empty?
  images.empty?
end

#ordered_imagesObject



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

def ordered_images
  images.sort_by.with_index do |image, index|
    [image.weight, index]
  end
end

#to_sObject



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

def to_s
  images.count
end