From 729abb50fddbb6f59b06e939f481b963abbbe2dc Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 2 Feb 2020 22:48:46 +0100 Subject: [PATCH] only show metrics in meta if count > 0. #390 --- app/controllers/concerns/facetable.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/facetable.rb b/app/controllers/concerns/facetable.rb index 77f23a67c..2fef2498e 100644 --- a/app/controllers/concerns/facetable.rb +++ b/app/controllers/concerns/facetable.rb @@ -34,10 +34,16 @@ def facet_by_year(arr) end def metric_facet_by_year(arr) - arr.map do |hsh| - { "id" => hsh["key_as_string"][0..3], - "title" => hsh["key_as_string"][0..3], - "count" => hsh.dig("metric_count", "value").to_i } + arr.reduce([]) do |sum, hsh| + if hsh.dig("metric_count", "value").to_i > 0 + sum << { + "id" => hsh["key_as_string"][0..3], + "title" => hsh["key_as_string"][0..3], + "count" => hsh.dig("metric_count", "value").to_i + } + end + + sum end end