Module: ActiveAdminBbs::Dashboard

Defined in:
lib/active_admin_bbs/dashboard.rb

Class Method Summary collapse

Class Method Details

.cumulate(count) ⇒ Object


61
62
63
64
65
66
67
# File 'lib/active_admin_bbs/dashboard.rb', line 61

def cumulate(count)
  total = 0

  count.to_a.sort {|day, value| day[0] <=> value[0] }
    .map {|day, value| {day => (total += value)}}
    .reduce({}, :merge)
end

.included(dsl) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_admin_bbs/dashboard.rb', line 3

def self.included(dsl)
  dsl.instance_eval do
    content title: I18n.t('active_admin_bbs.dashboard.chart.title') do
      columns do
        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.user_count') do
            div do
              span Bbs.config.user_class.count
            end
          end
        end

        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.topic_count') do
            div do
              span Bbs::Topic.count
            end
          end
        end

        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.comment_count') do
            div do
              span Bbs::Comment.count
            end
          end
        end
      end

      columns do
        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.user_count_by_day') do
            line_chart ActiveAdminBbs::Dashboard::cumulate(Bbs.config.user_class.group_by_day(:created_at).count)
          end
        end
      end

      columns do
        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.topic_count_by_day') do
            line_chart ActiveAdminBbs::Dashboard::cumulate(Bbs::Topic.group_by_day(:created_at).count)
          end
        end
      end

      columns do
        column do
          panel I18n.t('active_admin_bbs.dashboard.chart.comment_count_by_day') do
            line_chart ActiveAdminBbs::Dashboard::cumulate(Bbs::Comment.group_by_day(:created_at).count)
          end
        end
      end
    end
  end
end