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