proper display of group_by group names

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@239 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
rkh 15 years ago
parent 9abfdd20a5
commit 8024510d81
  1. 18
      app/models/cost_query.rb
  2. 6
      app/views/cost_reports/_list_group_by.rhtml

@ -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 = []

@ -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 = "<i>Not part of any group</i>" # FIXME
%>
<tr>
<td>
<%= entry.map { |k, v| v unless %w[count sum].include? k.to_s }.join(" ") %>
<%= name %>
</td>
<td><%= entry["count"] %> Entries</td>
<td class="currency"><%= number_to_currency(entry["sum"]) %></td>

Loading…
Cancel
Save