From bc18101438377a4d768b7de767fe5f6e75cd6e53 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 6 Oct 2014 15:50:38 -0300 Subject: [PATCH] proposals_discussion: fill graph with days that has no proposals/comments --- lib/proposals_discussion_plugin/topic.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/proposals_discussion_plugin/topic.rb b/lib/proposals_discussion_plugin/topic.rb index 9b9219c..57ace32 100644 --- a/lib/proposals_discussion_plugin/topic.rb +++ b/lib/proposals_discussion_plugin/topic.rb @@ -44,11 +44,21 @@ class ProposalsDiscussionPlugin::Topic < Folder end def proposals_per_day - proposals.group("date(created_at)").count + result = proposals.group("date(created_at)").count + fill_empty_days(result) end def comments_per_day - proposals.joins(:comments).group('date(comments.created_at)').count('comments.id') + result = proposals.joins(:comments).group('date(comments.created_at)').count('comments.id') + fill_empty_days(result) + end + + def fill_empty_days(result) + from = created_at.to_date + (from..Date.today).inject({}) do |h, date| + h[date.to_s] = result[date.to_s] || 0 + h + end end def cache_key_with_person(params = {}, user = nil, language = 'en') -- libgit2 0.21.2