Module: Crm::TagsHelper

Defined in:
app/helpers/crm/tags_helper.rb

Overview

View helpers for the CRM tags UI: resolve icons, display names, and CRM
paths for the various taggable record types shown by
+Crm::TagsController+ views.

See Also:

Instance Method Summary collapse

Instance Method Details

#taggable_display_name(record, type) ⇒ String

Returns a display name for a taggable record.

Parameters:

  • record (ActiveRecord::Base)

    the taggable record

  • type (String)

    the taggable class name (e.g. "Article", "Item")

Returns:

  • (String)

    human-readable label for the record



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/crm/tags_helper.rb', line 43

def taggable_display_name(record, type)
  case type
  when 'Article'
    record.try(:subject) || record.try(:title) || "Article ##{record.id}"
  when 'Showcase'
    record.try(:name) || "Showcase ##{record.id}"
  when 'DigitalAsset'
    record.try(:title) || record.try(:name) || "Digital Asset ##{record.id}"
  when 'FloorPlanDisplay'
    record.try(:name) || "Floor Plan Display ##{record.id}"
  when 'Item'
    [record.try(:sku), record.try(:name) || record.try(:name_en)].compact.join(' - ')
  when 'ProductLine'
    record.try(:name) || record.try(:name_en) || "Product Line ##{record.id}"
  when 'ActivityType'
    [record.try(:task_type), record.try(:description)].compact.join(' - ')
  when 'LocatorRecord'
    record.try(:name) || "Locator Record ##{record.id}"
  else
    record.try(:name) || record.try(:title) || "#{type} ##{record.id}"
  end
end

#taggable_type_icon(type) ⇒ String

Returns a Font Awesome icon class for a taggable type.

Parameters:

  • type (String)

    the taggable class name (e.g. "Article", "Item")

Returns:

  • (String)

    Font Awesome class list



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/crm/tags_helper.rb', line 15

def taggable_type_icon(type)
  case type
  when 'Article'
    'fa-solid fa-newspaper'
  when 'Showcase'
    'fa-solid fa-images'
  when 'DigitalAsset'
    'fa-solid fa-photo-film'
  when 'FloorPlanDisplay'
    'fa-solid fa-map'
  when 'Item'
    'fa-solid fa-box'
  when 'ProductLine'
    'fa-solid fa-boxes-stacked'
  when 'ActivityType'
    'fa-solid fa-list-check'
  when 'LocatorRecord'
    'fa-solid fa-location-dot'
  else
    'fa-solid fa-file'
  end
end

#taggable_url(record, type) ⇒ String?

Returns the URL path for viewing a taggable record in CRM.

Parameters:

  • record (ActiveRecord::Base)

    the taggable record

  • type (String)

    the taggable class name (e.g. "Article", "Item")

Returns:

  • (String, nil)

    the path, or nil when no route can be generated



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/crm/tags_helper.rb', line 71

def taggable_url(record, type)
  case type
  when 'Article'
    article_crm_path(record)
  when 'Showcase'
    begin
      showcase_path(record)
    rescue StandardError
      nil
    end
  when 'DigitalAsset'
    digital_asset_crm_path(record)
  when 'FloorPlanDisplay'
    begin
      floor_plan_display_path(record)
    rescue StandardError
      nil
    end
  when 'Item'
    begin
      item_path(record)
    rescue StandardError
      nil
    end
  when 'ProductLine'
    begin
      product_line_path(record)
    rescue StandardError
      nil
    end
  when 'ActivityType'
    begin
      activity_type_path(record)
    rescue StandardError
      nil
    end
  when 'LocatorRecord'
    begin
      locator_record_path(record)
    rescue StandardError
      nil
    end
  end
end