diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 1c0b59570..786932855 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -1,6 +1,45 @@ -module QueriesHelper +# redMine - project management software +# Copyright (C) 2006-2007 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +module QueriesHelper + def operators_for_select(filter_type) Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} 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 + 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) + else + h(value) + end + end end diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index c4f0f98cb..46d350a21 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -37,6 +37,8 @@ class Enumeration < ActiveRecord::Base OPTIONS[self.opt] end + def to_s; name end + private def check_integrity case self.opt diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb index b184c132f..9478504f1 100644 --- a/app/models/issue_category.rb +++ b/app/models/issue_category.rb @@ -34,4 +34,6 @@ class IssueCategory < ActiveRecord::Base end destroy_without_reassign end + + def to_s; name end end diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 13ed27f6c..3929c6774 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -51,7 +51,9 @@ class IssueStatus < ActiveRecord::Base :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status }.compact if role && tracker new_statuses ? new_statuses.sort{|x, y| x.position <=> y.position } : [] end - + + def to_s; name end + private def check_integrity raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) diff --git a/app/models/query.rb b/app/models/query.rb index 11460c1cb..c3d9d56e3 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -15,10 +15,23 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +class QueryColumn + attr_accessor :name, :sortable, :default + + def initialize(name, options={}) + self.name = name + self.sortable = options[:sortable] + self.default = options[:default] + end + + def default?; default end +end + class Query < ActiveRecord::Base belongs_to :project belongs_to :user serialize :filters + serialize :column_names attr_protected :project, :user attr_accessor :executed_by @@ -59,6 +72,22 @@ class Query < ActiveRecord::Base cattr_reader :operators_by_filter_type + @@available_columns = [ + QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :default => true), + QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :default => true), + QueryColumn.new(:priority, :sortable => "#{Issue.table_name}.priority_id", :default => true), + QueryColumn.new(:subject, :default => true), + QueryColumn.new(:assigned_to, :sortable => "#{User.table_name}.lastname", :default => true), + QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default => true), + QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"), + QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"), + QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"), + QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"), + QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"), + QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on"), + ] + cattr_reader :available_columns + def initialize(attributes = nil) super attributes self.filters ||= { 'status_id' => {:operator => "o", :values => [""]} } @@ -173,7 +202,30 @@ class Query < ActiveRecord::Base label = @available_filters[field][:name] if @available_filters.has_key?(field) label ||= field.gsub(/\_id$/, "") end + + def available_columns + cols = Query.available_columns + end + def columns + if column_names && !column_names.empty? + available_columns.select {|c| column_names.include?(c.name) } + else + # default columns + available_columns.select {|c| c.default? } + end + end + + def column_names=(names) + names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names + names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names + write_attribute(:column_names, names) + end + + def has_column?(column) + column_names && column_names.include?(column.name) + end + def statement # project/subprojects clause clause = '' diff --git a/app/models/tracker.rb b/app/models/tracker.rb index c024c0911..90ef31912 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -27,6 +27,8 @@ class Tracker < ActiveRecord::Base validates_length_of :name, :maximum => 30 validates_format_of :name, :with => /^[\w\s\'\-]*$/i + def to_s; name end + private def check_integrity raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) diff --git a/app/views/issues/_list.rhtml b/app/views/issues/_list.rhtml new file mode 100644 index 000000000..0af415946 --- /dev/null +++ b/app/views/issues/_list.rhtml @@ -0,0 +1,20 @@ +
+ <%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %> + <% query.columns.each do |column| %> + <%= column_header(column) %> + <% end %> + | |
---|---|
<%= check_box_tag "issue_ids[]", issue.id, false, :id => "issue_#{issue.id}" %> | +<%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %> | + <% query.columns.each do |column| %> + <%= content_tag 'td', column_content(column, issue), :class => column.name %> + <% end %> +
<%= l(:label_no_data) %>
<% else %> -<%=l(:field_subject)%> | - <%= sort_header_tag("#{User.table_name}.lastname", :caption => l(:field_assigned_to)) %> - <%= sort_header_tag("#{Issue.table_name}.updated_on", :caption => l(:field_updated_on)) %> -|||||||
---|---|---|---|---|---|---|---|
<%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %> | -<%=h issue.project.name %> | -<%= issue.tracker.name %> | -<%= issue.status.name %> | -<%= issue.priority.name %> | -<%= link_to h(issue.subject), :controller => 'issues', :action => 'show', :id => issue %> | -<%= issue.assigned_to.name if issue.assigned_to %> | -<%= format_time(issue.updated_on) %> | -
<%= pagination_links_full @issue_pages %> [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]
<% end %> diff --git a/app/views/projects/list_issues.rhtml b/app/views/projects/list_issues.rhtml index e17e8bc37..3c90c30f9 100644 --- a/app/views/projects/list_issues.rhtml +++ b/app/views/projects/list_issues.rhtml @@ -45,32 +45,7 @@ <% else %> <% form_tag({:controller => 'projects', :action => 'move_issues', :id => @project}, :id => 'issues_form' ) do %> -- <%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %> - <%= sort_header_tag("#{Issue.table_name}.tracker_id", :caption => l(:field_tracker)) %> - <%= sort_header_tag("#{IssueStatus.table_name}.name", :caption => l(:field_status)) %> - <%= sort_header_tag("#{Issue.table_name}.priority_id", :caption => l(:field_priority)) %> - | <%=l(:field_subject)%> | - <%= sort_header_tag("#{User.table_name}.lastname", :caption => l(:field_assigned_to)) %> - <%= sort_header_tag("#{Issue.table_name}.updated_on", :caption => l(:field_updated_on)) %> -||||||
---|---|---|---|---|---|---|---|
<%= check_box_tag "issue_ids[]", issue.id, false, :id => "issue_#{issue.id}" %> | -<%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %> | -<%= issue.tracker.name %> | -<%= issue.status.name %> | -<%= issue.priority.name %> | -<%= "#{issue.project.name} - " unless @project && @project == issue.project %><%= link_to h(issue.subject), :controller => 'issues', :action => 'show', :id => issue %> | -<%= issue.assigned_to.name if issue.assigned_to %> | -<%= format_time(issue.updated_on) %> | -
<%= check_box 'query', 'is_public' %>
<% end %> + +
+<% @query.available_columns.each do |column| %>
+<%= check_box_tag 'query[column_names][]', column.name, @query.has_column?(column) %> <%= l("field_#{column.name}") %>
+<% end %>
+<%= hidden_field_tag 'query[column_names][]', '' %>
+