Module: Lookout::ApplicationHelper

Defined in:
app/helpers/lookout/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_property_filterObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/lookout/application_helper.rb', line 3

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

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



50
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
# File 'app/helpers/lookout/application_helper.rb', line 50

def lookout_importmap_tags(entry_point = "application", shim: true)
  # Prefer modern helper if available (importmap-rails >= 1.1)
  if respond_to?(:javascript_importmap_tags)
    return safe_join [
      javascript_importmap_tags,
      javascript_import_module_tag(entry_point)
    ], "\n"
  end

  # Legacy helpers (importmap-rails 1.0 style) - guard per method
  parts = []
  if shim && respond_to?(:javascript_importmap_shim_tag)
    parts << javascript_importmap_shim_tag
  end
  if shim && respond_to?(:javascript_importmap_shim_nonce_configuration_tag)
    parts << javascript_importmap_shim_nonce_configuration_tag
  end
  parts << javascript_import_module_tag(entry_point)
  if respond_to?(:javascript_importmap_module_preload_tags)
    parts << javascript_importmap_module_preload_tags(Lookout.importmap)
  end
  if respond_to?(:javascript_inline_importmap_tag)
    parts << javascript_inline_importmap_tag(Lookout.importmap.to_json(resolver: self))
  end

  safe_join parts.compact, "\n"
end

#non_filter_ransack_paramsObject

gets put into the form as a hidden field



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
# File 'app/helpers/lookout/application_helper.rb', line 84

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/lookout/application_helper.rb', line 25

def number_to_duration(duration)
  seconds =
    case duration
    when nil
      nil
    when ActiveSupport::Duration
      duration.in_seconds
    else
      duration.to_f
    end

  if seconds && seconds > 0
    minutes = (seconds / 60).to_i
    seconds = (seconds % 60).to_i
    "#{minutes}m #{seconds}s"
  else
    "0m 0s"
  end
end

#number_to_percentage(number, options = {}) ⇒ Object



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

def number_to_percentage(number, options = {})
  precision = options.fetch(:precision, 0)
  "#{number.round(precision)}%"
end

#render_paginationObject



114
115
116
117
118
119
120
# File 'app/helpers/lookout/application_helper.rb', line 114

def render_pagination
  if @pagination
    @pagination.series_nav.html_safe
  else
    ""
  end
end

#search_paramsObject



78
79
80
# File 'app/helpers/lookout/application_helper.rb', line 78

def search_params
  request.query_parameters
end

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



17
18
19
20
21
22
23
# File 'app/helpers/lookout/application_helper.rb', line 17

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