Module: AhoyCaptain::ApplicationHelper

Includes:
Pagy::Frontend
Defined in:
app/helpers/ahoy_captain/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#ahoy_captain_importmap_tags(entry_point = "application", shim: true) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'app/helpers/ahoy_captain/application_helper.rb', line 35

def ahoy_captain_importmap_tags(entry_point = "application", shim: true)
  safe_join [
    (javascript_importmap_shim_tag if shim),
    (javascript_importmap_shim_nonce_configuration_tag if shim),
    javascript_import_module_tag(entry_point),
    javascript_importmap_module_preload_tags(AhoyCaptain.importmap),
    javascript_inline_importmap_tag(AhoyCaptain.importmap.to_json(resolver: self)),
  ].compact, "\n"
end

#current_property_filterObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/ahoy_captain/application_helper.rb', line 5

def current_property_filter
  return nil unless params[:q]

  prop = params[:q].to_unsafe_h.detect { |key, _| key.starts_with?("properties.") }
  if prop
    key = prop[0].dup
    Ransack::Predicate.detect_and_strip_from_string!(key)
    { key: key, value: prop[1] }

  else
    nil
  end
end

#non_filter_ransack_paramsObject

gets put into the form as a hidden field



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/ahoy_captain/application_helper.rb', line 51

def non_filter_ransack_params
  other_params = {}
  map = [
    :start_date,
    :end_date,
    :period,
    :interval,
    :comparison,
  ]

  # properties stuff falls into current_property_filter
  ransack = [:goal]

  map.each do |key|
    if params[key]
      other_params[key] = params[key]
    end
  end

  ransack.each do |key|
    Ransack.predicates.keys.each do |predicate|
      if value = params.dig(:q, "#{key}_#{predicate}")
        other_params["q[#{key}_#{predicate}]"] = value
      end
    end
  end

  other_params
end

#number_to_duration(duration) ⇒ Object



27
28
29
30
31
32
33
# File 'app/helpers/ahoy_captain/application_helper.rb', line 27

def number_to_duration(duration)
  if duration
    "#{duration.in_minutes.to_i}M #{duration.parts[:seconds].to_i}S"
  else
    "0M 0S"
  end
end

#render_paginationObject



81
82
83
84
85
86
87
# File 'app/helpers/ahoy_captain/application_helper.rb', line 81

def render_pagination
  if @pagination
    pagy_nav(@pagination).html_safe
  else
    ""
  end
end

#search_paramsObject



45
46
47
# File 'app/helpers/ahoy_captain/application_helper.rb', line 45

def search_params
  request.query_parameters
end

#stats_container(value, url, label, formatter, selected = false) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/ahoy_captain/application_helper.rb', line 19

def stats_container(value, url, label, formatter, selected = false)
  if value.is_a?(AhoyCaptain::ComparableQuery::Comparison)
    ::AhoyCaptain::Stats::ComparableContainerComponent.new(url, label, value, formatter, selected, compare_mode?)
  else
    ::AhoyCaptain::Stats::ContainerComponent.new(url, label, value, formatter, selected)
  end
end