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