Module: Crm::SiteMapsHelper

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

Constant Summary collapse

EXPECTED_SCHEMAS =

Expected schema types based on page category

{
  'post' => %w[BlogPosting],
  'faqs' => %w[FAQPage],
  'product' => %w[Product],
  'product_line' => %w[Product],
  'showcase' => %w[Article]
}.freeze

Instance Method Summary collapse

Instance Method Details

#expected_schema_types(category) ⇒ Object



344
345
346
# File 'app/helpers/crm/site_maps_helper.rb', line 344

def expected_schema_types(category)
  EXPECTED_SCHEMAS[category] || []
end

#site_map_ai_score_badge_class(score) ⇒ String

Badge class for AI analysis overall_score (0–100) in index table
Matches Crm::SeoDashboardComponent#score_badge_class

Parameters:

  • score (Integer, nil)

Returns:

  • (String)

    Bootstrap badge class



353
354
355
356
357
358
359
360
361
362
# File 'app/helpers/crm/site_maps_helper.rb', line 353

def site_map_ai_score_badge_class(score)
  return 'bg-secondary' unless score

  case score
  when 80..100 then 'bg-success'
  when 60..79 then 'bg-primary'
  when 40..59 then 'bg-warning text-dark'
  else 'bg-danger'
  end
end

#site_map_crawl_status(sm) ⇒ String

Compact display of last crawl time + content presence indicator

Parameters:

  • sm (SiteMap)

    The site map record

Returns:

  • (String)

    HTML-safe crawl status display



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'app/helpers/crm/site_maps_helper.rb', line 242

def site_map_crawl_status(sm)
  crawl_time = (sm.try(:rendered_schema_at) || sm.last_status_datetime)

  if crawl_time.nil?
    return (:span, 'never', class: 'text-muted fst-italic')
  end

  parts = []
  parts << (:span, time_ago_in_words(crawl_time) + ' ago',
                       title: crawl_time.to_fs(:short),
                       class: crawl_time < 7.days.ago ? 'text-warning' : 'text-body-secondary')

  # Content indicator
  if sm.extracted_content.present?
    parts << (:i, nil, class: 'fa-solid fa-file-lines fa-sm text-success ms-1',
                                  title: "Content extracted (#{sm.extracted_content.length} chars)")
  end

  safe_join(parts)
end

#site_map_resource_icon(site_map) ⇒ String

Returns an icon class for the resource type

Parameters:

  • site_map (SiteMap)

    The site map record

Returns:

  • (String)

    Font Awesome icon class



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/helpers/crm/site_maps_helper.rb', line 137

def site_map_resource_icon(site_map)
  return 'fa-solid fa-file' unless site_map.resource.present?

  resource = site_map.resource
  resource_type = site_map.resource_type

  case resource_type
  when 'Article'
    case resource.class.name
    when 'Post' then 'fa-solid fa-pen-fancy'
    when 'ArticleFaq' then 'fa-solid fa-circle-question'
    when 'ArticleTechnical' then 'fa-solid fa-screwdriver-wrench'
    when 'ArticleTraining' then 'fa-solid fa-graduation-cap'
    when 'ArticleProcedure' then 'fa-solid fa-file-lines'
    else 'fa-solid fa-file-lines'
    end
  when 'DigitalAsset'
    if resource.is_a?(Image)
      'fa-solid fa-image'
    elsif resource.is_a?(Video)
      'fa-solid fa-video'
    else
      'fa-solid fa-photo-film'
    end
  when 'Showcase'
    'fa-solid fa-images'
  when 'FloorPlanDisplay'
    'fa-solid fa-map'
  when 'Item'
    'fa-solid fa-box'
  when 'ProductLine'
    'fa-solid fa-boxes-stacked'
  when 'CatalogItem'
    'fa-solid fa-tag'
  else
    'fa-solid fa-file'
  end
end

#site_map_resource_name(site_map) ⇒ String

Returns a display name for the resource

Parameters:

  • site_map (SiteMap)

    The site map record

Returns:

  • (String)

    Display name for the resource



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/crm/site_maps_helper.rb', line 77

def site_map_resource_name(site_map)
  return nil unless site_map.resource.present?

  resource = site_map.resource
  resource_type = site_map.resource_type

  case resource_type
  when 'Article'
    resource.subject.presence || "#{site_map_resource_type_label(site_map)} ##{resource.id}"
  when 'DigitalAsset'
    resource.title.presence || resource.name.presence || "#{site_map_resource_type_label(site_map)} ##{resource.id}"
  else
    resource.try(:name) || resource.try(:title) || resource.try(:subject) || "#{resource_type} ##{resource.id}"
  end
end

#site_map_resource_path(site_map) ⇒ String?

Returns the CRM URL path for a SiteMap's linked resource

Parameters:

  • site_map (SiteMap)

    The site map record

Returns:

  • (String, nil)

    CRM path to the resource, or nil if not available



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/crm/site_maps_helper.rb', line 47

def site_map_resource_path(site_map)
  return nil unless site_map.resource.present?

  resource = site_map.resource
  resource_type = site_map.resource_type

  case resource_type
  when 'Article'
    article_resource_path(resource)
  when 'DigitalAsset'
    digital_asset_resource_path(resource)
  when 'Showcase'
    showcase_path(resource)
  when 'FloorPlanDisplay'
    floor_plan_display_path(resource)
  when 'Item'
    item_path(resource)
  when 'ProductLine'
    product_line_path(resource)
  when 'CatalogItem'
    catalog_item_path(resource)
  end
rescue StandardError
  nil
end

#site_map_resource_type_label(site_map) ⇒ String

Returns a human-readable label for the resource type
Handles Article subtypes (blog_post -> Blog Post, faq -> FAQ, etc.)

Parameters:

  • site_map (SiteMap)

    The site map record

Returns:

  • (String)

    Human-readable resource type label



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/helpers/crm/site_maps_helper.rb', line 98

def site_map_resource_type_label(site_map)
  return nil unless site_map.resource.present?

  resource = site_map.resource
  resource_type = site_map.resource_type

  case resource_type
  when 'Article'
    case resource.class.name
    when 'Post' then 'Blog Post'
    when 'ArticleFaq' then 'FAQ'
    when 'ArticleTechnical' then 'Technical Article'
    when 'ArticleTraining' then 'Training Article'
    when 'ArticleProcedure' then 'Procedure'
    else 'Article'
    end
  when 'DigitalAsset'
    if resource.is_a?(Image)
      'Image'
    elsif resource.is_a?(Video)
      'Video'
    else
      'Digital Asset'
    end
  when 'ProductLine'
    'Product Line'
  when 'FloorPlanDisplay'
    'Floor Plan'
  when 'CatalogItem'
    'Catalog Item'
  else
    resource_type.titleize
  end
end

#site_map_schema_badges(sm) ⇒ String

Schema types as small Bootstrap badges

Parameters:

  • sm (SiteMap)

    The site map record

Returns:

  • (String)

    HTML-safe badge display



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'app/helpers/crm/site_maps_helper.rb', line 267

def site_map_schema_badges(sm)
  types = sm.rendered_schema_types

  if types.blank?
    count_label = (:span, '0', class: 'text-muted')
    return safe_join([(:span, "\u2014", class: 'text-muted me-1'), count_label])
  end

  # Short display names for common schema types
  short_names = {
    'BlogPosting' => 'Blog',
    'FAQPage' => 'FAQ',
    'HowTo' => 'HowTo',
    'Article' => 'Article',
    'Product' => 'Product',
    'BreadcrumbList' => 'Bread',
    'Organization' => 'Org',
    'LocalBusiness' => 'Biz',
    'WebPage' => 'Page',
    'CollectionPage' => 'Coll',
    'OnlineStore' => 'Store',
    'VideoObject' => 'Video',
    'ImageObject' => 'Image'
  }

  badges = types.map do |type|
    label = short_names[type] || type.truncate(10)
    (:span, label, class: 'badge text-bg-info badge-sm me-1', title: type)
  end

  count = (:span, "(#{types.size})", class: 'text-muted ms-1')
  safe_join(badges + [count])
end

#site_map_schema_health(sm) ⇒ String

Health indicator icon based on expected schemas for the page category

Parameters:

  • sm (SiteMap)

    The site map record

Returns:

  • (String)

    HTML-safe icon



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'app/helpers/crm/site_maps_helper.rb', line 305

def site_map_schema_health(sm)
  if sm.rendered_schema_at.nil?
    return (:i, nil, class: 'fa-solid fa-minus fa-sm text-muted',
                                title: 'Not yet crawled for schema')
  end

  types = sm.rendered_schema_types
  expected = expected_schema_types(sm.category)

  if expected.blank?
    # No specific expectation for this category — neutral
    if types.any?
      (:i, nil, class: 'fa-solid fa-circle-check fa-sm text-success',
                           title: "#{types.size} schema type(s) found")
    else
      (:i, nil, class: 'fa-solid fa-minus fa-sm text-muted',
                           title: 'No schemas (none expected)')
    end
  else
    missing = expected - types
    if missing.empty?
      (:i, nil, class: 'fa-solid fa-circle-check fa-sm text-success',
                           title: "All expected schemas present: #{expected.join(', ')}")
    else
      (:i, nil, class: 'fa-solid fa-triangle-exclamation fa-sm text-warning',
                           title: "Missing expected: #{missing.join(', ')}")
    end
  end
end

#site_map_seo_commands(site_map) ⇒ Array<String>

Builds the link array for render_combo_drop_down.
Primary action: full SEO analysis. Dropdown: individual sync steps.

Parameters:

  • site_map (SiteMap)

    The site map record

Returns:

  • (Array<String>)

    Array of link_to HTML strings



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'app/helpers/crm/site_maps_helper.rb', line 185

def site_map_seo_commands(site_map)
  cmds = []

  # Primary action (becomes the main button)
  cmds << link_to(analyze_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-wand-magic-sparkles me-1"></i> Run Full Analysis')
  end

  # Individual sync steps (become dropdown items)
  cmds << link_to(analyze_only_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-brain me-1"></i> Analysis Only')
  end

  cmds << link_to(analyze_premium_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-gem me-1"></i> Premium Analysis (Opus)')
  end

  cmds << link_to(sync_visits_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-eye me-1"></i> Sync Visits Only')
  end

  cmds << link_to(sync_gsc_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-brands fa-google me-1"></i> Sync GSC Only')
  end

  cmds << link_to(sync_ga4_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-chart-bar me-1"></i> Sync GA4 Only')
  end

  cmds << link_to(sync_keywords_site_map_path(site_map),
                  data: { turbo_method: :post }) do
    raw('<i class="fa-solid fa-key me-1"></i> Sync Keywords Only')
  end

  cmds << link_to(recrawl_site_map_path(site_map),
                  data: { turbo_method: :post,
                          turbo_confirm: 'Recrawl this page? This will fetch the latest content and schema.' }) do
    raw('<i class="fa-solid fa-rotate me-1"></i> Recrawl Page')
  end

  cmds
end

#suggested_keyword_target(site_map, keyword, search_volume: nil) ⇒ Object

Intent-based suggestion (desired / undesired / ignore) for display and apply-to-selected.



5
6
7
# File 'app/helpers/crm/site_maps_helper.rb', line 5

def suggested_keyword_target(site_map, keyword, search_volume: nil)
  site_map.suggested_keyword_target_for(keyword, search_volume: search_volume)
end

#suggestion_badge_class(suggestion) ⇒ Object



9
10
11
12
13
14
15
16
# File 'app/helpers/crm/site_maps_helper.rb', line 9

def suggestion_badge_class(suggestion)
  case suggestion
  when 'desired' then 'bg-success'
  when 'undesired' then 'bg-warning text-dark'
  when 'ignore' then 'bg-secondary'
  else 'bg-light text-dark'
  end
end

#suggestion_label(suggestion) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/helpers/crm/site_maps_helper.rb', line 18

def suggestion_label(suggestion)
  case suggestion
  when 'desired' then 'Desired'
  when 'undesired' then 'Not desired'
  when 'ignore' then 'Ignore'
  else ''
  end
end

#url_path_only(site_map_or_url) ⇒ String

Returns the path portion for display
Now that SiteMap stores path directly, this is a simple accessor

Parameters:

  • site_map_or_url (SiteMap, String)

    SiteMap object or URL string

Returns:

  • (String)

    Relative path without locale prefix



32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/crm/site_maps_helper.rb', line 32

def url_path_only(site_map_or_url)
  case site_map_or_url
  when SiteMap
    site_map_or_url.path.presence || '/'
  when String
    SiteMap.extract_path_from_url(site_map_or_url)
  else
    '/'
  end
end