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 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

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

#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

Class Method Details

.new_docObject



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

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

Instance Method Details

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



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

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)


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

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 = %i[layout_button layout]
      unless (rest = hash_except!(cnf.dup, *supported)).empty?
        unused.push(rest)
      end

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  images.empty?
end

#ordered_imagesObject



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

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

#to_sObject



45
46
47
# File 'lib/ecoportal/api/v2/page/component/images_field.rb', line 45

def to_s
  images.count
end