diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb index 2c3e500a5..186f242be 100644 --- a/app/helpers/timelog_helper.rb +++ b/app/helpers/timelog_helper.rb @@ -125,4 +125,26 @@ module TimelogHelper cancel_button_tag(fallback_path) end + def report_to_chart_datas(report, period_name='month') + return {} if report.periods.nil? + chart_datas = {} + + chart_datas[period_name] = { :labels => [], :type => 'bar', :datasets => [{:data => []}] } + report.periods.each do |period| + chart_datas[period_name][:labels] << period + chart_datas[period_name][:datasets].first[:data] << sum_hours(select_hours(report.hours, report.columns, period.to_s)) + end + + report.criteria.each_with_index do |criteria, level| + chart_datas[criteria] = { :labels => [], :type => 'horizontalBar', :datasets => [{:data => []}]} + report.hours.collect {|h| h[criteria]}.uniq.each do |value| + hours_for_value = select_hours(report.hours, criteria, value) + next if hours_for_value.empty? + chart_datas[criteria][:labels] << format_criteria_value(report.available_criteria[report.criteria[level]], value, false).to_s + chart_datas[criteria][:datasets].first[:data] << report.periods.collect {|period| sum_hours(select_hours(hours_for_value, report.columns, period.to_s)) }.sum + end + end + + chart_datas + end end diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb index ee6f0f83b..f6998d1f3 100644 --- a/app/views/timelog/report.html.erb +++ b/app/views/timelog/report.html.erb @@ -14,6 +14,7 @@ <%= hidden_field_tag 'criteria[]', criterion, :id => nil %> <% end %> <%= render :partial => 'timelog/date_range' %> +

<%= link_to l(:label_statistics), '#', :onclick => "showAndScrollTo('timelog_chart')", :class => 'icon icon-stats' if @report.criteria.any? && @report.hours.any? %>

: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'], [l(:label_month), 'month'], @@ -68,6 +69,7 @@ <% other_formats_links do |f| %> <%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '330px'); return false;" %> <% end %> +

<% end %>