From 8024510d81736207b9c870823bad03e86d74f1d5 Mon Sep 17 00:00:00 2001 From: rkh Date: Thu, 29 Oct 2009 09:44:43 +0000 Subject: [PATCH] proper display of group_by group names git-svn-id: https://dev.finn.de/svn/cockpit/trunk@239 7926756e-e54e-46e6-9721-ed318f58905e --- app/models/cost_query.rb | 18 ++++++++++++++++-- app/views/cost_reports/_list_group_by.rhtml | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/models/cost_query.rb b/app/models/cost_query.rb index 03210fb883..a3e95da225 100644 --- a/app/models/cost_query.rb +++ b/app/models/cost_query.rb @@ -237,14 +237,28 @@ class CostQuery < ActiveRecord::Base def self.group_by_columns @group_by_columns ||= {} end + + def self.get_name(key, value) + data = group_by_columns[key.to_sym] + return value unless data + data[:display] ||= from_field($1.classify, :name) if key.to_s =~ /^(.+)_id$/ + data[:display].call value + end + + def self.from_field(klass, field) + Proc.new do |id| + a = klass.find_by_id(id) + (a ? a.send(field) : id).to_s + end + end grouping_scope(:issues) do grouping_column(:tracker_id, :fixed_version_id, :subproject_id) end grouping_scope(:costs) do - grouping_column(:user_id, :issue_id, :cost_type_id) - grouping_column(:activity_id, :display => Proc.new {|id|a = Enumeration.find_by_id(id); a ? a.name : id }) + grouping_column :user_id, :issue_id, :cost_type_id + grouping_column :activity_id, :display => from_field(Enumeration, :name) grouping_column(:spent_on, :tyear, :tmonth, :tweek, :time => true) do |column, fields| values = [] diff --git a/app/views/cost_reports/_list_group_by.rhtml b/app/views/cost_reports/_list_group_by.rhtml index 91e583368d..1e88a96ee8 100644 --- a/app/views/cost_reports/_list_group_by.rhtml +++ b/app/views/cost_reports/_list_group_by.rhtml @@ -38,11 +38,15 @@ filter_js = {:filters => {(@query.filters ? @query.filters.length : 0) => filter}}.to_query end group_by = {:group_by=>{:name=>"", :granularity=>"year"}} + + name = entry.map { |k, v| CostQuery.get_name(k, v) unless %w[count sum].include? k.to_s }.join(" ") + name.strip! + name = "Not part of any group" # FIXME %> - <%= entry.map { |k, v| v unless %w[count sum].include? k.to_s }.join(" ") %> + <%= name %> <%= entry["count"] %> Entries <%= number_to_currency(entry["sum"]) %>