##// END OF EJS Templates
Fixed: Update of time entry fails when the issue has been moved to an other project....
Jean-Philippe Lang -
r896:e2c606e97459
parent child
Show More
@@ -1,558 +1,551
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 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :except => [ :index, :list, :add ]
20 before_filter :find_project, :except => [ :index, :list, :add ]
21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
23 accept_key_auth :activity, :calendar
23 accept_key_auth :activity, :calendar
24
24
25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
27 cache_sweeper :version_sweeper, :only => [ :add_version ]
27 cache_sweeper :version_sweeper, :only => [ :add_version ]
28
28
29 helper :sort
29 helper :sort
30 include SortHelper
30 include SortHelper
31 helper :custom_fields
31 helper :custom_fields
32 include CustomFieldsHelper
32 include CustomFieldsHelper
33 helper :ifpdf
33 helper :ifpdf
34 include IfpdfHelper
34 include IfpdfHelper
35 helper :issues
35 helper :issues
36 helper IssuesHelper
36 helper IssuesHelper
37 helper :queries
37 helper :queries
38 include QueriesHelper
38 include QueriesHelper
39 helper :repositories
39 helper :repositories
40 include RepositoriesHelper
40 include RepositoriesHelper
41 include ProjectsHelper
41 include ProjectsHelper
42
42
43 def index
43 def index
44 list
44 list
45 render :action => 'list' unless request.xhr?
45 render :action => 'list' unless request.xhr?
46 end
46 end
47
47
48 # Lists visible projects
48 # Lists visible projects
49 def list
49 def list
50 projects = Project.find :all,
50 projects = Project.find :all,
51 :conditions => Project.visible_by(logged_in_user),
51 :conditions => Project.visible_by(logged_in_user),
52 :include => :parent
52 :include => :parent
53 @project_tree = projects.group_by {|p| p.parent || p}
53 @project_tree = projects.group_by {|p| p.parent || p}
54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
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, :order => "#{CustomField.table_name}.position")
59 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
61 @project = Project.new(params[:project])
61 @project = Project.new(params[:project])
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 if request.get?
63 if request.get?
64 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
64 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 else
65 else
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
67 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
68 @project.custom_values = @custom_values
68 @project.custom_values = @custom_values
69 if @project.save
69 if @project.save
70 @project.enabled_module_names = params[:enabled_modules]
70 @project.enabled_module_names = params[:enabled_modules]
71 flash[:notice] = l(:notice_successful_create)
71 flash[:notice] = l(:notice_successful_create)
72 redirect_to :controller => 'admin', :action => 'projects'
72 redirect_to :controller => 'admin', :action => 'projects'
73 end
73 end
74 end
74 end
75 end
75 end
76
76
77 # Show @project
77 # Show @project
78 def show
78 def show
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 @subprojects = @project.active_children
81 @subprojects = @project.active_children
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
83 @trackers = Tracker.find(:all, :order => 'position')
83 @trackers = Tracker.find(:all, :order => 'position')
84 @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])
84 @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])
85 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
85 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
86 @total_hours = @project.time_entries.sum(:hours)
86 @total_hours = @project.time_entries.sum(:hours)
87 @key = User.current.rss_key
87 @key = User.current.rss_key
88 end
88 end
89
89
90 def settings
90 def settings
91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
92 @custom_fields = IssueCustomField.find(:all)
92 @custom_fields = IssueCustomField.find(:all)
93 @issue_category ||= IssueCategory.new
93 @issue_category ||= IssueCategory.new
94 @member ||= @project.members.new
94 @member ||= @project.members.new
95 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
95 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
96 @repository ||= @project.repository
96 @repository ||= @project.repository
97 @wiki ||= @project.wiki
97 @wiki ||= @project.wiki
98 end
98 end
99
99
100 # Edit @project
100 # Edit @project
101 def edit
101 def edit
102 if request.post?
102 if request.post?
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
104 if params[:custom_fields]
104 if params[:custom_fields]
105 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
106 @project.custom_values = @custom_values
106 @project.custom_values = @custom_values
107 end
107 end
108 @project.attributes = params[:project]
108 @project.attributes = params[:project]
109 if @project.save
109 if @project.save
110 flash[:notice] = l(:notice_successful_update)
110 flash[:notice] = l(:notice_successful_update)
111 redirect_to :action => 'settings', :id => @project
111 redirect_to :action => 'settings', :id => @project
112 else
112 else
113 settings
113 settings
114 render :action => 'settings'
114 render :action => 'settings'
115 end
115 end
116 end
116 end
117 end
117 end
118
118
119 def modules
119 def modules
120 @project.enabled_module_names = params[:enabled_modules]
120 @project.enabled_module_names = params[:enabled_modules]
121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
122 end
122 end
123
123
124 def archive
124 def archive
125 @project.archive if request.post? && @project.active?
125 @project.archive if request.post? && @project.active?
126 redirect_to :controller => 'admin', :action => 'projects'
126 redirect_to :controller => 'admin', :action => 'projects'
127 end
127 end
128
128
129 def unarchive
129 def unarchive
130 @project.unarchive if request.post? && !@project.active?
130 @project.unarchive if request.post? && !@project.active?
131 redirect_to :controller => 'admin', :action => 'projects'
131 redirect_to :controller => 'admin', :action => 'projects'
132 end
132 end
133
133
134 # Delete @project
134 # Delete @project
135 def destroy
135 def destroy
136 @project_to_destroy = @project
136 @project_to_destroy = @project
137 if request.post? and params[:confirm]
137 if request.post? and params[:confirm]
138 @project_to_destroy.destroy
138 @project_to_destroy.destroy
139 redirect_to :controller => 'admin', :action => 'projects'
139 redirect_to :controller => 'admin', :action => 'projects'
140 end
140 end
141 # hide project in layout
141 # hide project in layout
142 @project = nil
142 @project = nil
143 end
143 end
144
144
145 # Add a new issue category to @project
145 # Add a new issue category to @project
146 def add_issue_category
146 def add_issue_category
147 @category = @project.issue_categories.build(params[:category])
147 @category = @project.issue_categories.build(params[:category])
148 if request.post? and @category.save
148 if request.post? and @category.save
149 respond_to do |format|
149 respond_to do |format|
150 format.html do
150 format.html do
151 flash[:notice] = l(:notice_successful_create)
151 flash[:notice] = l(:notice_successful_create)
152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
153 end
153 end
154 format.js do
154 format.js do
155 # IE doesn't support the replace_html rjs method for select box options
155 # IE doesn't support the replace_html rjs method for select box options
156 render(:update) {|page| page.replace "issue_category_id",
156 render(:update) {|page| page.replace "issue_category_id",
157 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]')
157 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]')
158 }
158 }
159 end
159 end
160 end
160 end
161 end
161 end
162 end
162 end
163
163
164 # Add a new version to @project
164 # Add a new version to @project
165 def add_version
165 def add_version
166 @version = @project.versions.build(params[:version])
166 @version = @project.versions.build(params[:version])
167 if request.post? and @version.save
167 if request.post? and @version.save
168 flash[:notice] = l(:notice_successful_create)
168 flash[:notice] = l(:notice_successful_create)
169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
170 end
170 end
171 end
171 end
172
172
173 # Add a new document to @project
173 # Add a new document to @project
174 def add_document
174 def add_document
175 @document = @project.documents.build(params[:document])
175 @document = @project.documents.build(params[:document])
176 if request.post? and @document.save
176 if request.post? and @document.save
177 # Save the attachments
177 # Save the attachments
178 params[:attachments].each { |a|
178 params[:attachments].each { |a|
179 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
179 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
180 } if params[:attachments] and params[:attachments].is_a? Array
180 } if params[:attachments] and params[:attachments].is_a? Array
181 flash[:notice] = l(:notice_successful_create)
181 flash[:notice] = l(:notice_successful_create)
182 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
182 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
183 redirect_to :action => 'list_documents', :id => @project
183 redirect_to :action => 'list_documents', :id => @project
184 end
184 end
185 end
185 end
186
186
187 # Show documents list of @project
187 # Show documents list of @project
188 def list_documents
188 def list_documents
189 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
189 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
190 documents = @project.documents.find :all, :include => [:attachments, :category]
190 documents = @project.documents.find :all, :include => [:attachments, :category]
191 case @sort_by
191 case @sort_by
192 when 'date'
192 when 'date'
193 @grouped = documents.group_by {|d| d.created_on.to_date }
193 @grouped = documents.group_by {|d| d.created_on.to_date }
194 when 'title'
194 when 'title'
195 @grouped = documents.group_by {|d| d.title.first.upcase}
195 @grouped = documents.group_by {|d| d.title.first.upcase}
196 when 'author'
196 when 'author'
197 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
197 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
198 else
198 else
199 @grouped = documents.group_by(&:category)
199 @grouped = documents.group_by(&:category)
200 end
200 end
201 render :layout => false if request.xhr?
201 render :layout => false if request.xhr?
202 end
202 end
203
203
204 # Add a new issue to @project
204 # Add a new issue to @project
205 # The new issue will be created from an existing one if copy_from parameter is given
205 # The new issue will be created from an existing one if copy_from parameter is given
206 def add_issue
206 def add_issue
207 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
207 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
208 @issue.project = @project
208 @issue.project = @project
209 @issue.author = User.current
209 @issue.author = User.current
210 @issue.tracker ||= Tracker.find(params[:tracker_id])
210 @issue.tracker ||= Tracker.find(params[:tracker_id])
211
211
212 default_status = IssueStatus.default
212 default_status = IssueStatus.default
213 unless default_status
213 unless default_status
214 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
214 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
215 render :nothing => true, :layout => true
215 render :nothing => true, :layout => true
216 return
216 return
217 end
217 end
218 @issue.status = default_status
218 @issue.status = default_status
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
220
220
221 if request.get?
221 if request.get?
222 @issue.start_date ||= Date.today
222 @issue.start_date ||= Date.today
223 @custom_values = @issue.custom_values.empty? ?
223 @custom_values = @issue.custom_values.empty? ?
224 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
224 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
225 @issue.custom_values
225 @issue.custom_values
226 else
226 else
227 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
227 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
228 # Check that the user is allowed to apply the requested status
228 # Check that the user is allowed to apply the requested status
229 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
229 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
230 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
230 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
231 @issue.custom_values = @custom_values
231 @issue.custom_values = @custom_values
232 if @issue.save
232 if @issue.save
233 if params[:attachments] && params[:attachments].is_a?(Array)
233 if params[:attachments] && params[:attachments].is_a?(Array)
234 # Save attachments
234 # Save attachments
235 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
235 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
236 end
236 end
237 flash[:notice] = l(:notice_successful_create)
237 flash[:notice] = l(:notice_successful_create)
238 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
238 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
239 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
239 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
240 return
240 return
241 end
241 end
242 end
242 end
243 @priorities = Enumeration::get_values('IPRI')
243 @priorities = Enumeration::get_values('IPRI')
244 end
244 end
245
245
246 # Bulk edit issues
246 # Bulk edit issues
247 def bulk_edit_issues
247 def bulk_edit_issues
248 if request.post?
248 if request.post?
249 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
249 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
250 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
250 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
251 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
251 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
252 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
252 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
253 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
253 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
254 issues = @project.issues.find_all_by_id(params[:issue_ids])
254 issues = @project.issues.find_all_by_id(params[:issue_ids])
255 unsaved_issue_ids = []
255 unsaved_issue_ids = []
256 issues.each do |issue|
256 issues.each do |issue|
257 journal = issue.init_journal(User.current, params[:notes])
257 journal = issue.init_journal(User.current, params[:notes])
258 issue.priority = priority if priority
258 issue.priority = priority if priority
259 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
259 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
260 issue.category = category if category
260 issue.category = category if category
261 issue.fixed_version = fixed_version if fixed_version
261 issue.fixed_version = fixed_version if fixed_version
262 issue.start_date = params[:start_date] unless params[:start_date].blank?
262 issue.start_date = params[:start_date] unless params[:start_date].blank?
263 issue.due_date = params[:due_date] unless params[:due_date].blank?
263 issue.due_date = params[:due_date] unless params[:due_date].blank?
264 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
264 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
265 # Don't save any change to the issue if the user is not authorized to apply the requested status
265 # Don't save any change to the issue if the user is not authorized to apply the requested status
266 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
266 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
267 # Send notification for each issue (if changed)
267 # Send notification for each issue (if changed)
268 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
268 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
269 else
269 else
270 # Keep unsaved issue ids to display them in flash error
270 # Keep unsaved issue ids to display them in flash error
271 unsaved_issue_ids << issue.id
271 unsaved_issue_ids << issue.id
272 end
272 end
273 end
273 end
274 if unsaved_issue_ids.empty?
274 if unsaved_issue_ids.empty?
275 flash[:notice] = l(:notice_successful_update) unless issues.empty?
275 flash[:notice] = l(:notice_successful_update) unless issues.empty?
276 else
276 else
277 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
277 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
278 end
278 end
279 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
279 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
280 return
280 return
281 end
281 end
282 if current_role && User.current.allowed_to?(:change_issue_status, @project)
282 if current_role && User.current.allowed_to?(:change_issue_status, @project)
283 # Find potential statuses the user could be allowed to switch issues to
283 # Find potential statuses the user could be allowed to switch issues to
284 @available_statuses = Workflow.find(:all, :include => :new_status,
284 @available_statuses = Workflow.find(:all, :include => :new_status,
285 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
285 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
286 end
286 end
287 render :update do |page|
287 render :update do |page|
288 page.hide 'query_form'
288 page.hide 'query_form'
289 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
289 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
290 end
290 end
291 end
291 end
292
292
293 def move_issues
293 def move_issues
294 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
294 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
295 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
295 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
296 @projects = []
296 @projects = []
297 # find projects to which the user is allowed to move the issue
297 # find projects to which the user is allowed to move the issue
298 if User.current.admin?
298 if User.current.admin?
299 # admin is allowed to move issues to any active (visible) project
299 # admin is allowed to move issues to any active (visible) project
300 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
300 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
301 else
301 else
302 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
302 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
303 end
303 end
304 # issue can be moved to any tracker
304 # issue can be moved to any tracker
305 @trackers = Tracker.find(:all)
305 @trackers = Tracker.find(:all)
306 if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id]
306 if request.post? && params[:new_project_id] && @projects.collect(&:id).include?(params[:new_project_id].to_i) && params[:new_tracker_id]
307 new_project = Project.find_by_id(params[:new_project_id])
307 new_project = Project.find_by_id(params[:new_project_id])
308 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
308 new_tracker = params[:new_tracker_id].blank? ? nil : Tracker.find_by_id(params[:new_tracker_id])
309 @issues.each do |i|
309 unsaved_issue_ids = []
310 if new_project && i.project_id != new_project.id
310 @issues.each do |issue|
311 # issue is moved to another project
311 unsaved_issue_ids << issue.id unless issue.move_to(new_project, new_tracker)
312 i.category = nil
312 end
313 i.fixed_version = nil
313 if unsaved_issue_ids.empty?
314 # delete issue relations
314 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
315 i.relations_from.clear
315 else
316 i.relations_to.clear
316 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
317 i.project = new_project
318 end
319 if new_tracker
320 i.tracker = new_tracker
321 end
322 i.save
323 end
317 end
324 flash[:notice] = l(:notice_successful_update)
325 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
318 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
326 end
319 end
327 end
320 end
328
321
329 # Add a news to @project
322 # Add a news to @project
330 def add_news
323 def add_news
331 @news = News.new(:project => @project)
324 @news = News.new(:project => @project)
332 if request.post?
325 if request.post?
333 @news.attributes = params[:news]
326 @news.attributes = params[:news]
334 @news.author_id = self.logged_in_user.id if self.logged_in_user
327 @news.author_id = self.logged_in_user.id if self.logged_in_user
335 if @news.save
328 if @news.save
336 flash[:notice] = l(:notice_successful_create)
329 flash[:notice] = l(:notice_successful_create)
337 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
330 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
338 redirect_to :controller => 'news', :action => 'index', :project_id => @project
331 redirect_to :controller => 'news', :action => 'index', :project_id => @project
339 end
332 end
340 end
333 end
341 end
334 end
342
335
343 def add_file
336 def add_file
344 if request.post?
337 if request.post?
345 @version = @project.versions.find_by_id(params[:version_id])
338 @version = @project.versions.find_by_id(params[:version_id])
346 # Save the attachments
339 # Save the attachments
347 @attachments = []
340 @attachments = []
348 params[:attachments].each { |file|
341 params[:attachments].each { |file|
349 next unless file.size > 0
342 next unless file.size > 0
350 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
343 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
351 @attachments << a unless a.new_record?
344 @attachments << a unless a.new_record?
352 } if params[:attachments] and params[:attachments].is_a? Array
345 } if params[:attachments] and params[:attachments].is_a? Array
353 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
346 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
354 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
347 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
355 end
348 end
356 @versions = @project.versions.sort
349 @versions = @project.versions.sort
357 end
350 end
358
351
359 def list_files
352 def list_files
360 @versions = @project.versions.sort
353 @versions = @project.versions.sort
361 end
354 end
362
355
363 # Show changelog for @project
356 # Show changelog for @project
364 def changelog
357 def changelog
365 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
358 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
366 retrieve_selected_tracker_ids(@trackers)
359 retrieve_selected_tracker_ids(@trackers)
367 @versions = @project.versions.sort
360 @versions = @project.versions.sort
368 end
361 end
369
362
370 def roadmap
363 def roadmap
371 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
364 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
372 retrieve_selected_tracker_ids(@trackers)
365 retrieve_selected_tracker_ids(@trackers)
373 @versions = @project.versions.sort
366 @versions = @project.versions.sort
374 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
367 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
375 end
368 end
376
369
377 def activity
370 def activity
378 if params[:year] and params[:year].to_i > 1900
371 if params[:year] and params[:year].to_i > 1900
379 @year = params[:year].to_i
372 @year = params[:year].to_i
380 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
373 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
381 @month = params[:month].to_i
374 @month = params[:month].to_i
382 end
375 end
383 end
376 end
384 @year ||= Date.today.year
377 @year ||= Date.today.year
385 @month ||= Date.today.month
378 @month ||= Date.today.month
386
379
387 case params[:format]
380 case params[:format]
388 when 'atom'
381 when 'atom'
389 # 30 last days
382 # 30 last days
390 @date_from = Date.today - 30
383 @date_from = Date.today - 30
391 @date_to = Date.today + 1
384 @date_to = Date.today + 1
392 else
385 else
393 # current month
386 # current month
394 @date_from = Date.civil(@year, @month, 1)
387 @date_from = Date.civil(@year, @month, 1)
395 @date_to = @date_from >> 1
388 @date_to = @date_from >> 1
396 end
389 end
397
390
398 @event_types = %w(issues news files documents changesets wiki_pages messages)
391 @event_types = %w(issues news files documents changesets wiki_pages messages)
399 @event_types.delete('wiki_pages') unless @project.wiki
392 @event_types.delete('wiki_pages') unless @project.wiki
400 @event_types.delete('changesets') unless @project.repository
393 @event_types.delete('changesets') unless @project.repository
401 @event_types.delete('messages') unless @project.boards.any?
394 @event_types.delete('messages') unless @project.boards.any?
402 # only show what the user is allowed to view
395 # only show what the user is allowed to view
403 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
396 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
404
397
405 @scope = @event_types.select {|t| params["show_#{t}"]}
398 @scope = @event_types.select {|t| params["show_#{t}"]}
406 # default events if none is specified in parameters
399 # default events if none is specified in parameters
407 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
400 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
408
401
409 @events = []
402 @events = []
410
403
411 if @scope.include?('issues')
404 if @scope.include?('issues')
412 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
405 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
413 @events += @project.issues_status_changes(@date_from, @date_to)
406 @events += @project.issues_status_changes(@date_from, @date_to)
414 end
407 end
415
408
416 if @scope.include?('news')
409 if @scope.include?('news')
417 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
410 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
418 end
411 end
419
412
420 if @scope.include?('files')
413 if @scope.include?('files')
421 @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 )
414 @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 )
422 end
415 end
423
416
424 if @scope.include?('documents')
417 if @scope.include?('documents')
425 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
418 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
426 @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 )
419 @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 )
427 end
420 end
428
421
429 if @scope.include?('wiki_pages')
422 if @scope.include?('wiki_pages')
430 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
423 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
431 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
424 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
432 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
425 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
433 "#{WikiContent.versioned_table_name}.id"
426 "#{WikiContent.versioned_table_name}.id"
434 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
427 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
435 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
428 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
436 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
429 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
437 @project.id, @date_from, @date_to]
430 @project.id, @date_from, @date_to]
438
431
439 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
432 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
440 end
433 end
441
434
442 if @scope.include?('changesets')
435 if @scope.include?('changesets')
443 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
436 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
444 end
437 end
445
438
446 if @scope.include?('messages')
439 if @scope.include?('messages')
447 @events += Message.find(:all,
440 @events += Message.find(:all,
448 :include => [:board, :author],
441 :include => [:board, :author],
449 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
442 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
450 end
443 end
451
444
452 @events_by_day = @events.group_by(&:event_date)
445 @events_by_day = @events.group_by(&:event_date)
453
446
454 respond_to do |format|
447 respond_to do |format|
455 format.html { render :layout => false if request.xhr? }
448 format.html { render :layout => false if request.xhr? }
456 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
449 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
457 end
450 end
458 end
451 end
459
452
460 def calendar
453 def calendar
461 @trackers = Tracker.find(:all, :order => 'position')
454 @trackers = Tracker.find(:all, :order => 'position')
462 retrieve_selected_tracker_ids(@trackers)
455 retrieve_selected_tracker_ids(@trackers)
463
456
464 if params[:year] and params[:year].to_i > 1900
457 if params[:year] and params[:year].to_i > 1900
465 @year = params[:year].to_i
458 @year = params[:year].to_i
466 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
459 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
467 @month = params[:month].to_i
460 @month = params[:month].to_i
468 end
461 end
469 end
462 end
470 @year ||= Date.today.year
463 @year ||= Date.today.year
471 @month ||= Date.today.month
464 @month ||= Date.today.month
472 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
465 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
473
466
474 events = []
467 events = []
475 @project.issues_with_subprojects(params[:with_subprojects]) do
468 @project.issues_with_subprojects(params[:with_subprojects]) do
476 events += Issue.find(:all,
469 events += Issue.find(:all,
477 :include => [:tracker, :status, :assigned_to, :priority, :project],
470 :include => [:tracker, :status, :assigned_to, :priority, :project],
478 :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]
471 :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]
479 ) unless @selected_tracker_ids.empty?
472 ) unless @selected_tracker_ids.empty?
480 end
473 end
481 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
474 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
482 @calendar.events = events
475 @calendar.events = events
483
476
484 render :layout => false if request.xhr?
477 render :layout => false if request.xhr?
485 end
478 end
486
479
487 def gantt
480 def gantt
488 @trackers = Tracker.find(:all, :order => 'position')
481 @trackers = Tracker.find(:all, :order => 'position')
489 retrieve_selected_tracker_ids(@trackers)
482 retrieve_selected_tracker_ids(@trackers)
490
483
491 if params[:year] and params[:year].to_i >0
484 if params[:year] and params[:year].to_i >0
492 @year_from = params[:year].to_i
485 @year_from = params[:year].to_i
493 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
486 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
494 @month_from = params[:month].to_i
487 @month_from = params[:month].to_i
495 else
488 else
496 @month_from = 1
489 @month_from = 1
497 end
490 end
498 else
491 else
499 @month_from ||= Date.today.month
492 @month_from ||= Date.today.month
500 @year_from ||= Date.today.year
493 @year_from ||= Date.today.year
501 end
494 end
502
495
503 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
496 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
504 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
497 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
505 months = (params[:months] || User.current.pref[:gantt_months]).to_i
498 months = (params[:months] || User.current.pref[:gantt_months]).to_i
506 @months = (months > 0 && months < 25) ? months : 6
499 @months = (months > 0 && months < 25) ? months : 6
507
500
508 # Save gantt paramters as user preference (zoom and months count)
501 # Save gantt paramters as user preference (zoom and months count)
509 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
502 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
510 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
503 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
511 User.current.preference.save
504 User.current.preference.save
512 end
505 end
513
506
514 @date_from = Date.civil(@year_from, @month_from, 1)
507 @date_from = Date.civil(@year_from, @month_from, 1)
515 @date_to = (@date_from >> @months) - 1
508 @date_to = (@date_from >> @months) - 1
516
509
517 @events = []
510 @events = []
518 @project.issues_with_subprojects(params[:with_subprojects]) do
511 @project.issues_with_subprojects(params[:with_subprojects]) do
519 @events += Issue.find(:all,
512 @events += Issue.find(:all,
520 :order => "start_date, due_date",
513 :order => "start_date, due_date",
521 :include => [:tracker, :status, :assigned_to, :priority, :project],
514 :include => [:tracker, :status, :assigned_to, :priority, :project],
522 :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]
515 :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]
523 ) unless @selected_tracker_ids.empty?
516 ) unless @selected_tracker_ids.empty?
524 end
517 end
525 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
518 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
526 @events.sort! {|x,y| x.start_date <=> y.start_date }
519 @events.sort! {|x,y| x.start_date <=> y.start_date }
527
520
528 if params[:format]=='pdf'
521 if params[:format]=='pdf'
529 @options_for_rfpdf ||= {}
522 @options_for_rfpdf ||= {}
530 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
523 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
531 render :template => "projects/gantt.rfpdf", :layout => false
524 render :template => "projects/gantt.rfpdf", :layout => false
532 elsif params[:format]=='png' && respond_to?('gantt_image')
525 elsif params[:format]=='png' && respond_to?('gantt_image')
533 image = gantt_image(@events, @date_from, @months, @zoom)
526 image = gantt_image(@events, @date_from, @months, @zoom)
534 image.format = 'PNG'
527 image.format = 'PNG'
535 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
528 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
536 else
529 else
537 render :template => "projects/gantt.rhtml"
530 render :template => "projects/gantt.rhtml"
538 end
531 end
539 end
532 end
540
533
541 private
534 private
542 # Find project of id params[:id]
535 # Find project of id params[:id]
543 # if not found, redirect to project list
536 # if not found, redirect to project list
544 # Used as a before_filter
537 # Used as a before_filter
545 def find_project
538 def find_project
546 @project = Project.find(params[:id])
539 @project = Project.find(params[:id])
547 rescue ActiveRecord::RecordNotFound
540 rescue ActiveRecord::RecordNotFound
548 render_404
541 render_404
549 end
542 end
550
543
551 def retrieve_selected_tracker_ids(selectable_trackers)
544 def retrieve_selected_tracker_ids(selectable_trackers)
552 if ids = params[:tracker_ids]
545 if ids = params[:tracker_ids]
553 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
546 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
554 else
547 else
555 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
548 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
556 end
549 end
557 end
550 end
558 end
551 end
@@ -1,191 +1,217
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 class Issue < ActiveRecord::Base
18 class Issue < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 belongs_to :tracker
20 belongs_to :tracker
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
21 belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
22 belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
23 belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
24 belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
25 belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
25 belongs_to :priority, :class_name => 'Enumeration', :foreign_key => 'priority_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
26 belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
27
27
28 has_many :journals, :as => :journalized, :dependent => :destroy
28 has_many :journals, :as => :journalized, :dependent => :destroy
29 has_many :attachments, :as => :container, :dependent => :destroy
29 has_many :attachments, :as => :container, :dependent => :destroy
30 has_many :time_entries, :dependent => :nullify
30 has_many :time_entries, :dependent => :nullify
31 has_many :custom_values, :dependent => :delete_all, :as => :customized
31 has_many :custom_values, :dependent => :delete_all, :as => :customized
32 has_many :custom_fields, :through => :custom_values
32 has_many :custom_fields, :through => :custom_values
33 has_and_belongs_to_many :changesets, :order => "revision ASC"
33 has_and_belongs_to_many :changesets, :order => "revision ASC"
34
34
35 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
35 has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
36 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36 has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
37
37
38 acts_as_watchable
38 acts_as_watchable
39 acts_as_searchable :columns => ['subject', 'description'], :with => {:journal => :issue}
39 acts_as_searchable :columns => ['subject', 'description'], :with => {:journal => :issue}
40 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
40 acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
41 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
41 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
42
42
43 validates_presence_of :subject, :description, :priority, :tracker, :author, :status
43 validates_presence_of :subject, :description, :priority, :tracker, :author, :status
44 validates_length_of :subject, :maximum => 255
44 validates_length_of :subject, :maximum => 255
45 validates_inclusion_of :done_ratio, :in => 0..100
45 validates_inclusion_of :done_ratio, :in => 0..100
46 validates_numericality_of :estimated_hours, :allow_nil => true
46 validates_numericality_of :estimated_hours, :allow_nil => true
47 validates_associated :custom_values, :on => :update
47 validates_associated :custom_values, :on => :update
48
48
49 def after_initialize
49 def after_initialize
50 if new_record?
50 if new_record?
51 # set default values for new records only
51 # set default values for new records only
52 self.status ||= IssueStatus.default
52 self.status ||= IssueStatus.default
53 self.priority ||= Enumeration.default('IPRI')
53 self.priority ||= Enumeration.default('IPRI')
54 end
54 end
55 end
55 end
56
56
57 def copy_from(arg)
57 def copy_from(arg)
58 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
58 issue = arg.is_a?(Issue) ? arg : Issue.find(arg)
59 self.attributes = issue.attributes.dup
59 self.attributes = issue.attributes.dup
60 self.custom_values = issue.custom_values.collect {|v| v.clone}
60 self.custom_values = issue.custom_values.collect {|v| v.clone}
61 self
61 self
62 end
62 end
63
63
64 # Move an issue to a new project and tracker
65 def move_to(new_project, new_tracker = nil)
66 transaction do
67 if new_project && project_id != new_project.id
68 # delete issue relations
69 self.relations_from.clear
70 self.relations_to.clear
71 # issue is moved to another project
72 self.category = nil
73 self.fixed_version = nil
74 self.project = new_project
75 end
76 if new_tracker
77 self.tracker = new_tracker
78 end
79 if save
80 # Manually update project_id on related time entries
81 TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
82 else
83 rollback_db_transaction
84 return false
85 end
86 end
87 return true
88 end
89
64 def priority_id=(pid)
90 def priority_id=(pid)
65 self.priority = nil
91 self.priority = nil
66 write_attribute(:priority_id, pid)
92 write_attribute(:priority_id, pid)
67 end
93 end
68
94
69 def validate
95 def validate
70 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
96 if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
71 errors.add :due_date, :activerecord_error_not_a_date
97 errors.add :due_date, :activerecord_error_not_a_date
72 end
98 end
73
99
74 if self.due_date and self.start_date and self.due_date < self.start_date
100 if self.due_date and self.start_date and self.due_date < self.start_date
75 errors.add :due_date, :activerecord_error_greater_than_start_date
101 errors.add :due_date, :activerecord_error_greater_than_start_date
76 end
102 end
77
103
78 if start_date && soonest_start && start_date < soonest_start
104 if start_date && soonest_start && start_date < soonest_start
79 errors.add :start_date, :activerecord_error_invalid
105 errors.add :start_date, :activerecord_error_invalid
80 end
106 end
81 end
107 end
82
108
83 def before_create
109 def before_create
84 # default assignment based on category
110 # default assignment based on category
85 if assigned_to.nil? && category && category.assigned_to
111 if assigned_to.nil? && category && category.assigned_to
86 self.assigned_to = category.assigned_to
112 self.assigned_to = category.assigned_to
87 end
113 end
88 end
114 end
89
115
90 def before_save
116 def before_save
91 if @current_journal
117 if @current_journal
92 # attributes changes
118 # attributes changes
93 (Issue.column_names - %w(id description)).each {|c|
119 (Issue.column_names - %w(id description)).each {|c|
94 @current_journal.details << JournalDetail.new(:property => 'attr',
120 @current_journal.details << JournalDetail.new(:property => 'attr',
95 :prop_key => c,
121 :prop_key => c,
96 :old_value => @issue_before_change.send(c),
122 :old_value => @issue_before_change.send(c),
97 :value => send(c)) unless send(c)==@issue_before_change.send(c)
123 :value => send(c)) unless send(c)==@issue_before_change.send(c)
98 }
124 }
99 # custom fields changes
125 # custom fields changes
100 custom_values.each {|c|
126 custom_values.each {|c|
101 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
127 next if (@custom_values_before_change[c.custom_field_id]==c.value ||
102 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
128 (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
103 @current_journal.details << JournalDetail.new(:property => 'cf',
129 @current_journal.details << JournalDetail.new(:property => 'cf',
104 :prop_key => c.custom_field_id,
130 :prop_key => c.custom_field_id,
105 :old_value => @custom_values_before_change[c.custom_field_id],
131 :old_value => @custom_values_before_change[c.custom_field_id],
106 :value => c.value)
132 :value => c.value)
107 }
133 }
108 @current_journal.save
134 @current_journal.save
109 end
135 end
110 # Save the issue even if the journal is not saved (because empty)
136 # Save the issue even if the journal is not saved (because empty)
111 true
137 true
112 end
138 end
113
139
114 def after_save
140 def after_save
115 # Update start/due dates of following issues
141 # Update start/due dates of following issues
116 relations_from.each(&:set_issue_to_dates)
142 relations_from.each(&:set_issue_to_dates)
117
143
118 # Close duplicates if the issue was closed
144 # Close duplicates if the issue was closed
119 if @issue_before_change && !@issue_before_change.closed? && self.closed?
145 if @issue_before_change && !@issue_before_change.closed? && self.closed?
120 duplicates.each do |duplicate|
146 duplicates.each do |duplicate|
121 # Don't re-close it if it's already closed
147 # Don't re-close it if it's already closed
122 next if duplicate.closed?
148 next if duplicate.closed?
123 # Same user and notes
149 # Same user and notes
124 duplicate.init_journal(@current_journal.user, @current_journal.notes)
150 duplicate.init_journal(@current_journal.user, @current_journal.notes)
125 duplicate.update_attribute :status, self.status
151 duplicate.update_attribute :status, self.status
126 end
152 end
127 end
153 end
128 end
154 end
129
155
130 def custom_value_for(custom_field)
156 def custom_value_for(custom_field)
131 self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
157 self.custom_values.each {|v| return v if v.custom_field_id == custom_field.id }
132 return nil
158 return nil
133 end
159 end
134
160
135 def init_journal(user, notes = "")
161 def init_journal(user, notes = "")
136 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
162 @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
137 @issue_before_change = self.clone
163 @issue_before_change = self.clone
138 @custom_values_before_change = {}
164 @custom_values_before_change = {}
139 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
165 self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
140 @current_journal
166 @current_journal
141 end
167 end
142
168
143 # Return true if the issue is closed, otherwise false
169 # Return true if the issue is closed, otherwise false
144 def closed?
170 def closed?
145 self.status.is_closed?
171 self.status.is_closed?
146 end
172 end
147
173
148 # Users the issue can be assigned to
174 # Users the issue can be assigned to
149 def assignable_users
175 def assignable_users
150 project.assignable_users
176 project.assignable_users
151 end
177 end
152
178
153 # Returns the mail adresses of users that should be notified for the issue
179 # Returns the mail adresses of users that should be notified for the issue
154 def recipients
180 def recipients
155 recipients = project.recipients
181 recipients = project.recipients
156 # Author and assignee are always notified
182 # Author and assignee are always notified
157 recipients << author.mail if author
183 recipients << author.mail if author
158 recipients << assigned_to.mail if assigned_to
184 recipients << assigned_to.mail if assigned_to
159 recipients.compact.uniq
185 recipients.compact.uniq
160 end
186 end
161
187
162 def spent_hours
188 def spent_hours
163 @spent_hours ||= time_entries.sum(:hours) || 0
189 @spent_hours ||= time_entries.sum(:hours) || 0
164 end
190 end
165
191
166 def relations
192 def relations
167 (relations_from + relations_to).sort
193 (relations_from + relations_to).sort
168 end
194 end
169
195
170 def all_dependent_issues
196 def all_dependent_issues
171 dependencies = []
197 dependencies = []
172 relations_from.each do |relation|
198 relations_from.each do |relation|
173 dependencies << relation.issue_to
199 dependencies << relation.issue_to
174 dependencies += relation.issue_to.all_dependent_issues
200 dependencies += relation.issue_to.all_dependent_issues
175 end
201 end
176 dependencies
202 dependencies
177 end
203 end
178
204
179 # Returns an array of the duplicate issues
205 # Returns an array of the duplicate issues
180 def duplicates
206 def duplicates
181 relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)}
207 relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)}
182 end
208 end
183
209
184 def duration
210 def duration
185 (start_date && due_date) ? due_date - start_date : 0
211 (start_date && due_date) ? due_date - start_date : 0
186 end
212 end
187
213
188 def soonest_start
214 def soonest_start
189 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
215 @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
190 end
216 end
191 end
217 end
@@ -1,73 +1,73
1 <% if @query.new_record? %>
1 <% if @query.new_record? %>
2 <h2><%=l(:label_issue_plural)%></h2>
2 <h2><%=l(:label_issue_plural)%></h2>
3 <% set_html_title l(:label_issue_plural) %>
3 <% set_html_title l(:label_issue_plural) %>
4
4
5 <% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %>
5 <% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %>
6 <%= hidden_field_tag('project_id', @project.id) if @project %>
6 <%= hidden_field_tag('project_id', @project.id) if @project %>
7 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
7 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
8 <div class="contextual">
8 <div class="contextual">
9 <%= link_to_remote l(:button_apply),
9 <%= link_to_remote l(:button_apply),
10 { :url => { :set_filter => 1 },
10 { :url => { :set_filter => 1 },
11 :update => "content",
11 :update => "content",
12 :with => "Form.serialize('query_form')"
12 :with => "Form.serialize('query_form')"
13 }, :class => 'icon icon-edit' %>
13 }, :class => 'icon icon-checked' %>
14
14
15 <%= link_to_remote l(:button_clear),
15 <%= link_to_remote l(:button_clear),
16 { :url => { :set_filter => 1 },
16 { :url => { :set_filter => 1 },
17 :update => "content",
17 :update => "content",
18 }, :class => 'icon icon-reload' %>
18 }, :class => 'icon icon-reload' %>
19
19
20 <% if current_role && current_role.allowed_to?(:save_queries) %>
20 <% if current_role && current_role.allowed_to?(:save_queries) %>
21 <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
21 <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
22 <% end %>
22 <% end %>
23 </div>
23 </div>
24 <br />
24 <br />
25 &nbsp;
25 &nbsp;
26 <% end %>
26 <% end %>
27 <% else %>
27 <% else %>
28 <div class="contextual">
28 <div class="contextual">
29 <% if @query.editable_by?(User.current) %>
29 <% if @query.editable_by?(User.current) %>
30 <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %>
30 <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => @query}, :class => 'icon icon-edit' %>
31 <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
31 <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => @query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
32 <% end %>
32 <% end %>
33 </div>
33 </div>
34
34
35 <h2><%= @query.name %></h2>
35 <h2><%= @query.name %></h2>
36 <div id="query_form"></div>
36 <div id="query_form"></div>
37 <% set_html_title @query.name %>
37 <% set_html_title @query.name %>
38 <% end %>
38 <% end %>
39 <%= error_messages_for 'query' %>
39 <%= error_messages_for 'query' %>
40 <% if @query.valid? %>
40 <% if @query.valid? %>
41 <% if @issues.empty? %>
41 <% if @issues.empty? %>
42 <p class="nodata"><%= l(:label_no_data) %></p>
42 <p class="nodata"><%= l(:label_no_data) %></p>
43 <% else %>
43 <% else %>
44 <% form_tag({:controller => 'projects', :action => 'bulk_edit_issues', :id => @project}, :id => 'issues_form', :onsubmit => "if (!checkBulkEdit(this)) {alert('#{l(:notice_no_issue_selected)}'); return false;}" ) do %>
44 <% form_tag({:controller => 'projects', :action => 'bulk_edit_issues', :id => @project}, :id => 'issues_form', :onsubmit => "if (!checkBulkEdit(this)) {alert('#{l(:notice_no_issue_selected)}'); return false;}" ) do %>
45 <%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %>
45 <%= render :partial => 'issues/list', :locals => {:issues => @issues, :query => @query} %>
46 <div class="contextual">
46 <div class="contextual">
47 <%= l(:label_export_to) %>
47 <%= l(:label_export_to) %>
48 <%= link_to 'CSV', {:format => 'csv'}, :class => 'icon icon-csv' %>,
48 <%= link_to 'CSV', {:format => 'csv'}, :class => 'icon icon-csv' %>,
49 <%= link_to 'PDF', {:format => 'pdf'}, :class => 'icon icon-pdf' %>
49 <%= link_to 'PDF', {:format => 'pdf'}, :class => 'icon icon-pdf' %>
50 </div>
50 </div>
51 <p><%= pagination_links_full @issue_pages %>
51 <p><%= pagination_links_full @issue_pages %>
52 [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]</p>
52 [ <%= @issue_pages.current.first_item %> - <%= @issue_pages.current.last_item %> / <%= @issue_count %> ]</p>
53 <% end %>
53 <% end %>
54 <% end %>
54 <% end %>
55 <% end %>
55 <% end %>
56
56
57 <% content_for :sidebar do %>
57 <% content_for :sidebar do %>
58 <%= render :partial => 'issues/sidebar' %>
58 <%= render :partial => 'issues/sidebar' %>
59 <% end if @project%>
59 <% end if @project%>
60
60
61 <% content_for :header_tags do %>
61 <% content_for :header_tags do %>
62 <%= auto_discovery_link_tag(:atom, {:query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_issue_plural)) %>
62 <%= auto_discovery_link_tag(:atom, {:query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_issue_plural)) %>
63 <%= auto_discovery_link_tag(:atom, {:action => 'changes', :query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_changes_details)) %>
63 <%= auto_discovery_link_tag(:atom, {:action => 'changes', :query_id => @query, :format => 'atom', :page => nil, :key => User.current.rss_key}, :title => l(:label_changes_details)) %>
64 <%= javascript_include_tag 'calendar/calendar' %>
64 <%= javascript_include_tag 'calendar/calendar' %>
65 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
65 <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %>
66 <%= javascript_include_tag 'calendar/calendar-setup' %>
66 <%= javascript_include_tag 'calendar/calendar-setup' %>
67 <%= stylesheet_link_tag 'calendar' %>
67 <%= stylesheet_link_tag 'calendar' %>
68 <%= javascript_include_tag 'context_menu' %>
68 <%= javascript_include_tag 'context_menu' %>
69 <%= stylesheet_link_tag 'context_menu' %>
69 <%= stylesheet_link_tag 'context_menu' %>
70 <% end %>
70 <% end %>
71
71
72 <div id="context-menu" style="display: none;"></div>
72 <div id="context-menu" style="display: none;"></div>
73 <%= javascript_tag 'new ContextMenu({})' %>
73 <%= javascript_tag 'new ContextMenu({})' %>
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,62 +1,73
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
19
20 class IssueTest < Test::Unit::TestCase
20 class IssueTest < Test::Unit::TestCase
21 fixtures :projects, :users, :members, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values
21 fixtures :projects, :users, :members, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :time_entries
22
22
23 def test_category_based_assignment
23 def test_category_based_assignment
24 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
24 issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1)
25 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
25 assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to
26 end
26 end
27
27
28 def test_copy
28 def test_copy
29 issue = Issue.new.copy_from(1)
29 issue = Issue.new.copy_from(1)
30 assert issue.save
30 assert issue.save
31 issue.reload
31 issue.reload
32 orig = Issue.find(1)
32 orig = Issue.find(1)
33 assert_equal orig.subject, issue.subject
33 assert_equal orig.subject, issue.subject
34 assert_equal orig.tracker, issue.tracker
34 assert_equal orig.tracker, issue.tracker
35 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
35 assert_equal orig.custom_values.first.value, issue.custom_values.first.value
36 end
36 end
37
37
38 def test_close_duplicates
38 def test_close_duplicates
39 # Create 3 issues
39 # Create 3 issues
40 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
40 issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test')
41 assert issue1.save
41 assert issue1.save
42 issue2 = issue1.clone
42 issue2 = issue1.clone
43 assert issue2.save
43 assert issue2.save
44 issue3 = issue1.clone
44 issue3 = issue1.clone
45 assert issue3.save
45 assert issue3.save
46
46
47 # 2 is a dupe of 1
47 # 2 is a dupe of 1
48 IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
48 IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES)
49 # And 3 is a dupe of 2
49 # And 3 is a dupe of 2
50 IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
50 IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES)
51
51
52 assert issue1.reload.duplicates.include?(issue2)
52 assert issue1.reload.duplicates.include?(issue2)
53
53
54 # Closing issue 1
54 # Closing issue 1
55 issue1.init_journal(User.find(:first), "Closing issue1")
55 issue1.init_journal(User.find(:first), "Closing issue1")
56 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
56 issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true}
57 assert issue1.save
57 assert issue1.save
58 # 2 and 3 should be also closed
58 # 2 and 3 should be also closed
59 assert issue2.reload.closed?
59 assert issue2.reload.closed?
60 assert issue3.reload.closed?
60 assert issue3.reload.closed?
61 end
61 end
62
63 def test_move_to_another_project
64 issue = Issue.find(1)
65 assert issue.move_to(Project.find(2))
66 issue.reload
67 assert_equal 2, issue.project_id
68 # Category removed
69 assert_nil issue.category
70 # Make sure time entries were move to the target project
71 assert_equal 2, issue.time_entries.first.project_id
72 end
62 end
73 end
General Comments 0
You need to be logged in to leave comments. Login now