diff --git a/app/controllers/avo/charts_controller.rb b/app/controllers/avo/charts_controller.rb index 5e872c874..e450af508 100644 --- a/app/controllers/avo/charts_controller.rb +++ b/app/controllers/avo/charts_controller.rb @@ -3,10 +3,30 @@ module Avo class ChartsController < BaseController def distribution_chart - @values_summary = resource.model_class.group(params[:field_id]).reorder("count_all desc").count + @values_summary = records.group(params[:field_id]).reorder("count_all desc").count + @field_id = params[:field_id] render "avo/partials/distribution_chart", layout: "avo/blank" end + + private + + def records + if is_associated_record? + related_records + else + resource.model_class + end + end + + def related_records + relation_class = BaseResource.get_model_by_name(params[:via_relation_class]) + parent = relation_class.find(params[:via_record_id]) + + association_name = BaseResource.valid_association_name(parent, resource.model_key) + + parent.send(association_name) + end end end diff --git a/app/views/avo/partials/_table_header.html.erb b/app/views/avo/partials/_table_header.html.erb index bafb43bc0..a29151f1b 100644 --- a/app/views/avo/partials/_table_header.html.erb +++ b/app/views/avo/partials/_table_header.html.erb @@ -1,9 +1,3 @@ -<% - # Currently there isn't a way to summarize records on associations. - # We'd love to support this feature so please send in a PR. - should_summarize = @parent_record.blank? -%> - @@ -83,14 +77,14 @@ <%= field.table_header_label %> <% end %> <% end %> - <% if field.summarizable && should_summarize %> + <% if field.summarizable %>
<%= svg 'heroicons/solid/chart-bar', class: 'h-3 ml-1' %>