Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graph of active POS Integrations #2530

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/graphs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def tables
protected

def set_variable_graph_kind
@graph_kinds = %w[general users bikes recoveries]
@graph_kinds = %w[general users bikes recoveries pos_integrations]
@kind = @graph_kinds.include?(params[:search_kind]) ? params[:search_kind] : @graph_kinds.first
end

Expand Down
32 changes: 16 additions & 16 deletions app/helpers/graphing_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@

module GraphingHelper
def time_range_counts(collection:, column: "created_at", time_range: nil)
time_range ||= @time_range
# Note: by specifying the range parameter, we force it to display empty days
collection.send(
group_by_method(time_range),
column,
range: time_range,
format: group_by_format(time_range)
).count
collection_grouped(collection: collection, column: column, time_range: time_range).count
end

def time_range_amounts(collection:, column: "created_at", amount_column: "amount_cents", time_range: nil, convert_to_dollars: false)
time_range ||= @time_range
# Note: by specifying the range parameter, we force it to display empty days
result = collection.send(
group_by_method(time_range),
column,
range: time_range,
format: group_by_format(time_range)
).sum(amount_column)
result = collection_grouped(collection: collection,
column: column, time_range: time_range).sum(amount_column)

return result unless convert_to_dollars

Expand Down Expand Up @@ -132,4 +119,17 @@ def organization_dashboard_bikes_graph_data
}
]
end

private

def collection_grouped(collection:, column: "created_at", time_range: nil, time_zone: nil)
time_range ||= @time_range
# Note: by specifying the range parameter, we force it to display empty days
collection.send(
group_by_method(time_range),
column,
range: time_range,
format: group_by_format(time_range)
)
end
end
2 changes: 1 addition & 1 deletion app/views/admin/graphs/_graphs_subnav.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
= link_to "Location count tables", tables_admin_graphs_path(location_count: true), class: location_count ? "nav-link active" : "nav-link"
- @graph_kinds.each do |kind|
%li.nav-item
= link_to "#{kind} graphs", admin_graphs_path(sortable_params.merge(search_kind: kind)), class: @kind == kind ? " nav-link active" : "nav-link"
= link_to kind.humanize, admin_graphs_path(sortable_params.merge(search_kind: kind)), class: @kind == kind ? " nav-link active" : "nav-link"

- if !["general", ""].include?(@kind) # General and location tables don't have period select :/
.col-12.mt-4
Expand Down
33 changes: 20 additions & 13 deletions app/views/admin/graphs/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
Bikes past year
= column_chart variable_admin_graphs_path(search_kind: "bikes", period: "year"), stacked: true, thousands: ","

- else
- elsif @kind == "bikes"
- show_search_statuses = !@ignored_only && @kind == "bikes"
- if @kind == "bikes"
%ul.nav.justify-content-end.small
- unless @ignored_only
%li.nav-item
= link_to "Ignored bikes only (deleted, test, spam)", admin_graphs_path(sortable_params.merge(search_ignored: true)), class: "nav-link"
- if show_search_statuses
%li.nav-item
%a.nav-link#showStatusesSearch{href: "#", class: (@not_default_statuses ? "active" : "")}
Search statuses
%ul.nav.justify-content-end.small
- unless @ignored_only
%li.nav-item
= link_to "Ignored bikes only (deleted, test, spam)", admin_graphs_path(sortable_params.merge(search_ignored: true)), class: "nav-link"
- if show_search_statuses
%li.nav-item
%a.nav-link#showStatusesSearch{href: "#", class: (@not_default_statuses ? "active" : "")}
Search statuses
.row.mt-4.mb-4
.col-md-6.order-2.order-md-1
- if params[:search_manufacturer].present?
Expand Down Expand Up @@ -64,8 +63,8 @@
= submit_tag "Search", name: "search", class: "btn btn-primary mb-2"


- if @ignored_only
= column_chart variable_admin_graphs_path(sortable_params.merge(bike_graph_kind: "ignored")), stacked: true, thousands: ","
- if @ignored_only
= column_chart variable_admin_graphs_path(sortable_params.merge(bike_graph_kind: "ignored")), stacked: true, thousands: ","

.mt-4
= column_chart variable_admin_graphs_path(sortable_params), thousands: ","
Expand All @@ -78,7 +77,7 @@
-# Don't render all the extra stuff if looking at a period that is longer than 1 year
- render_other_bike_graphs = time_range_length(@time_range) < 367.days.to_i

- if @kind == "bikes" && render_other_bike_graphs
- if render_other_bike_graphs
- shown_bike_graph_kinds.each do |graph_kind|
- if graph_kind == "stolen"
- next # because that's already rendered above
Expand Down Expand Up @@ -155,3 +154,11 @@
= organization.pos_kind.humanize
%td.text-right
= admin_number_display(bike_count)
- else
- if @total_count.present?
%p.mt-4
#{admin_number_display(@total_count)} matching #{@kind}
%em
= humanized_time_range(@time_range)
.mt-4
= column_chart variable_admin_graphs_path(sortable_params), thousands: ","
1 change: 1 addition & 0 deletions spec/helpers/graphing_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
describe "time_range_counts" do
let(:target_counts) { {" 1:16 PM" => 0, " 1:17 PM" => 1, " 1:18 PM" => 0, " 1:19 PM" => 0} }
it "returns the thing with want" do
pp send(:time_range_counts, collection: Payment.all)
expect(time_range_counts(collection: Payment.all)).to eq target_counts
end
end
Expand Down