diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb
index b44182a9..c822747a 100644
--- a/app/controllers/stats_controller.rb
+++ b/app/controllers/stats_controller.rb
@@ -15,8 +15,8 @@ class StatsController < ApplicationController
@hidden_contexts = current_user.contexts.hidden
@actions = Stats::Actions.new(current_user)
@projects = Stats::Projects.new(current_user)
+ @contexts = Stats::Contexts.new(current_user)
- get_stats_contexts
get_stats_tags
end
@@ -387,18 +387,6 @@ class StatsController < ApplicationController
@cut_off_3months = 3.months.ago.beginning_of_day
end
- def get_stats_contexts
- @actions_per_context = Stats::TopContextsQuery.new(current_user, :limit => 5).result
- @running_actions_per_context = Stats::TopContextsQuery.new(current_user, :limit => 5, :running => true).result
-
- @context_charts = %w{
- context_total_actions_data
- context_running_actions_data
- }.map do |action|
- Stats::Chart.new(action, :height => 325)
- end
- end
-
def get_stats_tags
tags = Stats::TagCloudQuery.new(current_user).result
@tag_cloud = Stats::TagCloud.new(tags)
diff --git a/app/models/stats/contexts.rb b/app/models/stats/contexts.rb
new file mode 100644
index 00000000..1aa04e38
--- /dev/null
+++ b/app/models/stats/contexts.rb
@@ -0,0 +1,27 @@
+module Stats
+ class Contexts
+
+ attr_reader :user
+ def initialize(user)
+ @user = user
+ end
+
+ def actions
+ @actions ||= Stats::TopContextsQuery.new(user, :limit => 5).result
+ end
+
+ def running_actions
+ @running_actions ||= Stats::TopContextsQuery.new(user, :limit => 5, :running => true).result
+ end
+
+ def charts
+ @charts = %w{
+ context_total_actions_data
+ context_running_actions_data
+ }.map do |action|
+ Stats::Chart.new(action, :height => 325)
+ end
+ end
+
+ end
+end
diff --git a/app/models/stats/top_contexts_query.rb b/app/models/stats/top_contexts_query.rb
index 69a5e9e9..d47abfb1 100644
--- a/app/models/stats/top_contexts_query.rb
+++ b/app/models/stats/top_contexts_query.rb
@@ -1,5 +1,5 @@
-# Get action count for the top 5 contexts
-# If initialized with :running, then only active
+# Get action count for the top n contexts (default: all)
+# If initialized with :running => true, then only active
# and visible contexts will be included.
module Stats
class TopContextsQuery
diff --git a/app/views/stats/_contexts.html.erb b/app/views/stats/_contexts.html.erb
index 1bd8e419..2f9502e1 100755
--- a/app/views/stats/_contexts.html.erb
+++ b/app/views/stats/_contexts.html.erb
@@ -1,9 +1,10 @@
-<% @context_charts.each do |chart| %><%=
+<% contexts.charts.each do |chart| %><%=
render :partial => 'chart', :locals => {:chart => chart}
-%><% end %>
-<%= render :partial => 'contexts_list', :locals => {:contexts => @actions_per_context, :key => 'contexts'} -%>
+<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.actions, :key => 'contexts'} -%>
+
+<%= render :partial => 'contexts_list', :locals => {:contexts => contexts.running_actions, :key => 'visible_contexts_with_incomplete_actions'} -%>
-<%= render :partial => 'contexts_list', :locals => {:contexts => @running_actions_per_context, :key => 'visible_contexts_with_incomplete_actions'} -%>
diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb
index f40f1dd3..65f7392a 100755
--- a/app/views/stats/index.html.erb
+++ b/app/views/stats/index.html.erb
@@ -9,7 +9,7 @@
<%= render :partial => 'actions', :locals => {:actions => @actions} -%>