summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-07 20:42:28 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-07 20:42:28 +0000
commit63ceea2e218367f4043580c15288c54ddc225114 (patch)
treeafedaf8e1b6a4086fb1682a441940bf2f938ff37
parentad68a82be19f44c8e9ab895075a4e932133ad6ee (diff)
downloadredmine-63ceea2e218367f4043580c15288c54ddc225114.tar.gz
redmine-63ceea2e218367f4043580c15288c54ddc225114.zip
Custom fields can now be displayed as columns on the issue list.
Custom fields marked as "for all projects" can be added to the default columns of the issue list (in application settings). Project specific custom fields can be displayed on custom queries. git-svn-id: http://redmine.rubyforge.org/svn/trunk@889 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/queries_helper.rb29
-rw-r--r--app/models/query.rb29
-rw-r--r--app/views/queries/_columns.rhtml4
-rw-r--r--app/views/settings/edit.rhtml4
4 files changed, 46 insertions, 20 deletions
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 786932855..6e5511f08 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -22,24 +22,25 @@ module QueriesHelper
end
def column_header(column)
- if column.sortable
- sort_header_tag(column.sortable, :caption => l("field_#{column.name}"))
- else
- content_tag('th', l("field_#{column.name}"))
- end
+ column.sortable ? sort_header_tag(column.sortable, :caption => column.caption) : content_tag('th', column.caption)
end
def column_content(column, issue)
- value = issue.send(column.name)
- if value.is_a?(Date)
- format_date(value)
- elsif value.is_a?(Time)
- format_time(value)
- elsif column.name == :subject
- ((@project.nil? || @project != issue.project) ? "#{issue.project.name} - " : '') +
- link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
+ if column.is_a?(QueryCustomFieldColumn)
+ cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
+ show_value(cv)
else
- h(value)
+ value = issue.send(column.name)
+ if value.is_a?(Date)
+ format_date(value)
+ elsif value.is_a?(Time)
+ format_time(value)
+ elsif column.name == :subject
+ ((@project.nil? || @project != issue.project) ? "#{issue.project.name} - " : '') +
+ link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
+ else
+ h(value)
+ end
end
end
end
diff --git a/app/models/query.rb b/app/models/query.rb
index db8906525..6e8654567 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -17,13 +17,33 @@
class QueryColumn
attr_accessor :name, :sortable
+ include GLoc
def initialize(name, options={})
self.name = name
self.sortable = options[:sortable]
end
- def default?; default end
+ def caption
+ l("field_#{name}")
+ end
+end
+
+class QueryCustomFieldColumn < QueryColumn
+
+ def initialize(custom_field)
+ self.name = "cf_#{custom_field.id}".to_sym
+ self.sortable = false
+ @cf = custom_field
+ end
+
+ def caption
+ @cf.name
+ end
+
+ def custom_field
+ @cf
+ end
end
class Query < ActiveRecord::Base
@@ -203,7 +223,12 @@ class Query < ActiveRecord::Base
end
def available_columns
- cols = Query.available_columns
+ return @available_columns if @available_columns
+ @available_columns = Query.available_columns
+ @available_columns += (project ?
+ project.custom_fields :
+ IssueCustomField.find(:all, :conditions => {:is_for_all => true})
+ ).collect {|cf| QueryCustomFieldColumn.new(cf) }
end
def columns
diff --git a/app/views/queries/_columns.rhtml b/app/views/queries/_columns.rhtml
index b03a3277d..8d3da7f6a 100644
--- a/app/views/queries/_columns.rhtml
+++ b/app/views/queries/_columns.rhtml
@@ -5,7 +5,7 @@
<table margin=0>
<tr>
<td><%= select_tag 'available_columns',
- options_for_select((query.available_columns - query.columns).collect {|column| [l("field_#{column.name}"), column.name]}),
+ options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
:multiple => true, :size => 10, :style => "width:150px" %>
</td>
<td align="center" valign="middle">
@@ -15,7 +15,7 @@
onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
</td>
<td><%= select_tag 'query[column_names][]',
- options_for_select(@query.columns.collect {|column| [l("field_#{column.name}"), column.name]}),
+ options_for_select(@query.columns.collect {|column| [column.caption, column.name]}),
:id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
</td>
</tr>
diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml
index d3f994d4f..b08b707bf 100644
--- a/app/views/settings/edit.rhtml
+++ b/app/views/settings/edit.rhtml
@@ -61,9 +61,9 @@
<fieldset class="box"><legend><%= l(:setting_issue_list_default_columns) %></legend>
<%= hidden_field_tag 'settings[issue_list_default_columns][]', '' %>
-<p><% Query.available_columns.each do |column| %>
+<p><% Query.new.available_columns.each do |column| %>
<label><%= check_box_tag 'settings[issue_list_default_columns][]', column.name, Setting.issue_list_default_columns.include?(column.name.to_s) %>
- <%= l("field_#{column.name}") %></label>
+ <%= column.caption %></label>
<% end %></p>
</fieldset>