##// END OF EJS Templates
Fixed: error when bulk editing with Postgresql...
Jean-Philippe Lang -
r853:295e8c86ab8c
parent child
Show More
@@ -1,675 +1,675
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'csv'
18 require 'csv'
19
19
20 class ProjectsController < ApplicationController
20 class ProjectsController < ApplicationController
21 layout 'base'
21 layout 'base'
22 before_filter :find_project, :except => [ :index, :list, :add ]
22 before_filter :find_project, :except => [ :index, :list, :add ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 accept_key_auth :activity, :calendar
25 accept_key_auth :activity, :calendar
26
26
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
30
30
31 helper :sort
31 helper :sort
32 include SortHelper
32 include SortHelper
33 helper :custom_fields
33 helper :custom_fields
34 include CustomFieldsHelper
34 include CustomFieldsHelper
35 helper :ifpdf
35 helper :ifpdf
36 include IfpdfHelper
36 include IfpdfHelper
37 helper :issues
37 helper :issues
38 helper IssuesHelper
38 helper IssuesHelper
39 helper :queries
39 helper :queries
40 include QueriesHelper
40 include QueriesHelper
41 helper :repositories
41 helper :repositories
42 include RepositoriesHelper
42 include RepositoriesHelper
43 include ProjectsHelper
43 include ProjectsHelper
44
44
45 def index
45 def index
46 list
46 list
47 render :action => 'list' unless request.xhr?
47 render :action => 'list' unless request.xhr?
48 end
48 end
49
49
50 # Lists visible projects
50 # Lists visible projects
51 def list
51 def list
52 projects = Project.find :all,
52 projects = Project.find :all,
53 :conditions => Project.visible_by(logged_in_user),
53 :conditions => Project.visible_by(logged_in_user),
54 :include => :parent
54 :include => :parent
55 @project_tree = projects.group_by {|p| p.parent || p}
55 @project_tree = projects.group_by {|p| p.parent || p}
56 @project_tree.each_key {|p| @project_tree[p] -= [p]}
56 @project_tree.each_key {|p| @project_tree[p] -= [p]}
57 end
57 end
58
58
59 # Add a new project
59 # Add a new project
60 def add
60 def add
61 @custom_fields = IssueCustomField.find(:all)
61 @custom_fields = IssueCustomField.find(:all)
62 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
62 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
63 @project = Project.new(params[:project])
63 @project = Project.new(params[:project])
64 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
64 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
65 if request.get?
65 if request.get?
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
67 else
67 else
68 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
68 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
69 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
69 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
70 @project.custom_values = @custom_values
70 @project.custom_values = @custom_values
71 if @project.save
71 if @project.save
72 @project.enabled_module_names = params[:enabled_modules]
72 @project.enabled_module_names = params[:enabled_modules]
73 flash[:notice] = l(:notice_successful_create)
73 flash[:notice] = l(:notice_successful_create)
74 redirect_to :controller => 'admin', :action => 'projects'
74 redirect_to :controller => 'admin', :action => 'projects'
75 end
75 end
76 end
76 end
77 end
77 end
78
78
79 # Show @project
79 # Show @project
80 def show
80 def show
81 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
81 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
82 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
82 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
83 @subprojects = @project.active_children
83 @subprojects = @project.active_children
84 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
84 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
85 @trackers = Tracker.find(:all, :order => 'position')
85 @trackers = Tracker.find(:all, :order => 'position')
86 @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])
86 @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])
87 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
87 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
88 @total_hours = @project.time_entries.sum(:hours)
88 @total_hours = @project.time_entries.sum(:hours)
89 @key = User.current.rss_key
89 @key = User.current.rss_key
90 end
90 end
91
91
92 def settings
92 def settings
93 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
93 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
94 @custom_fields = IssueCustomField.find(:all)
94 @custom_fields = IssueCustomField.find(:all)
95 @issue_category ||= IssueCategory.new
95 @issue_category ||= IssueCategory.new
96 @member ||= @project.members.new
96 @member ||= @project.members.new
97 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
97 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
98 @repository ||= @project.repository
98 @repository ||= @project.repository
99 @wiki ||= @project.wiki
99 @wiki ||= @project.wiki
100 end
100 end
101
101
102 # Edit @project
102 # Edit @project
103 def edit
103 def edit
104 if request.post?
104 if request.post?
105 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
105 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
106 if params[:custom_fields]
106 if params[:custom_fields]
107 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
107 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
108 @project.custom_values = @custom_values
108 @project.custom_values = @custom_values
109 end
109 end
110 @project.attributes = params[:project]
110 @project.attributes = params[:project]
111 if @project.save
111 if @project.save
112 flash[:notice] = l(:notice_successful_update)
112 flash[:notice] = l(:notice_successful_update)
113 redirect_to :action => 'settings', :id => @project
113 redirect_to :action => 'settings', :id => @project
114 else
114 else
115 settings
115 settings
116 render :action => 'settings'
116 render :action => 'settings'
117 end
117 end
118 end
118 end
119 end
119 end
120
120
121 def modules
121 def modules
122 @project.enabled_module_names = params[:enabled_modules]
122 @project.enabled_module_names = params[:enabled_modules]
123 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
123 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
124 end
124 end
125
125
126 def archive
126 def archive
127 @project.archive if request.post? && @project.active?
127 @project.archive if request.post? && @project.active?
128 redirect_to :controller => 'admin', :action => 'projects'
128 redirect_to :controller => 'admin', :action => 'projects'
129 end
129 end
130
130
131 def unarchive
131 def unarchive
132 @project.unarchive if request.post? && !@project.active?
132 @project.unarchive if request.post? && !@project.active?
133 redirect_to :controller => 'admin', :action => 'projects'
133 redirect_to :controller => 'admin', :action => 'projects'
134 end
134 end
135
135
136 # Delete @project
136 # Delete @project
137 def destroy
137 def destroy
138 @project_to_destroy = @project
138 @project_to_destroy = @project
139 if request.post? and params[:confirm]
139 if request.post? and params[:confirm]
140 @project_to_destroy.destroy
140 @project_to_destroy.destroy
141 redirect_to :controller => 'admin', :action => 'projects'
141 redirect_to :controller => 'admin', :action => 'projects'
142 end
142 end
143 # hide project in layout
143 # hide project in layout
144 @project = nil
144 @project = nil
145 end
145 end
146
146
147 # Add a new issue category to @project
147 # Add a new issue category to @project
148 def add_issue_category
148 def add_issue_category
149 @category = @project.issue_categories.build(params[:category])
149 @category = @project.issue_categories.build(params[:category])
150 if request.post? and @category.save
150 if request.post? and @category.save
151 respond_to do |format|
151 respond_to do |format|
152 format.html do
152 format.html do
153 flash[:notice] = l(:notice_successful_create)
153 flash[:notice] = l(:notice_successful_create)
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 end
155 end
156 format.js do
156 format.js do
157 # IE doesn't support the replace_html rjs method for select box options
157 # IE doesn't support the replace_html rjs method for select box options
158 render(:update) {|page| page.replace "issue_category_id",
158 render(:update) {|page| page.replace "issue_category_id",
159 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
159 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
160 }
160 }
161 end
161 end
162 end
162 end
163 end
163 end
164 end
164 end
165
165
166 # Add a new version to @project
166 # Add a new version to @project
167 def add_version
167 def add_version
168 @version = @project.versions.build(params[:version])
168 @version = @project.versions.build(params[:version])
169 if request.post? and @version.save
169 if request.post? and @version.save
170 flash[:notice] = l(:notice_successful_create)
170 flash[:notice] = l(:notice_successful_create)
171 redirect_to :action => 'settings', :tab => 'versions', :id => @project
171 redirect_to :action => 'settings', :tab => 'versions', :id => @project
172 end
172 end
173 end
173 end
174
174
175 # Add a new document to @project
175 # Add a new document to @project
176 def add_document
176 def add_document
177 @document = @project.documents.build(params[:document])
177 @document = @project.documents.build(params[:document])
178 if request.post? and @document.save
178 if request.post? and @document.save
179 # Save the attachments
179 # Save the attachments
180 params[:attachments].each { |a|
180 params[:attachments].each { |a|
181 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
181 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
182 } if params[:attachments] and params[:attachments].is_a? Array
182 } if params[:attachments] and params[:attachments].is_a? Array
183 flash[:notice] = l(:notice_successful_create)
183 flash[:notice] = l(:notice_successful_create)
184 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
184 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
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
188
189 # Show documents list of @project
189 # Show documents list of @project
190 def list_documents
190 def list_documents
191 @documents = @project.documents.find :all, :include => :category
191 @documents = @project.documents.find :all, :include => :category
192 end
192 end
193
193
194 # Add a new issue to @project
194 # Add a new issue to @project
195 def add_issue
195 def add_issue
196 @tracker = Tracker.find(params[:tracker_id])
196 @tracker = Tracker.find(params[:tracker_id])
197 @priorities = Enumeration::get_values('IPRI')
197 @priorities = Enumeration::get_values('IPRI')
198
198
199 default_status = IssueStatus.default
199 default_status = IssueStatus.default
200 unless default_status
200 unless default_status
201 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
201 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
202 render :nothing => true, :layout => true
202 render :nothing => true, :layout => true
203 return
203 return
204 end
204 end
205 @issue = Issue.new(:project => @project, :tracker => @tracker)
205 @issue = Issue.new(:project => @project, :tracker => @tracker)
206 @issue.status = default_status
206 @issue.status = default_status
207 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
207 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
208 if request.get?
208 if request.get?
209 @issue.start_date = Date.today
209 @issue.start_date = Date.today
210 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
210 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
211 else
211 else
212 @issue.attributes = params[:issue]
212 @issue.attributes = params[:issue]
213
213
214 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
214 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
215 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
215 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
216
216
217 @issue.author_id = self.logged_in_user.id if self.logged_in_user
217 @issue.author_id = self.logged_in_user.id if self.logged_in_user
218 # Multiple file upload
218 # Multiple file upload
219 @attachments = []
219 @attachments = []
220 params[:attachments].each { |a|
220 params[:attachments].each { |a|
221 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
221 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
222 } if params[:attachments] and params[:attachments].is_a? Array
222 } if params[:attachments] and params[:attachments].is_a? Array
223 @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]) }
223 @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]) }
224 @issue.custom_values = @custom_values
224 @issue.custom_values = @custom_values
225 if @issue.save
225 if @issue.save
226 @attachments.each(&:save)
226 @attachments.each(&:save)
227 flash[:notice] = l(:notice_successful_create)
227 flash[:notice] = l(:notice_successful_create)
228 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
228 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
229 redirect_to :action => 'list_issues', :id => @project
229 redirect_to :action => 'list_issues', :id => @project
230 end
230 end
231 end
231 end
232 end
232 end
233
233
234 # Show filtered/sorted issues list of @project
234 # Show filtered/sorted issues list of @project
235 def list_issues
235 def list_issues
236 sort_init "#{Issue.table_name}.id", "desc"
236 sort_init "#{Issue.table_name}.id", "desc"
237 sort_update
237 sort_update
238
238
239 retrieve_query
239 retrieve_query
240
240
241 @results_per_page_options = [ 15, 25, 50, 100 ]
241 @results_per_page_options = [ 15, 25, 50, 100 ]
242 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
242 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
243 @results_per_page = params[:per_page].to_i
243 @results_per_page = params[:per_page].to_i
244 session[:results_per_page] = @results_per_page
244 session[:results_per_page] = @results_per_page
245 else
245 else
246 @results_per_page = session[:results_per_page] || 25
246 @results_per_page = session[:results_per_page] || 25
247 end
247 end
248
248
249 if @query.valid?
249 if @query.valid?
250 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
250 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
251 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
251 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
252 @issues = Issue.find :all, :order => sort_clause,
252 @issues = Issue.find :all, :order => sort_clause,
253 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
253 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
254 :conditions => @query.statement,
254 :conditions => @query.statement,
255 :limit => @issue_pages.items_per_page,
255 :limit => @issue_pages.items_per_page,
256 :offset => @issue_pages.current.offset
256 :offset => @issue_pages.current.offset
257 end
257 end
258
258
259 render :layout => false if request.xhr?
259 render :layout => false if request.xhr?
260 end
260 end
261
261
262 # Export filtered/sorted issues list to CSV
262 # Export filtered/sorted issues list to CSV
263 def export_issues_csv
263 def export_issues_csv
264 sort_init "#{Issue.table_name}.id", "desc"
264 sort_init "#{Issue.table_name}.id", "desc"
265 sort_update
265 sort_update
266
266
267 retrieve_query
267 retrieve_query
268 render :action => 'list_issues' and return unless @query.valid?
268 render :action => 'list_issues' and return unless @query.valid?
269
269
270 @issues = Issue.find :all, :order => sort_clause,
270 @issues = Issue.find :all, :order => sort_clause,
271 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
271 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
272 :conditions => @query.statement,
272 :conditions => @query.statement,
273 :limit => Setting.issues_export_limit.to_i
273 :limit => Setting.issues_export_limit.to_i
274
274
275 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
275 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
276 export = StringIO.new
276 export = StringIO.new
277 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
277 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
278 # csv header fields
278 # csv header fields
279 headers = [ "#", l(:field_status),
279 headers = [ "#", l(:field_status),
280 l(:field_project),
280 l(:field_project),
281 l(:field_tracker),
281 l(:field_tracker),
282 l(:field_priority),
282 l(:field_priority),
283 l(:field_subject),
283 l(:field_subject),
284 l(:field_assigned_to),
284 l(:field_assigned_to),
285 l(:field_author),
285 l(:field_author),
286 l(:field_start_date),
286 l(:field_start_date),
287 l(:field_due_date),
287 l(:field_due_date),
288 l(:field_done_ratio),
288 l(:field_done_ratio),
289 l(:field_created_on),
289 l(:field_created_on),
290 l(:field_updated_on)
290 l(:field_updated_on)
291 ]
291 ]
292 for custom_field in @project.all_custom_fields
292 for custom_field in @project.all_custom_fields
293 headers << custom_field.name
293 headers << custom_field.name
294 end
294 end
295 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
295 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
296 # csv lines
296 # csv lines
297 @issues.each do |issue|
297 @issues.each do |issue|
298 fields = [issue.id, issue.status.name,
298 fields = [issue.id, issue.status.name,
299 issue.project.name,
299 issue.project.name,
300 issue.tracker.name,
300 issue.tracker.name,
301 issue.priority.name,
301 issue.priority.name,
302 issue.subject,
302 issue.subject,
303 (issue.assigned_to ? issue.assigned_to.name : ""),
303 (issue.assigned_to ? issue.assigned_to.name : ""),
304 issue.author.name,
304 issue.author.name,
305 issue.start_date ? l_date(issue.start_date) : nil,
305 issue.start_date ? l_date(issue.start_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
307 issue.done_ratio,
307 issue.done_ratio,
308 l_datetime(issue.created_on),
308 l_datetime(issue.created_on),
309 l_datetime(issue.updated_on)
309 l_datetime(issue.updated_on)
310 ]
310 ]
311 for custom_field in @project.all_custom_fields
311 for custom_field in @project.all_custom_fields
312 fields << (show_value issue.custom_value_for(custom_field))
312 fields << (show_value issue.custom_value_for(custom_field))
313 end
313 end
314 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
314 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
315 end
315 end
316 end
316 end
317 export.rewind
317 export.rewind
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
319 end
319 end
320
320
321 # Export filtered/sorted issues to PDF
321 # Export filtered/sorted issues to PDF
322 def export_issues_pdf
322 def export_issues_pdf
323 sort_init "#{Issue.table_name}.id", "desc"
323 sort_init "#{Issue.table_name}.id", "desc"
324 sort_update
324 sort_update
325
325
326 retrieve_query
326 retrieve_query
327 render :action => 'list_issues' and return unless @query.valid?
327 render :action => 'list_issues' and return unless @query.valid?
328
328
329 @issues = Issue.find :all, :order => sort_clause,
329 @issues = Issue.find :all, :order => sort_clause,
330 :include => [ :author, :status, :tracker, :priority, :project ],
330 :include => [ :author, :status, :tracker, :priority, :project ],
331 :conditions => @query.statement,
331 :conditions => @query.statement,
332 :limit => Setting.issues_export_limit.to_i
332 :limit => Setting.issues_export_limit.to_i
333
333
334 @options_for_rfpdf ||= {}
334 @options_for_rfpdf ||= {}
335 @options_for_rfpdf[:file_name] = "export.pdf"
335 @options_for_rfpdf[:file_name] = "export.pdf"
336 render :layout => false
336 render :layout => false
337 end
337 end
338
338
339 # Bulk edit issues
339 # Bulk edit issues
340 def bulk_edit_issues
340 def bulk_edit_issues
341 if request.post?
341 if request.post?
342 status = IssueStatus.find_by_id(params[:status_id])
342 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
343 priority = Enumeration.find_by_id(params[:priority_id])
343 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
344 assigned_to = User.find_by_id(params[:assigned_to_id])
344 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
345 category = @project.issue_categories.find_by_id(params[:category_id])
345 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
346 fixed_version = @project.versions.find_by_id(params[:fixed_version_id])
346 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
347 issues = @project.issues.find_all_by_id(params[:issue_ids])
347 issues = @project.issues.find_all_by_id(params[:issue_ids])
348 unsaved_issue_ids = []
348 unsaved_issue_ids = []
349 issues.each do |issue|
349 issues.each do |issue|
350 journal = issue.init_journal(User.current, params[:notes])
350 journal = issue.init_journal(User.current, params[:notes])
351 issue.priority = priority if priority
351 issue.priority = priority if priority
352 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
352 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
353 issue.category = category if category
353 issue.category = category if category
354 issue.fixed_version = fixed_version if fixed_version
354 issue.fixed_version = fixed_version if fixed_version
355 issue.start_date = params[:start_date] unless params[:start_date].blank?
355 issue.start_date = params[:start_date] unless params[:start_date].blank?
356 issue.due_date = params[:due_date] unless params[:due_date].blank?
356 issue.due_date = params[:due_date] unless params[:due_date].blank?
357 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
357 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
358 # Don't save any change to the issue if the user is not authorized to apply the requested status
358 # Don't save any change to the issue if the user is not authorized to apply the requested status
359 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
359 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
360 # Send notification for each issue (if changed)
360 # Send notification for each issue (if changed)
361 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
361 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
362 else
362 else
363 # Keep unsaved issue ids to display them in flash error
363 # Keep unsaved issue ids to display them in flash error
364 unsaved_issue_ids << issue.id
364 unsaved_issue_ids << issue.id
365 end
365 end
366 end
366 end
367 if unsaved_issue_ids.empty?
367 if unsaved_issue_ids.empty?
368 flash[:notice] = l(:notice_successful_update) unless issues.empty?
368 flash[:notice] = l(:notice_successful_update) unless issues.empty?
369 else
369 else
370 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
370 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
371 end
371 end
372 redirect_to :action => 'list_issues', :id => @project
372 redirect_to :action => 'list_issues', :id => @project
373 return
373 return
374 end
374 end
375 if current_role && User.current.allowed_to?(:change_issue_status, @project)
375 if current_role && User.current.allowed_to?(:change_issue_status, @project)
376 # Find potential statuses the user could be allowed to switch issues to
376 # Find potential statuses the user could be allowed to switch issues to
377 @available_statuses = Workflow.find(:all, :include => :new_status,
377 @available_statuses = Workflow.find(:all, :include => :new_status,
378 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
378 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
379 end
379 end
380 render :update do |page|
380 render :update do |page|
381 page.hide 'query_form'
381 page.hide 'query_form'
382 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
382 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
383 end
383 end
384 end
384 end
385
385
386 def move_issues
386 def move_issues
387 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
387 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
388 redirect_to :action => 'list_issues', :id => @project and return unless @issues
388 redirect_to :action => 'list_issues', :id => @project and return unless @issues
389 @projects = []
389 @projects = []
390 # find projects to which the user is allowed to move the issue
390 # find projects to which the user is allowed to move the issue
391 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
391 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
392 # issue can be moved to any tracker
392 # issue can be moved to any tracker
393 @trackers = Tracker.find(:all)
393 @trackers = Tracker.find(:all)
394 if request.post? and params[:new_project_id] and params[:new_tracker_id]
394 if request.post? and params[:new_project_id] and params[:new_tracker_id]
395 new_project = Project.find_by_id(params[:new_project_id])
395 new_project = Project.find_by_id(params[:new_project_id])
396 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
396 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
397 @issues.each do |i|
397 @issues.each do |i|
398 if new_project && i.project_id != new_project.id
398 if new_project && i.project_id != new_project.id
399 # issue is moved to another project
399 # issue is moved to another project
400 i.category = nil
400 i.category = nil
401 i.fixed_version = nil
401 i.fixed_version = nil
402 # delete issue relations
402 # delete issue relations
403 i.relations_from.clear
403 i.relations_from.clear
404 i.relations_to.clear
404 i.relations_to.clear
405 i.project = new_project
405 i.project = new_project
406 end
406 end
407 if new_tracker
407 if new_tracker
408 i.tracker = new_tracker
408 i.tracker = new_tracker
409 end
409 end
410 i.save
410 i.save
411 end
411 end
412 flash[:notice] = l(:notice_successful_update)
412 flash[:notice] = l(:notice_successful_update)
413 redirect_to :action => 'list_issues', :id => @project
413 redirect_to :action => 'list_issues', :id => @project
414 end
414 end
415 end
415 end
416
416
417 # Add a news to @project
417 # Add a news to @project
418 def add_news
418 def add_news
419 @news = News.new(:project => @project)
419 @news = News.new(:project => @project)
420 if request.post?
420 if request.post?
421 @news.attributes = params[:news]
421 @news.attributes = params[:news]
422 @news.author_id = self.logged_in_user.id if self.logged_in_user
422 @news.author_id = self.logged_in_user.id if self.logged_in_user
423 if @news.save
423 if @news.save
424 flash[:notice] = l(:notice_successful_create)
424 flash[:notice] = l(:notice_successful_create)
425 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
425 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
426 redirect_to :action => 'list_news', :id => @project
426 redirect_to :action => 'list_news', :id => @project
427 end
427 end
428 end
428 end
429 end
429 end
430
430
431 # Show news list of @project
431 # Show news list of @project
432 def list_news
432 def list_news
433 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
433 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
434
434
435 respond_to do |format|
435 respond_to do |format|
436 format.html { render :layout => false if request.xhr? }
436 format.html { render :layout => false if request.xhr? }
437 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
437 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
438 end
438 end
439 end
439 end
440
440
441 def add_file
441 def add_file
442 if request.post?
442 if request.post?
443 @version = @project.versions.find_by_id(params[:version_id])
443 @version = @project.versions.find_by_id(params[:version_id])
444 # Save the attachments
444 # Save the attachments
445 @attachments = []
445 @attachments = []
446 params[:attachments].each { |file|
446 params[:attachments].each { |file|
447 next unless file.size > 0
447 next unless file.size > 0
448 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
448 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
449 @attachments << a unless a.new_record?
449 @attachments << a unless a.new_record?
450 } if params[:attachments] and params[:attachments].is_a? Array
450 } if params[:attachments] and params[:attachments].is_a? Array
451 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
451 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
452 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
452 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
453 end
453 end
454 @versions = @project.versions.sort
454 @versions = @project.versions.sort
455 end
455 end
456
456
457 def list_files
457 def list_files
458 @versions = @project.versions.sort
458 @versions = @project.versions.sort
459 end
459 end
460
460
461 # Show changelog for @project
461 # Show changelog for @project
462 def changelog
462 def changelog
463 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
463 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
464 retrieve_selected_tracker_ids(@trackers)
464 retrieve_selected_tracker_ids(@trackers)
465 @versions = @project.versions.sort
465 @versions = @project.versions.sort
466 end
466 end
467
467
468 def roadmap
468 def roadmap
469 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
469 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
470 retrieve_selected_tracker_ids(@trackers)
470 retrieve_selected_tracker_ids(@trackers)
471 @versions = @project.versions.sort
471 @versions = @project.versions.sort
472 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
472 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
473 end
473 end
474
474
475 def activity
475 def activity
476 if params[:year] and params[:year].to_i > 1900
476 if params[:year] and params[:year].to_i > 1900
477 @year = params[:year].to_i
477 @year = params[:year].to_i
478 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
478 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
479 @month = params[:month].to_i
479 @month = params[:month].to_i
480 end
480 end
481 end
481 end
482 @year ||= Date.today.year
482 @year ||= Date.today.year
483 @month ||= Date.today.month
483 @month ||= Date.today.month
484
484
485 case params[:format]
485 case params[:format]
486 when 'atom'
486 when 'atom'
487 # 30 last days
487 # 30 last days
488 @date_from = Date.today - 30
488 @date_from = Date.today - 30
489 @date_to = Date.today + 1
489 @date_to = Date.today + 1
490 else
490 else
491 # current month
491 # current month
492 @date_from = Date.civil(@year, @month, 1)
492 @date_from = Date.civil(@year, @month, 1)
493 @date_to = @date_from >> 1
493 @date_to = @date_from >> 1
494 end
494 end
495
495
496 @event_types = %w(issues news files documents wiki_pages changesets)
496 @event_types = %w(issues news files documents wiki_pages changesets)
497 @event_types.delete('wiki_pages') unless @project.wiki
497 @event_types.delete('wiki_pages') unless @project.wiki
498 @event_types.delete('changesets') unless @project.repository
498 @event_types.delete('changesets') unless @project.repository
499 # only show what the user is allowed to view
499 # only show what the user is allowed to view
500 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
500 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
501
501
502 @scope = @event_types.select {|t| params["show_#{t}"]}
502 @scope = @event_types.select {|t| params["show_#{t}"]}
503 # default events if none is specified in parameters
503 # default events if none is specified in parameters
504 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
504 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
505
505
506 @events = []
506 @events = []
507
507
508 if @scope.include?('issues')
508 if @scope.include?('issues')
509 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
509 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
510 end
510 end
511
511
512 if @scope.include?('news')
512 if @scope.include?('news')
513 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
513 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
514 end
514 end
515
515
516 if @scope.include?('files')
516 if @scope.include?('files')
517 @events += 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 )
517 @events += 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 )
518 end
518 end
519
519
520 if @scope.include?('documents')
520 if @scope.include?('documents')
521 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
521 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
522 @events += 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 )
522 @events += 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 )
523 end
523 end
524
524
525 if @scope.include?('wiki_pages')
525 if @scope.include?('wiki_pages')
526 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
526 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
527 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
527 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
528 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
528 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
529 "#{WikiContent.versioned_table_name}.id"
529 "#{WikiContent.versioned_table_name}.id"
530 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
530 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
531 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
531 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
532 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
532 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
533 @project.id, @date_from, @date_to]
533 @project.id, @date_from, @date_to]
534
534
535 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
535 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
536 end
536 end
537
537
538 if @scope.include?('changesets')
538 if @scope.include?('changesets')
539 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
539 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
540 end
540 end
541
541
542 @events_by_day = @events.group_by(&:event_date)
542 @events_by_day = @events.group_by(&:event_date)
543
543
544 respond_to do |format|
544 respond_to do |format|
545 format.html { render :layout => false if request.xhr? }
545 format.html { render :layout => false if request.xhr? }
546 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
546 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
547 end
547 end
548 end
548 end
549
549
550 def calendar
550 def calendar
551 @trackers = Tracker.find(:all, :order => 'position')
551 @trackers = Tracker.find(:all, :order => 'position')
552 retrieve_selected_tracker_ids(@trackers)
552 retrieve_selected_tracker_ids(@trackers)
553
553
554 if params[:year] and params[:year].to_i > 1900
554 if params[:year] and params[:year].to_i > 1900
555 @year = params[:year].to_i
555 @year = params[:year].to_i
556 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
556 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
557 @month = params[:month].to_i
557 @month = params[:month].to_i
558 end
558 end
559 end
559 end
560 @year ||= Date.today.year
560 @year ||= Date.today.year
561 @month ||= Date.today.month
561 @month ||= Date.today.month
562 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
562 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
563
563
564 events = []
564 events = []
565 @project.issues_with_subprojects(params[:with_subprojects]) do
565 @project.issues_with_subprojects(params[:with_subprojects]) do
566 events += Issue.find(:all,
566 events += Issue.find(:all,
567 :include => [:tracker, :status, :assigned_to, :priority, :project],
567 :include => [:tracker, :status, :assigned_to, :priority, :project],
568 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
568 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
569 ) unless @selected_tracker_ids.empty?
569 ) unless @selected_tracker_ids.empty?
570 end
570 end
571 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
571 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
572 @calendar.events = events
572 @calendar.events = events
573
573
574 render :layout => false if request.xhr?
574 render :layout => false if request.xhr?
575 end
575 end
576
576
577 def gantt
577 def gantt
578 @trackers = Tracker.find(:all, :order => 'position')
578 @trackers = Tracker.find(:all, :order => 'position')
579 retrieve_selected_tracker_ids(@trackers)
579 retrieve_selected_tracker_ids(@trackers)
580
580
581 if params[:year] and params[:year].to_i >0
581 if params[:year] and params[:year].to_i >0
582 @year_from = params[:year].to_i
582 @year_from = params[:year].to_i
583 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
583 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
584 @month_from = params[:month].to_i
584 @month_from = params[:month].to_i
585 else
585 else
586 @month_from = 1
586 @month_from = 1
587 end
587 end
588 else
588 else
589 @month_from ||= Date.today.month
589 @month_from ||= Date.today.month
590 @year_from ||= Date.today.year
590 @year_from ||= Date.today.year
591 end
591 end
592
592
593 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
593 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
594 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
594 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
595 months = (params[:months] || User.current.pref[:gantt_months]).to_i
595 months = (params[:months] || User.current.pref[:gantt_months]).to_i
596 @months = (months > 0 && months < 25) ? months : 6
596 @months = (months > 0 && months < 25) ? months : 6
597
597
598 # Save gantt paramters as user preference (zoom and months count)
598 # Save gantt paramters as user preference (zoom and months count)
599 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
599 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
600 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
600 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
601 User.current.preference.save
601 User.current.preference.save
602 end
602 end
603
603
604 @date_from = Date.civil(@year_from, @month_from, 1)
604 @date_from = Date.civil(@year_from, @month_from, 1)
605 @date_to = (@date_from >> @months) - 1
605 @date_to = (@date_from >> @months) - 1
606
606
607 @events = []
607 @events = []
608 @project.issues_with_subprojects(params[:with_subprojects]) do
608 @project.issues_with_subprojects(params[:with_subprojects]) do
609 @events += Issue.find(:all,
609 @events += Issue.find(:all,
610 :order => "start_date, due_date",
610 :order => "start_date, due_date",
611 :include => [:tracker, :status, :assigned_to, :priority, :project],
611 :include => [:tracker, :status, :assigned_to, :priority, :project],
612 :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]
612 :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]
613 ) unless @selected_tracker_ids.empty?
613 ) unless @selected_tracker_ids.empty?
614 end
614 end
615 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
615 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
616 @events.sort! {|x,y| x.start_date <=> y.start_date }
616 @events.sort! {|x,y| x.start_date <=> y.start_date }
617
617
618 if params[:format]=='pdf'
618 if params[:format]=='pdf'
619 @options_for_rfpdf ||= {}
619 @options_for_rfpdf ||= {}
620 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
620 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
621 render :template => "projects/gantt.rfpdf", :layout => false
621 render :template => "projects/gantt.rfpdf", :layout => false
622 elsif params[:format]=='png' && respond_to?('gantt_image')
622 elsif params[:format]=='png' && respond_to?('gantt_image')
623 image = gantt_image(@events, @date_from, @months, @zoom)
623 image = gantt_image(@events, @date_from, @months, @zoom)
624 image.format = 'PNG'
624 image.format = 'PNG'
625 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
625 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
626 else
626 else
627 render :template => "projects/gantt.rhtml"
627 render :template => "projects/gantt.rhtml"
628 end
628 end
629 end
629 end
630
630
631 private
631 private
632 # Find project of id params[:id]
632 # Find project of id params[:id]
633 # if not found, redirect to project list
633 # if not found, redirect to project list
634 # Used as a before_filter
634 # Used as a before_filter
635 def find_project
635 def find_project
636 @project = Project.find(params[:id])
636 @project = Project.find(params[:id])
637 rescue ActiveRecord::RecordNotFound
637 rescue ActiveRecord::RecordNotFound
638 render_404
638 render_404
639 end
639 end
640
640
641 def retrieve_selected_tracker_ids(selectable_trackers)
641 def retrieve_selected_tracker_ids(selectable_trackers)
642 if ids = params[:tracker_ids]
642 if ids = params[:tracker_ids]
643 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
643 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
644 else
644 else
645 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
645 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
646 end
646 end
647 end
647 end
648
648
649 # Retrieve query from session or build a new query
649 # Retrieve query from session or build a new query
650 def retrieve_query
650 def retrieve_query
651 if params[:query_id]
651 if params[:query_id]
652 @query = @project.queries.find(params[:query_id])
652 @query = @project.queries.find(params[:query_id])
653 @query.executed_by = logged_in_user
653 @query.executed_by = logged_in_user
654 session[:query] = @query
654 session[:query] = @query
655 else
655 else
656 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
656 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
657 # Give it a name, required to be valid
657 # Give it a name, required to be valid
658 @query = Query.new(:name => "_", :executed_by => logged_in_user)
658 @query = Query.new(:name => "_", :executed_by => logged_in_user)
659 @query.project = @project
659 @query.project = @project
660 if params[:fields] and params[:fields].is_a? Array
660 if params[:fields] and params[:fields].is_a? Array
661 params[:fields].each do |field|
661 params[:fields].each do |field|
662 @query.add_filter(field, params[:operators][field], params[:values][field])
662 @query.add_filter(field, params[:operators][field], params[:values][field])
663 end
663 end
664 else
664 else
665 @query.available_filters.keys.each do |field|
665 @query.available_filters.keys.each do |field|
666 @query.add_short_filter(field, params[field]) if params[field]
666 @query.add_short_filter(field, params[field]) if params[field]
667 end
667 end
668 end
668 end
669 session[:query] = @query
669 session[:query] = @query
670 else
670 else
671 @query = session[:query]
671 @query = session[:query]
672 end
672 end
673 end
673 end
674 end
674 end
675 end
675 end
@@ -1,38 +1,38
1 <div id="bulk-edit-fields">
1 <div id="bulk-edit-fields">
2 <fieldset class="box"><legend><%= l(:label_bulk_edit_selected_issues) %></legend>
2 <fieldset class="box"><legend><%= l(:label_bulk_edit_selected_issues) %></legend>
3
3
4 <p>
4 <p>
5 <% if @available_statuses %>
5 <% if @available_statuses %>
6 <label><%= l(:field_status) %>:
6 <label><%= l(:field_status) %>:
7 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label>
7 <%= select_tag('status_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_statuses, :id, :name)) %></label>
8 <% end %>
8 <% end %>
9 <label><%= l(:field_priority) %>:
9 <label><%= l(:field_priority) %>:
10 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label>
10 <%= select_tag('priority_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(Enumeration.get_values('IPRI'), :id, :name)) %></label>
11 <label><%= l(:field_category) %>:
11 <label><%= l(:field_category) %>:
12 <%= select_tag('category_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
12 <%= select_tag('category_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.issue_categories, :id, :name)) %></label>
13 </p>
13 </p>
14 <p>
14 <p>
15 <label><%= l(:field_assigned_to) %>:
15 <label><%= l(:field_assigned_to) %>:
16 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option)) +
16 <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
17 content_tag('option', l(:label_nobody), :value => 'none') +
17 content_tag('option', l(:label_nobody), :value => 'none') +
18 options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label>
18 options_from_collection_for_select(@project.assignable_users, :id, :name)) %></label>
19 <label><%= l(:field_fixed_version) %>:
19 <label><%= l(:field_fixed_version) %>:
20 <%= select_tag('fixed_version_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.versions, :id, :name)) %></label>
20 <%= select_tag('fixed_version_id', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@project.versions, :id, :name)) %></label>
21 </p>
21 </p>
22
22
23 <p>
23 <p>
24 <label><%= l(:field_start_date) %>:
24 <label><%= l(:field_start_date) %>:
25 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %></label>
25 <%= text_field_tag 'start_date', '', :size => 10 %><%= calendar_for('start_date') %></label>
26 <label><%= l(:field_due_date) %>:
26 <label><%= l(:field_due_date) %>:
27 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %></label>
27 <%= text_field_tag 'due_date', '', :size => 10 %><%= calendar_for('due_date') %></label>
28 <label><%= l(:field_done_ratio) %>:
28 <label><%= l(:field_done_ratio) %>:
29 <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
29 <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
30 </p>
30 </p>
31
31
32 <label for="notes"><%= l(:field_notes) %></label><br />
32 <label for="notes"><%= l(:field_notes) %></label><br />
33 <%= text_area_tag 'notes', '', :cols => 80, :rows => 5 %>
33 <%= text_area_tag 'notes', '', :cols => 80, :rows => 5 %>
34
34
35 </fieldset>
35 </fieldset>
36 <p><%= submit_tag l(:button_apply) %>
36 <p><%= submit_tag l(:button_apply) %>
37 <%= link_to l(:button_cancel), {}, :onclick => 'Element.hide("bulk-edit-fields"); if ($("query_form")) {Element.show("query_form")}; return false;' %></p>
37 <%= link_to l(:button_cancel), {}, :onclick => 'Element.hide("bulk-edit-fields"); if ($("query_form")) {Element.show("query_form")}; return false;' %></p>
38 </div>
38 </div>
@@ -1,146 +1,146
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 File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :enabled_modules
25 fixtures :projects, :users, :roles, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 end
31 end
32
32
33 def test_index
33 def test_index
34 get :index
34 get :index
35 assert_response :success
35 assert_response :success
36 assert_template 'list'
36 assert_template 'list'
37 end
37 end
38
38
39 def test_list
39 def test_list
40 get :list
40 get :list
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:project_tree)
43 assert_not_nil assigns(:project_tree)
44 end
44 end
45
45
46 def test_show
46 def test_show
47 get :show, :id => 1
47 get :show, :id => 1
48 assert_response :success
48 assert_response :success
49 assert_template 'show'
49 assert_template 'show'
50 assert_not_nil assigns(:project)
50 assert_not_nil assigns(:project)
51 end
51 end
52
52
53 def test_list_documents
53 def test_list_documents
54 get :list_documents, :id => 1
54 get :list_documents, :id => 1
55 assert_response :success
55 assert_response :success
56 assert_template 'list_documents'
56 assert_template 'list_documents'
57 assert_not_nil assigns(:documents)
57 assert_not_nil assigns(:documents)
58 end
58 end
59
59
60 def test_list_issues
60 def test_list_issues
61 get :list_issues, :id => 1
61 get :list_issues, :id => 1
62 assert_response :success
62 assert_response :success
63 assert_template 'list_issues'
63 assert_template 'list_issues'
64 assert_not_nil assigns(:issues)
64 assert_not_nil assigns(:issues)
65 end
65 end
66
66
67 def test_list_issues_with_filter
67 def test_list_issues_with_filter
68 get :list_issues, :id => 1, :set_filter => 1
68 get :list_issues, :id => 1, :set_filter => 1
69 assert_response :success
69 assert_response :success
70 assert_template 'list_issues'
70 assert_template 'list_issues'
71 assert_not_nil assigns(:issues)
71 assert_not_nil assigns(:issues)
72 end
72 end
73
73
74 def test_list_issues_reset_filter
74 def test_list_issues_reset_filter
75 post :list_issues, :id => 1
75 post :list_issues, :id => 1
76 assert_response :success
76 assert_response :success
77 assert_template 'list_issues'
77 assert_template 'list_issues'
78 assert_not_nil assigns(:issues)
78 assert_not_nil assigns(:issues)
79 end
79 end
80
80
81 def test_export_issues_csv
81 def test_export_issues_csv
82 get :export_issues_csv, :id => 1
82 get :export_issues_csv, :id => 1
83 assert_response :success
83 assert_response :success
84 assert_not_nil assigns(:issues)
84 assert_not_nil assigns(:issues)
85 end
85 end
86
86
87 def test_bulk_edit_issues
87 def test_bulk_edit_issues
88 @request.session[:user_id] = 2
88 @request.session[:user_id] = 2
89 # update issues priority
89 # update issues priority
90 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => "Bulk editing"
90 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
91 assert_response 302
91 assert_response 302
92 # check that the issues were updated
92 # check that the issues were updated
93 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
93 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
94 assert_equal "Bulk editing", Issue.find(1).journals.last.notes
94 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
95 end
95 end
96
96
97 def test_list_news
97 def test_list_news
98 get :list_news, :id => 1
98 get :list_news, :id => 1
99 assert_response :success
99 assert_response :success
100 assert_template 'list_news'
100 assert_template 'list_news'
101 assert_not_nil assigns(:newss)
101 assert_not_nil assigns(:newss)
102 end
102 end
103
103
104 def test_list_files
104 def test_list_files
105 get :list_files, :id => 1
105 get :list_files, :id => 1
106 assert_response :success
106 assert_response :success
107 assert_template 'list_files'
107 assert_template 'list_files'
108 assert_not_nil assigns(:versions)
108 assert_not_nil assigns(:versions)
109 end
109 end
110
110
111 def test_changelog
111 def test_changelog
112 get :changelog, :id => 1
112 get :changelog, :id => 1
113 assert_response :success
113 assert_response :success
114 assert_template 'changelog'
114 assert_template 'changelog'
115 assert_not_nil assigns(:versions)
115 assert_not_nil assigns(:versions)
116 end
116 end
117
117
118 def test_roadmap
118 def test_roadmap
119 get :roadmap, :id => 1
119 get :roadmap, :id => 1
120 assert_response :success
120 assert_response :success
121 assert_template 'roadmap'
121 assert_template 'roadmap'
122 assert_not_nil assigns(:versions)
122 assert_not_nil assigns(:versions)
123 end
123 end
124
124
125 def test_activity
125 def test_activity
126 get :activity, :id => 1
126 get :activity, :id => 1
127 assert_response :success
127 assert_response :success
128 assert_template 'activity'
128 assert_template 'activity'
129 assert_not_nil assigns(:events_by_day)
129 assert_not_nil assigns(:events_by_day)
130 end
130 end
131
131
132 def test_archive
132 def test_archive
133 @request.session[:user_id] = 1 # admin
133 @request.session[:user_id] = 1 # admin
134 post :archive, :id => 1
134 post :archive, :id => 1
135 assert_redirected_to 'admin/projects'
135 assert_redirected_to 'admin/projects'
136 assert !Project.find(1).active?
136 assert !Project.find(1).active?
137 end
137 end
138
138
139 def test_unarchive
139 def test_unarchive
140 @request.session[:user_id] = 1 # admin
140 @request.session[:user_id] = 1 # admin
141 Project.find(1).archive
141 Project.find(1).archive
142 post :unarchive, :id => 1
142 post :unarchive, :id => 1
143 assert_redirected_to 'admin/projects'
143 assert_redirected_to 'admin/projects'
144 assert Project.find(1).active?
144 assert Project.find(1).active?
145 end
145 end
146 end
146 end
General Comments 0
You need to be logged in to leave comments. Login now