From 07ba1e3458dedfa12d2743531f80d96c131487ac Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 18 Oct 2018 18:26:37 +0200 Subject: [PATCH] correctly count deleted clients and providers. #118 --- app/controllers/concerns/countable.rb | 10 +++++----- app/models/concerns/indexable.rb | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/countable.rb b/app/controllers/concerns/countable.rb index 0fb1196e9..4e5ae65a3 100644 --- a/app/controllers/concerns/countable.rb +++ b/app/controllers/concerns/countable.rb @@ -11,7 +11,7 @@ def doi_count(client_id: nil, provider_id: nil) response = Doi.query(nil, page: { number: 1, size: 0 }) end - response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil + response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : [] end # cumulative count clients by year @@ -21,10 +21,10 @@ def client_count(provider_id: nil) if provider_id response = Client.query(nil, provider_id: provider_id, include_deleted: true, page: { number: 1, size: 0 }) else - response = Client.query(nil, page: { number: 1, size: 0 }) + response = Client.query(nil, include_deleted: true, page: { number: 1, size: 0 }) end - response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : nil + response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : [] end # show provider count for admin @@ -32,8 +32,8 @@ def client_count(provider_id: nil) def provider_count(provider_id: nil) return nil if provider_id - response = Provider.query(nil, page: { number: 1, size: 0 }) - response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : nil + response = Provider.query(nil, include_deleted: true, page: { number: 1, size: 0 }) + response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : [] end end end diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 26813b77f..3610af70e 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -131,10 +131,10 @@ def query(query, options={}) must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present? must << { term: { region: options[:region].upcase }} if options[:region].present? must << { term: { role_name: "ROLE_ALLOCATOR" }} unless options[:all_members] - must_not << { exists: { field: "deleted_at" }} + must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted] elsif self.name == "Client" must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present? - must_not << { exists: { field: "deleted_at" }} + must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted] elsif self.name == "Doi" must << { range: { published: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present? end