From 3babc05a2d2cdf6bae9734bae05c54632321b8a9 Mon Sep 17 00:00:00 2001 From: Don Cruse Date: Thu, 18 Jul 2013 23:56:57 -0500 Subject: [PATCH] Moving time labels to separate methods --- app/controllers/stats_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 405aafbd..2ba4eb7e 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -36,7 +36,7 @@ class StatsController < ApplicationController @created_count_array = Array.new(13, actions_last12months.created_after(@cut_off_year).count/12.0) @done_count_array = Array.new(13, actions_last12months.completed_after(@cut_off_year).count/12.0) - @month_names = Array.new(13){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]} + @month_names = Array.new(13){ |i| label_for_month_ago(i) } render :layout => false end @@ -48,6 +48,14 @@ class StatsController < ApplicationController Time.zone.now.day / Time.zone.now.end_of_month.day.to_f end + def label_for_month_and_year_ago(i) + t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.now - i.months).year.to_s + end + + def label_for_month_ago(i) + t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ] + end + def actions_done_last_years @page_title = t('stats.index_title') @chart = Stats::Chart.new('actions_done_lastyears_data', :height => 400, :width => 900) @@ -77,7 +85,7 @@ class StatsController < ApplicationController @created_count_array = Array.new(month_count+1, actions_last_months.select { |x| x.created_at }.size/month_count) @done_count_array = Array.new(month_count+1, actions_last_months.select { |x| x.completed_at }.size/month_count) - @month_names = Array.new(month_count+1){ |i| t('date.month_names')[ (Time.now.mon - i -1 ) % 12 + 1 ]+ " " + (Time.now - i.months).year.to_s} + @month_names = Array.new(month_count+1){ |i| label_for_month_and_year_ago(i) } render :layout => false end