Class: Crm::ImagePresenter

Inherits:
BasePresenter show all
Includes:
Presenters::ImageTag
Defined in:
app/presenters/crm/image_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from Crm::BasePresenter

Instance Method Details

#advanced_infoObject



8
9
10
11
12
# File 'app/presenters/crm/image_presenter.rb', line 8

def advanced_info
  return unless image.image_info

  h.simple_format(image.image_info.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: ''))
end

#embedding_status_badgeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/presenters/crm/image_presenter.rb', line 48

def embedding_status_badge
  unified = r.find_content_embedding(:unified)
  has_phash = r.fingerprint.present?
  has_vision = r.ai_visual_description.present?
  has_embedding = unified&.unified_embedding.present? && unified&.content_hash.present?

  count = [has_phash, has_vision, has_embedding].count(true)

  case count
  when 3
    '<i class="fa-solid fa-circle-check text-success ms-1" title="All AI analysis complete"></i>'
  when 0
    '<i class="fa-solid fa-circle-xmark text-danger ms-1" title="No AI analysis"></i>'
  else
    '<i class="fa-solid fa-circle-half-stroke text-warning ms-1" title="AI analysis incomplete"></i>'
  end
end

#image_asset_tag(options = {}) ⇒ Object

image_asset_tag('mudroom-with-slab-heating-cable-01ea58', width: 600, class: 'img-fluid img-room')



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/presenters/crm/image_presenter.rb', line 15

def image_asset_tag(options = {})
  render_tag = options.delete(:render_tag).to_b
  options[:class] ||= 'img-fluid'
  options[:encode_format] ||= @options&.dig(:img_options, :encode_format) || :jpeg
  options_str = +''
  options.each_with_index do |(k, v), idx|
    options_str << ', ' unless idx == 0
    options_str << "#{k}: '#{v}'"
  end
  if render_tag
    h.image_asset_tag(r, **options)
  else
    "<%= image_asset_tag(#{r.id}, #{options_str}) %>"
  end
end

#image_tab_optionsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/presenters/crm/image_presenter.rb', line 31

def image_tab_options
  tabs = {}
  tabs[:main_attributes] = { partial: '/crm/images/main_attributes', locals: { ip: self } }
  tabs[:preview] = { partial: '/crm/images/preview', locals: { ip: self } }
  tabs[:links] = { partial: '/crm/images/links', locals: { ip: self } }
  tabs[:file_info] = { remote_href: h.tab_file_info_image_path(r.id) }
  tabs[:ai_embeddings] = {
    remote_href: h.tab_embeddings_image_path(r.id),
    counter_html: embedding_status_badge
  }
  tabs[:items] = { remote_href: h.tab_items_image_path(r.id), counter: all_my_items.size }
  tabs[:profiles] = { remote_href: h.tab_profiles_image_path(r.id), counter: image_profiles.size }
  tabs[:videos] = { remote_href: h.tab_videos_image_path(r.id), counter: video_posters.size } if video_posters.any?
  tabs[:duplicates] = { remote_href: h.tab_duplicates_image_path(r.id) }
  tabs
end