git-svn-id: http://redmine.rubyforge.org/svn/trunk@6 e93f8b46-1217-0410-a6f0-8f06a7374b81

This commit is contained in:
Jean-Philippe Lang 2006-07-03 19:38:10 +00:00
parent b1ede59d02
commit 366ca57c36
5 changed files with 147 additions and 84 deletions

View File

@ -186,24 +186,42 @@ class ProjectsController < ApplicationController
sort_init 'issues.id', 'desc'
sort_update
search_filter_criteria 'issues.tracker_id', :values => "Tracker.find(:all)"
search_filter_criteria 'issues.priority_id', :values => "Enumeration.find(:all, :conditions => ['opt=?','IPRI'])"
search_filter_criteria 'issues.category_id', :values => "@project.issue_categories"
search_filter_criteria 'issues.status_id', :values => "IssueStatus.find(:all)"
search_filter_criteria 'issues.author_id', :values => "User.find(:all)", :label => "display_name"
search_filter_init_list_issues
search_filter_update if params[:set_filter] or request.post?
@issue_count = @project.issues.count(search_filter_clause)
@issue_pages = Paginator.new self, @issue_count,
15,
@params['page']
@issues = @project.issues.find :all, :order => sort_clause,
@issue_count = Issue.count(:include => :status, :conditions => search_filter_clause)
@issue_pages = Paginator.new self, @issue_count, 15, @params['page']
@issues = Issue.find :all, :order => sort_clause,
:include => [ :author, :status, :tracker ],
:conditions => search_filter_clause,
:limit => @issue_pages.items_per_page,
:offset => @issue_pages.current.offset
end
# Export filtered/sorted issues list to CSV
def export_issues_csv
sort_init 'issues.id', 'desc'
sort_update
search_filter_init_list_issues
@issues = Issue.find :all, :order => sort_clause,
:include => [ :author, :status, :tracker ],
:conditions => search_filter_clause
export = StringIO.new
CSV::Writer.generate(export, ',') do |csv|
csv << %w(Id Status Tracker Subject Author Created Updated)
@issues.each do |issue|
csv << [issue.id, issue.status.name, issue.tracker.name, issue.subject, issue.author.display_name, _('(time)', issue.created_on), _('(time)', issue.updated_on)]
end
end
export.rewind
send_data(export.read,
:type => 'text/csv; charset=utf-8; header=present',
:filename => 'export.csv')
end
# Add a news to @project
def add_news
@news = @project.news.build(params[:news])

View File

@ -17,39 +17,69 @@
module SearchFilterHelper
def search_filter_criteria(field, options = {})
def search_filter_criteria(name, options = {})
session[:search_filter] ||= {}
session[:search_filter][field] ||= options
# session[:search_filter][field][:values] = options[:values] unless options[:values].nil?
# session[:search_filter][field][:label] = options[:label] unless options[:label].nil?
session[:search_filter][name] ||= {}
unless session[:search_filter][name][:options] and session[:search_filter][name][:conditions]
session[:search_filter][name][:options] = []
session[:search_filter][name][:conditions] = {}
yield.each { |c|
session[:search_filter][name][:options] << [c[0], c[1].to_s]
session[:search_filter][name][:conditions].store(c[1].to_s, c[2])
}
end
end
def search_filter_update
session[:search_filter].each_key {|field| session[:search_filter][field][:value] = params[field] }
#@search_filter[:value] = params[@search_filter[:field]]
end
def search_filter_clause
clause = "1=1"
session[:search_filter].each {|field, criteria| clause = clause + " AND " + field + "='" + session[:search_filter][field][:value] + "'" unless session[:search_filter][field][:value].nil? || session[:search_filter][field][:value].empty? }
clause = ["issues.project_id=?", @project.id]
session[:search_filter].each { |k, v|
v[:value] ||= v[:options][0][1]
if (!v[:conditions][v[:value]][0].empty?)
clause[0] = clause[0] + " AND " + v[:conditions][v[:value]][0]
clause << v[:conditions][v[:value]][1] if !v[:conditions][v[:value]][1].nil?
end
}
clause
#@search_filter[:field] + "='" + @search_filter[:value] + "'" unless @search_filter[:value].nil? || @search_filter[:value].empty?
end
def search_filter_tag(field)
option_values = []
#values = eval @search_filter[:values_expr]
option_values = eval session[:search_filter][field][:values]
def search_filter_tag(criteria)
content_tag("select",
content_tag("option", "[All]", :value => "") +
options_from_collection_for_select(option_values,
"id",
session[:search_filter][field][:label] || "name",
session[:search_filter][field][:value].to_i
),
:name => field
options_for_select(session[:search_filter][criteria][:options], session[:search_filter][criteria][:value]),
:name => criteria
)
end
def search_filter_init_list_issues
search_filter_criteria('status_id') {
[ ["[Open]", "O", ["issue_statuses.is_closed=?", false]],
["[All]", "A", ["", false]]
] + IssueStatus.find(:all).collect {|s| [s.name, s.id, ["issues.status_id=?", s.id]] }
}
search_filter_criteria('tracker_id') {
[ ["[All]", "A", ["", false]]
] + Tracker.find(:all).collect {|s| [s.name, s.id, ["issues.tracker_id=?", s.id]] }
}
search_filter_criteria('priority_id') {
[ ["[All]", "A", ["", false]]
] + Enumeration.find(:all, :conditions => ['opt=?','IPRI']).collect {|s| [s.name, s.id, ["issues.priority_id=?", s.id]] }
}
search_filter_criteria('category_id') {
[ ["[All]", "A", ["", false]],
["[None]", "N", ["issues.category_id is null"]]
] + @project.issue_categories.find(:all).collect {|s| [s.name, s.id, ["issues.category_id=?", s.id]] }
}
search_filter_criteria('assigned_to_id') {
[ ["[All]", "A", ["", false]],
["[Nobody]", "N", ["issues.assigned_to_id is null"]]
] + User.find(:all).collect {|s| [s.display_name, s.id, ["issues.assigned_to_id=?", s.id]] }
}
end
end

View File

@ -3,11 +3,11 @@
<form method="post" class="noborder">
<table cellpadding=2>
<tr>
<td><%=_('Status')%>:<br /><%= search_filter_tag("issues.status_id") %></td>
<td><%=_('Tracker')%>:<br /><%= search_filter_tag("issues.tracker_id") %></td>
<td><%=_('Priority')%>:<br /><%= search_filter_tag("issues.priority_id") %></td>
<td><%=_('Category')%>:<br /><%= search_filter_tag("issues.category_id") %></td>
<td><%=_('Author')%>:<br /><%= search_filter_tag("issues.author_id") %></td>
<td><%=_('Status')%>:<br /><%= search_filter_tag("status_id") %></td>
<td><%=_('Tracker')%>:<br /><%= search_filter_tag("tracker_id") %></td>
<td><%=_('Priority')%>:<br /><%= search_filter_tag("priority_id") %></td>
<td><%=_('Category')%>:<br /><%= search_filter_tag("category_id") %></td>
<td><%=_('Assigned to')%>:<br /><%= search_filter_tag("assigned_to_id") %></td>
<td valign="bottom">
<%= submit_tag _('Apply filter') %>
<%= end_form_tag %>
@ -18,11 +18,13 @@
</td>
</tr>
</table>
&nbsp;
<table border="0" cellspacing="1" cellpadding="2" class="listTableContent">
<tr><td colspan="7" align="right">
<small><%= link_to 'Export to CSV', :action => 'export_issues_csv', :id => @project.id %></small>
</td></tr>
<tr class="ListHead">
<%= sort_header_tag('issues.id', :caption => '#') %>
<%= sort_header_tag('issue_statuses.name', :caption => _('Status')) %>

View File

@ -15,20 +15,25 @@
<tr style="background-color:#CEE1ED">
<td><%= link_to row.name, :controller => 'projects', :action => 'list_issues', :id => @project,
:set_filter => 1,
"issues.#{field_name}" => row.id %></td>
"#{field_name}" => row.id %></td>
<% for status in @statuses %>
<td align="center"><%= link_to (aggregate data, { field_name => row.id, "status_id" => status.id }),
:controller => 'projects', :action => 'list_issues', :id => @project,
:set_filter => 1,
"issues.status_id" => status.id,
"issues.#{field_name}" => row.id %></td>
"status_id" => status.id,
"#{field_name}" => row.id %></td>
<% end %>
<td align="center"><%= aggregate data, { field_name => row.id, "closed" => 0 } %></td>
<td align="center"><%= link_to (aggregate data, { field_name => row.id, "closed" => 0 }),
:controller => 'projects', :action => 'list_issues', :id => @project,
:set_filter => 1,
"#{field_name}" => row.id,
"status_id" => "O" %></td>
<td align="center"><%= aggregate data, { field_name => row.id, "closed" => 1 } %></td>
<td align="center"><%= link_to (aggregate data, { field_name => row.id }),
:controller => 'projects', :action => 'list_issues', :id => @project,
:set_filter => 1,
"issues.#{field_name}" => row.id %></td>
"#{field_name}" => row.id,
"status_id" => "A" %></td>
<% end %>
</tr>
</table>

View File

@ -5,6 +5,14 @@ Copyright (C) 2006 Jean-Philippe Lang
http://redmine.sourceforge.net/
== xx/xx/2006
* More filter options in issues list
* Issues list exportable to CSV
* Fixed: Error on tables creation with PostgreSQL (rev5)
* Fixed: SQL error in "issue reports" view with PostgreSQL (rev5)
== 06/25/2006 - v0.1.0
* multiple users/multiple projects