##// END OF EJS Templates
better rendering time for projects/calendar...
Jean-Philippe Lang -
r340:db3e8616c89b
parent child
Show More
@@ -1,619 +1,624
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, :authorize, :except => [ :index, :list, :add ]
23 23 before_filter :require_admin, :only => [ :add, :destroy ]
24 24
25 25 helper :sort
26 26 include SortHelper
27 27 helper :custom_fields
28 28 include CustomFieldsHelper
29 29 helper :ifpdf
30 30 include IfpdfHelper
31 31 helper IssuesHelper
32 32 helper :queries
33 33 include QueriesHelper
34 34
35 35 def index
36 36 list
37 37 render :action => 'list' unless request.xhr?
38 38 end
39 39
40 40 # Lists public projects
41 41 def list
42 42 sort_init 'name', 'asc'
43 43 sort_update
44 44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
45 45 @project_pages = Paginator.new self, @project_count,
46 46 15,
47 47 params['page']
48 48 @projects = Project.find :all, :order => sort_clause,
49 49 :conditions => ["is_public=?", true],
50 50 :limit => @project_pages.items_per_page,
51 51 :offset => @project_pages.current.offset
52 52
53 53 render :action => "list", :layout => false if request.xhr?
54 54 end
55 55
56 56 # Add a new project
57 57 def add
58 58 @custom_fields = IssueCustomField.find(:all)
59 59 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 60 @project = Project.new(params[:project])
61 61 if request.get?
62 62 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 63 else
64 64 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 66 @project.custom_values = @custom_values
67 67 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 68 @project.repository = Repository.new
69 69 @project.repository.attributes = params[:repository]
70 70 end
71 71 if "1" == params[:wiki_enabled]
72 72 @project.wiki = Wiki.new
73 73 @project.wiki.attributes = params[:wiki]
74 74 end
75 75 if @project.save
76 76 flash[:notice] = l(:notice_successful_create)
77 77 redirect_to :controller => 'admin', :action => 'projects'
78 78 end
79 79 end
80 80 end
81 81
82 82 # Show @project
83 83 def show
84 84 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
85 85 @members = @project.members.find(:all, :include => [:user, :role], :order => 'position')
86 86 @subprojects = @project.children if @project.children.size > 0
87 87 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
88 88 @trackers = Tracker.find(:all, :order => 'position')
89 89 @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 90 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
91 91 end
92 92
93 93 def settings
94 94 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
95 95 @custom_fields = IssueCustomField.find(:all)
96 96 @issue_category ||= IssueCategory.new
97 97 @member ||= @project.members.new
98 98 @roles = Role.find(:all, :order => 'position')
99 99 @users = User.find_active(:all) - @project.users
100 100 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
101 101 end
102 102
103 103 # Edit @project
104 104 def edit
105 105 if request.post?
106 106 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
107 107 if params[:custom_fields]
108 108 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
109 109 @project.custom_values = @custom_values
110 110 end
111 111 if params[:repository_enabled]
112 112 case params[:repository_enabled]
113 113 when "0"
114 114 @project.repository = nil
115 115 when "1"
116 116 @project.repository ||= Repository.new
117 117 @project.repository.update_attributes params[:repository]
118 118 end
119 119 end
120 120 if params[:wiki_enabled]
121 121 case params[:wiki_enabled]
122 122 when "0"
123 123 @project.wiki.destroy if @project.wiki
124 124 when "1"
125 125 @project.wiki ||= Wiki.new
126 126 @project.wiki.update_attributes params[:wiki]
127 127 end
128 128 end
129 129 @project.attributes = params[:project]
130 130 if @project.save
131 131 flash[:notice] = l(:notice_successful_update)
132 132 redirect_to :action => 'settings', :id => @project
133 133 else
134 134 settings
135 135 render :action => 'settings'
136 136 end
137 137 end
138 138 end
139 139
140 140 # Delete @project
141 141 def destroy
142 142 if request.post? and params[:confirm]
143 143 @project.destroy
144 144 redirect_to :controller => 'admin', :action => 'projects'
145 145 end
146 146 end
147 147
148 148 # Add a new issue category to @project
149 149 def add_issue_category
150 150 if request.post?
151 151 @issue_category = @project.issue_categories.build(params[:issue_category])
152 152 if @issue_category.save
153 153 flash[:notice] = l(:notice_successful_create)
154 154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 155 else
156 156 settings
157 157 render :action => 'settings'
158 158 end
159 159 end
160 160 end
161 161
162 162 # Add a new version to @project
163 163 def add_version
164 164 @version = @project.versions.build(params[:version])
165 165 if request.post? and @version.save
166 166 flash[:notice] = l(:notice_successful_create)
167 167 redirect_to :action => 'settings', :tab => 'versions', :id => @project
168 168 end
169 169 end
170 170
171 171 # Add a new member to @project
172 172 def add_member
173 173 @member = @project.members.build(params[:member])
174 174 if request.post?
175 175 if @member.save
176 176 flash[:notice] = l(:notice_successful_create)
177 177 redirect_to :action => 'settings', :tab => 'members', :id => @project
178 178 else
179 179 settings
180 180 render :action => 'settings'
181 181 end
182 182 end
183 183 end
184 184
185 185 # Show members list of @project
186 186 def list_members
187 187 @members = @project.members.find(:all)
188 188 end
189 189
190 190 # Add a new document to @project
191 191 def add_document
192 192 @categories = Enumeration::get_values('DCAT')
193 193 @document = @project.documents.build(params[:document])
194 194 if request.post? and @document.save
195 195 # Save the attachments
196 196 params[:attachments].each { |a|
197 197 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
198 198 } if params[:attachments] and params[:attachments].is_a? Array
199 199 flash[:notice] = l(:notice_successful_create)
200 200 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
201 201 redirect_to :action => 'list_documents', :id => @project
202 202 end
203 203 end
204 204
205 205 # Show documents list of @project
206 206 def list_documents
207 207 @documents = @project.documents.find :all, :include => :category
208 208 end
209 209
210 210 # Add a new issue to @project
211 211 def add_issue
212 212 @tracker = Tracker.find(params[:tracker_id])
213 213 @priorities = Enumeration::get_values('IPRI')
214 214 @issue = Issue.new(:project => @project, :tracker => @tracker)
215 215 if request.get?
216 216 @issue.start_date = Date.today
217 217 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
218 218 else
219 219 @issue.attributes = params[:issue]
220 220 @issue.author_id = self.logged_in_user.id if self.logged_in_user
221 221 # Multiple file upload
222 222 @attachments = []
223 223 params[:attachments].each { |a|
224 224 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
225 225 } if params[:attachments] and params[:attachments].is_a? Array
226 226 @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]) }
227 227 @issue.custom_values = @custom_values
228 228 if @issue.save
229 229 @attachments.each(&:save)
230 230 flash[:notice] = l(:notice_successful_create)
231 231 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
232 232 redirect_to :action => 'list_issues', :id => @project
233 233 end
234 234 end
235 235 end
236 236
237 237 # Show filtered/sorted issues list of @project
238 238 def list_issues
239 239 sort_init "#{Issue.table_name}.id", "desc"
240 240 sort_update
241 241
242 242 retrieve_query
243 243
244 244 @results_per_page_options = [ 15, 25, 50, 100 ]
245 245 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
246 246 @results_per_page = params[:per_page].to_i
247 247 session[:results_per_page] = @results_per_page
248 248 else
249 249 @results_per_page = session[:results_per_page] || 25
250 250 end
251 251
252 252 if @query.valid?
253 253 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
254 254 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
255 255 @issues = Issue.find :all, :order => sort_clause,
256 256 :include => [ :author, :status, :tracker, :project, :priority ],
257 257 :conditions => @query.statement,
258 258 :limit => @issue_pages.items_per_page,
259 259 :offset => @issue_pages.current.offset
260 260 end
261 261 @trackers = Tracker.find :all, :order => 'position'
262 262 render :layout => false if request.xhr?
263 263 end
264 264
265 265 # Export filtered/sorted issues list to CSV
266 266 def export_issues_csv
267 267 sort_init "#{Issue.table_name}.id", "desc"
268 268 sort_update
269 269
270 270 retrieve_query
271 271 render :action => 'list_issues' and return unless @query.valid?
272 272
273 273 @issues = Issue.find :all, :order => sort_clause,
274 274 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
275 275 :conditions => @query.statement,
276 276 :limit => Setting.issues_export_limit
277 277
278 278 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
279 279 export = StringIO.new
280 280 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
281 281 # csv header fields
282 282 headers = [ "#", l(:field_status),
283 283 l(:field_tracker),
284 284 l(:field_priority),
285 285 l(:field_subject),
286 286 l(:field_author),
287 287 l(:field_start_date),
288 288 l(:field_due_date),
289 289 l(:field_done_ratio),
290 290 l(:field_created_on),
291 291 l(:field_updated_on)
292 292 ]
293 293 for custom_field in @project.all_custom_fields
294 294 headers << custom_field.name
295 295 end
296 296 csv << headers.collect {|c| ic.iconv(c) }
297 297 # csv lines
298 298 @issues.each do |issue|
299 299 fields = [issue.id, issue.status.name,
300 300 issue.tracker.name,
301 301 issue.priority.name,
302 302 issue.subject,
303 303 issue.author.display_name,
304 304 issue.start_date ? l_date(issue.start_date) : nil,
305 305 issue.due_date ? l_date(issue.due_date) : nil,
306 306 issue.done_ratio,
307 307 l_datetime(issue.created_on),
308 308 l_datetime(issue.updated_on)
309 309 ]
310 310 for custom_field in @project.all_custom_fields
311 311 fields << (show_value issue.custom_value_for(custom_field))
312 312 end
313 313 csv << fields.collect {|c| ic.iconv(c.to_s) }
314 314 end
315 315 end
316 316 export.rewind
317 317 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
318 318 end
319 319
320 320 # Export filtered/sorted issues to PDF
321 321 def export_issues_pdf
322 322 sort_init "#{Issue.table_name}.id", "desc"
323 323 sort_update
324 324
325 325 retrieve_query
326 326 render :action => 'list_issues' and return unless @query.valid?
327 327
328 328 @issues = Issue.find :all, :order => sort_clause,
329 329 :include => [ :author, :status, :tracker, :priority ],
330 330 :conditions => @query.statement,
331 331 :limit => Setting.issues_export_limit
332 332
333 333 @options_for_rfpdf ||= {}
334 334 @options_for_rfpdf[:file_name] = "export.pdf"
335 335 render :layout => false
336 336 end
337 337
338 338 def move_issues
339 339 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
340 340 redirect_to :action => 'list_issues', :id => @project and return unless @issues
341 341 @projects = []
342 342 # find projects to which the user is allowed to move the issue
343 343 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
344 344 # issue can be moved to any tracker
345 345 @trackers = Tracker.find(:all)
346 346 if request.post? and params[:new_project_id] and params[:new_tracker_id]
347 347 new_project = Project.find(params[:new_project_id])
348 348 new_tracker = Tracker.find(params[:new_tracker_id])
349 349 @issues.each { |i|
350 350 # project dependent properties
351 351 unless i.project_id == new_project.id
352 352 i.category = nil
353 353 i.fixed_version = nil
354 354 end
355 355 # move the issue
356 356 i.project = new_project
357 357 i.tracker = new_tracker
358 358 i.save
359 359 }
360 360 flash[:notice] = l(:notice_successful_update)
361 361 redirect_to :action => 'list_issues', :id => @project
362 362 end
363 363 end
364 364
365 365 def add_query
366 366 @query = Query.new(params[:query])
367 367 @query.project = @project
368 368 @query.user = logged_in_user
369 369
370 370 params[:fields].each do |field|
371 371 @query.add_filter(field, params[:operators][field], params[:values][field])
372 372 end if params[:fields]
373 373
374 374 if request.post? and @query.save
375 375 flash[:notice] = l(:notice_successful_create)
376 376 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
377 377 end
378 378 render :layout => false if request.xhr?
379 379 end
380 380
381 381 # Add a news to @project
382 382 def add_news
383 383 @news = News.new(:project => @project)
384 384 if request.post?
385 385 @news.attributes = params[:news]
386 386 @news.author_id = self.logged_in_user.id if self.logged_in_user
387 387 if @news.save
388 388 flash[:notice] = l(:notice_successful_create)
389 389 redirect_to :action => 'list_news', :id => @project
390 390 end
391 391 end
392 392 end
393 393
394 394 # Show news list of @project
395 395 def list_news
396 396 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
397 397 render :action => "list_news", :layout => false if request.xhr?
398 398 end
399 399
400 400 def add_file
401 401 if request.post?
402 402 @version = @project.versions.find_by_id(params[:version_id])
403 403 # Save the attachments
404 404 @attachments = []
405 405 params[:attachments].each { |file|
406 406 next unless file.size > 0
407 407 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
408 408 @attachments << a unless a.new_record?
409 409 } if params[:attachments] and params[:attachments].is_a? Array
410 410 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
411 411 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
412 412 end
413 413 @versions = @project.versions
414 414 end
415 415
416 416 def list_files
417 417 @versions = @project.versions
418 418 end
419 419
420 420 # Show changelog for @project
421 421 def changelog
422 422 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
423 423 if request.get?
424 424 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
425 425 else
426 426 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
427 427 end
428 428 @selected_tracker_ids ||= []
429 429 @fixed_issues = @project.issues.find(:all,
430 430 :include => [ :fixed_version, :status, :tracker ],
431 431 :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],
432 432 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
433 433 ) unless @selected_tracker_ids.empty?
434 434 @fixed_issues ||= []
435 435 end
436 436
437 437 def roadmap
438 438 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
439 439 if request.get?
440 440 @selected_tracker_ids = @trackers.collect {|t| t.id.to_s }
441 441 else
442 442 @selected_tracker_ids = params[:tracker_ids].collect { |id| id.to_i.to_s } if params[:tracker_ids] and params[:tracker_ids].is_a? Array
443 443 end
444 444 @selected_tracker_ids ||= []
445 445 @versions = @project.versions.find(:all,
446 446 :conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
447 447 :order => "#{Version.table_name}.effective_date ASC"
448 448 )
449 449 end
450 450
451 451 def activity
452 452 if params[:year] and params[:year].to_i > 1900
453 453 @year = params[:year].to_i
454 454 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
455 455 @month = params[:month].to_i
456 456 end
457 457 end
458 458 @year ||= Date.today.year
459 459 @month ||= Date.today.month
460 460
461 461 @date_from = Date.civil(@year, @month, 1)
462 462 @date_to = (@date_from >> 1)-1
463 463
464 464 @events_by_day = {}
465 465
466 466 unless params[:show_issues] == "0"
467 467 @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
468 468 @events_by_day[i.created_on.to_date] ||= []
469 469 @events_by_day[i.created_on.to_date] << i
470 470 }
471 471 @show_issues = 1
472 472 end
473 473
474 474 unless params[:show_news] == "0"
475 475 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
476 476 @events_by_day[i.created_on.to_date] ||= []
477 477 @events_by_day[i.created_on.to_date] << i
478 478 }
479 479 @show_news = 1
480 480 end
481 481
482 482 unless params[:show_files] == "0"
483 483 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|
484 484 @events_by_day[i.created_on.to_date] ||= []
485 485 @events_by_day[i.created_on.to_date] << i
486 486 }
487 487 @show_files = 1
488 488 end
489 489
490 490 unless params[:show_documents] == "0"
491 491 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
492 492 @events_by_day[i.created_on.to_date] ||= []
493 493 @events_by_day[i.created_on.to_date] << i
494 494 }
495 495 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|
496 496 @events_by_day[i.created_on.to_date] ||= []
497 497 @events_by_day[i.created_on.to_date] << i
498 498 }
499 499 @show_documents = 1
500 500 end
501 501
502 502 render :layout => false if request.xhr?
503 503 end
504 504
505 505 def calendar
506 506 if params[:year] and params[:year].to_i > 1900
507 507 @year = params[:year].to_i
508 508 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
509 509 @month = params[:month].to_i
510 510 end
511 511 end
512 512 @year ||= Date.today.year
513 513 @month ||= Date.today.month
514 514
515 515 @date_from = Date.civil(@year, @month, 1)
516 516 @date_to = (@date_from >> 1)-1
517 517 # start on monday
518 518 @date_from = @date_from - (@date_from.cwday-1)
519 519 # finish on sunday
520 520 @date_to = @date_to + (7-@date_to.cwday)
521 521
522 @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])
522 @issues = @project.issues.find(:all, :include => [:tracker, :status, :assigned_to, :priority],
523 :conditions => ["((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?))", @date_from, @date_to, @date_from, @date_to])
524
525 @ending_issues_by_days = @issues.group_by {|issue| issue.due_date}
526 @starting_issues_by_days = @issues.group_by {|issue| issue.start_date}
527
523 528 render :layout => false if request.xhr?
524 529 end
525 530
526 531 def gantt
527 532 if params[:year] and params[:year].to_i >0
528 533 @year_from = params[:year].to_i
529 534 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
530 535 @month_from = params[:month].to_i
531 536 else
532 537 @month_from = 1
533 538 end
534 539 else
535 540 @month_from ||= (Date.today << 1).month
536 541 @year_from ||= (Date.today << 1).year
537 542 end
538 543
539 544 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
540 545 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
541 546
542 547 @date_from = Date.civil(@year_from, @month_from, 1)
543 548 @date_to = (@date_from >> @months) - 1
544 549 @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])
545 550
546 551 if params[:output]=='pdf'
547 552 @options_for_rfpdf ||= {}
548 553 @options_for_rfpdf[:file_name] = "gantt.pdf"
549 554 render :template => "projects/gantt.rfpdf", :layout => false
550 555 else
551 556 render :template => "projects/gantt.rhtml"
552 557 end
553 558 end
554 559
555 560 def search
556 561 @question = params[:q] || ""
557 562 @question.strip!
558 563 @all_words = params[:all_words] || (params[:submit] ? false : true)
559 564 @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents wiki) )
560 565 if !@question.empty?
561 566 # tokens must be at least 3 character long
562 567 @tokens = @question.split.uniq.select {|w| w.length > 2 }
563 568 # no more than 5 tokens to search for
564 569 @tokens.slice! 5..-1 if @tokens.size > 5
565 570 # strings used in sql like statement
566 571 like_tokens = @tokens.collect {|w| "%#{w}%"}
567 572 operator = @all_words ? " AND " : " OR "
568 573 limit = 10
569 574 @results = []
570 575 @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues'
571 576 @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news'
572 577 @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents'
573 578 @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki')
574 579 @question = @tokens.join(" ")
575 580 end
576 581 end
577 582
578 583 def feeds
579 584 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
580 585 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
581 586 end
582 587
583 588 private
584 589 # Find project of id params[:id]
585 590 # if not found, redirect to project list
586 591 # Used as a before_filter
587 592 def find_project
588 593 @project = Project.find(params[:id])
589 594 @html_title = @project.name
590 595 rescue ActiveRecord::RecordNotFound
591 596 render_404
592 597 end
593 598
594 599 # Retrieve query from session or build a new query
595 600 def retrieve_query
596 601 if params[:query_id]
597 602 @query = @project.queries.find(params[:query_id])
598 603 session[:query] = @query
599 604 else
600 605 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
601 606 # Give it a name, required to be valid
602 607 @query = Query.new(:name => "_")
603 608 @query.project = @project
604 609 if params[:fields] and params[:fields].is_a? Array
605 610 params[:fields].each do |field|
606 611 @query.add_filter(field, params[:operators][field], params[:values][field])
607 612 end
608 613 else
609 614 @query.available_filters.keys.each do |field|
610 615 @query.add_short_filter(field, params[field]) if params[field]
611 616 end
612 617 end
613 618 session[:query] = @query
614 619 else
615 620 @query = session[:query]
616 621 end
617 622 end
618 623 end
619 624 end
@@ -1,74 +1,72
1 1 <h2><%= l(:label_calendar) %></h2>
2 2
3 3 <% form_tag({:action => 'calendar', :id => @project}) do %>
4 4 <table width="100%">
5 5 <tr>
6 6 <td align="left" style="width:150px">
7 7 <%= link_to_remote ('&#171; ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
8 8 {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) }},
9 9 {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1))}
10 10 %>
11 11 </td>
12 12 <td align="center">
13 13 <%= select_month(@month, :prefix => "month", :discard_type => true) %>
14 14 <%= select_year(@year, :prefix => "year", :discard_type => true) %>
15 15 <%= submit_tag l(:button_submit), :class => "button-small" %>
16 16 </td>
17 17 <td align="right" style="width:150px">
18 18 <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' &#187;'),
19 19 {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) }},
20 20 {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1))}
21 21 %>&nbsp;
22 22 </td>
23 23 </tr>
24 24 </table>
25 25 <% end %>
26 26 <br />
27 27
28 28 <table class="list with-cells">
29 29 <thead>
30 30 <tr>
31 31 <th></th>
32 32 <% 1.upto(7) do |d| %>
33 33 <th style="width:14%"><%= day_name(d) %></th>
34 34 <% end %>
35 35 </tr>
36 36 </thead>
37 37 <tbody>
38 38 <tr style="height:100px">
39 39 <% day = @date_from
40 40 while day <= @date_to
41 41 if day.cwday == 1 %>
42 42 <th><%= day.cweek %></th>
43 43 <% end %>
44 44 <td valign="top" class="<%= day.month==@month ? "even" : "odd" %>" style="width:14%; <%= Date.today == day ? 'background:#FDFED0;' : '' %>">
45 45 <p class="textright"><%= day==Date.today ? "<b>#{day.day}</b>" : day.day %></p>
46 <% day_issues = []
47 @issues.each { |i| day_issues << i if i.start_date == day or i.due_date == day }
48 day_issues.each do |i| %>
46 <% ((@ending_issues_by_days[day] || []) + (@starting_issues_by_days[day] || [])).uniq.each do |i| %>
49 47 <div class="tooltip">
50 48 <%= if day == i.start_date and day == i.due_date
51 49 image_tag('arrow_bw.png')
52 50 elsif day == i.start_date
53 51 image_tag('arrow_from.png')
54 52 elsif day == i.due_date
55 53 image_tag('arrow_to.png')
56 54 end %>
57 55 <small><%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i } %>: <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small>
58 56 <span class="tip">
59 57 <%= render :partial => "issues/tooltip", :locals => { :issue => i }%>
60 58 </span>
61 59 </div>
62 60 <% end %>
63 61 </td>
64 62 <%= '</tr><tr style="height:100px">' if day.cwday >= 7 and day!=@date_to %>
65 63 <%
66 64 day = day + 1
67 65 end %>
68 66 </tr>
69 67 </tbody>
70 68 </table>
71 69
72 70 <%= image_tag 'arrow_from.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_day) %><br />
73 71 <%= image_tag 'arrow_to.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_end_day) %><br />
74 72 <%= image_tag 'arrow_bw.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_end_day) %><br /> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now