diff --git a/app/assets/javascripts/controllers/admin/statistics.coffee.erb b/app/assets/javascripts/controllers/admin/statistics.coffee.erb index 88c785bef..9306a96d3 100644 --- a/app/assets/javascripts/controllers/admin/statistics.coffee.erb +++ b/app/assets/javascripts/controllers/admin/statistics.coffee.erb @@ -55,6 +55,9 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state", ## total of the stat field for non simple types $scope.sumStat = 0 + ## Results of custom aggregations for the current type + $scope.customAggs = {} + ## default: results are not sorted $scope.sorting = ca: 'none' @@ -337,6 +340,7 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state", $scope.sumCA = 0 $scope.averageAge = 0 $scope.sumStat = 0 + $scope.customAggs = {} $scope.totalHits = null $scope.searchDate = new Date() custom = buildCustomFilterQuery() @@ -350,6 +354,9 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state", $scope.averageAge = Math.round(res.aggregations.average_age.value * 100) / 100 $scope.sumStat = res.aggregations.total_stat.value $scope.scrollId = res._scroll_id + for custom in $scope.type.active.custom_aggregations + $scope.customAggs[custom.field] = res.aggregations[custom.field].value + diff --git a/app/assets/templates/admin/statistics/index.html.erb b/app/assets/templates/admin/statistics/index.html.erb index c3770b4d8..075fb6800 100644 --- a/app/assets/templates/admin/statistics/index.html.erb +++ b/app/assets/templates/admin/statistics/index.html.erb @@ -235,6 +235,7 @@
  • {{ 'revenue_' | translate }} {{sumCA | currency}}
  • {{ 'average_age' | translate }} {{averageAge}} {{ 'years_old' | translate }}
  • {{ 'total' | translate }} {{type.active.label}} : {{sumStat}}
  • +
  • {{ custom.field | translate }} : {{customAggs[custom.field]}}
  • diff --git a/app/views/api/statistics/index.json.jbuilder b/app/views/api/statistics/index.json.jbuilder index e5f78eedf..d0f638d66 100644 --- a/app/views/api/statistics/index.json.jbuilder +++ b/app/views/api/statistics/index.json.jbuilder @@ -5,6 +5,9 @@ json.array!(@statistics) do |s| end json.types s.statistic_types do |t| json.extract! t, :id, :key, :label, :graph, :simple + json.custom_aggregations t.statistic_custom_aggregations do |c| + json.extract! c, :id, :field + end json.subtypes t.statistic_sub_types do |st| json.extract! st, :id, :key, :label end