##// END OF EJS Templates
Subproject name added in csv and pdf exports....
Jean-Philippe Lang -
r493:7faf77804d17
parent child
Show More
@@ -1,665 +1,667
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'csv'
18 require 'csv'
19
19
20 class ProjectsController < ApplicationController
20 class ProjectsController < ApplicationController
21 layout 'base'
21 layout 'base'
22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
24
24
25 helper :sort
25 helper :sort
26 include SortHelper
26 include SortHelper
27 helper :custom_fields
27 helper :custom_fields
28 include CustomFieldsHelper
28 include CustomFieldsHelper
29 helper :ifpdf
29 helper :ifpdf
30 include IfpdfHelper
30 include IfpdfHelper
31 helper IssuesHelper
31 helper IssuesHelper
32 helper :queries
32 helper :queries
33 include QueriesHelper
33 include QueriesHelper
34
34
35 def index
35 def index
36 list
36 list
37 render :action => 'list' unless request.xhr?
37 render :action => 'list' unless request.xhr?
38 end
38 end
39
39
40 # Lists public projects
40 # Lists public projects
41 def list
41 def list
42 sort_init "#{Project.table_name}.name", "asc"
42 sort_init "#{Project.table_name}.name", "asc"
43 sort_update
43 sort_update
44 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
44 @project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
45 @project_pages = Paginator.new self, @project_count,
45 @project_pages = Paginator.new self, @project_count,
46 15,
46 15,
47 params['page']
47 params['page']
48 @projects = Project.find :all, :order => sort_clause,
48 @projects = Project.find :all, :order => sort_clause,
49 :conditions => Project.visible_by(logged_in_user),
49 :conditions => Project.visible_by(logged_in_user),
50 :include => :parent,
50 :include => :parent,
51 :limit => @project_pages.items_per_page,
51 :limit => @project_pages.items_per_page,
52 :offset => @project_pages.current.offset
52 :offset => @project_pages.current.offset
53
53
54 render :action => "list", :layout => false if request.xhr?
54 render :action => "list", :layout => false if request.xhr?
55 end
55 end
56
56
57 # Add a new project
57 # Add a new project
58 def add
58 def add
59 @custom_fields = IssueCustomField.find(:all)
59 @custom_fields = IssueCustomField.find(:all)
60 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 @root_projects = Project.find(:all, :conditions => "parent_id is null")
61 @project = Project.new(params[:project])
61 @project = Project.new(params[:project])
62 if request.get?
62 if request.get?
63 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
64 else
64 else
65 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
67 @project.custom_values = @custom_values
67 @project.custom_values = @custom_values
68 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 if params[:repository_enabled] && params[:repository_enabled] == "1"
69 @project.repository = Repository.new
69 @project.repository = Repository.new
70 @project.repository.attributes = params[:repository]
70 @project.repository.attributes = params[:repository]
71 end
71 end
72 if "1" == params[:wiki_enabled]
72 if "1" == params[:wiki_enabled]
73 @project.wiki = Wiki.new
73 @project.wiki = Wiki.new
74 @project.wiki.attributes = params[:wiki]
74 @project.wiki.attributes = params[:wiki]
75 end
75 end
76 if @project.save
76 if @project.save
77 flash[:notice] = l(:notice_successful_create)
77 flash[:notice] = l(:notice_successful_create)
78 redirect_to :controller => 'admin', :action => 'projects'
78 redirect_to :controller => 'admin', :action => 'projects'
79 end
79 end
80 end
80 end
81 end
81 end
82
82
83 # Show @project
83 # Show @project
84 def show
84 def show
85 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
85 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
86 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
86 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
87 @subprojects = @project.children if @project.children.size > 0
87 @subprojects = @project.children if @project.children.size > 0
88 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
88 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
89 @trackers = Tracker.find(:all, :order => 'position')
89 @trackers = Tracker.find(:all, :order => 'position')
90 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
90 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
91 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
91 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
92 end
92 end
93
93
94 def settings
94 def settings
95 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
95 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
96 @custom_fields = IssueCustomField.find(:all)
96 @custom_fields = IssueCustomField.find(:all)
97 @issue_category ||= IssueCategory.new
97 @issue_category ||= IssueCategory.new
98 @member ||= @project.members.new
98 @member ||= @project.members.new
99 @roles = Role.find(:all, :order => 'position')
99 @roles = Role.find(:all, :order => 'position')
100 @users = User.find_active(:all) - @project.users
100 @users = User.find_active(:all) - @project.users
101 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
101 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
102 end
102 end
103
103
104 # Edit @project
104 # Edit @project
105 def edit
105 def edit
106 if request.post?
106 if request.post?
107 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
107 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
108 if params[:custom_fields]
108 if params[:custom_fields]
109 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
109 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
110 @project.custom_values = @custom_values
110 @project.custom_values = @custom_values
111 end
111 end
112 if params[:repository_enabled]
112 if params[:repository_enabled]
113 case params[:repository_enabled]
113 case params[:repository_enabled]
114 when "0"
114 when "0"
115 @project.repository = nil
115 @project.repository = nil
116 when "1"
116 when "1"
117 @project.repository ||= Repository.new
117 @project.repository ||= Repository.new
118 @project.repository.update_attributes params[:repository]
118 @project.repository.update_attributes params[:repository]
119 end
119 end
120 end
120 end
121 if params[:wiki_enabled]
121 if params[:wiki_enabled]
122 case params[:wiki_enabled]
122 case params[:wiki_enabled]
123 when "0"
123 when "0"
124 @project.wiki.destroy if @project.wiki
124 @project.wiki.destroy if @project.wiki
125 when "1"
125 when "1"
126 @project.wiki ||= Wiki.new
126 @project.wiki ||= Wiki.new
127 @project.wiki.update_attributes params[:wiki]
127 @project.wiki.update_attributes params[:wiki]
128 end
128 end
129 end
129 end
130 @project.attributes = params[:project]
130 @project.attributes = params[:project]
131 if @project.save
131 if @project.save
132 flash[:notice] = l(:notice_successful_update)
132 flash[:notice] = l(:notice_successful_update)
133 redirect_to :action => 'settings', :id => @project
133 redirect_to :action => 'settings', :id => @project
134 else
134 else
135 settings
135 settings
136 render :action => 'settings'
136 render :action => 'settings'
137 end
137 end
138 end
138 end
139 end
139 end
140
140
141 # Delete @project
141 # Delete @project
142 def destroy
142 def destroy
143 if request.post? and params[:confirm]
143 if request.post? and params[:confirm]
144 @project.destroy
144 @project.destroy
145 redirect_to :controller => 'admin', :action => 'projects'
145 redirect_to :controller => 'admin', :action => 'projects'
146 end
146 end
147 end
147 end
148
148
149 # Add a new issue category to @project
149 # Add a new issue category to @project
150 def add_issue_category
150 def add_issue_category
151 if request.post?
151 if request.post?
152 @issue_category = @project.issue_categories.build(params[:issue_category])
152 @issue_category = @project.issue_categories.build(params[:issue_category])
153 if @issue_category.save
153 if @issue_category.save
154 flash[:notice] = l(:notice_successful_create)
154 flash[:notice] = l(:notice_successful_create)
155 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 redirect_to :action => 'settings', :tab => 'categories', :id => @project
156 else
156 else
157 settings
157 settings
158 render :action => 'settings'
158 render :action => 'settings'
159 end
159 end
160 end
160 end
161 end
161 end
162
162
163 # Add a new version to @project
163 # Add a new version to @project
164 def add_version
164 def add_version
165 @version = @project.versions.build(params[:version])
165 @version = @project.versions.build(params[:version])
166 if request.post? and @version.save
166 if request.post? and @version.save
167 flash[:notice] = l(:notice_successful_create)
167 flash[:notice] = l(:notice_successful_create)
168 redirect_to :action => 'settings', :tab => 'versions', :id => @project
168 redirect_to :action => 'settings', :tab => 'versions', :id => @project
169 end
169 end
170 end
170 end
171
171
172 # Add a new member to @project
172 # Add a new member to @project
173 def add_member
173 def add_member
174 @member = @project.members.build(params[:member])
174 @member = @project.members.build(params[:member])
175 if request.post?
175 if request.post?
176 if @member.save
176 if @member.save
177 flash[:notice] = l(:notice_successful_create)
177 flash[:notice] = l(:notice_successful_create)
178 redirect_to :action => 'settings', :tab => 'members', :id => @project
178 redirect_to :action => 'settings', :tab => 'members', :id => @project
179 else
179 else
180 settings
180 settings
181 render :action => 'settings'
181 render :action => 'settings'
182 end
182 end
183 end
183 end
184 end
184 end
185
185
186 # Show members list of @project
186 # Show members list of @project
187 def list_members
187 def list_members
188 @members = @project.members.find(:all)
188 @members = @project.members.find(:all)
189 end
189 end
190
190
191 # Add a new document to @project
191 # Add a new document to @project
192 def add_document
192 def add_document
193 @categories = Enumeration::get_values('DCAT')
193 @categories = Enumeration::get_values('DCAT')
194 @document = @project.documents.build(params[:document])
194 @document = @project.documents.build(params[:document])
195 if request.post? and @document.save
195 if request.post? and @document.save
196 # Save the attachments
196 # Save the attachments
197 params[:attachments].each { |a|
197 params[:attachments].each { |a|
198 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
198 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
199 } if params[:attachments] and params[:attachments].is_a? Array
199 } if params[:attachments] and params[:attachments].is_a? Array
200 flash[:notice] = l(:notice_successful_create)
200 flash[:notice] = l(:notice_successful_create)
201 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
201 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
202 redirect_to :action => 'list_documents', :id => @project
202 redirect_to :action => 'list_documents', :id => @project
203 end
203 end
204 end
204 end
205
205
206 # Show documents list of @project
206 # Show documents list of @project
207 def list_documents
207 def list_documents
208 @documents = @project.documents.find :all, :include => :category
208 @documents = @project.documents.find :all, :include => :category
209 end
209 end
210
210
211 # Add a new issue to @project
211 # Add a new issue to @project
212 def add_issue
212 def add_issue
213 @tracker = Tracker.find(params[:tracker_id])
213 @tracker = Tracker.find(params[:tracker_id])
214 @priorities = Enumeration::get_values('IPRI')
214 @priorities = Enumeration::get_values('IPRI')
215
215
216 default_status = IssueStatus.default
216 default_status = IssueStatus.default
217 @issue = Issue.new(:project => @project, :tracker => @tracker)
217 @issue = Issue.new(:project => @project, :tracker => @tracker)
218 @issue.status = default_status
218 @issue.status = default_status
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
220 if request.get?
220 if request.get?
221 @issue.start_date = Date.today
221 @issue.start_date = Date.today
222 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
222 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
223 else
223 else
224 @issue.attributes = params[:issue]
224 @issue.attributes = params[:issue]
225
225
226 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
226 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
227 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
227 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
228
228
229 @issue.author_id = self.logged_in_user.id if self.logged_in_user
229 @issue.author_id = self.logged_in_user.id if self.logged_in_user
230 # Multiple file upload
230 # Multiple file upload
231 @attachments = []
231 @attachments = []
232 params[:attachments].each { |a|
232 params[:attachments].each { |a|
233 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
233 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
234 } if params[:attachments] and params[:attachments].is_a? Array
234 } if params[:attachments] and params[:attachments].is_a? Array
235 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
235 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
236 @issue.custom_values = @custom_values
236 @issue.custom_values = @custom_values
237 if @issue.save
237 if @issue.save
238 @attachments.each(&:save)
238 @attachments.each(&:save)
239 flash[:notice] = l(:notice_successful_create)
239 flash[:notice] = l(:notice_successful_create)
240 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
240 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
241 redirect_to :action => 'list_issues', :id => @project
241 redirect_to :action => 'list_issues', :id => @project
242 end
242 end
243 end
243 end
244 end
244 end
245
245
246 # Show filtered/sorted issues list of @project
246 # Show filtered/sorted issues list of @project
247 def list_issues
247 def list_issues
248 sort_init "#{Issue.table_name}.id", "desc"
248 sort_init "#{Issue.table_name}.id", "desc"
249 sort_update
249 sort_update
250
250
251 retrieve_query
251 retrieve_query
252
252
253 @results_per_page_options = [ 15, 25, 50, 100 ]
253 @results_per_page_options = [ 15, 25, 50, 100 ]
254 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
254 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
255 @results_per_page = params[:per_page].to_i
255 @results_per_page = params[:per_page].to_i
256 session[:results_per_page] = @results_per_page
256 session[:results_per_page] = @results_per_page
257 else
257 else
258 @results_per_page = session[:results_per_page] || 25
258 @results_per_page = session[:results_per_page] || 25
259 end
259 end
260
260
261 if @query.valid?
261 if @query.valid?
262 @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
262 @issue_count = Issue.count(:include => [:status, :project, :custom_values], :conditions => @query.statement)
263 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
263 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
264 @issues = Issue.find :all, :order => sort_clause,
264 @issues = Issue.find :all, :order => sort_clause,
265 :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
265 :include => [ :assigned_to, :status, :tracker, :project, :priority, :custom_values ],
266 :conditions => @query.statement,
266 :conditions => @query.statement,
267 :limit => @issue_pages.items_per_page,
267 :limit => @issue_pages.items_per_page,
268 :offset => @issue_pages.current.offset
268 :offset => @issue_pages.current.offset
269 end
269 end
270 @trackers = Tracker.find :all, :order => 'position'
270 @trackers = Tracker.find :all, :order => 'position'
271 render :layout => false if request.xhr?
271 render :layout => false if request.xhr?
272 end
272 end
273
273
274 # Export filtered/sorted issues list to CSV
274 # Export filtered/sorted issues list to CSV
275 def export_issues_csv
275 def export_issues_csv
276 sort_init "#{Issue.table_name}.id", "desc"
276 sort_init "#{Issue.table_name}.id", "desc"
277 sort_update
277 sort_update
278
278
279 retrieve_query
279 retrieve_query
280 render :action => 'list_issues' and return unless @query.valid?
280 render :action => 'list_issues' and return unless @query.valid?
281
281
282 @issues = Issue.find :all, :order => sort_clause,
282 @issues = Issue.find :all, :order => sort_clause,
283 :include => [ :assigned_to, :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
283 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
284 :conditions => @query.statement,
284 :conditions => @query.statement,
285 :limit => Setting.issues_export_limit
285 :limit => Setting.issues_export_limit
286
286
287 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
287 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
288 export = StringIO.new
288 export = StringIO.new
289 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
289 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
290 # csv header fields
290 # csv header fields
291 headers = [ "#", l(:field_status),
291 headers = [ "#", l(:field_status),
292 l(:field_project),
292 l(:field_tracker),
293 l(:field_tracker),
293 l(:field_priority),
294 l(:field_priority),
294 l(:field_subject),
295 l(:field_subject),
295 l(:field_assigned_to),
296 l(:field_assigned_to),
296 l(:field_author),
297 l(:field_author),
297 l(:field_start_date),
298 l(:field_start_date),
298 l(:field_due_date),
299 l(:field_due_date),
299 l(:field_done_ratio),
300 l(:field_done_ratio),
300 l(:field_created_on),
301 l(:field_created_on),
301 l(:field_updated_on)
302 l(:field_updated_on)
302 ]
303 ]
303 for custom_field in @project.all_custom_fields
304 for custom_field in @project.all_custom_fields
304 headers << custom_field.name
305 headers << custom_field.name
305 end
306 end
306 csv << headers.collect {|c| ic.iconv(c) }
307 csv << headers.collect {|c| ic.iconv(c) }
307 # csv lines
308 # csv lines
308 @issues.each do |issue|
309 @issues.each do |issue|
309 fields = [issue.id, issue.status.name,
310 fields = [issue.id, issue.status.name,
311 issue.project.name,
310 issue.tracker.name,
312 issue.tracker.name,
311 issue.priority.name,
313 issue.priority.name,
312 issue.subject,
314 issue.subject,
313 (issue.assigned_to ? issue.assigned_to.name : ""),
315 (issue.assigned_to ? issue.assigned_to.name : ""),
314 issue.author.name,
316 issue.author.name,
315 issue.start_date ? l_date(issue.start_date) : nil,
317 issue.start_date ? l_date(issue.start_date) : nil,
316 issue.due_date ? l_date(issue.due_date) : nil,
318 issue.due_date ? l_date(issue.due_date) : nil,
317 issue.done_ratio,
319 issue.done_ratio,
318 l_datetime(issue.created_on),
320 l_datetime(issue.created_on),
319 l_datetime(issue.updated_on)
321 l_datetime(issue.updated_on)
320 ]
322 ]
321 for custom_field in @project.all_custom_fields
323 for custom_field in @project.all_custom_fields
322 fields << (show_value issue.custom_value_for(custom_field))
324 fields << (show_value issue.custom_value_for(custom_field))
323 end
325 end
324 csv << fields.collect {|c| ic.iconv(c.to_s) }
326 csv << fields.collect {|c| ic.iconv(c.to_s) }
325 end
327 end
326 end
328 end
327 export.rewind
329 export.rewind
328 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
330 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
329 end
331 end
330
332
331 # Export filtered/sorted issues to PDF
333 # Export filtered/sorted issues to PDF
332 def export_issues_pdf
334 def export_issues_pdf
333 sort_init "#{Issue.table_name}.id", "desc"
335 sort_init "#{Issue.table_name}.id", "desc"
334 sort_update
336 sort_update
335
337
336 retrieve_query
338 retrieve_query
337 render :action => 'list_issues' and return unless @query.valid?
339 render :action => 'list_issues' and return unless @query.valid?
338
340
339 @issues = Issue.find :all, :order => sort_clause,
341 @issues = Issue.find :all, :order => sort_clause,
340 :include => [ :author, :status, :tracker, :priority, :custom_values ],
342 :include => [ :author, :status, :tracker, :priority, :project, :custom_values ],
341 :conditions => @query.statement,
343 :conditions => @query.statement,
342 :limit => Setting.issues_export_limit
344 :limit => Setting.issues_export_limit
343
345
344 @options_for_rfpdf ||= {}
346 @options_for_rfpdf ||= {}
345 @options_for_rfpdf[:file_name] = "export.pdf"
347 @options_for_rfpdf[:file_name] = "export.pdf"
346 render :layout => false
348 render :layout => false
347 end
349 end
348
350
349 def move_issues
351 def move_issues
350 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
352 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
351 redirect_to :action => 'list_issues', :id => @project and return unless @issues
353 redirect_to :action => 'list_issues', :id => @project and return unless @issues
352 @projects = []
354 @projects = []
353 # find projects to which the user is allowed to move the issue
355 # find projects to which the user is allowed to move the issue
354 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
356 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
355 # issue can be moved to any tracker
357 # issue can be moved to any tracker
356 @trackers = Tracker.find(:all)
358 @trackers = Tracker.find(:all)
357 if request.post? and params[:new_project_id] and params[:new_tracker_id]
359 if request.post? and params[:new_project_id] and params[:new_tracker_id]
358 new_project = Project.find(params[:new_project_id])
360 new_project = Project.find(params[:new_project_id])
359 new_tracker = Tracker.find(params[:new_tracker_id])
361 new_tracker = Tracker.find(params[:new_tracker_id])
360 @issues.each { |i|
362 @issues.each { |i|
361 # project dependent properties
363 # project dependent properties
362 unless i.project_id == new_project.id
364 unless i.project_id == new_project.id
363 i.category = nil
365 i.category = nil
364 i.fixed_version = nil
366 i.fixed_version = nil
365 end
367 end
366 # move the issue
368 # move the issue
367 i.project = new_project
369 i.project = new_project
368 i.tracker = new_tracker
370 i.tracker = new_tracker
369 i.save
371 i.save
370 }
372 }
371 flash[:notice] = l(:notice_successful_update)
373 flash[:notice] = l(:notice_successful_update)
372 redirect_to :action => 'list_issues', :id => @project
374 redirect_to :action => 'list_issues', :id => @project
373 end
375 end
374 end
376 end
375
377
376 def add_query
378 def add_query
377 @query = Query.new(params[:query])
379 @query = Query.new(params[:query])
378 @query.project = @project
380 @query.project = @project
379 @query.user = logged_in_user
381 @query.user = logged_in_user
380
382
381 params[:fields].each do |field|
383 params[:fields].each do |field|
382 @query.add_filter(field, params[:operators][field], params[:values][field])
384 @query.add_filter(field, params[:operators][field], params[:values][field])
383 end if params[:fields]
385 end if params[:fields]
384
386
385 if request.post? and @query.save
387 if request.post? and @query.save
386 flash[:notice] = l(:notice_successful_create)
388 flash[:notice] = l(:notice_successful_create)
387 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
389 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
388 end
390 end
389 render :layout => false if request.xhr?
391 render :layout => false if request.xhr?
390 end
392 end
391
393
392 # Add a news to @project
394 # Add a news to @project
393 def add_news
395 def add_news
394 @news = News.new(:project => @project)
396 @news = News.new(:project => @project)
395 if request.post?
397 if request.post?
396 @news.attributes = params[:news]
398 @news.attributes = params[:news]
397 @news.author_id = self.logged_in_user.id if self.logged_in_user
399 @news.author_id = self.logged_in_user.id if self.logged_in_user
398 if @news.save
400 if @news.save
399 flash[:notice] = l(:notice_successful_create)
401 flash[:notice] = l(:notice_successful_create)
400 redirect_to :action => 'list_news', :id => @project
402 redirect_to :action => 'list_news', :id => @project
401 end
403 end
402 end
404 end
403 end
405 end
404
406
405 # Show news list of @project
407 # Show news list of @project
406 def list_news
408 def list_news
407 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
409 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
408 render :action => "list_news", :layout => false if request.xhr?
410 render :action => "list_news", :layout => false if request.xhr?
409 end
411 end
410
412
411 def add_file
413 def add_file
412 if request.post?
414 if request.post?
413 @version = @project.versions.find_by_id(params[:version_id])
415 @version = @project.versions.find_by_id(params[:version_id])
414 # Save the attachments
416 # Save the attachments
415 @attachments = []
417 @attachments = []
416 params[:attachments].each { |file|
418 params[:attachments].each { |file|
417 next unless file.size > 0
419 next unless file.size > 0
418 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
420 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
419 @attachments << a unless a.new_record?
421 @attachments << a unless a.new_record?
420 } if params[:attachments] and params[:attachments].is_a? Array
422 } if params[:attachments] and params[:attachments].is_a? Array
421 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
423 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
422 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
424 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
423 end
425 end
424 @versions = @project.versions
426 @versions = @project.versions
425 end
427 end
426
428
427 def list_files
429 def list_files
428 @versions = @project.versions
430 @versions = @project.versions
429 end
431 end
430
432
431 # Show changelog for @project
433 # Show changelog for @project
432 def changelog
434 def changelog
433 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
435 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
434 retrieve_selected_tracker_ids(@trackers)
436 retrieve_selected_tracker_ids(@trackers)
435
437
436 @fixed_issues = @project.issues.find(:all,
438 @fixed_issues = @project.issues.find(:all,
437 :include => [ :fixed_version, :status, :tracker ],
439 :include => [ :fixed_version, :status, :tracker ],
438 :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true],
440 :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true],
439 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
441 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
440 ) unless @selected_tracker_ids.empty?
442 ) unless @selected_tracker_ids.empty?
441 @fixed_issues ||= []
443 @fixed_issues ||= []
442 end
444 end
443
445
444 def roadmap
446 def roadmap
445 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
447 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
446 retrieve_selected_tracker_ids(@trackers)
448 retrieve_selected_tracker_ids(@trackers)
447
449
448 @versions = @project.versions.find(:all,
450 @versions = @project.versions.find(:all,
449 :conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
451 :conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
450 :order => "#{Version.table_name}.effective_date ASC"
452 :order => "#{Version.table_name}.effective_date ASC"
451 )
453 )
452 end
454 end
453
455
454 def activity
456 def activity
455 if params[:year] and params[:year].to_i > 1900
457 if params[:year] and params[:year].to_i > 1900
456 @year = params[:year].to_i
458 @year = params[:year].to_i
457 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
459 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
458 @month = params[:month].to_i
460 @month = params[:month].to_i
459 end
461 end
460 end
462 end
461 @year ||= Date.today.year
463 @year ||= Date.today.year
462 @month ||= Date.today.month
464 @month ||= Date.today.month
463
465
464 @date_from = Date.civil(@year, @month, 1)
466 @date_from = Date.civil(@year, @month, 1)
465 @date_to = @date_from >> 1
467 @date_to = @date_from >> 1
466
468
467 @events_by_day = {}
469 @events_by_day = {}
468
470
469 unless params[:show_issues] == "0"
471 unless params[:show_issues] == "0"
470 @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
472 @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
471 @events_by_day[i.created_on.to_date] ||= []
473 @events_by_day[i.created_on.to_date] ||= []
472 @events_by_day[i.created_on.to_date] << i
474 @events_by_day[i.created_on.to_date] << i
473 }
475 }
474 @show_issues = 1
476 @show_issues = 1
475 end
477 end
476
478
477 unless params[:show_news] == "0"
479 unless params[:show_news] == "0"
478 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
480 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
479 @events_by_day[i.created_on.to_date] ||= []
481 @events_by_day[i.created_on.to_date] ||= []
480 @events_by_day[i.created_on.to_date] << i
482 @events_by_day[i.created_on.to_date] << i
481 }
483 }
482 @show_news = 1
484 @show_news = 1
483 end
485 end
484
486
485 unless params[:show_files] == "0"
487 unless params[:show_files] == "0"
486 Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
488 Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
487 @events_by_day[i.created_on.to_date] ||= []
489 @events_by_day[i.created_on.to_date] ||= []
488 @events_by_day[i.created_on.to_date] << i
490 @events_by_day[i.created_on.to_date] << i
489 }
491 }
490 @show_files = 1
492 @show_files = 1
491 end
493 end
492
494
493 unless params[:show_documents] == "0"
495 unless params[:show_documents] == "0"
494 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
496 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
495 @events_by_day[i.created_on.to_date] ||= []
497 @events_by_day[i.created_on.to_date] ||= []
496 @events_by_day[i.created_on.to_date] << i
498 @events_by_day[i.created_on.to_date] << i
497 }
499 }
498 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
500 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
499 @events_by_day[i.created_on.to_date] ||= []
501 @events_by_day[i.created_on.to_date] ||= []
500 @events_by_day[i.created_on.to_date] << i
502 @events_by_day[i.created_on.to_date] << i
501 }
503 }
502 @show_documents = 1
504 @show_documents = 1
503 end
505 end
504
506
505 unless params[:show_wiki_edits] == "0"
507 unless params[:show_wiki_edits] == "0"
506 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
508 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
507 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
509 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
508 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
510 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
509 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
511 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
510 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
512 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
511 @project.id, @date_from, @date_to]
513 @project.id, @date_from, @date_to]
512
514
513 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
515 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
514 # We provide this alias so all events can be treated in the same manner
516 # We provide this alias so all events can be treated in the same manner
515 def i.created_on
517 def i.created_on
516 self.updated_on
518 self.updated_on
517 end
519 end
518
520
519 @events_by_day[i.created_on.to_date] ||= []
521 @events_by_day[i.created_on.to_date] ||= []
520 @events_by_day[i.created_on.to_date] << i
522 @events_by_day[i.created_on.to_date] << i
521 }
523 }
522 @show_wiki_edits = 1
524 @show_wiki_edits = 1
523 end
525 end
524
526
525 unless @project.repository.nil? || params[:show_changesets] == "0"
527 unless @project.repository.nil? || params[:show_changesets] == "0"
526 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
528 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
527 def i.created_on
529 def i.created_on
528 self.committed_on
530 self.committed_on
529 end
531 end
530 @events_by_day[i.created_on.to_date] ||= []
532 @events_by_day[i.created_on.to_date] ||= []
531 @events_by_day[i.created_on.to_date] << i
533 @events_by_day[i.created_on.to_date] << i
532 }
534 }
533 @show_changesets = 1
535 @show_changesets = 1
534 end
536 end
535
537
536 render :layout => false if request.xhr?
538 render :layout => false if request.xhr?
537 end
539 end
538
540
539 def calendar
541 def calendar
540 @trackers = Tracker.find(:all, :order => 'position')
542 @trackers = Tracker.find(:all, :order => 'position')
541 retrieve_selected_tracker_ids(@trackers)
543 retrieve_selected_tracker_ids(@trackers)
542
544
543 if params[:year] and params[:year].to_i > 1900
545 if params[:year] and params[:year].to_i > 1900
544 @year = params[:year].to_i
546 @year = params[:year].to_i
545 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
547 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
546 @month = params[:month].to_i
548 @month = params[:month].to_i
547 end
549 end
548 end
550 end
549 @year ||= Date.today.year
551 @year ||= Date.today.year
550 @month ||= Date.today.month
552 @month ||= Date.today.month
551
553
552 @date_from = Date.civil(@year, @month, 1)
554 @date_from = Date.civil(@year, @month, 1)
553 @date_to = (@date_from >> 1)-1
555 @date_to = (@date_from >> 1)-1
554 # start on monday
556 # start on monday
555 @date_from = @date_from - (@date_from.cwday-1)
557 @date_from = @date_from - (@date_from.cwday-1)
556 # finish on sunday
558 # finish on sunday
557 @date_to = @date_to + (7-@date_to.cwday)
559 @date_to = @date_to + (7-@date_to.cwday)
558
560
559 @events = []
561 @events = []
560 @project.issues_with_subprojects(params[:with_subprojects]) do
562 @project.issues_with_subprojects(params[:with_subprojects]) do
561 @events += Issue.find(:all,
563 @events += Issue.find(:all,
562 :include => [:tracker, :status, :assigned_to, :priority, :project],
564 :include => [:tracker, :status, :assigned_to, :priority, :project],
563 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
565 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)) and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')})", @date_from, @date_to, @date_from, @date_to]
564 ) unless @selected_tracker_ids.empty?
566 ) unless @selected_tracker_ids.empty?
565 end
567 end
566 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
568 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
567
569
568 @ending_events_by_days = @events.group_by {|event| event.due_date}
570 @ending_events_by_days = @events.group_by {|event| event.due_date}
569 @starting_events_by_days = @events.group_by {|event| event.start_date}
571 @starting_events_by_days = @events.group_by {|event| event.start_date}
570
572
571 render :layout => false if request.xhr?
573 render :layout => false if request.xhr?
572 end
574 end
573
575
574 def gantt
576 def gantt
575 @trackers = Tracker.find(:all, :order => 'position')
577 @trackers = Tracker.find(:all, :order => 'position')
576 retrieve_selected_tracker_ids(@trackers)
578 retrieve_selected_tracker_ids(@trackers)
577
579
578 if params[:year] and params[:year].to_i >0
580 if params[:year] and params[:year].to_i >0
579 @year_from = params[:year].to_i
581 @year_from = params[:year].to_i
580 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
582 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
581 @month_from = params[:month].to_i
583 @month_from = params[:month].to_i
582 else
584 else
583 @month_from = 1
585 @month_from = 1
584 end
586 end
585 else
587 else
586 @month_from ||= (Date.today << 1).month
588 @month_from ||= (Date.today << 1).month
587 @year_from ||= (Date.today << 1).year
589 @year_from ||= (Date.today << 1).year
588 end
590 end
589
591
590 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
592 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
591 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
593 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
592
594
593 @date_from = Date.civil(@year_from, @month_from, 1)
595 @date_from = Date.civil(@year_from, @month_from, 1)
594 @date_to = (@date_from >> @months) - 1
596 @date_to = (@date_from >> @months) - 1
595
597
596 @events = []
598 @events = []
597 @project.issues_with_subprojects(params[:with_subprojects]) do
599 @project.issues_with_subprojects(params[:with_subprojects]) do
598 @events += Issue.find(:all,
600 @events += Issue.find(:all,
599 :order => "start_date, due_date",
601 :order => "start_date, due_date",
600 :include => [:tracker, :status, :assigned_to, :priority, :project],
602 :include => [:tracker, :status, :assigned_to, :priority, :project],
601 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
603 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
602 ) unless @selected_tracker_ids.empty?
604 ) unless @selected_tracker_ids.empty?
603 end
605 end
604 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
606 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
605 @events.sort! {|x,y| x.start_date <=> y.start_date }
607 @events.sort! {|x,y| x.start_date <=> y.start_date }
606
608
607 if params[:output]=='pdf'
609 if params[:output]=='pdf'
608 @options_for_rfpdf ||= {}
610 @options_for_rfpdf ||= {}
609 @options_for_rfpdf[:file_name] = "gantt.pdf"
611 @options_for_rfpdf[:file_name] = "gantt.pdf"
610 render :template => "projects/gantt.rfpdf", :layout => false
612 render :template => "projects/gantt.rfpdf", :layout => false
611 else
613 else
612 render :template => "projects/gantt.rhtml"
614 render :template => "projects/gantt.rhtml"
613 end
615 end
614 end
616 end
615
617
616 def feeds
618 def feeds
617 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
619 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
618 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
620 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
619 end
621 end
620
622
621 private
623 private
622 # Find project of id params[:id]
624 # Find project of id params[:id]
623 # if not found, redirect to project list
625 # if not found, redirect to project list
624 # Used as a before_filter
626 # Used as a before_filter
625 def find_project
627 def find_project
626 @project = Project.find(params[:id])
628 @project = Project.find(params[:id])
627 @html_title = @project.name
629 @html_title = @project.name
628 rescue ActiveRecord::RecordNotFound
630 rescue ActiveRecord::RecordNotFound
629 render_404
631 render_404
630 end
632 end
631
633
632 def retrieve_selected_tracker_ids(selectable_trackers)
634 def retrieve_selected_tracker_ids(selectable_trackers)
633 if ids = params[:tracker_ids]
635 if ids = params[:tracker_ids]
634 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
636 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
635 else
637 else
636 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
638 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
637 end
639 end
638 end
640 end
639
641
640 # Retrieve query from session or build a new query
642 # Retrieve query from session or build a new query
641 def retrieve_query
643 def retrieve_query
642 if params[:query_id]
644 if params[:query_id]
643 @query = @project.queries.find(params[:query_id])
645 @query = @project.queries.find(params[:query_id])
644 session[:query] = @query
646 session[:query] = @query
645 else
647 else
646 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
648 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
647 # Give it a name, required to be valid
649 # Give it a name, required to be valid
648 @query = Query.new(:name => "_")
650 @query = Query.new(:name => "_")
649 @query.project = @project
651 @query.project = @project
650 if params[:fields] and params[:fields].is_a? Array
652 if params[:fields] and params[:fields].is_a? Array
651 params[:fields].each do |field|
653 params[:fields].each do |field|
652 @query.add_filter(field, params[:operators][field], params[:values][field])
654 @query.add_filter(field, params[:operators][field], params[:values][field])
653 end
655 end
654 else
656 else
655 @query.available_filters.keys.each do |field|
657 @query.available_filters.keys.each do |field|
656 @query.add_short_filter(field, params[field]) if params[field]
658 @query.add_short_filter(field, params[field]) if params[field]
657 end
659 end
658 end
660 end
659 session[:query] = @query
661 session[:query] = @query
660 else
662 else
661 @query = session[:query]
663 @query = session[:query]
662 end
664 end
663 end
665 end
664 end
666 end
665 end
667 end
@@ -1,49 +1,49
1 <% pdf=IfpdfHelper::IFPDF.new(current_language)
1 <% pdf=IfpdfHelper::IFPDF.new(current_language)
2 pdf.SetTitle("#{@project.name} - #{l(:label_issue_plural)}")
2 pdf.SetTitle("#{@project.name} - #{l(:label_issue_plural)}")
3 pdf.AliasNbPages
3 pdf.AliasNbPages
4 pdf.footer_date = format_date(Date.today)
4 pdf.footer_date = format_date(Date.today)
5 pdf.AddPage("L")
5 pdf.AddPage("L")
6 row_height = 7
6 row_height = 7
7
7
8 #
8 #
9 # title
9 # title
10 #
10 #
11 pdf.SetFontStyle('B',11)
11 pdf.SetFontStyle('B',11)
12 pdf.Cell(190,10, "#{@project.name} - #{l(:label_issue_plural)}")
12 pdf.Cell(190,10, "#{@project.name} - #{l(:label_issue_plural)}")
13 pdf.Ln
13 pdf.Ln
14
14
15 #
15 #
16 # headers
16 # headers
17 #
17 #
18 pdf.SetFontStyle('B',10)
18 pdf.SetFontStyle('B',10)
19 pdf.SetFillColor(230, 230, 230)
19 pdf.SetFillColor(230, 230, 230)
20 pdf.Cell(15, row_height, "#", 0, 0, 'L', 1)
20 pdf.Cell(15, row_height, "#", 0, 0, 'L', 1)
21 pdf.Cell(30, row_height, l(:field_tracker), 0, 0, 'L', 1)
21 pdf.Cell(30, row_height, l(:field_tracker), 0, 0, 'L', 1)
22 pdf.Cell(30, row_height, l(:field_status), 0, 0, 'L', 1)
22 pdf.Cell(30, row_height, l(:field_status), 0, 0, 'L', 1)
23 pdf.Cell(30, row_height, l(:field_priority), 0, 0, 'L', 1)
23 pdf.Cell(30, row_height, l(:field_priority), 0, 0, 'L', 1)
24 pdf.Cell(40, row_height, l(:field_author), 0, 0, 'L', 1)
24 pdf.Cell(40, row_height, l(:field_author), 0, 0, 'L', 1)
25 pdf.Cell(25, row_height, l(:field_updated_on), 0, 0, 'L', 1)
25 pdf.Cell(25, row_height, l(:field_updated_on), 0, 0, 'L', 1)
26 pdf.Cell(0, row_height, l(:field_subject), 0, 0, 'L', 1)
26 pdf.Cell(0, row_height, l(:field_subject), 0, 0, 'L', 1)
27 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
27 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
28 pdf.Ln
28 pdf.Ln
29 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
29 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
30 pdf.SetY(pdf.GetY() + 1)
30 pdf.SetY(pdf.GetY() + 1)
31
31
32 #
32 #
33 # rows
33 # rows
34 #
34 #
35 pdf.SetFontStyle('',9)
35 pdf.SetFontStyle('',9)
36 pdf.SetFillColor(255, 255, 255)
36 pdf.SetFillColor(255, 255, 255)
37 @issues.each do |issue|
37 @issues.each do |issue|
38 pdf.Cell(15, row_height, issue.id.to_s, 0, 0, 'L', 1)
38 pdf.Cell(15, row_height, issue.id.to_s, 0, 0, 'L', 1)
39 pdf.Cell(30, row_height, issue.tracker.name, 0, 0, 'L', 1)
39 pdf.Cell(30, row_height, issue.tracker.name, 0, 0, 'L', 1)
40 pdf.Cell(30, row_height, issue.status.name, 0, 0, 'L', 1)
40 pdf.Cell(30, row_height, issue.status.name, 0, 0, 'L', 1)
41 pdf.Cell(30, row_height, issue.priority.name, 0, 0, 'L', 1)
41 pdf.Cell(30, row_height, issue.priority.name, 0, 0, 'L', 1)
42 pdf.Cell(40, row_height, issue.author.name, 0, 0, 'L', 1)
42 pdf.Cell(40, row_height, issue.author.name, 0, 0, 'L', 1)
43 pdf.Cell(25, row_height, format_date(issue.updated_on), 0, 0, 'L', 1)
43 pdf.Cell(25, row_height, format_date(issue.updated_on), 0, 0, 'L', 1)
44 pdf.MultiCell(0, row_height, issue.subject)
44 pdf.MultiCell(0, row_height, (@project == issue.project ? issue.subject : "#{issue.project.name} - #{issue.subject}"))
45 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
45 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
46 pdf.SetY(pdf.GetY() + 1)
46 pdf.SetY(pdf.GetY() + 1)
47 end
47 end
48 %>
48 %>
49 <%= pdf.Output %> No newline at end of file
49 <%= pdf.Output %>
@@ -1,84 +1,84
1 <% if @query.new_record? %>
1 <% if @query.new_record? %>
2 <div class="contextual">
2 <div class="contextual">
3 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
3 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
4 </div>
4 </div>
5 <h2><%=l(:label_issue_plural)%></h2>
5 <h2><%=l(:label_issue_plural)%></h2>
6
6
7 <% form_tag({:action => 'list_issues'}, :id => 'query_form') do %>
7 <% form_tag({:action => 'list_issues'}, :id => 'query_form') do %>
8 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
8 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
9 <% end %>
9 <% end %>
10 <div class="contextual">
10 <div class="contextual">
11 <%= link_to_remote l(:button_apply),
11 <%= link_to_remote l(:button_apply),
12 { :url => { :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 },
12 { :url => { :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 },
13 :update => "content",
13 :update => "content",
14 :with => "Form.serialize('query_form')"
14 :with => "Form.serialize('query_form')"
15 }, :class => 'icon icon-edit' %>
15 }, :class => 'icon icon-edit' %>
16
16
17 <%= link_to l(:button_clear), {:controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1}, :class => 'icon icon-del' %>
17 <%= link_to l(:button_clear), {:controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1}, :class => 'icon icon-del' %>
18 <% if authorize_for('projects', 'add_query') %>
18 <% if authorize_for('projects', 'add_query') %>
19
19
20 <%= link_to_remote l(:button_save),
20 <%= link_to_remote l(:button_save),
21 { :url => { :controller => 'projects', :action => "add_query", :id => @project },
21 { :url => { :controller => 'projects', :action => "add_query", :id => @project },
22 :method => 'get',
22 :method => 'get',
23 :update => "content",
23 :update => "content",
24 :with => "Form.serialize('query_form')"
24 :with => "Form.serialize('query_form')"
25 }, :class => 'icon icon-save' %>
25 }, :class => 'icon icon-save' %>
26 <% end %>
26 <% end %>
27 </div>
27 </div>
28 <br />
28 <br />
29 <% else %>
29 <% else %>
30 <div class="contextual">
30 <div class="contextual">
31 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
31 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
32 <% if authorize_for('projects', 'add_query') %>
32 <% if authorize_for('projects', 'add_query') %>
33 <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %>
33 <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %>
34 <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
34 <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
35 <% end %>
35 <% end %>
36 </div>
36 </div>
37 <h2><%= @query.name %></h2>
37 <h2><%= @query.name %></h2>
38 <% end %>
38 <% end %>
39 <%= error_messages_for 'query' %>
39 <%= error_messages_for 'query' %>
40 <% if @query.valid? %>
40 <% if @query.valid? %>
41 <% if @issues.empty? %>
41 <% if @issues.empty? %>
42 <p><i><%= l(:label_no_data) %></i></p>
42 <p><i><%= l(:label_no_data) %></i></p>
43 <% else %>
43 <% else %>
44 &nbsp;
44 &nbsp;
45 <% form_tag({:controller => 'projects', :action => 'move_issues', :id => @project}, :id => 'issues_form' ) do %>
45 <% form_tag({:controller => 'projects', :action => 'move_issues', :id => @project}, :id => 'issues_form' ) do %>
46 <table class="list">
46 <table class="list">
47 <thead><tr>
47 <thead><tr>
48 <th></th>
48 <th></th>
49 <%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %>
49 <%= sort_header_tag("#{Issue.table_name}.id", :caption => '#') %>
50 <%= sort_header_tag("#{Issue.table_name}.tracker_id", :caption => l(:field_tracker)) %>
50 <%= sort_header_tag("#{Issue.table_name}.tracker_id", :caption => l(:field_tracker)) %>
51 <%= sort_header_tag("#{IssueStatus.table_name}.name", :caption => l(:field_status)) %>
51 <%= sort_header_tag("#{IssueStatus.table_name}.name", :caption => l(:field_status)) %>
52 <%= sort_header_tag("#{Issue.table_name}.priority_id", :caption => l(:field_priority)) %>
52 <%= sort_header_tag("#{Issue.table_name}.priority_id", :caption => l(:field_priority)) %>
53 <th><%=l(:field_subject)%></th>
53 <th><%=l(:field_subject)%></th>
54 <%= sort_header_tag("#{User.table_name}.lastname", :caption => l(:field_assigned_to)) %>
54 <%= sort_header_tag("#{User.table_name}.lastname", :caption => l(:field_assigned_to)) %>
55 <%= sort_header_tag("#{Issue.table_name}.updated_on", :caption => l(:field_updated_on)) %>
55 <%= sort_header_tag("#{Issue.table_name}.updated_on", :caption => l(:field_updated_on)) %>
56 </tr></thead>
56 </tr></thead>
57 <tbody>
57 <tbody>
58 <% for issue in @issues %>
58 <% for issue in @issues %>
59 <tr class="<%= cycle("odd", "even") %>">
59 <tr class="<%= cycle("odd", "even") %>">
60 <th style="width:15px;"><%= check_box_tag "issue_ids[]", issue.id, false, :id => "issue_#{issue.id}" %></th>
60 <th style="width:15px;"><%= check_box_tag "issue_ids[]", issue.id, false, :id => "issue_#{issue.id}" %></th>
61 <td align="center"><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
61 <td align="center"><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
62 <td align="center"><%= issue.tracker.name %> <%= "(#{issue.project.name})" unless @project && @project == issue.project %></td>
62 <td align="center"><%= issue.tracker.name %></td>
63 <td><div class="square" style="background:#<%= issue.status.html_color %>;"></div> <%= issue.status.name %></td>
63 <td><div class="square" style="background:#<%= issue.status.html_color %>;"></div> <%= issue.status.name %></td>
64 <td align="center"><%= issue.priority.name %></td>
64 <td align="center"><%= issue.priority.name %></td>
65 <td><%= link_to h(issue.subject), :controller => 'issues', :action => 'show', :id => issue %></td>
65 <td><%= "#{issue.project.name} - " unless @project && @project == issue.project %><%= link_to h(issue.subject), :controller => 'issues', :action => 'show', :id => issue %></td>
66 <td align="center"><%= issue.assigned_to.name if issue.assigned_to %></td>
66 <td align="center"><%= issue.assigned_to.name if issue.assigned_to %></td>
67 <td align="center"><%= format_time(issue.updated_on) %></td>
67 <td align="center"><%= format_time(issue.updated_on) %></td>
68 </tr>
68 </tr>
69 <% end %>
69 <% end %>
70 </tbody>
70 </tbody>
71 </table>
71 </table>
72 <div class="contextual">
72 <div class="contextual">
73 <%= l(:label_export_to) %>
73 <%= l(:label_export_to) %>
74 <%= link_to 'CSV', {:action => 'export_issues_csv', :id => @project}, :class => 'icon icon-csv' %>,
74 <%= link_to 'CSV', {:action => 'export_issues_csv', :id => @project}, :class => 'icon icon-csv' %>,
75 <%= link_to 'PDF', {:action => 'export_issues_pdf', :id => @project}, :class => 'icon icon-pdf' %>
75 <%= link_to 'PDF', {:action => 'export_issues_pdf', :id => @project}, :class => 'icon icon-pdf' %>
76 </div>
76 </div>
77 <p><%= submit_tag l(:button_move), :class => "button-small" %>
77 <p><%= submit_tag l(:button_move), :class => "button-small" %>
78 &nbsp;
78 &nbsp;
79 <%= pagination_links_full @issue_pages %>
79 <%= pagination_links_full @issue_pages %>
80 [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]
80 [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]
81 </p>
81 </p>
82 <% end %>
82 <% end %>
83 <% end %>
83 <% end %>
84 <% end %> No newline at end of file
84 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now