Module: Crm::VideosHelper

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

Overview

View helpers for the CRM videos area: action link lists, info tooltips,
Ransack sort options, and duration formatting for
+Crm::VideosController+ views.

See Also:

  • VideosController

Instance Method Summary collapse

Instance Method Details

#applied_filters_count(q) ⇒ Integer

Counts the filters currently applied to a Ransack search.

Parameters:

  • q (Ransack::Search, nil)

    the search object

Returns:

  • (Integer)

    number of applied conditions (0 when +q+ is nil)



82
83
84
85
86
87
# File 'app/helpers/crm/videos_helper.rb', line 82

def applied_filters_count(q)
  return 0 unless q

  # Use Ransack's conditions method to get all applied conditions
  q.conditions.count
end

#current_sort_optionString

Currently applied sort, from Ransack (+q[s]+) or a plain +sort+ param.

Returns:

  • (String)

    the sort string, defaulting to "created_at desc"



73
74
75
76
# File 'app/helpers/crm/videos_helper.rb', line 73

def current_sort_option
  # Check for sort parameter in q[s] (Ransack format) or as a separate sort parameter
  params.dig(:q, :s) || params[:sort] || 'created_at desc'
end

#format_video_duration(seconds) ⇒ String?

Formats a duration in seconds as +h:mm:ss+ (or +m:ss+ under an hour).

Parameters:

  • seconds (Numeric, String, nil)

    the duration in seconds

Returns:

  • (String, nil)

    the formatted duration, or nil when blank/non-positive



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/helpers/crm/videos_helper.rb', line 93

def format_video_duration(seconds)
  return nil unless seconds.present? && seconds.to_i.positive?

  total_seconds = seconds.to_i
  hours = total_seconds / 3600
  minutes = (total_seconds % 3600) / 60
  secs = total_seconds % 60

  if hours.positive?
    format('%d:%02d:%02d', hours, minutes, secs)
  else
    format('%d:%02d', minutes, secs)
  end
end

#video_actions(video) ⇒ Array

Builds the list of action links for a video row/detail view.

Parameters:

  • video (Video)

    the video the actions apply to

Returns:

  • (Array)

    link markup entries (and +:separator+ dividers), empty
    when the user cannot update the video



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

def video_actions(video)
  return [] unless can?(:update, video)

  links = []

  links << link_to(fa_icon('wrench', text: 'Edit'), edit_video_path(video))

  links << link_to(fa_icon('microphone', text: 'Generate Transcript'), transcription_options_video_path(video))
  links << link_to(fa_icon('cloud', text: 'Cloudflare Updates'), cloudflare_updates_video_path(video)) if video.is_cloudflare?
  links << link_to(fa_icon('image', text: 'Extract Poster'), extract_poster_video_path(video)) if video.is_cloudflare?
  links << link_to(fa_icon('broom', text: 'Flush Cache'), flush_cache_video_path(video), data: { turbo_method: :post }) if can?(:update, video)
  links << link_to(fa_icon('download', text: 'Download'), download_video_path(video))
  links << :separator

  # Delete link - always go to confirmation page for safety
  links << link_to(fa_icon('trash', text: 'Delete'), delete_confirmation_video_path(video), class: 'text-danger')

  links
end

#video_info(video) ⇒ String

Multi-line plain-text summary of a video for tooltips/titles.

Parameters:

  • video (Video)

    the video to describe

Returns:

  • (String)

    newline-separated attribute listing



38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/crm/videos_helper.rb', line 38

def video_info(video)
  [
    "Title: #{video.title}",
    "Slug: #{video.slug}",
    "Category: #{video.category}",
    "Series: #{video.series}",
    "ID: #{video.id}",
    "Tags: #{video.tags.join(', ')}",
    "Locales: #{video.locales&.join(', ')}"
  ].join("\n")
end

#video_sort_optionsArray<Array(String, String)>

[label, Ransack sort string] options for the video list sort select.

Returns:

  • (Array<Array(String, String)>)

    [label, sort] pairs



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/crm/videos_helper.rb', line 53

def video_sort_options
  [
    ['Newest First', 'created_at desc'],
    ['Oldest First', 'created_at asc'],
    ['Title A-Z', 'title asc'],
    ['Title Z-A', 'title desc'],
    ['Category A-Z', 'category asc'],
    ['Category Z-A', 'category desc'],
    ['Series A-Z', 'series asc'],
    ['Series Z-A', 'series desc'],
    ['Air Date Newest', 'air_date desc'],
    ['Air Date Oldest', 'air_date asc'],
    ['Duration Ascending', 'duration_in_seconds asc'],
    ['Duration Descending', 'duration_in_seconds desc']
  ]
end