Class: Crm::ImagePresenter

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

Overview

Presenter: image presenter.

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



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

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



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

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
    h.fa_icon('circle-check', family: :solid, class: 'text-success ms-1', title: 'All AI analysis complete')
  when 0
    h.fa_icon('circle-xmark', family: :solid, class: 'text-danger ms-1', title: 'No AI analysis')
  else
    h.fa_icon('circle-half-stroke', family: :solid, class: 'text-warning ms-1', title: 'AI analysis incomplete')
  end
end

#image_asset_tag(options = {}) ⇒ Object

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



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

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



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

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