diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 5180ef63..15ded4a9 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -8,15 +8,7 @@ class StatsController < ApplicationController def index @page_title = t('stats.index_title') @hidden_contexts = current_user.contexts.hidden - @actions = Stats::Actions.new(current_user) - @totals = Stats::Totals.new(current_user) - @projects = Stats::Projects.new(current_user) - @contexts = Stats::Contexts.new(current_user) - tags = Stats::TagCloudQuery.new(current_user).result - @tag_cloud = Stats::TagCloud.new(tags) - cutoff = 3.months.ago.beginning_of_day - tags = Stats::TagCloudQuery.new(current_user, cutoff).result - @tag_cloud_90days = Stats::TagCloud.new(tags) + @stats = Stats::IndexPage.new(current_user) end def actions_done_last12months_data diff --git a/app/models/stats/index_page.rb b/app/models/stats/index_page.rb new file mode 100644 index 00000000..0fabe7b1 --- /dev/null +++ b/app/models/stats/index_page.rb @@ -0,0 +1,43 @@ +module Stats + class IndexPage + + attr_reader :user + def initialize(user) + @user = user + end + + def actions + @actions ||= Stats::Actions.new(user) + end + + def totals + @totals ||= Stats::Totals.new(user) + end + + def projects + @projects ||= Stats::Projects.new(user) + end + + def contexts + @contexts ||= Stats::Contexts.new(user) + end + + def tag_cloud + unless @tag_cloud + tags = Stats::TagCloudQuery.new(user).result + @tag_cloud = Stats::TagCloud.new(tags) + end + @tag_cloud + end + + def tag_cloud_90days + unless @tag_cloud_90days + cutoff = 3.months.ago.beginning_of_day + tags = Stats::TagCloudQuery.new(user, cutoff).result + @tag_cloud_90days = Stats::TagCloud.new(tags) + end + @tag_cloud_90days + end + + end +end diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb index 1dff44c2..44c4f458 100755 --- a/app/views/stats/index.html.erb +++ b/app/views/stats/index.html.erb @@ -1,22 +1,22 @@

<%= t('stats.totals') %>

- <%= render :partial => 'totals', :locals => {:totals => @totals} -%> + <%= render :partial => 'totals', :locals => {:totals => @stats.totals} -%> <% unless current_user.todos.empty? -%>

<%= t('stats.actions') %>

- <%= render :partial => 'actions', :locals => {:actions => @actions} -%> + <%= render :partial => 'actions', :locals => {:actions => @stats.actions} -%>

<%= t('stats.contexts') %>

- <%= render :partial => 'contexts', :locals => {:contexts => @contexts} -%> + <%= render :partial => 'contexts', :locals => {:contexts => @stats.contexts} -%>

<%= t('stats.projects') %>

- <%= render :partial => 'projects', :locals => {:projects => @projects} -%> + <%= render :partial => 'projects', :locals => {:projects => @stats.projects} -%>

<%= t('stats.tags') %>

- <%= render :partial => 'tags', :locals => {:tag_cloud => @tag_cloud, :key => ''} -%> - <%= render :partial => 'tags', :locals => {:tag_cloud => @tag_cloud_90days, :key => '_90days'} -%> + <%= render :partial => 'tags', :locals => {:tag_cloud => @stats.tag_cloud, :key => ''} -%> + <%= render :partial => 'tags', :locals => {:tag_cloud => @stats.tag_cloud_90days, :key => '_90days'} -%> <% else -%>