ahoy_captain 0.11.1 → 0.76
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -25
- data/Rakefile +2 -23
- data/app/assets/javascript/ahoy_captain/application.js +4 -4
- data/app/assets/javascript/ahoy_captain/controllers/application.js +5 -5
- data/app/assets/javascript/ahoy_captain/controllers/application_controller.js +8 -27
- 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_controller.js +145 -0
- data/app/assets/javascript/ahoy_captain/controllers/filter_tag_controller.js +17 -0
- data/app/assets/javascript/ahoy_captain/controllers/funnel_chart_controller.js +127 -113
- data/app/assets/javascript/ahoy_captain/controllers/index.js +3 -4
- data/app/assets/javascript/ahoy_captain/controllers/link_controller.js +43 -0
- data/app/assets/javascript/ahoy_captain/controllers/navigation_controller.js +25 -0
- data/app/assets/javascript/ahoy_captain/controllers/realtime_controller.js +9 -12
- data/app/components/ahoy_captain/dropdown_button_component.html.erb +5 -5
- data/app/components/ahoy_captain/dropdown_link_component.html.erb +7 -5
- data/app/components/ahoy_captain/dropdown_link_component.rb +0 -4
- data/app/components/ahoy_captain/filter/modal_component.html.erb +9 -12
- data/app/components/ahoy_captain/filter/select_component.html.erb +19 -23
- data/app/components/ahoy_captain/filter/select_component.rb +9 -41
- data/app/components/ahoy_captain/filter/tag_component.html.erb +4 -8
- data/app/components/ahoy_captain/filter/tag_component.rb +30 -6
- data/app/components/ahoy_captain/filter/tag_container_component.html.erb +3 -2
- data/app/components/ahoy_captain/filter/tag_container_component.rb +8 -1
- data/app/components/ahoy_captain/sticky_nav_component.html.erb +33 -28
- data/app/components/ahoy_captain/sticky_nav_component.rb +0 -19
- data/app/components/ahoy_captain/table_component.html.erb +37 -4
- data/app/components/ahoy_captain/table_component.rb +5 -25
- data/app/components/ahoy_captain/tile_component.html.erb +10 -21
- data/app/components/ahoy_captain/tile_component.rb +2 -10
- data/app/components/ahoy_captain/tooltip_component.html.erb +2 -2
- data/app/controllers/ahoy_captain/application_controller.rb +30 -23
- data/app/controllers/ahoy_captain/campaigns_controller.rb +10 -2
- data/app/controllers/ahoy_captain/cities_controller.rb +24 -0
- data/app/controllers/ahoy_captain/countries_controller.rb +24 -0
- data/app/controllers/ahoy_captain/devices_controller.rb +6 -3
- data/app/controllers/ahoy_captain/entry_pages_controller.rb +4 -2
- data/app/controllers/ahoy_captain/exit_pages_controller.rb +4 -3
- data/app/controllers/ahoy_captain/filters/base_controller.rb +3 -1
- 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 +3 -2
- 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/realtimes_controller.rb +1 -1
- data/app/controllers/ahoy_captain/regions_controller.rb +24 -0
- data/app/controllers/ahoy_captain/sources_controller.rb +5 -2
- data/app/controllers/ahoy_captain/stats/base_controller.rb +0 -142
- data/app/controllers/ahoy_captain/stats/bounce_rates_controller.rb +2 -4
- data/app/controllers/ahoy_captain/stats/total_pageviews_controller.rb +1 -2
- data/app/controllers/ahoy_captain/stats/total_visits_controller.rb +1 -2
- data/app/controllers/ahoy_captain/stats/unique_visitors_controller.rb +1 -3
- data/app/controllers/ahoy_captain/stats/views_per_visits_controller.rb +8 -3
- data/app/controllers/ahoy_captain/stats/visit_durations_controller.rb +1 -2
- data/app/controllers/ahoy_captain/top_pages_controller.rb +8 -2
- data/app/decorators/ahoy_captain/application_decorator.rb +3 -27
- data/app/decorators/ahoy_captain/campaign_decorator.rb +0 -8
- data/app/decorators/ahoy_captain/city_decorator.rb +0 -12
- data/app/decorators/ahoy_captain/country_decorator.rb +0 -10
- data/app/decorators/ahoy_captain/device_decorator.rb +2 -13
- data/app/decorators/ahoy_captain/page_decorator.rb +0 -11
- data/app/decorators/ahoy_captain/region_decorator.rb +0 -16
- data/app/decorators/ahoy_captain/source_decorator.rb +0 -7
- data/app/helpers/ahoy_captain/application_helper.rb +3 -60
- data/app/models/ahoy_captain/current.rb +9 -0
- data/app/models/ahoy_captain/rangeable.rb +3 -0
- data/app/models/ahoy_captain/url_helpers.rb +6 -0
- data/app/models/concerns/ahoy_captain/range_options.rb +14 -1
- data/app/presenters/ahoy_captain/dashboard_presenter.rb +46 -18
- data/app/presenters/ahoy_captain/funnel_presenter.rb +29 -32
- data/app/presenters/ahoy_captain/goals_presenter.rb +23 -33
- data/app/queries/ahoy_captain/application_query.rb +13 -81
- data/app/queries/ahoy_captain/entry_pages_query.rb +2 -3
- data/app/queries/ahoy_captain/event_query.rb +8 -30
- data/app/queries/ahoy_captain/exit_pages_query.rb +4 -6
- data/app/queries/ahoy_captain/stats/average_views_per_visit_query.rb +4 -11
- data/app/queries/ahoy_captain/stats/average_visit_duration_query.rb +7 -15
- data/app/queries/ahoy_captain/stats/bounce_rates_query.rb +7 -24
- data/app/queries/ahoy_captain/stats/total_pageviews_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/total_visitors_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/unique_visitors_query.rb +2 -2
- data/app/queries/ahoy_captain/stats/views_per_visit_query.rb +3 -3
- data/app/queries/ahoy_captain/stats/visit_duration_query.rb +5 -5
- data/app/queries/ahoy_captain/visit_query.rb +13 -12
- 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 +2 -5
- data/app/views/ahoy_captain/goals/index.html.erb +37 -2
- data/app/views/ahoy_captain/layouts/application.html.erb +4 -3
- data/app/views/ahoy_captain/realtimes/show.html.erb +1 -1
- data/app/views/ahoy_captain/roots/show.html.erb +118 -117
- data/app/views/ahoy_captain/stats/base/index.html.erb +1 -38
- data/app/views/ahoy_captain/stats/show.html.erb +56 -14
- data/config/routes.rb +3 -16
- data/lib/ahoy_captain/ahoy/event_methods.rb +75 -36
- data/lib/ahoy_captain/ahoy/visit_methods.rb +1 -1
- data/lib/ahoy_captain/configuration.rb +7 -18
- data/lib/ahoy_captain/engine.rb +0 -22
- data/lib/ahoy_captain/goals.rb +4 -16
- data/lib/ahoy_captain/period_collection.rb +1 -1
- data/lib/ahoy_captain/version.rb +1 -1
- data/lib/ahoy_captain.rb +1 -8
- data/lib/generators/ahoy_captain/templates/config.rb.tt +3 -50
- metadata +17 -185
- data/app/assets/javascript/ahoy_captain/controllers/combobox_controller.js +0 -371
- data/app/assets/javascript/ahoy_captain/controllers/filter/item_controller.js +0 -12
- data/app/assets/javascript/ahoy_captain/controllers/filter_form_controller.js +0 -13
- data/app/assets/javascript/ahoy_captain/controllers/filter_modal_controller.js +0 -45
- data/app/assets/javascript/ahoy_captain/controllers/frame_link_controller.js +0 -20
- data/app/assets/javascript/ahoy_captain/controllers/interval_controller.js +0 -15
- data/app/assets/javascript/ahoy_captain/controllers/line_chart_controller.js +0 -251
- data/app/assets/javascript/ahoy_captain/controllers/map_controller.js +0 -47
- data/app/assets/javascript/ahoy_captain/controllers/predicate_select_controller.js +0 -10
- data/app/assets/javascript/ahoy_captain/controllers/properties_controller.js +0 -8
- data/app/assets/javascript/ahoy_captain/controllers/property_filter_controller.js +0 -45
- data/app/assets/javascript/ahoy_captain/controllers/tile_controller.js +0 -33
- data/app/assets/javascript/ahoy_captain/controllers/toggle_controller.js +0 -17
- data/app/assets/javascript/ahoy_captain/helpers/chart_utils.js +0 -156
- data/app/assets/javascript/ahoy_captain/helpers/countries.js +0 -2261
- data/app/assets/javascript/ahoy_captain/helpers/number_formatters.js +0 -55
- data/app/components/ahoy_captain/combobox_component.html.erb +0 -33
- data/app/components/ahoy_captain/combobox_component.rb +0 -13
- data/app/components/ahoy_captain/comparison_link_component.html.erb +0 -17
- data/app/components/ahoy_captain/comparison_link_component.rb +0 -44
- data/app/components/ahoy_captain/filter/dropdown_component.html.erb +0 -50
- data/app/components/ahoy_captain/filter/dropdown_component.rb +0 -51
- data/app/components/ahoy_captain/previous_next_component.html.erb +0 -8
- data/app/components/ahoy_captain/previous_next_component.rb +0 -11
- data/app/components/ahoy_captain/stats/comparable_container_component.html.erb +0 -25
- data/app/components/ahoy_captain/stats/comparable_container_component.rb +0 -86
- data/app/components/ahoy_captain/stats/container_component.html.erb +0 -15
- data/app/components/ahoy_captain/stats/container_component.rb +0 -26
- data/app/components/ahoy_captain/tables/devices_table_component.rb +0 -11
- data/app/components/ahoy_captain/tables/dynamic_table.rb +0 -13
- data/app/components/ahoy_captain/tables/dynamic_table_component.rb +0 -204
- data/app/components/ahoy_captain/tables/goals_table_component.rb +0 -17
- data/app/components/ahoy_captain/tables/header_component.html.erb +0 -5
- data/app/components/ahoy_captain/tables/header_component.rb +0 -18
- data/app/components/ahoy_captain/tables/headers/header_component.html.erb +0 -5
- data/app/components/ahoy_captain/tables/headers/header_component.rb +0 -16
- data/app/components/ahoy_captain/tables/properties_table_component.rb +0 -27
- data/app/components/ahoy_captain/tables/row_component.html.erb +0 -4
- data/app/components/ahoy_captain/tables/rows/row_component.html.erb +0 -6
- data/app/components/ahoy_captain/tables/rows/row_component.rb +0 -40
- data/app/controllers/ahoy_captain/exports_controller.rb +0 -14
- data/app/controllers/ahoy_captain/filters/goals_controller.rb +0 -9
- data/app/controllers/ahoy_captain/filters/properties/names_controller.rb +0 -11
- data/app/controllers/ahoy_captain/filters/properties/values_controller.rb +0 -15
- data/app/controllers/ahoy_captain/locations/cities_controller.rb +0 -22
- data/app/controllers/ahoy_captain/locations/countries_controller.rb +0 -22
- data/app/controllers/ahoy_captain/locations/maps_controller.rb +0 -24
- data/app/controllers/ahoy_captain/locations/regions_controller.rb +0 -22
- data/app/controllers/ahoy_captain/properties_controller.rb +0 -41
- data/app/models/ahoy_captain/comparison_mode.rb +0 -72
- data/app/models/ahoy_captain/export.rb +0 -48
- data/app/models/ahoy_captain/filter_parser.rb +0 -82
- data/app/models/ahoy_captain/range_from_params.rb +0 -78
- data/app/models/concerns/ahoy_captain/compare_mode.rb +0 -19
- data/app/models/concerns/ahoy_captain/limitable.rb +0 -17
- data/app/queries/ahoy_captain/campaign_query.rb +0 -14
- data/app/queries/ahoy_captain/city_query.rb +0 -11
- data/app/queries/ahoy_captain/country_query.rb +0 -10
- data/app/queries/ahoy_captain/device_query.rb +0 -10
- data/app/queries/ahoy_captain/region_query.rb +0 -11
- data/app/queries/ahoy_captain/source_query.rb +0 -10
- data/app/queries/ahoy_captain/stats/base_query.rb +0 -18
- data/app/queries/ahoy_captain/top_page_query.rb +0 -13
- data/app/queries/concerns/ahoy_captain/comparable_queries.rb +0 -25
- data/app/queries/concerns/ahoy_captain/comparable_query.rb +0 -138
- data/app/queries/concerns/ahoy_captain/lazy_comparable_query.rb +0 -42
- data/app/views/ahoy_captain/devices/_table.html.erb +0 -2
- data/app/views/ahoy_captain/layouts/shared/_tile_loader.html.erb +0 -12
- data/app/views/ahoy_captain/locations/maps/show.html.erb +0 -3
- data/app/views/ahoy_captain/properties/_form.html.erb +0 -6
- data/app/views/ahoy_captain/properties/index.html.erb +0 -3
- data/app/views/ahoy_captain/properties/show.html.erb +0 -6
- data/app/views/ahoy_captain/roots/_filters.html.erb +0 -80
- data/lib/ahoy_captain/filter_configuration/filter.rb +0 -16
- data/lib/ahoy_captain/filter_configuration/filter_collection.rb +0 -48
- data/lib/ahoy_captain/filters_configuration.rb +0 -77
- data/lib/ahoy_captain/predicate_label.rb +0 -7
- data/lib/generators/ahoy_captain/migration_generator.rb +0 -21
- data/lib/generators/ahoy_captain/templates/migration.rb.tt +0 -7
- /data/app/views/ahoy_captain/{locations/cities → cities}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{locations/cities → cities}/index.html.erb +0 -0
- /data/app/views/ahoy_captain/{locations/countries → countries}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{locations/countries → countries}/index.html.erb +0 -0
- /data/app/views/ahoy_captain/{locations/regions → regions}/index.html+details.erb +0 -0
- /data/app/views/ahoy_captain/{locations/regions → regions}/index.html.erb +0 -0
@@ -1,55 +0,0 @@
|
|
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
|
-
}
|
@@ -1,33 +0,0 @@
|
|
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>
|
@@ -1,13 +0,0 @@
|
|
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
|
@@ -1,17 +0,0 @@
|
|
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>
|
@@ -1,44 +0,0 @@
|
|
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,50 +0,0 @@
|
|
1
|
-
<div class="dropdown dropdown-end">
|
2
|
-
<label
|
3
|
-
tabindex="0"
|
4
|
-
class="btn btn-sm 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.column.titleize %> <%= filter.predicate.titleize %>
|
22
|
-
<%= filter.values.to_sentence %>
|
23
|
-
</span>
|
24
|
-
<% if filter.modal %>
|
25
|
-
<span class="group-hover:text-primary hover:text-primary ">
|
26
|
-
<%= edit_icon %>
|
27
|
-
</span>
|
28
|
-
<% end %>
|
29
|
-
</button>
|
30
|
-
<a title="Remove filter: <%= filter.title %>"
|
31
|
-
class="hover:text-primary link no-underline pl-2" href="<%= filter.url %>">
|
32
|
-
<%= remove_icon %>
|
33
|
-
</a>
|
34
|
-
</li>
|
35
|
-
<div class="divider my-1" data-toggle-target='toggleable'></div>
|
36
|
-
<% end %>
|
37
|
-
<li data-toggle-target='toggleable'>
|
38
|
-
<a class="block mx-auto pl-4 pb-1 " href="<%= AhoyCaptain::Engine.app.url_helpers.root_path %>">Clear all filters</a>
|
39
|
-
</li>
|
40
|
-
</div>
|
41
|
-
<% end %>
|
42
|
-
|
43
|
-
<ul id="core-filters" class="menu <%= 'hidden' if advanced_filter_menu? %> pt-0" data-toggle-target='toggleable'>
|
44
|
-
<% AhoyCaptain.config.filters.each do |label, filter_group| %>
|
45
|
-
<li><button onClick="<%= filter_group.modal_name %>.showModal()" class='link no-underline' data-action="click->toggle#trigger"><%= label %></button></li>
|
46
|
-
<% end %>
|
47
|
-
<li><button onClick="customPropertyFilterModal.showModal()" class='link no-underline' data-action="click->toggle#trigger">Property</button></li>
|
48
|
-
</ul>
|
49
|
-
</ul>
|
50
|
-
</div>
|
@@ -1,51 +0,0 @@
|
|
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,8 +0,0 @@
|
|
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>
|
@@ -1,25 +0,0 @@
|
|
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>
|
@@ -1,86 +0,0 @@
|
|
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,15 +0,0 @@
|
|
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>
|
13
|
-
</div>
|
14
|
-
</div>
|
15
|
-
</a>
|
@@ -1,26 +0,0 @@
|
|
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,204 +0,0 @@
|
|
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
|