##// END OF EJS Templates
associations loading correction in projects/export_issues_pdf...
Jean-Philippe Lang -
r230:4ff7b395dd7a
parent child
Show More
@@ -1,578 +1,578
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 'name', 'asc'
42 sort_init 'name', 'asc'
43 sort_update
43 sort_update
44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
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 => ["is_public=?", true],
49 :conditions => ["is_public=?", true],
50 :limit => @project_pages.items_per_page,
50 :limit => @project_pages.items_per_page,
51 :offset => @project_pages.current.offset
51 :offset => @project_pages.current.offset
52
52
53 render :action => "list", :layout => false if request.xhr?
53 render :action => "list", :layout => false if request.xhr?
54 end
54 end
55
55
56 # Add a new project
56 # Add a new project
57 def add
57 def add
58 @custom_fields = IssueCustomField.find(:all)
58 @custom_fields = IssueCustomField.find(:all)
59 @root_projects = Project.find(:all, :conditions => "parent_id is null")
59 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 @project = Project.new(params[:project])
60 @project = Project.new(params[:project])
61 if request.get?
61 if request.get?
62 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
62 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 else
63 else
64 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
64 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 @project.custom_values = @custom_values
66 @project.custom_values = @custom_values
67 if params[:repository_enabled] && params[:repository_enabled] == "1"
67 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 @project.repository = Repository.new
68 @project.repository = Repository.new
69 @project.repository.attributes = params[:repository]
69 @project.repository.attributes = params[:repository]
70 end
70 end
71 if @project.save
71 if @project.save
72 flash[:notice] = l(:notice_successful_create)
72 flash[:notice] = l(:notice_successful_create)
73 redirect_to :controller => 'admin', :action => 'projects'
73 redirect_to :controller => 'admin', :action => 'projects'
74 end
74 end
75 end
75 end
76 end
76 end
77
77
78 # Show @project
78 # Show @project
79 def show
79 def show
80 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
80 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
81 @members = @project.members.find(:all, :include => [:user, :role])
81 @members = @project.members.find(:all, :include => [:user, :role])
82 @subprojects = @project.children if @project.children.size > 0
82 @subprojects = @project.children if @project.children.size > 0
83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
83 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC")
84 @trackers = Tracker.find(:all, :order => 'position')
84 @trackers = Tracker.find(:all, :order => 'position')
85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id", :conditions => ["project_id=? and issue_statuses.is_closed=?", @project.id, false])
85 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN issue_statuses ON issue_statuses.id = issues.status_id", :conditions => ["project_id=? and issue_statuses.is_closed=?", @project.id, false])
86 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
86 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
87 end
87 end
88
88
89 def settings
89 def settings
90 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
90 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
91 @custom_fields = IssueCustomField.find(:all)
91 @custom_fields = IssueCustomField.find(:all)
92 @issue_category ||= IssueCategory.new
92 @issue_category ||= IssueCategory.new
93 @member ||= @project.members.new
93 @member ||= @project.members.new
94 @roles = Role.find(:all, :order => 'position')
94 @roles = Role.find(:all, :order => 'position')
95 @users = User.find_active(:all) - @project.users
95 @users = User.find_active(:all) - @project.users
96 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
96 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
97 end
97 end
98
98
99 # Edit @project
99 # Edit @project
100 def edit
100 def edit
101 if request.post?
101 if request.post?
102 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
102 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 if params[:custom_fields]
103 if params[:custom_fields]
104 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
104 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 @project.custom_values = @custom_values
105 @project.custom_values = @custom_values
106 end
106 end
107 if params[:repository_enabled]
107 if params[:repository_enabled]
108 case params[:repository_enabled]
108 case params[:repository_enabled]
109 when "0"
109 when "0"
110 @project.repository = nil
110 @project.repository = nil
111 when "1"
111 when "1"
112 @project.repository ||= Repository.new
112 @project.repository ||= Repository.new
113 @project.repository.attributes = params[:repository]
113 @project.repository.attributes = params[:repository]
114 end
114 end
115 end
115 end
116 @project.attributes = params[:project]
116 @project.attributes = params[:project]
117 if @project.save
117 if @project.save
118 flash[:notice] = l(:notice_successful_update)
118 flash[:notice] = l(:notice_successful_update)
119 redirect_to :action => 'settings', :id => @project
119 redirect_to :action => 'settings', :id => @project
120 else
120 else
121 settings
121 settings
122 render :action => 'settings'
122 render :action => 'settings'
123 end
123 end
124 end
124 end
125 end
125 end
126
126
127 # Delete @project
127 # Delete @project
128 def destroy
128 def destroy
129 if request.post? and params[:confirm]
129 if request.post? and params[:confirm]
130 @project.destroy
130 @project.destroy
131 redirect_to :controller => 'admin', :action => 'projects'
131 redirect_to :controller => 'admin', :action => 'projects'
132 end
132 end
133 end
133 end
134
134
135 # Add a new issue category to @project
135 # Add a new issue category to @project
136 def add_issue_category
136 def add_issue_category
137 if request.post?
137 if request.post?
138 @issue_category = @project.issue_categories.build(params[:issue_category])
138 @issue_category = @project.issue_categories.build(params[:issue_category])
139 if @issue_category.save
139 if @issue_category.save
140 flash[:notice] = l(:notice_successful_create)
140 flash[:notice] = l(:notice_successful_create)
141 redirect_to :action => 'settings', :tab => 'categories', :id => @project
141 redirect_to :action => 'settings', :tab => 'categories', :id => @project
142 else
142 else
143 settings
143 settings
144 render :action => 'settings'
144 render :action => 'settings'
145 end
145 end
146 end
146 end
147 end
147 end
148
148
149 # Add a new version to @project
149 # Add a new version to @project
150 def add_version
150 def add_version
151 @version = @project.versions.build(params[:version])
151 @version = @project.versions.build(params[:version])
152 if request.post? and @version.save
152 if request.post? and @version.save
153 flash[:notice] = l(:notice_successful_create)
153 flash[:notice] = l(:notice_successful_create)
154 redirect_to :action => 'settings', :tab => 'versions', :id => @project
154 redirect_to :action => 'settings', :tab => 'versions', :id => @project
155 end
155 end
156 end
156 end
157
157
158 # Add a new member to @project
158 # Add a new member to @project
159 def add_member
159 def add_member
160 @member = @project.members.build(params[:member])
160 @member = @project.members.build(params[:member])
161 if request.post?
161 if request.post?
162 if @member.save
162 if @member.save
163 flash[:notice] = l(:notice_successful_create)
163 flash[:notice] = l(:notice_successful_create)
164 redirect_to :action => 'settings', :tab => 'members', :id => @project
164 redirect_to :action => 'settings', :tab => 'members', :id => @project
165 else
165 else
166 settings
166 settings
167 render :action => 'settings'
167 render :action => 'settings'
168 end
168 end
169 end
169 end
170 end
170 end
171
171
172 # Show members list of @project
172 # Show members list of @project
173 def list_members
173 def list_members
174 @members = @project.members
174 @members = @project.members
175 end
175 end
176
176
177 # Add a new document to @project
177 # Add a new document to @project
178 def add_document
178 def add_document
179 @categories = Enumeration::get_values('DCAT')
179 @categories = Enumeration::get_values('DCAT')
180 @document = @project.documents.build(params[:document])
180 @document = @project.documents.build(params[:document])
181 if request.post? and @document.save
181 if request.post? and @document.save
182 # Save the attachments
182 # Save the attachments
183 params[:attachments].each { |a|
183 params[:attachments].each { |a|
184 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
184 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
185 } if params[:attachments] and params[:attachments].is_a? Array
185 } if params[:attachments] and params[:attachments].is_a? Array
186 flash[:notice] = l(:notice_successful_create)
186 flash[:notice] = l(:notice_successful_create)
187 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
187 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
188 redirect_to :action => 'list_documents', :id => @project
188 redirect_to :action => 'list_documents', :id => @project
189 end
189 end
190 end
190 end
191
191
192 # Show documents list of @project
192 # Show documents list of @project
193 def list_documents
193 def list_documents
194 @documents = @project.documents.find :all, :include => :category
194 @documents = @project.documents.find :all, :include => :category
195 end
195 end
196
196
197 # Add a new issue to @project
197 # Add a new issue to @project
198 def add_issue
198 def add_issue
199 @tracker = Tracker.find(params[:tracker_id])
199 @tracker = Tracker.find(params[:tracker_id])
200 @priorities = Enumeration::get_values('IPRI')
200 @priorities = Enumeration::get_values('IPRI')
201 @issue = Issue.new(:project => @project, :tracker => @tracker)
201 @issue = Issue.new(:project => @project, :tracker => @tracker)
202 if request.get?
202 if request.get?
203 @issue.start_date = Date.today
203 @issue.start_date = Date.today
204 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
204 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
205 else
205 else
206 @issue.attributes = params[:issue]
206 @issue.attributes = params[:issue]
207 @issue.author_id = self.logged_in_user.id if self.logged_in_user
207 @issue.author_id = self.logged_in_user.id if self.logged_in_user
208 # Multiple file upload
208 # Multiple file upload
209 @attachments = []
209 @attachments = []
210 params[:attachments].each { |a|
210 params[:attachments].each { |a|
211 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
211 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
212 } if params[:attachments] and params[:attachments].is_a? Array
212 } if params[:attachments] and params[:attachments].is_a? Array
213 @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]) }
213 @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]) }
214 @issue.custom_values = @custom_values
214 @issue.custom_values = @custom_values
215 if @issue.save
215 if @issue.save
216 @attachments.each(&:save)
216 @attachments.each(&:save)
217 flash[:notice] = l(:notice_successful_create)
217 flash[:notice] = l(:notice_successful_create)
218 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
218 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
219 redirect_to :action => 'list_issues', :id => @project
219 redirect_to :action => 'list_issues', :id => @project
220 end
220 end
221 end
221 end
222 end
222 end
223
223
224 # Show filtered/sorted issues list of @project
224 # Show filtered/sorted issues list of @project
225 def list_issues
225 def list_issues
226 sort_init 'issues.id', 'desc'
226 sort_init 'issues.id', 'desc'
227 sort_update
227 sort_update
228
228
229 retrieve_query
229 retrieve_query
230
230
231 @results_per_page_options = [ 15, 25, 50, 100 ]
231 @results_per_page_options = [ 15, 25, 50, 100 ]
232 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
232 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
233 @results_per_page = params[:per_page].to_i
233 @results_per_page = params[:per_page].to_i
234 session[:results_per_page] = @results_per_page
234 session[:results_per_page] = @results_per_page
235 else
235 else
236 @results_per_page = session[:results_per_page] || 25
236 @results_per_page = session[:results_per_page] || 25
237 end
237 end
238
238
239 if @query.valid?
239 if @query.valid?
240 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
240 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
241 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
241 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
242 @issues = Issue.find :all, :order => sort_clause,
242 @issues = Issue.find :all, :order => sort_clause,
243 :include => [ :author, :status, :tracker, :project, :priority ],
243 :include => [ :author, :status, :tracker, :project, :priority ],
244 :conditions => @query.statement,
244 :conditions => @query.statement,
245 :limit => @issue_pages.items_per_page,
245 :limit => @issue_pages.items_per_page,
246 :offset => @issue_pages.current.offset
246 :offset => @issue_pages.current.offset
247 end
247 end
248 @trackers = Tracker.find :all, :order => 'position'
248 @trackers = Tracker.find :all, :order => 'position'
249 render :layout => false if request.xhr?
249 render :layout => false if request.xhr?
250 end
250 end
251
251
252 # Export filtered/sorted issues list to CSV
252 # Export filtered/sorted issues list to CSV
253 def export_issues_csv
253 def export_issues_csv
254 sort_init 'issues.id', 'desc'
254 sort_init 'issues.id', 'desc'
255 sort_update
255 sort_update
256
256
257 retrieve_query
257 retrieve_query
258 render :action => 'list_issues' and return unless @query.valid?
258 render :action => 'list_issues' and return unless @query.valid?
259
259
260 @issues = Issue.find :all, :order => sort_clause,
260 @issues = Issue.find :all, :order => sort_clause,
261 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
261 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
262 :conditions => @query.statement,
262 :conditions => @query.statement,
263 :limit => 500
263 :limit => 500
264
264
265 ic = Iconv.new('ISO-8859-1', 'UTF-8')
265 ic = Iconv.new('ISO-8859-1', 'UTF-8')
266 export = StringIO.new
266 export = StringIO.new
267 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
267 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
268 # csv header fields
268 # csv header fields
269 headers = [ "#", l(:field_status),
269 headers = [ "#", l(:field_status),
270 l(:field_tracker),
270 l(:field_tracker),
271 l(:field_priority),
271 l(:field_priority),
272 l(:field_subject),
272 l(:field_subject),
273 l(:field_author),
273 l(:field_author),
274 l(:field_start_date),
274 l(:field_start_date),
275 l(:field_due_date),
275 l(:field_due_date),
276 l(:field_done_ratio),
276 l(:field_done_ratio),
277 l(:field_created_on),
277 l(:field_created_on),
278 l(:field_updated_on)
278 l(:field_updated_on)
279 ]
279 ]
280 for custom_field in @project.all_custom_fields
280 for custom_field in @project.all_custom_fields
281 headers << custom_field.name
281 headers << custom_field.name
282 end
282 end
283 csv << headers.collect {|c| ic.iconv(c) }
283 csv << headers.collect {|c| ic.iconv(c) }
284 # csv lines
284 # csv lines
285 @issues.each do |issue|
285 @issues.each do |issue|
286 fields = [issue.id, issue.status.name,
286 fields = [issue.id, issue.status.name,
287 issue.tracker.name,
287 issue.tracker.name,
288 issue.priority.name,
288 issue.priority.name,
289 issue.subject,
289 issue.subject,
290 issue.author.display_name,
290 issue.author.display_name,
291 issue.start_date ? l_date(issue.start_date) : nil,
291 issue.start_date ? l_date(issue.start_date) : nil,
292 issue.due_date ? l_date(issue.due_date) : nil,
292 issue.due_date ? l_date(issue.due_date) : nil,
293 issue.done_ratio,
293 issue.done_ratio,
294 l_datetime(issue.created_on),
294 l_datetime(issue.created_on),
295 l_datetime(issue.updated_on)
295 l_datetime(issue.updated_on)
296 ]
296 ]
297 for custom_field in @project.all_custom_fields
297 for custom_field in @project.all_custom_fields
298 fields << (show_value issue.custom_value_for(custom_field))
298 fields << (show_value issue.custom_value_for(custom_field))
299 end
299 end
300 csv << fields.collect {|c| ic.iconv(c.to_s) }
300 csv << fields.collect {|c| ic.iconv(c.to_s) }
301 end
301 end
302 end
302 end
303 export.rewind
303 export.rewind
304 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
304 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
305 end
305 end
306
306
307 # Export filtered/sorted issues to PDF
307 # Export filtered/sorted issues to PDF
308 def export_issues_pdf
308 def export_issues_pdf
309 sort_init 'issues.id', 'desc'
309 sort_init 'issues.id', 'desc'
310 sort_update
310 sort_update
311
311
312 retrieve_query
312 retrieve_query
313 render :action => 'list_issues' and return unless @query.valid?
313 render :action => 'list_issues' and return unless @query.valid?
314
314
315 @issues = Issue.find :all, :order => sort_clause,
315 @issues = Issue.find :all, :order => sort_clause,
316 :include => [ :author, :status, :tracker, :project, :custom_values ],
316 :include => [ :author, :status, :tracker, :priority ],
317 :conditions => @query.statement,
317 :conditions => @query.statement,
318 :limit => 500
318 :limit => 500
319
319
320 @options_for_rfpdf ||= {}
320 @options_for_rfpdf ||= {}
321 @options_for_rfpdf[:file_name] = "export.pdf"
321 @options_for_rfpdf[:file_name] = "export.pdf"
322 render :layout => false
322 render :layout => false
323 end
323 end
324
324
325 def move_issues
325 def move_issues
326 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
326 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
327 redirect_to :action => 'list_issues', :id => @project and return unless @issues
327 redirect_to :action => 'list_issues', :id => @project and return unless @issues
328 @projects = []
328 @projects = []
329 # find projects to which the user is allowed to move the issue
329 # find projects to which the user is allowed to move the issue
330 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
330 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
331 # issue can be moved to any tracker
331 # issue can be moved to any tracker
332 @trackers = Tracker.find(:all)
332 @trackers = Tracker.find(:all)
333 if request.post? and params[:new_project_id] and params[:new_tracker_id]
333 if request.post? and params[:new_project_id] and params[:new_tracker_id]
334 new_project = Project.find(params[:new_project_id])
334 new_project = Project.find(params[:new_project_id])
335 new_tracker = Tracker.find(params[:new_tracker_id])
335 new_tracker = Tracker.find(params[:new_tracker_id])
336 @issues.each { |i|
336 @issues.each { |i|
337 # project dependent properties
337 # project dependent properties
338 unless i.project_id == new_project.id
338 unless i.project_id == new_project.id
339 i.category = nil
339 i.category = nil
340 i.fixed_version = nil
340 i.fixed_version = nil
341 end
341 end
342 # move the issue
342 # move the issue
343 i.project = new_project
343 i.project = new_project
344 i.tracker = new_tracker
344 i.tracker = new_tracker
345 i.save
345 i.save
346 }
346 }
347 flash[:notice] = l(:notice_successful_update)
347 flash[:notice] = l(:notice_successful_update)
348 redirect_to :action => 'list_issues', :id => @project
348 redirect_to :action => 'list_issues', :id => @project
349 end
349 end
350 end
350 end
351
351
352 def add_query
352 def add_query
353 @query = Query.new(params[:query])
353 @query = Query.new(params[:query])
354 @query.project = @project
354 @query.project = @project
355 @query.user = logged_in_user
355 @query.user = logged_in_user
356
356
357 params[:fields].each do |field|
357 params[:fields].each do |field|
358 @query.add_filter(field, params[:operators][field], params[:values][field])
358 @query.add_filter(field, params[:operators][field], params[:values][field])
359 end if params[:fields]
359 end if params[:fields]
360
360
361 if request.post? and @query.save
361 if request.post? and @query.save
362 flash[:notice] = l(:notice_successful_create)
362 flash[:notice] = l(:notice_successful_create)
363 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
363 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
364 end
364 end
365 render :layout => false if request.xhr?
365 render :layout => false if request.xhr?
366 end
366 end
367
367
368 # Add a news to @project
368 # Add a news to @project
369 def add_news
369 def add_news
370 @news = News.new(:project => @project)
370 @news = News.new(:project => @project)
371 if request.post?
371 if request.post?
372 @news.attributes = params[:news]
372 @news.attributes = params[:news]
373 @news.author_id = self.logged_in_user.id if self.logged_in_user
373 @news.author_id = self.logged_in_user.id if self.logged_in_user
374 if @news.save
374 if @news.save
375 flash[:notice] = l(:notice_successful_create)
375 flash[:notice] = l(:notice_successful_create)
376 redirect_to :action => 'list_news', :id => @project
376 redirect_to :action => 'list_news', :id => @project
377 end
377 end
378 end
378 end
379 end
379 end
380
380
381 # Show news list of @project
381 # Show news list of @project
382 def list_news
382 def list_news
383 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC"
383 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "news.created_on DESC"
384 render :action => "list_news", :layout => false if request.xhr?
384 render :action => "list_news", :layout => false if request.xhr?
385 end
385 end
386
386
387 def add_file
387 def add_file
388 if request.post?
388 if request.post?
389 @version = @project.versions.find_by_id(params[:version_id])
389 @version = @project.versions.find_by_id(params[:version_id])
390 # Save the attachments
390 # Save the attachments
391 @attachments = []
391 @attachments = []
392 params[:attachments].each { |file|
392 params[:attachments].each { |file|
393 next unless file.size > 0
393 next unless file.size > 0
394 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
394 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
395 @attachments << a unless a.new_record?
395 @attachments << a unless a.new_record?
396 } if params[:attachments] and params[:attachments].is_a? Array
396 } if params[:attachments] and params[:attachments].is_a? Array
397 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
397 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
398 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
398 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
399 end
399 end
400 @versions = @project.versions
400 @versions = @project.versions
401 end
401 end
402
402
403 def list_files
403 def list_files
404 @versions = @project.versions
404 @versions = @project.versions
405 end
405 end
406
406
407 # Show changelog for @project
407 # Show changelog for @project
408 def changelog
408 def changelog
409 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
409 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
410 if request.get?
410 if request.get?
411 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
411 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
412 else
412 else
413 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
413 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
414 end
414 end
415 @selected_tracker_ids ||= []
415 @selected_tracker_ids ||= []
416 @fixed_issues = @project.issues.find(:all,
416 @fixed_issues = @project.issues.find(:all,
417 :include => [ :fixed_version, :status, :tracker ],
417 :include => [ :fixed_version, :status, :tracker ],
418 :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true],
418 :conditions => [ "issue_statuses.is_closed=? and issues.tracker_id in (#{@selected_tracker_ids.join(',')}) and issues.fixed_version_id is not null", true],
419 :order => "versions.effective_date DESC, issues.id DESC"
419 :order => "versions.effective_date DESC, issues.id DESC"
420 ) unless @selected_tracker_ids.empty?
420 ) unless @selected_tracker_ids.empty?
421 @fixed_issues ||= []
421 @fixed_issues ||= []
422 end
422 end
423
423
424 def roadmap
424 def roadmap
425 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
425 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
426 if request.get?
426 if request.get?
427 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
427 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
428 else
428 else
429 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
429 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
430 end
430 end
431 @selected_tracker_ids ||= []
431 @selected_tracker_ids ||= []
432 @versions = @project.versions.find(:all,
432 @versions = @project.versions.find(:all,
433 :conditions => [ "versions.effective_date>?", Date.today],
433 :conditions => [ "versions.effective_date>?", Date.today],
434 :order => "versions.effective_date ASC"
434 :order => "versions.effective_date ASC"
435 )
435 )
436 end
436 end
437
437
438 def activity
438 def activity
439 if params[:year] and params[:year].to_i > 1900
439 if params[:year] and params[:year].to_i > 1900
440 @year = params[:year].to_i
440 @year = params[:year].to_i
441 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
441 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
442 @month = params[:month].to_i
442 @month = params[:month].to_i
443 end
443 end
444 end
444 end
445 @year ||= Date.today.year
445 @year ||= Date.today.year
446 @month ||= Date.today.month
446 @month ||= Date.today.month
447
447
448 @date_from = Date.civil(@year, @month, 1)
448 @date_from = Date.civil(@year, @month, 1)
449 @date_to = (@date_from >> 1)-1
449 @date_to = (@date_from >> 1)-1
450
450
451 @events_by_day = {}
451 @events_by_day = {}
452
452
453 unless params[:show_issues] == "0"
453 unless params[:show_issues] == "0"
454 @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i|
454 @project.issues.find(:all, :include => [:author, :status], :conditions => ["issues.created_on>=? and issues.created_on<=?", @date_from, @date_to] ).each { |i|
455 @events_by_day[i.created_on.to_date] ||= []
455 @events_by_day[i.created_on.to_date] ||= []
456 @events_by_day[i.created_on.to_date] << i
456 @events_by_day[i.created_on.to_date] << i
457 }
457 }
458 @show_issues = 1
458 @show_issues = 1
459 end
459 end
460
460
461 unless params[:show_news] == "0"
461 unless params[:show_news] == "0"
462 @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
462 @project.news.find(:all, :conditions => ["news.created_on>=? and news.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
463 @events_by_day[i.created_on.to_date] ||= []
463 @events_by_day[i.created_on.to_date] ||= []
464 @events_by_day[i.created_on.to_date] << i
464 @events_by_day[i.created_on.to_date] << i
465 }
465 }
466 @show_news = 1
466 @show_news = 1
467 end
467 end
468
468
469 unless params[:show_files] == "0"
469 unless params[:show_files] == "0"
470 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
470 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN versions ON versions.id = attachments.container_id", :conditions => ["attachments.container_type='Version' and versions.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
471 @events_by_day[i.created_on.to_date] ||= []
471 @events_by_day[i.created_on.to_date] ||= []
472 @events_by_day[i.created_on.to_date] << i
472 @events_by_day[i.created_on.to_date] << i
473 }
473 }
474 @show_files = 1
474 @show_files = 1
475 end
475 end
476
476
477 unless params[:show_documents] == "0"
477 unless params[:show_documents] == "0"
478 @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i|
478 @project.documents.find(:all, :conditions => ["documents.created_on>=? and documents.created_on<=?", @date_from, @date_to] ).each { |i|
479 @events_by_day[i.created_on.to_date] ||= []
479 @events_by_day[i.created_on.to_date] ||= []
480 @events_by_day[i.created_on.to_date] << i
480 @events_by_day[i.created_on.to_date] << i
481 }
481 }
482 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
482 Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN documents ON documents.id = attachments.container_id", :conditions => ["attachments.container_type='Document' and documents.project_id=? and attachments.created_on>=? and attachments.created_on<=?", @project.id, @date_from, @date_to], :include => :author ).each { |i|
483 @events_by_day[i.created_on.to_date] ||= []
483 @events_by_day[i.created_on.to_date] ||= []
484 @events_by_day[i.created_on.to_date] << i
484 @events_by_day[i.created_on.to_date] << i
485 }
485 }
486 @show_documents = 1
486 @show_documents = 1
487 end
487 end
488
488
489 render :layout => false if request.xhr?
489 render :layout => false if request.xhr?
490 end
490 end
491
491
492 def calendar
492 def calendar
493 if params[:year] and params[:year].to_i > 1900
493 if params[:year] and params[:year].to_i > 1900
494 @year = params[:year].to_i
494 @year = params[:year].to_i
495 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
495 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
496 @month = params[:month].to_i
496 @month = params[:month].to_i
497 end
497 end
498 end
498 end
499 @year ||= Date.today.year
499 @year ||= Date.today.year
500 @month ||= Date.today.month
500 @month ||= Date.today.month
501
501
502 @date_from = Date.civil(@year, @month, 1)
502 @date_from = Date.civil(@year, @month, 1)
503 @date_to = (@date_from >> 1)-1
503 @date_to = (@date_from >> 1)-1
504 # start on monday
504 # start on monday
505 @date_from = @date_from - (@date_from.cwday-1)
505 @date_from = @date_from - (@date_from.cwday-1)
506 # finish on sunday
506 # finish on sunday
507 @date_to = @date_to + (7-@date_to.cwday)
507 @date_to = @date_to + (7-@date_to.cwday)
508
508
509 @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
509 @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
510 render :layout => false if request.xhr?
510 render :layout => false if request.xhr?
511 end
511 end
512
512
513 def gantt
513 def gantt
514 if params[:year] and params[:year].to_i >0
514 if params[:year] and params[:year].to_i >0
515 @year_from = params[:year].to_i
515 @year_from = params[:year].to_i
516 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
516 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
517 @month_from = params[:month].to_i
517 @month_from = params[:month].to_i
518 else
518 else
519 @month_from = 1
519 @month_from = 1
520 end
520 end
521 else
521 else
522 @month_from ||= (Date.today << 1).month
522 @month_from ||= (Date.today << 1).month
523 @year_from ||= (Date.today << 1).year
523 @year_from ||= (Date.today << 1).year
524 end
524 end
525
525
526 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
526 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
527 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
527 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
528
528
529 @date_from = Date.civil(@year_from, @month_from, 1)
529 @date_from = Date.civil(@year_from, @month_from, 1)
530 @date_to = (@date_from >> @months) - 1
530 @date_to = (@date_from >> @months) - 1
531 @issues = @project.issues.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :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)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to])
531 @issues = @project.issues.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :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)", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to])
532
532
533 if params[:output]=='pdf'
533 if params[:output]=='pdf'
534 @options_for_rfpdf ||= {}
534 @options_for_rfpdf ||= {}
535 @options_for_rfpdf[:file_name] = "gantt.pdf"
535 @options_for_rfpdf[:file_name] = "gantt.pdf"
536 render :template => "projects/gantt.rfpdf", :layout => false
536 render :template => "projects/gantt.rfpdf", :layout => false
537 else
537 else
538 render :template => "projects/gantt.rhtml"
538 render :template => "projects/gantt.rhtml"
539 end
539 end
540 end
540 end
541
541
542 private
542 private
543 # Find project of id params[:id]
543 # Find project of id params[:id]
544 # if not found, redirect to project list
544 # if not found, redirect to project list
545 # Used as a before_filter
545 # Used as a before_filter
546 def find_project
546 def find_project
547 @project = Project.find(params[:id])
547 @project = Project.find(params[:id])
548 @html_title = @project.name
548 @html_title = @project.name
549 rescue ActiveRecord::RecordNotFound
549 rescue ActiveRecord::RecordNotFound
550 render_404
550 render_404
551 end
551 end
552
552
553 # Retrieve query from session or build a new query
553 # Retrieve query from session or build a new query
554 def retrieve_query
554 def retrieve_query
555 if params[:query_id]
555 if params[:query_id]
556 @query = @project.queries.find(params[:query_id])
556 @query = @project.queries.find(params[:query_id])
557 session[:query] = @query
557 session[:query] = @query
558 else
558 else
559 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
559 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
560 # Give it a name, required to be valid
560 # Give it a name, required to be valid
561 @query = Query.new(:name => "_")
561 @query = Query.new(:name => "_")
562 @query.project = @project
562 @query.project = @project
563 if params[:fields] and params[:fields].is_a? Array
563 if params[:fields] and params[:fields].is_a? Array
564 params[:fields].each do |field|
564 params[:fields].each do |field|
565 @query.add_filter(field, params[:operators][field], params[:values][field])
565 @query.add_filter(field, params[:operators][field], params[:values][field])
566 end
566 end
567 else
567 else
568 @query.available_filters.keys.each do |field|
568 @query.available_filters.keys.each do |field|
569 @query.add_short_filter(field, params[field]) if params[field]
569 @query.add_short_filter(field, params[field]) if params[field]
570 end
570 end
571 end
571 end
572 session[:query] = @query
572 session[:query] = @query
573 else
573 else
574 @query = session[:query]
574 @query = session[:query]
575 end
575 end
576 end
576 end
577 end
577 end
578 end
578 end
General Comments 0
You need to be logged in to leave comments. Login now