Commit bc18101438377a4d768b7de767fe5f6e75cd6e53
1 parent
eac71f92
Exists in
master
and in
11 other branches
proposals_discussion: fill graph with days that has no proposals/comments
Showing
1 changed file
with
12 additions
and
2 deletions
Show diff stats
lib/proposals_discussion_plugin/topic.rb
| ... | ... | @@ -44,11 +44,21 @@ class ProposalsDiscussionPlugin::Topic < Folder |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 46 | def proposals_per_day |
| 47 | - proposals.group("date(created_at)").count | |
| 47 | + result = proposals.group("date(created_at)").count | |
| 48 | + fill_empty_days(result) | |
| 48 | 49 | end |
| 49 | 50 | |
| 50 | 51 | def comments_per_day |
| 51 | - proposals.joins(:comments).group('date(comments.created_at)').count('comments.id') | |
| 52 | + result = proposals.joins(:comments).group('date(comments.created_at)').count('comments.id') | |
| 53 | + fill_empty_days(result) | |
| 54 | + end | |
| 55 | + | |
| 56 | + def fill_empty_days(result) | |
| 57 | + from = created_at.to_date | |
| 58 | + (from..Date.today).inject({}) do |h, date| | |
| 59 | + h[date.to_s] = result[date.to_s] || 0 | |
| 60 | + h | |
| 61 | + end | |
| 52 | 62 | end |
| 53 | 63 | |
| 54 | 64 | def cache_key_with_person(params = {}, user = nil, language = 'en') | ... | ... |