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