ahoy_captain 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -13
  3. data/app/assets/javascript/ahoy_captain/application.js +4 -4
  4. data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +14 -0
  5. data/app/assets/javascript/ahoy_captain/controllers/application.js +5 -5
  6. data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +9 -10
  7. data/app/assets/javascript/ahoy_captain/controllers/details_modal_controller.js +5 -5
  8. data/app/assets/javascript/ahoy_captain/controllers/dropdown_label_controller.js +2 -2
  9. data/app/assets/javascript/ahoy_captain/controllers/filter/item_controller.js +12 -0
  10. data/app/assets/javascript/ahoy_captain/controllers/filter_form_controller.js +13 -0
  11. data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +11 -8
  12. data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +77 -107
  13. data/app/assets/javascript/ahoy_captain/controllers/index.js +4 -3
  14. data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +3 -3
  15. data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +37 -0
  16. data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +10 -0
  17. data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +9 -8
  18. data/app/assets/javascript/ahoy_captain/controllers/search_select_controller.js +65 -0
  19. data/app/assets/javascript/ahoy_captain/controllers/toggle_controller.js +17 -0
  20. data/app/components/ahoy_captain/dropdown_button_component.html.erb +5 -5
  21. data/app/components/ahoy_captain/dropdown_link_component.html.erb +5 -5
  22. data/app/components/ahoy_captain/filter/dropdown_component.html.erb +48 -0
  23. data/app/components/ahoy_captain/filter/dropdown_component.rb +51 -0
  24. data/app/components/ahoy_captain/filter/modal_component.html.erb +8 -7
  25. data/app/components/ahoy_captain/filter/select_component.html.erb +14 -12
  26. data/app/components/ahoy_captain/filter/select_component.rb +40 -9
  27. data/app/components/ahoy_captain/filter/tag_component.html.erb +8 -4
  28. data/app/components/ahoy_captain/filter/tag_component.rb +6 -30
  29. data/app/components/ahoy_captain/filter/tag_container_component.html.erb +2 -3
  30. data/app/components/ahoy_captain/filter/tag_container_component.rb +1 -8
  31. data/app/components/ahoy_captain/stats/container_component.html.erb +8 -0
  32. data/app/components/ahoy_captain/stats/container_component.rb +11 -0
  33. data/app/components/ahoy_captain/sticky_nav_component.html.erb +7 -19
  34. data/app/components/ahoy_captain/sticky_nav_component.rb +8 -0
  35. data/app/components/ahoy_captain/table_component.html.erb +4 -37
  36. data/app/components/ahoy_captain/table_component.rb +15 -4
  37. data/app/components/ahoy_captain/tables/headers/devices_header_component.html.erb +3 -0
  38. data/app/components/ahoy_captain/tables/headers/devices_header_component.rb +9 -0
  39. data/app/components/ahoy_captain/tables/headers/goals_header_component.html.erb +6 -0
  40. data/app/components/ahoy_captain/tables/headers/goals_header_component.rb +9 -0
  41. data/app/components/ahoy_captain/tables/headers/header_component.html.erb +5 -0
  42. data/app/components/ahoy_captain/tables/headers/header_component.rb +12 -0
  43. data/app/components/ahoy_captain/tables/rows/devices_row_component.html.erb +5 -0
  44. data/app/components/ahoy_captain/tables/rows/devices_row_component.rb +12 -0
  45. data/app/components/ahoy_captain/tables/rows/goals_row_component.html.erb +11 -0
  46. data/app/components/ahoy_captain/tables/rows/goals_row_component.rb +20 -0
  47. data/app/components/ahoy_captain/tables/rows/row_component.html.erb +6 -0
  48. data/app/components/ahoy_captain/tables/rows/row_component.rb +41 -0
  49. data/app/components/ahoy_captain/tile_component.html.erb +4 -3
  50. data/app/components/ahoy_captain/tile_component.rb +1 -1
  51. data/app/components/ahoy_captain/tooltip_component.html.erb +2 -2
  52. data/app/controllers/ahoy_captain/application_controller.rb +13 -14
  53. data/app/controllers/ahoy_captain/campaigns_controller.rb +2 -10
  54. data/app/controllers/ahoy_captain/cities_controller.rb +2 -6
  55. data/app/controllers/ahoy_captain/countries_controller.rb +2 -6
  56. data/app/controllers/ahoy_captain/devices_controller.rb +3 -6
  57. data/app/controllers/ahoy_captain/entry_pages_controller.rb +2 -4
  58. data/app/controllers/ahoy_captain/exit_pages_controller.rb +3 -4
  59. data/app/controllers/ahoy_captain/exports_controller.rb +15 -0
  60. data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +2 -2
  61. data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +1 -2
  62. data/app/controllers/ahoy_captain/filters/properties/names_controller.rb +11 -0
  63. data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +15 -0
  64. data/app/controllers/ahoy_captain/filters/sources_controller.rb +1 -1
  65. data/app/controllers/ahoy_captain/regions_controller.rb +3 -7
  66. data/app/controllers/ahoy_captain/sources_controller.rb +2 -5
  67. data/app/controllers/ahoy_captain/stats/base_controller.rb +3 -3
  68. data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +1 -0
  69. data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -0
  70. data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -0
  71. data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +1 -0
  72. data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +3 -2
  73. data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -0
  74. data/app/controllers/ahoy_captain/top_pages_controller.rb +2 -8
  75. data/app/decorators/ahoy_captain/application_decorator.rb +27 -3
  76. data/app/decorators/ahoy_captain/campaign_decorator.rb +8 -0
  77. data/app/decorators/ahoy_captain/city_decorator.rb +12 -0
  78. data/app/decorators/ahoy_captain/country_decorator.rb +10 -0
  79. data/app/decorators/ahoy_captain/device_decorator.rb +13 -2
  80. data/app/decorators/ahoy_captain/page_decorator.rb +11 -0
  81. data/app/decorators/ahoy_captain/region_decorator.rb +16 -0
  82. data/app/decorators/ahoy_captain/source_decorator.rb +7 -0
  83. data/app/helpers/ahoy_captain/application_helper.rb +33 -0
  84. data/app/models/ahoy_captain/export.rb +48 -0
  85. data/app/models/ahoy_captain/filter_parser.rb +67 -0
  86. data/app/presenters/ahoy_captain/dashboard_presenter.rb +6 -1
  87. data/app/presenters/ahoy_captain/goals_presenter.rb +3 -2
  88. data/app/queries/ahoy_captain/application_query.rb +4 -3
  89. data/app/queries/ahoy_captain/campaign_query.rb +14 -0
  90. data/app/queries/ahoy_captain/city_query.rb +11 -0
  91. data/app/queries/ahoy_captain/country_query.rb +10 -0
  92. data/app/queries/ahoy_captain/device_query.rb +10 -0
  93. data/app/queries/ahoy_captain/entry_pages_query.rb +3 -2
  94. data/app/queries/ahoy_captain/event_query.rb +17 -15
  95. data/app/queries/ahoy_captain/exit_pages_query.rb +6 -4
  96. data/app/queries/ahoy_captain/region_query.rb +11 -0
  97. data/app/queries/ahoy_captain/source_query.rb +10 -0
  98. data/app/queries/ahoy_captain/top_page_query.rb +13 -0
  99. data/app/queries/ahoy_captain/visit_query.rb +1 -1
  100. data/app/views/ahoy_captain/devices/_table.html.erb +5 -0
  101. data/app/views/ahoy_captain/devices/index.html+details.erb +1 -1
  102. data/app/views/ahoy_captain/devices/index.html.erb +2 -2
  103. data/app/views/ahoy_captain/funnels/show.html.erb +5 -2
  104. data/app/views/ahoy_captain/goals/index.html.erb +3 -35
  105. data/app/views/ahoy_captain/layouts/application.html.erb +3 -3
  106. data/app/views/ahoy_captain/realtimes/show.html.erb +1 -1
  107. data/app/views/ahoy_captain/roots/_filters.html.erb +34 -0
  108. data/app/views/ahoy_captain/roots/show.html.erb +33 -95
  109. data/app/views/ahoy_captain/stats/base/index.html.erb +4 -7
  110. data/app/views/ahoy_captain/stats/show.html.erb +6 -51
  111. data/config/routes.rb +7 -0
  112. data/lib/ahoy_captain/ahoy/event_methods.rb +36 -73
  113. data/lib/ahoy_captain/ahoy/visit_methods.rb +1 -1
  114. data/lib/ahoy_captain/configuration.rb +13 -3
  115. data/lib/ahoy_captain/engine.rb +18 -0
  116. data/lib/ahoy_captain/filter_configuration/filter.rb +16 -0
  117. data/lib/ahoy_captain/filter_configuration/filter_collection.rb +48 -0
  118. data/lib/ahoy_captain/filters_configuration.rb +73 -0
  119. data/lib/ahoy_captain/goals.rb +10 -2
  120. data/lib/ahoy_captain/period_collection.rb +1 -1
  121. data/lib/ahoy_captain/predicate_label.rb +7 -0
  122. data/lib/ahoy_captain/version.rb +1 -1
  123. data/lib/ahoy_captain.rb +1 -0
  124. data/lib/generators/ahoy_captain/templates/config.rb.tt +25 -0
  125. metadata +56 -20
  126. data/app/assets/javascript/ahoy_captain/controllers/filter_controller.js +0 -145
  127. data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +0 -43
  128. data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +0 -25
  129. data/app/models/ahoy_captain/current.rb +0 -9
  130. data/app/models/ahoy_captain/url_helpers.rb +0 -6
@@ -1,7 +1,7 @@
1
- <div class="dropdown dropdown-end" data-controller='dropdown-label'>
2
- <label
3
- tabindex="0"
4
- class="cursor-pointer flex <%= classes %>"
1
+ <div class="dropdown dropdown-end " data-controller='dropdown-label'>
2
+ <label
3
+ tabindex="0"
4
+ class="cursor-pointer flex <%= classes %>"
5
5
  data-action='click->dropdown-label#removeHidden'
6
6
  >
7
7
  <span data-dropdown-label-target="label"><%= title %></span>
@@ -16,4 +16,4 @@
16
16
  <li>
17
17
  <% end %>
18
18
  </ul>
19
- </div>
19
+ </div>
@@ -0,0 +1,48 @@
1
+ <div class="dropdown dropdown-end">
2
+ <label
3
+ tabindex="0"
4
+ class="btn btn-ghost dark:hover:bg-neutral flex"
5
+ >
6
+ <%= header_icon %>
7
+ <span><%= title %></span>
8
+ </label>
9
+
10
+ <ul class="w-72 dropdown-content z-[1] p-2 shadow bg-base-100 rounded-box" data-controller='toggle' data-toggle-enable-value="<%= advanced_filter_menu? %>">
11
+ <% if advanced_filter_menu? %>
12
+ <div id="advanced-filters" class="w-full text-sm leading-tight" >
13
+ <button class='w-full cursor-pointer block pl-4 pt-1 text-left hover:text-primary' data-action="click->toggle#trigger">+ Add filter</button>
14
+ <div class="divider my-1"></div>
15
+ <% filters.each do |_, filter| %>
16
+ <li class='flex flex-inline px-4 items-center' data-toggle-target='toggleable'>
17
+ <button title="Edit filter: <%= filter.title %>"
18
+ class="flex w-full justify-between link no-underline items-center group <% if filter.modal %>cursor-pointer<% else %>cursor-text<% end %> text-left"
19
+ onclick="<% if filter.modal %><%= filter.modal %>.showModal() <% end %>">
20
+ <span class="truncate w-48 ">
21
+ <%= filter.description %>
22
+ </span>
23
+ <% if filter.modal %>
24
+ <span class="group-hover:text-primary hover:text-primary ">
25
+ <%= edit_icon %>
26
+ </span>
27
+ <% end %>
28
+ </button>
29
+ <a title="Remove filter: <%= filter.title %>"
30
+ class="hover:text-primary link no-underline pl-2" href="<%= filter.url %>">
31
+ <%= remove_icon %>
32
+ </a>
33
+ <li>
34
+ <div class="divider my-1" data-toggle-target='toggleable'></div>
35
+ <% end %>
36
+ <li data-toggle-target='toggleable'>
37
+ <a class="block mx-auto pl-4 pb-1 " href="<%= AhoyCaptain::Engine.app.url_helpers.root_path %>">Clear all filters</a>
38
+ </li>
39
+ </div>
40
+ <% end %>
41
+
42
+ <div id="core-filters" class="menu <%= 'hidden' if advanced_filter_menu? %> pt-0" data-toggle-target='toggleable'>
43
+ <% AhoyCaptain.config.filters.each do |label, filter_group| %>
44
+ <li><button onClick="<%= filter_group.modal_name %>.showModal()" class='link no-underline' data-action="click->toggle#trigger"><%= label %></button></li>
45
+ <% end %>
46
+ </div>
47
+ </ul>
48
+ </div>
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AhoyCaptain::Filter::DropdownComponent < ViewComponent::Base
4
+ def initialize(filters:)
5
+ @filters = filters
6
+ end
7
+
8
+ private
9
+
10
+ attr_reader :filters
11
+
12
+ def header_icon
13
+ advanced_filter_menu? ? filters_icon : magnifier_icon
14
+ end
15
+
16
+ def title
17
+ advanced_filter_menu? ? "#{filters.size} Filters" : 'Filter'
18
+ end
19
+
20
+ def advanced_filter_menu?
21
+ filter_categories.count >= ::AhoyCaptain::FilterParser::FILTER_MENU_MAX_SIZE
22
+ end
23
+
24
+ def filter_categories
25
+ filters.values.map(&:values).flatten
26
+ end
27
+
28
+ def magnifier_icon
29
+ %Q(
30
+ <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"><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></svg>
31
+ ).html_safe
32
+ end
33
+
34
+ def filters_icon
35
+ %Q(
36
+ <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"><path d="M17 2.75a.75.75 0 00-1.5 0v5.5a.75.75 0 001.5 0v-5.5zM17 15.75a.75.75 0 00-1.5 0v1.5a.75.75 0 001.5 0v-1.5zM3.75 15a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5a.75.75 0 01.75-.75zM4.5 2.75a.75.75 0 00-1.5 0v5.5a.75.75 0 001.5 0v-5.5zM10 11a.75.75 0 01.75.75v5.5a.75.75 0 01-1.5 0v-5.5A.75.75 0 0110 11zM10.75 2.75a.75.75 0 00-1.5 0v1.5a.75.75 0 001.5 0v-1.5zM10 6a2 2 0 100 4 2 2 0 000-4zM3.75 10a2 2 0 100 4 2 2 0 000-4zM16.25 10a2 2 0 100 4 2 2 0 000-4z"></path></svg>
37
+ ).html_safe
38
+ end
39
+
40
+ def edit_icon
41
+ %Q(
42
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="w-4 h-4 ml-1 cursor-pointer"><path d="M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z"></path><path d="M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z"></path></svg>
43
+ ).html_safe
44
+ end
45
+
46
+ def remove_icon
47
+ %Q(
48
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="w-4 h-4"><path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"></path></svg>
49
+ ).html_safe
50
+ end
51
+ end
@@ -1,13 +1,14 @@
1
1
  <dialog id="<%= id %>" class="modal">
2
- <form method="dialog" class="modal-box w-11/12 max-w-5xl" data-controller='filter' data-action="submit->filter#applyFilters reset->filter#resetFilters">
2
+ <div class="modal-box w-11/12 max-w-5xl">
3
3
  <fieldset>
4
4
  <h5><%= title %></h5>
5
5
  <%= modal_display %>
6
- <button class="btn btn-primary mt-4" type="submit">Apply</button>
7
- <button class="btn btn-primary mt-4" type="reset">Reset</button>
6
+ <button class="btn btn-active btn-primary mt-4" type="submit">Apply</button>
7
+ <button class="btn btn-active btn-primary mt-4" type="reset">Reset</button>
8
8
  </fieldset>
9
- </form>
10
- <form method="dialog" class="modal-backdrop">
11
- <button>close</button>
12
- </form>
9
+ </div>
10
+ <label class="modal-backdrop">
11
+ <button onclick="event.preventDefault(); <%=id %>.close();">Close</button>
12
+ </label>
13
13
  </dialog>
14
+
@@ -1,21 +1,23 @@
1
- <fieldset class="flex space-x-4 items-end">
1
+ <fieldset class="flex space-x-4 items-end" data-controller="predicate-select">
2
2
  <div class="flex flex-col w-[20%]">
3
3
  <label class="label"><%= label %></label>
4
- <select class='select select-bordered' data-filter-target='predicate' name="<%= column %>">
5
- <% predicates.each do |predicate| %>
6
- <option value="<%= column %>_<%= predicate %>" <%= 'selected' if selected_predicate == "#{column}_#{predicate}" %>>
7
- <%= predicate.to_s.humanize %>
4
+ <select class='select select-bordered' data-action='change->predicate-select#handleChange'>
5
+ <% @predicates.each do |predicate| %>
6
+ <option value="<%= option_value(predicate) %>" <%= 'selected' if selected_predicate?(predicate) %>>
7
+ <%= predicate_label(predicate) %>
8
8
  </option>
9
9
  <% end %>
10
10
  </select>
11
11
  </div>
12
+
12
13
  <select
14
+ data-predicate-select-target="select"
15
+ data-controller="search-select"
13
16
  class='w-[50%] border-base-content border-opacity-20 rounded-lg min-h-[3rem]'
14
- name="<%= column %>"
15
- multiple
16
- data-filter-target="select"
17
- data-filter-column-value="<%= column %>"
18
- data-filter-url-value="<%= url %>"
19
- data-filter-selected="<%= values %>"
20
- ></select>
17
+ name="<%= column_name_with_predicate %>"
18
+ <% if multiple %>multiple<% end %>
19
+ data-search-select-query-value="q[<%= column %>_i_cont]"
20
+ data-search-select-url-value="<%= url %>"
21
+ data-search-select-selected-value="<%= values %>"
22
+ ></select>
21
23
  </fieldset>
@@ -1,20 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AhoyCaptain::Filter::SelectComponent < ViewComponent::Base
4
- def initialize(label:, column:, url:, predicates:)
4
+ def initialize(label:, column:, url:, predicates:, form:, multiple: true)
5
5
  @label = label
6
6
  @column = column
7
7
  @url = url
8
8
  @predicates = predicates
9
+ @form = form
10
+ @multiple = multiple
11
+ end
12
+
13
+ private
14
+
15
+ def selected_predicate?(predicate)
16
+ params.dig(:q, predicate_name(predicate)).present?
17
+ end
18
+
19
+ def option_value(predicate)
20
+ name = "q[#{predicate_name(predicate)}]"
21
+ name += "[]" if multiple
22
+ name
23
+ end
24
+
25
+ def predicate_name(predicate)
26
+ "#{@column}_#{predicate}"
9
27
  end
10
28
 
11
29
  def selected_predicate
12
- predicate_options.detect { |option| params.dig(:q, option) }
30
+ @predicates.each do |predicate|
31
+ if params.dig(:q, predicate_name(predicate))
32
+ return predicate
33
+ end
34
+ end
35
+
36
+ nil
37
+ end
38
+
39
+ def column_name_with_predicate
40
+ if selected_predicate
41
+ option_value(selected_predicate)
42
+ else
43
+ option_value(@predicates.first)
44
+ end
13
45
  end
14
46
 
15
47
  def values
16
- predicate_options.each do |predicate|
17
- option = params.dig(:q, predicate)
48
+ @predicates.each do |predicate|
49
+ option = params.dig(:q, predicate_name(predicate))
18
50
  if option
19
51
  return option
20
52
  end
@@ -23,10 +55,9 @@ class AhoyCaptain::Filter::SelectComponent < ViewComponent::Base
23
55
  []
24
56
  end
25
57
 
26
- private
27
-
28
- def predicate_options
29
- @predicate_options ||= @predicates.map { |predicate| "#{@column}_#{predicate}" }
58
+ def predicate_label(predicate)
59
+ AhoyCaptain::PredicateLabel[predicate]
30
60
  end
31
- attr_reader :label, :column, :url, :predicates
61
+
62
+ attr_reader :label, :column, :url, :predicates, :form, :multiple
32
63
  end
@@ -1,7 +1,11 @@
1
- <div class="bg-base-100 py-2 px-4 mx-2 flex items-center" data-controller='filter-tag' data-filter-tag-category-value="<%= category %>" data-filter-tag-column-predicate-value="<%= column_predicate %>">
2
- <%= column_with_predicate %>
3
- <span class="font-bold mx-2"> <%= category %></span>
4
- <a class="hover:text-primary" href="<%= url %>">
1
+ <div class="bg-base-200 py-2 px-4 mx-2 flex items-center text-base-content" data-controller="filter--item" data-filter--item-modal-value="<%= tag_item.modal %>">
2
+ <span data-action='click->filter--item#openModal'>
3
+ <%= tag_item.column.titleize %> <%= tag_item.predicate %>
4
+ <span class="font-bold">
5
+ <%= tag_item.label %>
6
+ </span>
7
+ </span>
8
+ <a class="hover:text-primary" href="<%= tag_item.url %>">
5
9
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" class="w-4 h-4">
6
10
  <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"></path>
7
11
  </svg>
@@ -1,38 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AhoyCaptain::Filter::TagComponent < ViewComponent::Base
4
- PREDICATES = {
5
- eq: 'equals',
6
- not_eq: 'not equals',
7
- cont: 'contains',
8
- in: 'in',
9
- not_in: 'not in',
10
- }
11
- def initialize(column_predicate:, category:)
12
- @column_predicate = column_predicate
13
- @category = category
4
+ def initialize(tag_item:)
5
+ @tag_item = tag_item
14
6
  end
15
7
 
16
- def url
17
- search_params = helpers.search_params.deep_dup
18
- if search_params["q"][@column_predicate].is_a?(Array)
19
- search_params["q"][@column_predicate] = search_params["q"][@column_predicate] - [@category]
20
- else
21
- search_params["q"].delete(@column_predicate)
22
- end
8
+ private
9
+ attr_reader :tag_item
23
10
 
24
- request.path + "?" + search_params.to_query
25
- end
26
-
27
- private
28
- attr_reader :column_predicate, :category
29
-
30
- def column_with_predicate
31
- PREDICATES.keys.map(&:to_s).each do |predicate|
32
- if column_predicate.include?(predicate)
33
- before, match, after = column_predicate.partition(predicate)
34
- return [before.gsub('_',' '), PREDICATES[match.to_sym]].join(' ').humanize
35
- end
36
- end
11
+ def modal
12
+ tag_item.modal
37
13
  end
38
14
  end
@@ -1,5 +1,4 @@
1
- <% filters.each do |param| %>
2
- <% column_predicate, category = param %>
3
- <%= render AhoyCaptain::Filter::TagComponent.new(column_predicate: column_predicate, category: category) %>
1
+ <% ::AhoyCaptain::FilterParser.parse(request).each do |_, filter| %>
2
+ <%= render AhoyCaptain::Filter::TagComponent.new(tag_item: filter) %>
4
3
  <% end %>
5
4
 
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AhoyCaptain::Filter::TagContainerComponent < ViewComponent::Base
4
- def initialize(filters:)
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,8 @@
1
+ <a href="<%= @url %>" class="hover:text-primary text-base-content" data-turbo-frame="chart">
2
+ <dt class="font-normal"><%= @label %></dt>
3
+ <dd class="mt-1 flex items-baseline justify-between md:block lg:flex">
4
+ <div class="flex items-baseline text-2xl font-semibold">
5
+ <%= @value %>
6
+ </div>
7
+ </dd>
8
+ </a>
@@ -0,0 +1,11 @@
1
+ module AhoyCaptain
2
+ module Stats
3
+ class ContainerComponent < ViewComponent::Base
4
+ def initialize(url, label, value)
5
+ @url = url
6
+ @label = label
7
+ @value = value
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,37 +1,25 @@
1
- <div class="max-w-6xl flex justify-between sticky top-0 min-h-sm z-[99999] bg-base-300 py-4">
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
4
  <img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='w-16 h-16 rounded-full'>
5
5
  </a>
6
- <% if params[:q] %>
7
- <%= render AhoyCaptain::Filter::TagContainerComponent.new(filters: params.require(:q)) %>
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
12
  <div class="flex flex-row-reverse col-span-2 items-center">
13
- <%= render AhoyCaptain::DropdownLinkComponent.new(title: params[:start_date] ? "Custom Range" : (AhoyCaptain.config.ranges.find(params[:period]).try(:label) || "Period"), classes: 'btn btn-base-100 no-underline text-base-content hover:text-base-content hover:bg-base-100') do |dropdown| %>
13
+ <%= render AhoyCaptain::DropdownLinkComponent.new(title: params[:start_date] ? "Custom Range" : (AhoyCaptain.config.ranges.find(params[:period]).try(:label) || "Period"), classes: 'btn btn-base-100 no-underline hover:bg-base-100') do |dropdown| %>
14
14
  <% dropdown.with_option do %>
15
15
  <% AhoyCaptain.config.ranges.each do |param, range| %>
16
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>
17
17
  <% end %>
18
18
 
19
- <a class='link no-underline' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
20
- <% end %>
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>
19
+ <a class='link no-underline ' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
34
20
  <% end %>
35
21
  <% end %>
22
+
23
+ <%= render AhoyCaptain::Filter::DropdownComponent.new(filters: filters) %>
36
24
  </div>
37
25
  </div>
@@ -2,4 +2,12 @@
2
2
 
3
3
  class AhoyCaptain::StickyNavComponent < ViewComponent::Base
4
4
  renders_one :realtime_update
5
+
6
+ def filters
7
+ @filters ||= ::AhoyCaptain::FilterParser.parse(request)
8
+ end
9
+
10
+ def tag_list_hidden?
11
+ filters.values.map(&:values).flatten.size < ::AhoyCaptain::FilterParser::FILTER_MENU_MAX_SIZE
12
+ end
5
13
  end
@@ -1,44 +1,11 @@
1
- <div class="flex flex-col min-h-[380px] w-full pt-4">
2
- <div class="flex text-sm font-bold text-base-content mb-4">
3
- <span class="grow"><%= category_name %></span>
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
- <progress class='progress-primary bg-base-100 h-8 grow' value="<%= item.unit_amount %>" max="<%= max_amount %>">
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,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AhoyCaptain::TableComponent < ViewComponent::Base
4
- SUPPORTED_COLS = [:percent_total, :total, :conversion_rate]
4
+ DEFAULT_HEADER = AhoyCaptain::Tables::Headers::HeaderComponent
5
+ DEFAULT_ROW = AhoyCaptain::Tables::Rows::RowComponent
5
6
 
6
- def initialize(items:, category_name:, unit_name:, additional_cols: [])
7
+ def initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW)
7
8
  @items = items
8
9
  @category_name = category_name
9
10
  @unit_name = unit_name
10
11
  @additional_cols = additional_cols
12
+ if header.nil?
13
+ @header = DEFAULT_HEADER.new(category_name: category_name, unit_name: unit_name)
14
+ else
15
+ @header = header.new
16
+ end
17
+ @row = row
18
+ end
19
+
20
+ def render_row(item)
21
+ @row.new(table: self, item: item).render_in(view_context)
11
22
  end
12
23
 
13
24
  private
@@ -22,7 +33,7 @@ class AhoyCaptain::TableComponent < ViewComponent::Base
22
33
  @total ||= items.first.total_count
23
34
  end
24
35
 
25
- def percent_total(item)
26
- '%.1f' % ((item.unit_amount.to_i * 1.0 / total)*100.0)
36
+ def fixed_height?
37
+ !@header.is_a?(::AhoyCaptain::Tables::Headers::GoalsHeaderComponent)
27
38
  end
28
39
  end
@@ -0,0 +1,3 @@
1
+ <%= render ::AhoyCaptain::Tables::Headers::HeaderComponent.new(category_name: "Device", unit_name: "Visitors") do %>
2
+ <span class="w-8 ml-8 text-right">%</span>
3
+ <% end %>
@@ -0,0 +1,9 @@
1
+ module AhoyCaptain
2
+ module Tables
3
+ module Headers
4
+ class DevicesHeaderComponent < ViewComponent::Base
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ <div class="flex text-sm font-bold mb-4">
2
+ <span class="grow">Goal</span>
3
+ <span class="w-8 ml-8 text-right">Uniques</span>
4
+ <span class="w-8 ml-8 text-right">Total</span>
5
+ <span class="w-8 ml-8 text-right">CR</span>
6
+ </div>
@@ -0,0 +1,9 @@
1
+ module AhoyCaptain
2
+ module Tables
3
+ module Headers
4
+ class GoalsHeaderComponent < ViewComponent::Base
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ <div class=" flex text-sm font-bold mb-4">
2
+ <span class="grow"><%= @category_name %></span>
3
+ <span ><%= @unit_name %></span>
4
+ <%= content %>
5
+ </div>
@@ -0,0 +1,12 @@
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
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ <%= progress_bar(@item.count, @item.total_count, @item.display_name) %>
2
+ <%= item do %>
3
+ <%= tooltip(@item.count) %>
4
+ <% end %>
5
+ <%= item(percent_total(@item)) %>
@@ -0,0 +1,12 @@
1
+ module AhoyCaptain
2
+ module Tables
3
+ module Rows
4
+ class DevicesRowComponent < RowComponent
5
+
6
+ def total
7
+ @item.total_count
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ <%= progress_bar(@item.cr, 100, link_to(@item.name, url, target: :_top)) %>
2
+ <%= item do %>
3
+ <%= tooltip(@item.unique_visits) %>
4
+ <% end %>
5
+ <%= item do %>
6
+ <%= tooltip(@item.total_events) %>
7
+ <% end %>
8
+ <%= item do %>
9
+ <%= tooltip(@item.cr) %>
10
+ <% end %>
11
+
@@ -0,0 +1,20 @@
1
+ module AhoyCaptain
2
+ module Tables
3
+ module Rows
4
+ class GoalsRowComponent < RowComponent
5
+ def search_params
6
+ view_context.search_params
7
+ end
8
+
9
+ def url
10
+ query = search_params.dup.merge(q: { goal_in: @item.goal_id}).to_query
11
+ AhoyCaptain::Engine.app.url_helpers.root_path + "?#{query}"
12
+ end
13
+
14
+ def total
15
+ @item.total_count
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ <%= progress_bar(@item.count, @item.total_count, @item.display_name) %>
2
+ <%=
3
+ item do
4
+ tooltip(@item.count)
5
+ end
6
+ %>