ahoy_captain 0.91 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/Rakefile +23 -2
  4. data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +20 -0
  5. data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +371 -0
  6. data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +45 -0
  7. data/app/assets/javascript/ahoy_captain/controllers/frame_link_controller.js +20 -0
  8. data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +58 -16
  9. data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +5 -0
  10. data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +235 -21
  11. data/app/assets/javascript/ahoy_captain/controllers/map_controller.js +47 -0
  12. data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +1 -1
  13. data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +8 -0
  14. data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +45 -0
  15. data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +4 -2
  16. data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +33 -0
  17. data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +156 -0
  18. data/app/assets/javascript/ahoy_captain/helpers/countries.js +2261 -0
  19. data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +55 -0
  20. data/app/components/ahoy_captain/combobox_component.html.erb +33 -0
  21. data/app/components/ahoy_captain/combobox_component.rb +13 -0
  22. data/app/components/ahoy_captain/comparison_link_component.html.erb +17 -0
  23. data/app/components/ahoy_captain/comparison_link_component.rb +44 -0
  24. data/app/components/ahoy_captain/dropdown_link_component.html.erb +2 -4
  25. data/app/components/ahoy_captain/dropdown_link_component.rb +4 -0
  26. data/app/components/ahoy_captain/filter/dropdown_component.html.erb +8 -6
  27. data/app/components/ahoy_captain/filter/modal_component.html.erb +7 -5
  28. data/app/components/ahoy_captain/filter/select_component.html.erb +23 -21
  29. data/app/components/ahoy_captain/filter/select_component.rb +2 -1
  30. data/app/components/ahoy_captain/filter/tag_component.html.erb +1 -1
  31. data/app/components/ahoy_captain/previous_next_component.html.erb +8 -0
  32. data/app/components/ahoy_captain/previous_next_component.rb +11 -0
  33. data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +25 -0
  34. data/app/components/ahoy_captain/stats/comparable_container_component.rb +86 -0
  35. data/app/components/ahoy_captain/stats/container_component.html.erb +13 -6
  36. data/app/components/ahoy_captain/stats/container_component.rb +15 -1
  37. data/app/components/ahoy_captain/sticky_nav_component.html.erb +27 -20
  38. data/app/components/ahoy_captain/sticky_nav_component.rb +11 -0
  39. data/app/components/ahoy_captain/table_component.rb +13 -4
  40. data/app/components/ahoy_captain/tables/devices_table_component.rb +11 -0
  41. data/app/components/ahoy_captain/tables/dynamic_table.rb +13 -0
  42. data/app/components/ahoy_captain/tables/dynamic_table_component.rb +204 -0
  43. data/app/components/ahoy_captain/tables/goals_table_component.rb +17 -0
  44. data/app/components/ahoy_captain/tables/header_component.html.erb +5 -0
  45. data/app/components/ahoy_captain/tables/header_component.rb +18 -0
  46. data/app/components/ahoy_captain/tables/headers/header_component.rb +4 -0
  47. data/app/components/ahoy_captain/tables/properties_table_component.rb +27 -0
  48. data/app/components/ahoy_captain/tables/row_component.html.erb +4 -0
  49. data/app/components/ahoy_captain/tables/rows/row_component.rb +0 -1
  50. data/app/components/ahoy_captain/tile_component.html.erb +19 -9
  51. data/app/components/ahoy_captain/tile_component.rb +9 -1
  52. data/app/controllers/ahoy_captain/application_controller.rb +7 -16
  53. data/app/controllers/ahoy_captain/exports_controller.rb +1 -2
  54. data/app/controllers/ahoy_captain/filters/base_controller.rb +1 -3
  55. data/app/controllers/ahoy_captain/filters/goals_controller.rb +9 -0
  56. data/app/controllers/ahoy_captain/filters/pages/actions_controller.rb +1 -1
  57. data/app/controllers/ahoy_captain/filters/pages/entry_pages_controller.rb +1 -1
  58. data/app/controllers/ahoy_captain/filters/pages/exit_pages_controller.rb +1 -1
  59. data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +4 -4
  60. data/app/controllers/ahoy_captain/filters/utms_controller.rb +1 -1
  61. data/app/controllers/ahoy_captain/locations/cities_controller.rb +22 -0
  62. data/app/controllers/ahoy_captain/locations/countries_controller.rb +22 -0
  63. data/app/controllers/ahoy_captain/locations/maps_controller.rb +24 -0
  64. data/app/controllers/ahoy_captain/locations/regions_controller.rb +22 -0
  65. data/app/controllers/ahoy_captain/properties_controller.rb +41 -0
  66. data/app/controllers/ahoy_captain/stats/base_controller.rb +86 -5
  67. data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +1 -1
  68. data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -1
  69. data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -1
  70. data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +2 -1
  71. data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +1 -10
  72. data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -1
  73. data/app/helpers/ahoy_captain/application_helper.rb +33 -9
  74. data/app/models/ahoy_captain/comparison_mode.rb +72 -0
  75. data/app/models/ahoy_captain/filter_parser.rb +33 -18
  76. data/app/models/ahoy_captain/range_from_params.rb +78 -0
  77. data/app/models/ahoy_captain/rangeable.rb +0 -3
  78. data/app/models/concerns/ahoy_captain/compare_mode.rb +19 -0
  79. data/app/models/concerns/ahoy_captain/limitable.rb +17 -0
  80. data/app/models/concerns/ahoy_captain/range_options.rb +1 -14
  81. data/app/presenters/ahoy_captain/dashboard_presenter.rb +18 -54
  82. data/app/queries/ahoy_captain/application_query.rb +74 -10
  83. data/app/queries/ahoy_captain/event_query.rb +7 -2
  84. data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +11 -4
  85. data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +14 -2
  86. data/app/queries/ahoy_captain/stats/base_query.rb +18 -0
  87. data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +15 -1
  88. data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
  89. data/app/queries/ahoy_captain/stats/total_visitors_query.rb +1 -1
  90. data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +1 -1
  91. data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +1 -1
  92. data/app/queries/ahoy_captain/stats/visit_duration_query.rb +2 -2
  93. data/app/queries/ahoy_captain/visit_query.rb +1 -2
  94. data/app/queries/concerns/ahoy_captain/comparable_queries.rb +25 -0
  95. data/app/queries/concerns/ahoy_captain/comparable_query.rb +138 -0
  96. data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +42 -0
  97. data/app/views/ahoy_captain/devices/_table.html.erb +1 -4
  98. data/app/views/ahoy_captain/goals/index.html.erb +1 -4
  99. data/app/views/ahoy_captain/layouts/application.html.erb +0 -1
  100. data/app/views/ahoy_captain/layouts/shared/_tile_loader.html.erb +12 -0
  101. data/app/views/ahoy_captain/locations/maps/show.html.erb +3 -0
  102. data/app/views/ahoy_captain/properties/_form.html.erb +6 -0
  103. data/app/views/ahoy_captain/properties/index.html.erb +3 -0
  104. data/app/views/ahoy_captain/properties/show.html.erb +6 -0
  105. data/app/views/ahoy_captain/roots/_filters.html.erb +47 -1
  106. data/app/views/ahoy_captain/roots/show.html.erb +109 -48
  107. data/app/views/ahoy_captain/stats/base/index.html.erb +37 -8
  108. data/app/views/ahoy_captain/stats/show.html.erb +14 -11
  109. data/config/routes.rb +9 -3
  110. data/lib/ahoy_captain/ahoy/event_methods.rb +12 -14
  111. data/lib/ahoy_captain/configuration.rb +2 -1
  112. data/lib/ahoy_captain/engine.rb +4 -0
  113. data/lib/ahoy_captain/filters_configuration.rb +10 -6
  114. data/lib/ahoy_captain/version.rb +1 -1
  115. data/lib/ahoy_captain.rb +7 -1
  116. data/lib/generators/ahoy_captain/templates/config.rb.tt +7 -0
  117. metadata +137 -22
  118. data/app/assets/javascript/ahoy_captain/controllers/active_links_controller.js +0 -18
  119. data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +0 -20
  120. data/app/assets/javascript/ahoy_captain/controllers/search_select_controller.js +0 -65
  121. data/app/components/ahoy_captain/tables/headers/devices_header_component.html.erb +0 -3
  122. data/app/components/ahoy_captain/tables/headers/devices_header_component.rb +0 -9
  123. data/app/components/ahoy_captain/tables/headers/goals_header_component.html.erb +0 -6
  124. data/app/components/ahoy_captain/tables/headers/goals_header_component.rb +0 -9
  125. data/app/components/ahoy_captain/tables/rows/devices_row_component.html.erb +0 -5
  126. data/app/components/ahoy_captain/tables/rows/devices_row_component.rb +0 -12
  127. data/app/components/ahoy_captain/tables/rows/goals_row_component.html.erb +0 -11
  128. data/app/components/ahoy_captain/tables/rows/goals_row_component.rb +0 -20
  129. data/app/controllers/ahoy_captain/cities_controller.rb +0 -20
  130. data/app/controllers/ahoy_captain/countries_controller.rb +0 -20
  131. data/app/controllers/ahoy_captain/regions_controller.rb +0 -20
  132. /data/app/views/ahoy_captain/{cities → locations/cities}/index.html+details.erb +0 -0
  133. /data/app/views/ahoy_captain/{cities → locations/cities}/index.html.erb +0 -0
  134. /data/app/views/ahoy_captain/{countries → locations/countries}/index.html+details.erb +0 -0
  135. /data/app/views/ahoy_captain/{countries → locations/countries}/index.html.erb +0 -0
  136. /data/app/views/ahoy_captain/{regions → locations/regions}/index.html+details.erb +0 -0
  137. /data/app/views/ahoy_captain/{regions → locations/regions}/index.html.erb +0 -0
@@ -0,0 +1,55 @@
1
+ const THOUSAND = 1000
2
+ const HUNDRED_THOUSAND = 100000
3
+ const MILLION = 1000000
4
+ const HUNDRED_MILLION = 100000000
5
+ const BILLION = 1000000000
6
+ const HUNDRED_BILLION = 100000000000
7
+ const TRILLION = 1000000000000
8
+
9
+ export function numberFormatter(num) {
10
+ if (num >= THOUSAND && num < MILLION) {
11
+ const thousands = num / THOUSAND
12
+ if (thousands === Math.floor(thousands) || num >= HUNDRED_THOUSAND) {
13
+ return Math.floor(thousands) + 'k'
14
+ } else {
15
+ return (Math.floor(thousands * 10) / 10) + 'k'
16
+ }
17
+ } else if (num >= MILLION && num < BILLION) {
18
+ const millions = num / MILLION
19
+ if (millions === Math.floor(millions) || num >= HUNDRED_MILLION) {
20
+ return Math.floor(millions) + 'M'
21
+ } else {
22
+ return (Math.floor(millions * 10) / 10) + 'M'
23
+ }
24
+ } else if (num >= BILLION && num < TRILLION) {
25
+ const billions = num / BILLION
26
+ if (billions === Math.floor(billions) || num >= HUNDRED_BILLION) {
27
+ return Math.floor(billions) + 'B'
28
+ } else {
29
+ return (Math.floor(billions * 10) / 10) + 'B'
30
+ }
31
+ } else {
32
+ return num
33
+ }
34
+ }
35
+
36
+ function pad(num, size) {
37
+ return ('000' + num).slice(size * -1);
38
+ }
39
+
40
+ export function durationFormatter(duration) {
41
+ const hours = Math.floor(duration / 60 / 60)
42
+ const minutes = Math.floor(duration / 60) % 60
43
+ const seconds = Math.floor(duration - (minutes * 60) - (hours * 60 * 60))
44
+ if (hours > 0) {
45
+ return `${hours}h ${minutes}m ${seconds}s`
46
+ } else if (minutes > 0) {
47
+ return `${minutes}m ${pad(seconds, 2)}s`
48
+ } else {
49
+ return `${seconds}s`
50
+ }
51
+ }
52
+
53
+ export function percentageFormatter(float) {
54
+ return Number(float/100).toLocaleString(undefined,{style: 'percent', minimumFractionDigits:2});
55
+ }
@@ -0,0 +1,33 @@
1
+ <div data-controller="combobox"
2
+ data-combobox-single-option-value="<%= !@multiple %>"
3
+ data-combobox-placeholder-value="Select an option..."
4
+ data-combobox-is-disabled-value="false"
5
+ data-combobox-url-value="<%= @url %>"
6
+ data-combobox-disabled-value="<%= @disabled %>"
7
+ data-combobox-query-value="q[<%= @column %>_i_cont]"
8
+ data-combobox-selected-value="<%= @value.map { |value| { text: value, value: value } }.to_json %>"
9
+ class=" w-full "
10
+ >
11
+ <div data-action="click->combobox#toggleOpen" data-combobox-target="box"
12
+ class="
13
+ bg-gray-900 ring-0 focus-within:ring-0 focus-within:ring-0 focus:ring-0 focus:outline-none w-full rounded-md py-2 text-sm
14
+ w-full"
15
+ data-combobox-box-open-class="border-secondary-500 ring-1 ring-secondary-500">
16
+ <select data-combobox-target="select" style="display:none;"
17
+ data-predicate-select-target="select"
18
+ name="<%= @name %>"
19
+ id="<%= @select_html[:id] || "filter_#{@name}" %>"
20
+ <% @select_html.each do |k,v| %><%=k %>="<%=v %>"<% end %>
21
+ ><% @value.each do |value| %><option value="<%= value %>" selected><%= value %></option><% end %></select>
22
+ <div data-combobox-target="selected" class="px-2" style="display:none;"></div>
23
+ <input data-combobox-target="input"
24
+ data-action="input->combobox#onInput"
25
+ class="input input-sm input-ghost w-full inline-block rounded-md focus:outline-none focus:ring-0 focus:bg-gray-900"
26
+ type="text"
27
+ placeholder="Select an option...">
28
+ </div>
29
+ <ul data-combobox-target="list"
30
+ class="z-50 absolute mt-1 max-h-60 w-full overflow-auto rounded-md py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm bg-gray-800 text-gray-350"
31
+ style="display: none;">
32
+ </ul>
33
+ </div>
@@ -0,0 +1,13 @@
1
+ module AhoyCaptain
2
+ class ComboboxComponent < ViewComponent::Base
3
+ def initialize(name:, multiple: false, disabled: false, column:, url:, value: [], select_html: {})
4
+ @name = name
5
+ @multiple = multiple
6
+ @column = column
7
+ @url = url
8
+ @value = Array(value)
9
+ @select_html = select_html
10
+ @disabled = disabled
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ <div class="dropdown dropdown-end" data-controller='dropdown-label'>
2
+ <label
3
+ tabindex="0"
4
+ class="cursor-pointer flex <%= classes %>"
5
+ data-action='click->dropdown-label#removeHidden'
6
+ >
7
+ <span data-dropdown-label-target="label"><%= title %></span>
8
+
9
+ </label>
10
+ <ul class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52" data-dropdown-label-target="close">
11
+ <% links.each do |link| %>
12
+ <li data-action="click->dropdown-label#setLabel">
13
+ <%= link %>
14
+ <li>
15
+ <% end %>
16
+ </ul>
17
+ </div>
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AhoyCaptain::ComparisonLinkComponent < ViewComponent::Base
4
+ include ::AhoyCaptain::CompareMode
5
+ include ::AhoyCaptain::RangeOptions
6
+ include ::AhoyCaptain::Rangeable
7
+
8
+ renders_many :links
9
+ renders_one :header
10
+
11
+ attr_reader :title, :classes
12
+ def initialize(title: "", classes: "btn btn-sm btn-base-100 no-underline hover:bg-base-100")
13
+ @classes = classes
14
+ end
15
+
16
+ # cheating
17
+ def title
18
+ self.with_link_content(options_for_option)
19
+
20
+ comparison_mode.label
21
+ end
22
+
23
+ def render?
24
+ comparison_mode.enabled?
25
+ end
26
+
27
+ def options_for_option
28
+ [
29
+ (link_to "Custom period", "javascript:customComparisonModal.showModal()", class: selected(:custom)),
30
+ (link_to "Year-over-year", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: :year)), class: selected(:year)),
31
+ (link_to "Previous period", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: :previous)), class: selected(:previous, :true)),
32
+ (link_to "Disable Comparison", AhoyCaptain::Engine.routes.url_helpers.root_path(**helpers.search_params.merge(comparison: false))),
33
+
34
+ ].reverse.join.html_safe
35
+ end
36
+
37
+ private
38
+
39
+ def selected(*types)
40
+ return "font-bold" if comparison_mode.type.in?(types)
41
+
42
+ nil
43
+ end
44
+ end
@@ -1,13 +1,11 @@
1
- <div class="dropdown dropdown-end " data-controller='dropdown-label'>
1
+ <div class="dropdown dropdown-end" data-controller='dropdown-label'>
2
2
  <label
3
3
  tabindex="0"
4
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>
8
- <svg class="h-8 w-8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
9
- <path fill="currentColor" d="M16.53 8.97a.75.75 0 0 1 0 1.06l-4 4a.75.75 0 0 1-1.06 0l-4-4a.75.75 0 1 1 1.06-1.06L12 12.44l3.47-3.47a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd" />
10
- </svg>
8
+
11
9
  </label>
12
10
  <ul class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52" data-dropdown-label-target="close">
13
11
  <% options.each do |option| %>
@@ -9,6 +9,10 @@ class AhoyCaptain::DropdownLinkComponent < ViewComponent::Base
9
9
  @classes = classes
10
10
  end
11
11
 
12
+ def link_to(name, url, **options)
13
+ self.with_option_content view_context.link_to name, url, options
14
+ end
15
+
12
16
  private
13
17
 
14
18
  attr_reader :title, :classes
@@ -1,7 +1,7 @@
1
1
  <div class="dropdown dropdown-end">
2
2
  <label
3
3
  tabindex="0"
4
- class="btn btn-ghost dark:hover:bg-neutral flex"
4
+ class="btn btn-sm btn-ghost dark:hover:bg-neutral flex"
5
5
  >
6
6
  <%= header_icon %>
7
7
  <span><%= title %></span>
@@ -18,7 +18,8 @@
18
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
19
  onclick="<% if filter.modal %><%= filter.modal %>.showModal() <% end %>">
20
20
  <span class="truncate w-48 ">
21
- <%= filter.description %>
21
+ <%= filter.column.titleize %> <%= filter.predicate.titleize %>
22
+ <%= filter.values.to_sentence %>
22
23
  </span>
23
24
  <% if filter.modal %>
24
25
  <span class="group-hover:text-primary hover:text-primary ">
@@ -30,8 +31,8 @@
30
31
  class="hover:text-primary link no-underline pl-2" href="<%= filter.url %>">
31
32
  <%= remove_icon %>
32
33
  </a>
33
- <li>
34
- <div class="divider my-1" data-toggle-target='toggleable'></div>
34
+ </li>
35
+ <div class="divider my-1" data-toggle-target='toggleable'></div>
35
36
  <% end %>
36
37
  <li data-toggle-target='toggleable'>
37
38
  <a class="block mx-auto pl-4 pb-1 " href="<%= AhoyCaptain::Engine.app.url_helpers.root_path %>">Clear all filters</a>
@@ -39,10 +40,11 @@
39
40
  </div>
40
41
  <% end %>
41
42
 
42
- <div id="core-filters" class="menu <%= 'hidden' if advanced_filter_menu? %> pt-0" data-toggle-target='toggleable'>
43
+ <ul id="core-filters" class="menu <%= 'hidden' if advanced_filter_menu? %> pt-0" data-toggle-target='toggleable'>
43
44
  <% AhoyCaptain.config.filters.each do |label, filter_group| %>
44
45
  <li><button onClick="<%= filter_group.modal_name %>.showModal()" class='link no-underline' data-action="click->toggle#trigger"><%= label %></button></li>
45
46
  <% end %>
46
- </div>
47
+ <li><button onClick="customPropertyFilterModal.showModal()" class='link no-underline' data-action="click->toggle#trigger">Property</button></li>
48
+ </ul>
47
49
  </ul>
48
50
  </div>
@@ -1,11 +1,13 @@
1
- <dialog id="<%= id %>" class="modal">
2
- <div class="modal-box w-11/12 max-w-5xl">
1
+ <dialog id="<%= id %>" class="modal" data-controller="filter-modal">
2
+ <div class="modal-box h-5/6 max-w-5xl">
3
+ <h1 class="text-xl mb-4"><%= title %></h1>
3
4
  <fieldset>
4
- <h5><%= title %></h5>
5
5
  <%= modal_display %>
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
6
  </fieldset>
7
+ <div class="mt-10">
8
+ <button class="btn btn-active btn-primary" type="submit">Apply</button>
9
+ <button class="btn btn-active btn-primary" type="reset">Reset</button>
10
+ </div>
9
11
  </div>
10
12
  <label class="modal-backdrop">
11
13
  <button onclick="event.preventDefault(); <%=id %>.close();">Close</button>
@@ -1,23 +1,25 @@
1
- <fieldset class="flex space-x-4 items-end" data-controller="predicate-select">
2
- <div class="flex flex-col w-[20%]">
3
- <label class="label"><%= label %></label>
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
- </option>
9
- <% end %>
10
- </select>
1
+ <div class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-1"><%= label %></div>
2
+ <fieldset class="grid grid-cols-11 mb-3" data-controller="predicate-select">
3
+ <div class="col-span-3 mr-2">
4
+ <div class="w-full">
5
+ <div class="relative inline-block text-left w-full">
6
+ <div class="w-full">
7
+ <% if @predicates.any? %>
8
+ <select id="<%= column %>_predicate" class='select border-0 select-primary bg-gray-900 ring-0 focus-within:ring-0 focus-within:ring-0 focus:ring-0 focus:outline-none inline-flex justify-between items-center w-full rounded-md ' data-action='change->predicate-select#handleChange'>
9
+ <% @predicates.each do |predicate| %>
10
+ <option value="<%= option_value(predicate) %>" <%= 'selected' if selected_predicate?(predicate) %>>
11
+ <%= predicate_label(predicate) %>
12
+ </option>
13
+ <% end %>
14
+ </select>
15
+ <% end %>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ <div class="col-span-8">
21
+ <div class="relative w-full">
22
+ <%= render ::AhoyCaptain::ComboboxComponent.new(name: column_name_with_predicate, multiple: multiple, column: column, url: url, value: values) %>
23
+ </div>
11
24
  </div>
12
-
13
- <select
14
- data-predicate-select-target="select"
15
- data-controller="search-select"
16
- class='w-[50%] border-base-content border-opacity-20 rounded-lg min-h-[3rem]'
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>
23
25
  </fieldset>
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AhoyCaptain::Filter::SelectComponent < ViewComponent::Base
4
- def initialize(label:, column:, url:, predicates:, form:, multiple: true)
4
+ def initialize(label:, column:, url:, predicates:, form:, multiple: true, input_html: {})
5
5
  @label = label
6
6
  @column = column
7
7
  @url = url
8
8
  @predicates = predicates
9
9
  @form = form
10
10
  @multiple = multiple
11
+ @input_html_options = input_html
11
12
  end
12
13
 
13
14
  private
@@ -1,6 +1,6 @@
1
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
2
  <span data-action='click->filter--item#openModal'>
3
- <%= tag_item.column.titleize %> <%= tag_item.predicate %>
3
+ <%= tag_item.column.titleize %> <%= tag_item.predicate.titleize %>
4
4
  <span class="font-bold">
5
5
  <%= tag_item.label %>
6
6
  </span>
@@ -0,0 +1,8 @@
1
+ <div class="rounded shadow bg-white cursor-pointer dark:bg-gray-800 flex h-8">
2
+ <button class="flex items-center px-1 sm:px-2 border-r border-gray-300 rounded-l dark:border-gray-500 dark:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-900" type="button">
3
+ <svg class="feather h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"></polyline></svg>
4
+ </button>
5
+ <button class="flex items-center px-1 sm:px-2 rounded-r dark:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-900" type="button">
6
+ <svg class="feather h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>
7
+ </button>
8
+ </div>
@@ -0,0 +1,11 @@
1
+ module AhoyCaptain
2
+ class PreviousNextComponent < ViewComponent::Base
3
+ def initialize(range)
4
+ @range = range
5
+ end
6
+
7
+ def render?
8
+ false
9
+ end
10
+ end
11
+ 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-controller="frame-link" 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
@@ -1,8 +1,15 @@
1
- <a href="<%= @url %>" class="hover:text-primary text-base-content link no-underline" data-turbo-frame="chart">
2
- <dt class="font-normal <%= 'text-primary' if @selected %>" data-active-links-target="link"><%= @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 %>
1
+ <a href="<%= @url %>" class="relative px-4 md:px-6 w-1/2 my-4 lg:w-auto group cursor-pointer" data-controller="frame-link" 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>
6
13
  </div>
7
- </dd>
14
+ </div>
8
15
  </a>
@@ -1,12 +1,26 @@
1
1
  module AhoyCaptain
2
2
  module Stats
3
3
  class ContainerComponent < ViewComponent::Base
4
- def initialize(url, label, value, selected = false)
4
+ def initialize(url, label, value, formatter, selected = false)
5
5
  @url = url
6
6
  @label = label
7
7
  @value = value
8
+ @formatter = formatter
8
9
  @selected = selected
9
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
10
24
  end
11
25
  end
12
26
  end
@@ -1,25 +1,32 @@
1
- <div class="max-w-6xl flex justify-between sticky top-0 min-h-sm z-[99999] py-4 bg-base-100">
2
- <div class="flex items-center">
3
- <a href="/">
4
- <img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='w-16 h-16 rounded-full'>
5
- </a>
6
- <% if tag_list_hidden? %>
7
- <%= render AhoyCaptain::Filter::TagContainerComponent.new %>
8
- <% else %>
9
- <%= realtime_update %>
10
- <% end %>
11
- </div>
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 hover:bg-base-100') do |dropdown| %>
14
- <% dropdown.with_option do %>
15
- <% 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>
17
- <% end %>
1
+ <div class=" sticky top-0 min-h-sm z-[99999] py-4 bg-base-100 pb-4">
2
+ <div class="max-w-6xl mx-auto max-w-6xl flex justify-between ">
3
+ <div class="flex items-center">
4
+ <a href="/">
5
+ <img src="<%= image_path "ahoy_captain/logo.png" %>" alt="AhoyCaptainLogo" class='max-h-20 md:h-16 rounded-full'>
6
+ </a>
7
+ <% if tag_list_hidden? %>
8
+ <%= render AhoyCaptain::Filter::TagContainerComponent.new %>
9
+ <% else %>
10
+ <%= realtime_update %>
11
+ <% end %>
12
+ </div>
13
+ <div class="flex flex-row-reverse col-span-2 items-center gap-3">
14
+ <%= render AhoyCaptain::ComparisonLinkComponent.new %>
15
+ <%= render AhoyCaptain::PreviousNextComponent.new(range) %>
18
16
 
19
- <a class='link no-underline ' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom range</a>
17
+ <%= render AhoyCaptain::DropdownLinkComponent.new(title: params[:start_date] ? custom_range_label : (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| %>
18
+ <% dropdown.with_option do %>
19
+ <% AhoyCaptain.config.ranges.each do |param, range| %>
20
+ <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>
21
+ <% end %>
22
+
23
+ <a class='link no-underline ' href='#' onclick="event.preventDefault(); customRangeModal.showModal()">Custom Range</a>
24
+ <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>
25
+ <% end %>
20
26
  <% end %>
21
- <% end %>
22
27
 
23
- <%= render AhoyCaptain::Filter::DropdownComponent.new(filters: filters) %>
28
+ <%= render AhoyCaptain::Filter::DropdownComponent.new(filters: filters) %>
29
+ </div>
24
30
  </div>
31
+
25
32
  </div>
@@ -2,11 +2,22 @@
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
5
8
 
6
9
  def filters
7
10
  @filters ||= ::AhoyCaptain::FilterParser.parse(request)
8
11
  end
9
12
 
13
+ def custom_range_label
14
+ if range.custom?
15
+ [range.starts_at, range.ends_at].map { |date| date.strftime('%b %d, %Y') }.join("-")
16
+ else
17
+ "Custom Range"
18
+ end
19
+ end
20
+
10
21
  def tag_list_hidden?
11
22
  filters.values.map(&:values).flatten.size < ::AhoyCaptain::FilterParser::FILTER_MENU_MAX_SIZE
12
23
  end
@@ -4,21 +4,30 @@ class AhoyCaptain::TableComponent < ViewComponent::Base
4
4
  DEFAULT_HEADER = AhoyCaptain::Tables::Headers::HeaderComponent
5
5
  DEFAULT_ROW = AhoyCaptain::Tables::Rows::RowComponent
6
6
 
7
- def initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW)
7
+ def initialize(items:, category_name: nil, unit_name: nil, header: nil, row: DEFAULT_ROW, table: nil)
8
8
  @items = items
9
9
  @category_name = category_name
10
10
  @unit_name = unit_name
11
- @additional_cols = additional_cols
12
11
  if header.nil?
13
12
  @header = DEFAULT_HEADER.new(category_name: category_name, unit_name: unit_name)
14
13
  else
15
14
  @header = header.new
16
15
  end
16
+
17
17
  @row = row
18
+
19
+ if table
20
+ @table = table.table
21
+ @header = @table.headers
22
+ end
18
23
  end
19
24
 
20
25
  def render_row(item)
21
- @row.new(table: self, item: item).render_in(view_context)
26
+ if @table
27
+ @table.row(item, view_context)
28
+ else
29
+ @row.new(table: self, item: item).render_in(view_context)
30
+ end
22
31
  end
23
32
 
24
33
  private
@@ -34,6 +43,6 @@ class AhoyCaptain::TableComponent < ViewComponent::Base
34
43
  end
35
44
 
36
45
  def fixed_height?
37
- !@header.is_a?(::AhoyCaptain::Tables::Headers::GoalsHeaderComponent)
46
+ @header.fixed_height?
38
47
  end
39
48
  end