Class: Integral::Image

Inherits:
ApplicationRecord show all
Defined in:
app/models/integral/image.rb

Overview

Represents an image uploaded by a user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

available_statuses

Class Method Details

.integral_backend_create_menu_itemHash

Returns hash representing the class, used to render within the create menu.

Returns:

  • (Hash)

    hash representing the class, used to render within the create menu



78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/integral/image.rb', line 78

def self.integral_backend_create_menu_item
  {
    icon: integral_icon,
    order: integral_options.dig(:backend_create_menu, :order),
    label: model_name.human,
    url: url_helpers.send("new_backend_img_url"),
    # authorize: proc { policy(self).index? }, can't use this as self is in wrong context
    authorize_class: self,
    authorize_action: :new,
  }
end

.integral_backend_main_menu_itemObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/integral/image.rb', line 61

def self.integral_backend_main_menu_item
  {
    icon: integral_icon,
    order: integral_options.dig(:backend_main_menu, :order),
    label: model_name.human.pluralize,
    url: url_helpers.send("backend_img_index_url"),
    authorize_class: self,
    authorize_action: :index,
    list_items: [
      { label: I18n.t('integral.navigation.dashboard'), url: url_helpers.send("backend_img_index_url"), authorize_class: self, authorize_action: :index },
      { label: I18n.t('integral.actions.create'), url: url_helpers.send("new_backend_img_url"), authorize_class: self, authorize_action: :new },
      { label: I18n.t('integral.navigation.listing'), url: url_helpers.send("list_backend_img_index_url"), authorize_class: self, authorize_action: :list },
    ]
  }
end

.integral_iconObject



57
58
59
# File 'app/models/integral/image.rb', line 57

def self.integral_icon
  'image'
end

.listable_optionsHash

Returns listable options to be used within a RecordSelector widget.

Returns:

  • (Hash)

    listable options to be used within a RecordSelector widget



49
50
51
52
53
54
55
# File 'app/models/integral/image.rb', line 49

def self.listable_options
  {
    record_title: I18n.t('integral.backend.record_selector.images.record'),
    selector_path: Engine.routes.url_helpers.list_backend_images_path,
    selector_title: I18n.t('integral.backend.record_selector.images.title')
  }
end

Instance Method Details

#dimensionsString

Returns represents the dimensions of the original image.

Returns:

  • (String)

    represents the dimensions of the original image



33
34
35
# File 'app/models/integral/image.rb', line 33

def dimensions
  "#{width}x#{height}px" if width && height
end

#to_list_itemHash

Returns the instance as a list item.

Returns:

  • (Hash)

    the instance as a list item



38
39
40
41
42
43
44
45
46
# File 'app/models/integral/image.rb', line 38

def to_list_item
  {
    id: id,
    title: title,
    subtitle: description,
    description: description,
    image: file
  }
end