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