ahoy_captain 0.8 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -13
- data/app/assets/javascript/ahoy_captain/application.js +4 -4
- data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +30 -0
- data/app/assets/javascript/ahoy_captain/controllers/application.js +5 -5
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +16 -9
- data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +341 -0
- data/app/assets/javascript/ahoy_captain/controllers/details_modal_controller.js +5 -5
- data/app/assets/javascript/ahoy_captain/controllers/dropdown_label_controller.js +2 -2
- data/app/assets/javascript/ahoy_captain/controllers/filter/item_controller.js +12 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_form_controller.js +13 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +45 -0
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +116 -104
- data/app/assets/javascript/ahoy_captain/controllers/index.js +4 -3
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +8 -3
- data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +188 -0
- data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +9 -0
- data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +8 -0
- data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +46 -0
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +12 -9
- data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +9 -0
- data/app/assets/javascript/ahoy_captain/controllers/toggle_controller.js +17 -0
- data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +156 -0
- data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +55 -0
- data/app/components/ahoy_captain/combobox_component.html.erb +33 -0
- data/app/components/ahoy_captain/combobox_component.rb +13 -0
- data/app/components/ahoy_captain/comparison_link_component.rb +40 -0
- data/app/components/ahoy_captain/dropdown_button_component.html.erb +5 -5
- data/app/components/ahoy_captain/dropdown_link_component.html.erb +5 -5
- data/app/components/ahoy_captain/filter/dropdown_component.html.erb +50 -0
- data/app/components/ahoy_captain/filter/dropdown_component.rb +51 -0
- data/app/components/ahoy_captain/filter/modal_component.html.erb +12 -9
- data/app/components/ahoy_captain/filter/select_component.html.erb +23 -19
- data/app/components/ahoy_captain/filter/select_component.rb +41 -9
- data/app/components/ahoy_captain/filter/tag_component.html.erb +8 -4
- data/app/components/ahoy_captain/filter/tag_component.rb +6 -30
- data/app/components/ahoy_captain/filter/tag_container_component.html.erb +2 -3
- data/app/components/ahoy_captain/filter/tag_container_component.rb +1 -8
- data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +25 -0
- data/app/components/ahoy_captain/stats/comparable_container_component.rb +86 -0
- data/app/components/ahoy_captain/stats/container_component.html.erb +15 -0
- data/app/components/ahoy_captain/stats/container_component.rb +26 -0
- data/app/components/ahoy_captain/sticky_nav_component.html.erb +13 -22
- data/app/components/ahoy_captain/sticky_nav_component.rb +11 -0
- data/app/components/ahoy_captain/table_component.html.erb +4 -37
- data/app/components/ahoy_captain/table_component.rb +25 -5
- data/app/components/ahoy_captain/tables/devices_table_component.rb +11 -0
- data/app/components/ahoy_captain/tables/dynamic_table.rb +13 -0
- data/app/components/ahoy_captain/tables/dynamic_table_component.rb +204 -0
- data/app/components/ahoy_captain/tables/goals_table_component.rb +17 -0
- data/app/components/ahoy_captain/tables/header_component.html.erb +5 -0
- data/app/components/ahoy_captain/tables/header_component.rb +18 -0
- data/app/components/ahoy_captain/tables/headers/header_component.html.erb +5 -0
- data/app/components/ahoy_captain/tables/headers/header_component.rb +16 -0
- data/app/components/ahoy_captain/tables/properties_table_component.rb +27 -0
- data/app/components/ahoy_captain/tables/row_component.html.erb +4 -0
- data/app/components/ahoy_captain/tables/rows/row_component.html.erb +6 -0
- data/app/components/ahoy_captain/tables/rows/row_component.rb +40 -0
- data/app/components/ahoy_captain/tile_component.html.erb +21 -10
- data/app/components/ahoy_captain/tile_component.rb +3 -2
- data/app/components/ahoy_captain/tooltip_component.html.erb +2 -2
- data/app/controllers/ahoy_captain/application_controller.rb +19 -29
- data/app/controllers/ahoy_captain/campaigns_controller.rb +2 -10
- data/app/controllers/ahoy_captain/cities_controller.rb +2 -6
- data/app/controllers/ahoy_captain/countries_controller.rb +2 -6
- data/app/controllers/ahoy_captain/devices_controller.rb +3 -6
- data/app/controllers/ahoy_captain/entry_pages_controller.rb +2 -4
- data/app/controllers/ahoy_captain/exit_pages_controller.rb +3 -4
- data/app/controllers/ahoy_captain/exports_controller.rb +14 -0
- data/app/controllers/ahoy_captain/filters/base_controller.rb +1 -3
- data/app/controllers/ahoy_captain/filters/goals_controller.rb +9 -0
- data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +3 -3
- data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +2 -3
- data/app/controllers/ahoy_captain/filters/properties/names_controller.rb +11 -0
- data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +15 -0
- data/app/controllers/ahoy_captain/filters/sources_controller.rb +1 -1
- data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
- data/app/controllers/ahoy_captain/properties_controller.rb +41 -0
- data/app/controllers/ahoy_captain/regions_controller.rb +3 -7
- data/app/controllers/ahoy_captain/sources_controller.rb +2 -5
- data/app/controllers/ahoy_captain/stats/base_controller.rb +86 -5
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +2 -1
- data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +2 -1
- data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +2 -1
- data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +3 -1
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +3 -11
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +2 -1
- data/app/controllers/ahoy_captain/top_pages_controller.rb +2 -8
- data/app/decorators/ahoy_captain/application_decorator.rb +27 -3
- data/app/decorators/ahoy_captain/campaign_decorator.rb +8 -0
- data/app/decorators/ahoy_captain/city_decorator.rb +12 -0
- data/app/decorators/ahoy_captain/country_decorator.rb +10 -0
- data/app/decorators/ahoy_captain/device_decorator.rb +13 -2
- data/app/decorators/ahoy_captain/page_decorator.rb +11 -0
- data/app/decorators/ahoy_captain/region_decorator.rb +16 -0
- data/app/decorators/ahoy_captain/source_decorator.rb +7 -0
- data/app/helpers/ahoy_captain/application_helper.rb +62 -3
- data/app/models/ahoy_captain/comparison_mode.rb +72 -0
- data/app/models/ahoy_captain/export.rb +48 -0
- data/app/models/ahoy_captain/filter_parser.rb +82 -0
- data/app/models/ahoy_captain/range_from_params.rb +75 -0
- data/app/models/ahoy_captain/rangeable.rb +0 -3
- data/app/models/concerns/ahoy_captain/compare_mode.rb +19 -0
- data/app/models/concerns/ahoy_captain/limitable.rb +17 -0
- data/app/models/concerns/ahoy_captain/range_options.rb +1 -14
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +18 -49
- data/app/presenters/ahoy_captain/goals_presenter.rb +3 -2
- data/app/queries/ahoy_captain/application_query.rb +78 -13
- data/app/queries/ahoy_captain/campaign_query.rb +14 -0
- data/app/queries/ahoy_captain/city_query.rb +11 -0
- data/app/queries/ahoy_captain/country_query.rb +10 -0
- data/app/queries/ahoy_captain/device_query.rb +10 -0
- data/app/queries/ahoy_captain/entry_pages_query.rb +3 -2
- data/app/queries/ahoy_captain/event_query.rb +20 -13
- data/app/queries/ahoy_captain/exit_pages_query.rb +6 -4
- data/app/queries/ahoy_captain/region_query.rb +11 -0
- data/app/queries/ahoy_captain/source_query.rb +10 -0
- data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +11 -4
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +14 -2
- data/app/queries/ahoy_captain/stats/base_query.rb +18 -0
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +15 -1
- data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/total_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +1 -1
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +3 -3
- data/app/queries/ahoy_captain/top_page_query.rb +13 -0
- data/app/queries/ahoy_captain/visit_query.rb +2 -3
- data/app/queries/concerns/ahoy_captain/comparable_queries.rb +25 -0
- data/app/queries/concerns/ahoy_captain/comparable_query.rb +138 -0
- data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +42 -0
- data/app/views/ahoy_captain/devices/_table.html.erb +2 -0
- data/app/views/ahoy_captain/devices/index.html+details.erb +1 -1
- data/app/views/ahoy_captain/devices/index.html.erb +2 -2
- data/app/views/ahoy_captain/funnels/show.html.erb +5 -2
- data/app/views/ahoy_captain/goals/index.html.erb +2 -37
- data/app/views/ahoy_captain/layouts/application.html.erb +3 -4
- data/app/views/ahoy_captain/properties/_form.html.erb +6 -0
- data/app/views/ahoy_captain/properties/index.html.erb +3 -0
- data/app/views/ahoy_captain/properties/show.html.erb +6 -0
- data/app/views/ahoy_captain/realtimes/show.html.erb +1 -1
- data/app/views/ahoy_captain/roots/_filters.html.erb +80 -0
- data/app/views/ahoy_captain/roots/show.html.erb +76 -109
- data/app/views/ahoy_captain/stats/base/index.html.erb +34 -9
- data/app/views/ahoy_captain/stats/show.html.erb +8 -55
- data/config/routes.rb +9 -0
- data/lib/ahoy_captain/ahoy/event_methods.rb +35 -74
- data/lib/ahoy_captain/ahoy/visit_methods.rb +1 -1
- data/lib/ahoy_captain/configuration.rb +18 -7
- data/lib/ahoy_captain/engine.rb +22 -0
- data/lib/ahoy_captain/filter_configuration/filter.rb +16 -0
- data/lib/ahoy_captain/filter_configuration/filter_collection.rb +48 -0
- data/lib/ahoy_captain/filters_configuration.rb +77 -0
- data/lib/ahoy_captain/goals.rb +10 -2
- data/lib/ahoy_captain/period_collection.rb +1 -1
- data/lib/ahoy_captain/predicate_label.rb +7 -0
- data/lib/ahoy_captain/version.rb +1 -1
- data/lib/ahoy_captain.rb +7 -1
- data/lib/generators/ahoy_captain/templates/config.rb.tt +32 -0
- metadata +80 -21
- data/app/assets/javascript/ahoy_captain/controllers/filter_controller.js +0 -145
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +0 -17
- data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +0 -43
- data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +0 -25
- data/app/models/ahoy_captain/current.rb +0 -9
- data/app/models/ahoy_captain/url_helpers.rb +0 -6
@@ -1,13 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class AhoyCaptain::Filter::TagContainerComponent < ViewComponent::Base
|
4
|
-
def initialize
|
5
|
-
@filters = filters.to_unsafe_h.to_a.map do |key, values|
|
6
|
-
Array(values).map { |value| [key, value] }
|
7
|
-
end.flatten(1).reject { |k,v| v.blank? }
|
8
|
-
|
4
|
+
def initialize
|
9
5
|
end
|
10
|
-
|
11
|
-
private
|
12
|
-
attr_reader :filters
|
13
6
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<a href="<%= @url %>" class="relative px-4 md:px-6 w-1/2 my-4 w-auto group cursor-pointer" data-turbo-frame="chart">
|
2
|
+
<div>
|
3
|
+
<h5 class="text-sm font-bold uppercase whitespace-nowrap flex w-content border-transparent tooltip tooltip-bottom "
|
4
|
+
data-active-links-target="link" data-tip="<%= tooltip %>">
|
5
|
+
<%= @label %>
|
6
|
+
<div class="<%= klass %> ms-2"><%= arrow %></div>
|
7
|
+
</h5>
|
8
|
+
<div class="md:block flex gap-4">
|
9
|
+
<div>
|
10
|
+
<span class="flex items-center justify-between whitespace-nowrap">
|
11
|
+
<p class="font-bold text-xl"><%= formatted(value.current) %></p>
|
12
|
+
</span>
|
13
|
+
<% if compare_mode? %>
|
14
|
+
<p class="text-xs"><%= range_string %></p>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
<% if compare_mode? %>
|
18
|
+
<div>
|
19
|
+
<p class="font-bold text-xl text-gray-500"><%= formatted(value.compared_to) %></p>
|
20
|
+
<p class="text-xs text-gray-500"><%= compare_range_string %></p>
|
21
|
+
</div>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</a>
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Stats
|
3
|
+
class ComparableContainerComponent < ViewComponent::Base
|
4
|
+
include CompareMode
|
5
|
+
include Rangeable
|
6
|
+
|
7
|
+
def initialize(url, label, comparable, formatter = nil, selected = false, compare = false)
|
8
|
+
@url = url
|
9
|
+
@label = label
|
10
|
+
@comparable = comparable
|
11
|
+
@formatter = formatter
|
12
|
+
@selected = selected
|
13
|
+
@compare = compare
|
14
|
+
end
|
15
|
+
|
16
|
+
def compare?
|
17
|
+
@compare
|
18
|
+
end
|
19
|
+
|
20
|
+
def klass
|
21
|
+
if percentage.negative?
|
22
|
+
"text-red-400"
|
23
|
+
else
|
24
|
+
"text-green-400"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# 〰 ↓ ↑
|
29
|
+
def arrow
|
30
|
+
if percentage.negative?
|
31
|
+
"↓"
|
32
|
+
elsif percentage.positive?
|
33
|
+
"↑"
|
34
|
+
else
|
35
|
+
"〰"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def percentage
|
40
|
+
begin
|
41
|
+
diff = value.current - value.compared_to
|
42
|
+
if diff.zero?
|
43
|
+
return 0
|
44
|
+
end
|
45
|
+
(value.current / diff).round(2) * 100
|
46
|
+
rescue ZeroDivisionError
|
47
|
+
0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def number_to_duration(duration)
|
52
|
+
if duration
|
53
|
+
"#{duration.in_minutes.to_i}M #{duration.parts[:seconds].to_i}S"
|
54
|
+
else
|
55
|
+
"0M 0S"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def compare_range_string
|
60
|
+
range_to_string(@comparable.compare_range)
|
61
|
+
end
|
62
|
+
|
63
|
+
def range_string
|
64
|
+
range_to_string(@comparable.range)
|
65
|
+
end
|
66
|
+
|
67
|
+
def value
|
68
|
+
@comparable.result
|
69
|
+
end
|
70
|
+
|
71
|
+
def tooltip
|
72
|
+
"#{formatted(value.current)} vs #{formatted(value.compared_to)} — #{number_to_percentage percentage} (#{arrow}) "
|
73
|
+
end
|
74
|
+
|
75
|
+
def formatted(value)
|
76
|
+
public_send(@formatter, value)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def range_to_string(range)
|
82
|
+
[range[0], range[1]].map { |item| item.strftime('%m %B') }.join(' - ')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<a href="<%= @url %>" class="relative px-4 md:px-6 w-1/2 my-4 lg:w-auto group cursor-pointer" data-turbo-frame="chart">
|
2
|
+
<div>
|
3
|
+
<h5 class="text-sm font-bold uppercase whitespace-nowrap flex w-content border-transparent tooltip tooltip-bottom "
|
4
|
+
data-active-links-target="link">
|
5
|
+
<%= @label %>
|
6
|
+
</h5>
|
7
|
+
<div class="my-1 space-y-2">
|
8
|
+
<div>
|
9
|
+
<span class="flex items-center justify-between whitespace-nowrap">
|
10
|
+
<p class="font-bold text-xl"><%= formatted(@value) %></p>
|
11
|
+
</span>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
</a>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Stats
|
3
|
+
class ContainerComponent < ViewComponent::Base
|
4
|
+
def initialize(url, label, value, formatter, selected = false)
|
5
|
+
@url = url
|
6
|
+
@label = label
|
7
|
+
@value = value
|
8
|
+
@formatter = formatter
|
9
|
+
@selected = selected
|
10
|
+
end
|
11
|
+
|
12
|
+
def formatted(value)
|
13
|
+
public_send(@formatter, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def number_to_duration(duration)
|
18
|
+
if duration
|
19
|
+
"#{duration.in_minutes.to_i}M #{duration.parts[:seconds].to_i}S"
|
20
|
+
else
|
21
|
+
"0M 0S"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,37 +1,28 @@
|
|
1
|
-
<div class="max-w-6xl flex justify-between sticky top-0 min-h-sm z-[99999] bg-base-
|
1
|
+
<div class="max-w-6xl flex justify-between sticky top-0 min-h-sm z-[99999] py-4 bg-base-100">
|
2
2
|
<div class="flex items-center">
|
3
3
|
<a href="/">
|
4
|
-
<img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='
|
4
|
+
<img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='max-h-20 md:h-16 rounded-full'>
|
5
5
|
</a>
|
6
|
-
<% if
|
7
|
-
<%= render AhoyCaptain::Filter::TagContainerComponent.new
|
6
|
+
<% if tag_list_hidden? %>
|
7
|
+
<%= render AhoyCaptain::Filter::TagContainerComponent.new %>
|
8
8
|
<% else %>
|
9
9
|
<%= realtime_update %>
|
10
10
|
<% end %>
|
11
11
|
</div>
|
12
|
-
<div class="flex flex-row-reverse col-span-2 items-center">
|
13
|
-
<%= render AhoyCaptain::
|
12
|
+
<div class="flex flex-row-reverse col-span-2 items-center gap-3">
|
13
|
+
<%= render AhoyCaptain::ComparisonLinkComponent.new %>
|
14
|
+
|
15
|
+
<%= render AhoyCaptain::DropdownLinkComponent.new(title: params[:start_date] ? "Custom Range" : (AhoyCaptain.config.ranges.find(params[:period] || AhoyCaptain.config.ranges.default).try(:label) || "Period"), classes: 'btn btn-sm btn-base-100 no-underline hover:bg-base-100') do |dropdown| %>
|
14
16
|
<% dropdown.with_option do %>
|
15
17
|
<% AhoyCaptain.config.ranges.each do |param, range| %>
|
16
|
-
<a class='link no-underline' href="<%= request.path %>?<%= request.query_parameters.except("start_date", "end_date").merge("period" => param).to_query %>"><%= range.label %></a>
|
18
|
+
<a class='link no-underline' href="<%= request.path %>?<%= request.query_parameters.except("start_date", "end_date", "date", "compare_to_start_date", "compare_to_end_date").merge("period" => param).to_query %>"><%= range.label %></a>
|
17
19
|
<% end %>
|
18
20
|
|
19
|
-
<a class='link no-underline' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
|
20
|
-
|
21
|
-
<% end %>
|
22
|
-
<%= render AhoyCaptain::DropdownButtonComponent.new(title: 'Filter') do |dropdown| %>
|
23
|
-
<% dropdown.with_header_icon do %>
|
24
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="-ml-1 mr-1 h-4 w-4 md:h-4 md:w-4">
|
25
|
-
<path fill-rule="evenodd" d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z" clip-rule="evenodd"></path>
|
26
|
-
</svg>
|
27
|
-
<% end %>
|
28
|
-
<% dropdown.with_option do %>
|
29
|
-
<button onClick="pageModal.showModal()" class='link no-underline'>Page</button>
|
30
|
-
<button onClick="countryModal.showModal()" class='link no-underline'>Geography</button>
|
31
|
-
<button onClick="screenModal.showModal()" class='link no-underline'>Screen</button>
|
32
|
-
<button onClick="osModal.showModal()" class='link no-underline'>Operating System</button>
|
33
|
-
<button onClick="utmModal.showModal()" class='link no-underline'>UTM Tags</button>
|
21
|
+
<a class='link no-underline ' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
|
22
|
+
<a class='link no-underline ' href='<%= AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: !compare_mode?)) %>'><%= compare_mode? ? "Disable Comparison" : "Compare" %></a>
|
34
23
|
<% end %>
|
35
24
|
<% end %>
|
25
|
+
|
26
|
+
<%= render AhoyCaptain::Filter::DropdownComponent.new(filters: filters) %>
|
36
27
|
</div>
|
37
28
|
</div>
|
@@ -2,4 +2,15 @@
|
|
2
2
|
|
3
3
|
class AhoyCaptain::StickyNavComponent < ViewComponent::Base
|
4
4
|
renders_one :realtime_update
|
5
|
+
include ::AhoyCaptain::CompareMode
|
6
|
+
include ::AhoyCaptain::RangeOptions
|
7
|
+
include ::AhoyCaptain::Rangeable
|
8
|
+
|
9
|
+
def filters
|
10
|
+
@filters ||= ::AhoyCaptain::FilterParser.parse(request)
|
11
|
+
end
|
12
|
+
|
13
|
+
def tag_list_hidden?
|
14
|
+
filters.values.map(&:values).flatten.size < ::AhoyCaptain::FilterParser::FILTER_MENU_MAX_SIZE
|
15
|
+
end
|
5
16
|
end
|
@@ -1,44 +1,11 @@
|
|
1
|
-
<div class="flex flex-col min-h-[380px] w-full pt-4">
|
2
|
-
|
3
|
-
|
4
|
-
<span ><%= unit_name %></span>
|
5
|
-
<% if additional_cols.include?(:percent_total) %>
|
6
|
-
<span class="w-8 ml-8 text-right">%</span>
|
7
|
-
<% end %>
|
8
|
-
<% if additional_cols.include?(:total) %>
|
9
|
-
<span class="w-8 ml-8 text-right">Total</span>
|
10
|
-
<% end %>
|
11
|
-
<% if additional_cols.include?(:conversion_rate) %>
|
12
|
-
<span class="w-8 ml-8 text-right">CR</span>
|
13
|
-
<% end %>
|
14
|
-
</div>
|
15
|
-
<div class='min-h-[420px]'>
|
1
|
+
<div class="flex flex-col <%= 'min-h-[380px]' if fixed_height? %> w-full pt-4">
|
2
|
+
<%= render @header %>
|
3
|
+
<div class='<%= 'min-h-[420px]' if fixed_height? %>'>
|
16
4
|
<div class="grow">
|
17
5
|
<% if items.respond_to?(:each) && items.any? %>
|
18
6
|
<% items.each do |item| %>
|
19
7
|
<div class='leading-10 flex relative'>
|
20
|
-
|
21
|
-
</progress>
|
22
|
-
<span class="grow text-elipsis overflow-hidden absolute left-4 bottom-3 h-8 text-base-content">
|
23
|
-
<%= item.display_name %>
|
24
|
-
</span>
|
25
|
-
<span class="w-8 ml-8 text-right">
|
26
|
-
<%= render AhoyCaptain::TooltipComponent.new(amount: item.unit_amount) %>
|
27
|
-
</span>
|
28
|
-
|
29
|
-
<% if additional_cols.include?(:percent_total) %>
|
30
|
-
<span class="w-8 ml-8 text-right"><%= percent_total(item) %></span>
|
31
|
-
<% end %>
|
32
|
-
<% if additional_cols.include?(:total) %>
|
33
|
-
<span class="w-8 ml-8 text-right">
|
34
|
-
<%= render AhoyCaptain::TooltipComponent.new(amount: item.total) %>
|
35
|
-
</span>
|
36
|
-
<% end %>
|
37
|
-
<% if additional_cols.include?(:conversion_rate) %>
|
38
|
-
<span class="w-8 ml-8 text-right">
|
39
|
-
<%= item.conversion_rate * 100.0 %>%
|
40
|
-
</span>
|
41
|
-
<% end %>
|
8
|
+
<%= render_row(item) %>
|
42
9
|
</div>
|
43
10
|
<% end %>
|
44
11
|
<% else %>
|
@@ -1,13 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class AhoyCaptain::TableComponent < ViewComponent::Base
|
4
|
-
|
4
|
+
DEFAULT_HEADER = AhoyCaptain::Tables::Headers::HeaderComponent
|
5
|
+
DEFAULT_ROW = AhoyCaptain::Tables::Rows::RowComponent
|
5
6
|
|
6
|
-
def initialize(items:, category_name
|
7
|
+
def initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW, table: nil)
|
7
8
|
@items = items
|
8
9
|
@category_name = category_name
|
9
10
|
@unit_name = unit_name
|
10
|
-
|
11
|
+
if header.nil?
|
12
|
+
@header = DEFAULT_HEADER.new(category_name: category_name, unit_name: unit_name)
|
13
|
+
else
|
14
|
+
@header = header.new
|
15
|
+
end
|
16
|
+
|
17
|
+
@row = row
|
18
|
+
|
19
|
+
if table
|
20
|
+
@table = table.table
|
21
|
+
@header = @table.headers
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_row(item)
|
26
|
+
if @table
|
27
|
+
@table.row(item, view_context)
|
28
|
+
else
|
29
|
+
@row.new(table: self, item: item).render_in(view_context)
|
30
|
+
end
|
11
31
|
end
|
12
32
|
|
13
33
|
private
|
@@ -22,7 +42,7 @@ class AhoyCaptain::TableComponent < ViewComponent::Base
|
|
22
42
|
@total ||= items.first.total_count
|
23
43
|
end
|
24
44
|
|
25
|
-
def
|
26
|
-
|
45
|
+
def fixed_height?
|
46
|
+
@header.fixed_height?
|
27
47
|
end
|
28
48
|
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Tables
|
3
|
+
class DynamicTableComponent < ViewComponent::Base
|
4
|
+
class TableDefinition
|
5
|
+
attr_reader :rows
|
6
|
+
class Row
|
7
|
+
attr_reader :attribute, :view_context
|
8
|
+
attr_reader :item
|
9
|
+
def initialize(attribute, options = {}, &block)
|
10
|
+
@attribute = attribute
|
11
|
+
@options = options
|
12
|
+
@block = block
|
13
|
+
@view_context = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(item, view_context)
|
17
|
+
@view_context = view_context
|
18
|
+
@item = item
|
19
|
+
if @options[:type] == :progress_bar
|
20
|
+
progress_bar(item)
|
21
|
+
else
|
22
|
+
if @block
|
23
|
+
column(@block.call(item))
|
24
|
+
else
|
25
|
+
column(item.public_send(attribute).presence)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def header
|
32
|
+
@options[:title] || @attribute.to_s.titleize
|
33
|
+
end
|
34
|
+
|
35
|
+
def link_to(*args)
|
36
|
+
@view_context.link_to(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def request
|
40
|
+
@view_context.request
|
41
|
+
end
|
42
|
+
|
43
|
+
def h
|
44
|
+
@view_context.helpers
|
45
|
+
end
|
46
|
+
|
47
|
+
def search_params
|
48
|
+
@view_context.search_params
|
49
|
+
end
|
50
|
+
|
51
|
+
# needed for tricky instance_eval with blocks and view_context
|
52
|
+
def method_missing(method, *args, &block)
|
53
|
+
if klass.respond_to?(method)
|
54
|
+
klass.send(method, *args, &block)
|
55
|
+
else
|
56
|
+
@item.send method, *args, &block
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def klass
|
61
|
+
@options[:klass]
|
62
|
+
end
|
63
|
+
|
64
|
+
def progress_bar(item)
|
65
|
+
@item = item
|
66
|
+
value = if @options[:value]
|
67
|
+
build_option(item, @options[:value]).to_s
|
68
|
+
else
|
69
|
+
item.public_send(@attribute)
|
70
|
+
end
|
71
|
+
|
72
|
+
max = build_option(item, @options[:max]).to_s
|
73
|
+
label = if @block
|
74
|
+
instance_eval(&@block)
|
75
|
+
else
|
76
|
+
item.public_send(@attribute)
|
77
|
+
end.to_s
|
78
|
+
|
79
|
+
items = []
|
80
|
+
items << view_context.content_tag(:progress, "", class: "progress-primary bg-base-100 h-8 grow", value: value, max: max)
|
81
|
+
items << view_context.content_tag(:span, class: "grow text-elipsis overflow-hidden absolute left-4 bottom-3 h-8 text-primary-content") do
|
82
|
+
label
|
83
|
+
end
|
84
|
+
|
85
|
+
items.join.html_safe
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_option(item, value)
|
89
|
+
if value.is_a?(Symbol)
|
90
|
+
item.public_send(value)
|
91
|
+
else
|
92
|
+
value
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def column(value = nil, &block)
|
97
|
+
view_context.content_tag(:span, class: "w-8 ml-8 text-right") do
|
98
|
+
if value
|
99
|
+
if @options[:formatter]
|
100
|
+
if respond_to?(@options[:formatter])
|
101
|
+
public_send(@options[:formatter], value)
|
102
|
+
else
|
103
|
+
view_context.public_send(@options[:formatter], value)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
value.to_s
|
107
|
+
end
|
108
|
+
else
|
109
|
+
view_context.capture(&block).to_s
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def number_to_human(amount)
|
115
|
+
tooltip(amount) do
|
116
|
+
view_context.number_to_human(amount, format: '%n%u', precision: 2, units: { thousand: 'k', million: 'm', billion: 'b' })
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def percent_total(item)
|
121
|
+
'%.1f' % ((item.unit_amount.to_i * 1.0 / total)*100.0)
|
122
|
+
end
|
123
|
+
|
124
|
+
def tooltip(value)
|
125
|
+
AhoyCaptain::TooltipComponent.new(amount: value).render_in(view_context)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def initialize(klass)
|
130
|
+
@klass = klass
|
131
|
+
@rows = []
|
132
|
+
end
|
133
|
+
|
134
|
+
def column(key = nil, options = {}, &block)
|
135
|
+
options[:klass] = @klass
|
136
|
+
@rows << Row.new(key, options, &block)
|
137
|
+
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def progress_bar(*args, &block)
|
142
|
+
options = args.extract_options!
|
143
|
+
options.assert_valid_keys(:value, :max, :title)
|
144
|
+
options[:klass] = @klass
|
145
|
+
|
146
|
+
@rows << Row.new(args[0], options.merge(type: :progress_bar), &block)
|
147
|
+
|
148
|
+
self
|
149
|
+
end
|
150
|
+
|
151
|
+
def number(key = nil, options = {}, &block)
|
152
|
+
options[:klass] = @klass
|
153
|
+
|
154
|
+
@rows << Row.new(key, options.merge(formatter: :number_to_human), &block)
|
155
|
+
|
156
|
+
self
|
157
|
+
end
|
158
|
+
|
159
|
+
def percent(key = nil, options = {}, &block)
|
160
|
+
options[:klass] = @klass
|
161
|
+
|
162
|
+
@rows << Row.new(key, options.merge(formatter: :number_to_percentage), &block)
|
163
|
+
|
164
|
+
self
|
165
|
+
end
|
166
|
+
|
167
|
+
def row(item, view_context)
|
168
|
+
items = []
|
169
|
+
@rows.each do |row|
|
170
|
+
items << row.render(item, view_context)
|
171
|
+
end
|
172
|
+
items.join.html_safe
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.build(klass, options = {}, &block)
|
177
|
+
if options.key?(:fixed_height)
|
178
|
+
options[:header_options] = { fixed_height: options.delete(:fixed_height) }
|
179
|
+
end
|
180
|
+
table = TableDefinition.new(klass).instance_exec(&block)
|
181
|
+
new(klass, table, options)
|
182
|
+
end
|
183
|
+
|
184
|
+
def initialize(klass, table, options = {})
|
185
|
+
@klass = klass
|
186
|
+
@table = table
|
187
|
+
@options = options
|
188
|
+
end
|
189
|
+
|
190
|
+
def for(item)
|
191
|
+
@item = item
|
192
|
+
self
|
193
|
+
end
|
194
|
+
|
195
|
+
def row(item, view_context)
|
196
|
+
@table.row(item, view_context)
|
197
|
+
end
|
198
|
+
|
199
|
+
def headers
|
200
|
+
HeaderComponent.new(@table.rows.map.with_index { |row, index| { label: row.header, grow: index.zero? } }, @options[:header_options] || {})
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Tables
|
3
|
+
class GoalsTableComponent < DynamicTable
|
4
|
+
register fixed_height: false do
|
5
|
+
progress_bar value: :cr, max: 100, title: "Name" do |row|
|
6
|
+
search_params = view_context.search_params
|
7
|
+
query = search_params.dup.merge(q: { goal_in: row.goal_id}).to_query
|
8
|
+
url = AhoyCaptain::Engine.app.url_helpers.root_path + "?#{query}"
|
9
|
+
link_to row.item.name, url, target: :_top
|
10
|
+
end
|
11
|
+
number :unique_visits, title: "Uniques"
|
12
|
+
number :total_events, title: "Total"
|
13
|
+
percent :cr, title: "CR"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Tables
|
3
|
+
class HeaderComponent < ViewComponent::Base
|
4
|
+
def initialize(headers, options = {})
|
5
|
+
@headers = headers.flatten
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def fixed_height?
|
10
|
+
if @options.key?(:fixed_height)
|
11
|
+
@options[:fixed_height]
|
12
|
+
else
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Tables
|
3
|
+
module Headers
|
4
|
+
class HeaderComponent < ViewComponent::Base
|
5
|
+
def initialize(category_name:, unit_name:)
|
6
|
+
@category_name = category_name
|
7
|
+
@unit_name = unit_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def fixed_height?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AhoyCaptain
|
2
|
+
module Tables
|
3
|
+
class PropertiesTableComponent < DynamicTable
|
4
|
+
register do
|
5
|
+
progress_bar :label, value: :percentage, max: 100, title: "Name" do |item|
|
6
|
+
link_to item.label, url(item), target: :_top
|
7
|
+
end
|
8
|
+
number :unique_visitors_count, title: "Visitors"
|
9
|
+
number :events_count, title: "Events"
|
10
|
+
percent :percentage, title: "%"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.url(item)
|
14
|
+
name = Base64.decode64(item.request.params[:id])
|
15
|
+
params = item.search_params.dup
|
16
|
+
if params["q"] && params["q"].key?("properties_json_cont")
|
17
|
+
json = JSON.parse(params["q"]["properties_json_cont"])
|
18
|
+
json[name] = item.item.label
|
19
|
+
params["q"]["properties_json_cont"] = json.to_json
|
20
|
+
else
|
21
|
+
params[:q] = { "properties_json_cont" => { name => item.item.label }.to_json }
|
22
|
+
end
|
23
|
+
params
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|