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