De-dupe pie chart view

Pull logic into the controller from the view. There were only a couple
of tiny differences between the running actions and the total actions
view, so I added a couple of instance variables and then called the same
template twice.
This commit is contained in:
Katrina Owen 2013-03-17 19:38:57 -06:00
parent 0cd6656be2
commit 6e2f1a8e5f
4 changed files with 19 additions and 32 deletions

View file

@ -179,17 +179,21 @@ class StatsController < ApplicationController
def context_total_actions_data
all_actions_per_context = Stats::TopContextsQuery.new(current_user).result
@title = t('stats.spread_of_actions_for_all_context')
@alpha = 70
prep_context_data_for_view(all_actions_per_context)
render :layout => false
render :pie_chart_data, :layout => false
end
def context_running_actions_data
all_actions_per_context = Stats::TopContextsQuery.new(current_user, :running => true).result
@title = t('stats.spread_of_running_actions_for_visible_contexts')
@alpha = 60
prep_context_data_for_view(all_actions_per_context)
render :layout => false
render :pie_chart_data, :layout => false
end
def actions_day_of_week_all_data
@ -363,6 +367,10 @@ class StatsController < ApplicationController
end
@truncate_chars = 15
@pie_slices = Array.new(size){|i| @actions_per_context[i]['total'].to_i*100/@sum }
@pie_labels = Array.new(size){|i| @actions_per_context[i]['name'].truncate(@truncate_chars, :omission => '...') }
@pie_links = Array.new(size){|i| context_path(@actions_per_context[i]['id'])}
end
def init