##// END OF EJS Templates
Ported r1009 from 0.6-stable branch....
Jean-Philippe Lang -
r1000:4a2efa9252ba
parent child
Show More
@@ -1,520 +1,520
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(User.current),
51 :conditions => Project.visible_by(User.current),
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 @trackers = Tracker.all
60 @trackers = Tracker.all
61 @root_projects = Project.find(:all,
61 @root_projects = Project.find(:all,
62 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
62 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
63 :order => 'name')
63 :order => 'name')
64 @project = Project.new(params[:project])
64 @project = Project.new(params[:project])
65 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
65 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
66 if request.get?
66 if request.get?
67 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
67 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
68 @project.trackers = Tracker.all
68 @project.trackers = Tracker.all
69 else
69 else
70 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
70 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
71 @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)) }
71 @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)) }
72 @project.custom_values = @custom_values
72 @project.custom_values = @custom_values
73 if @project.save
73 if @project.save
74 @project.enabled_module_names = params[:enabled_modules]
74 @project.enabled_module_names = params[:enabled_modules]
75 flash[:notice] = l(:notice_successful_create)
75 flash[:notice] = l(:notice_successful_create)
76 redirect_to :controller => 'admin', :action => 'projects'
76 redirect_to :controller => 'admin', :action => 'projects'
77 end
77 end
78 end
78 end
79 end
79 end
80
80
81 # Show @project
81 # Show @project
82 def show
82 def show
83 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
83 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
84 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
84 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
85 @subprojects = @project.active_children
85 @subprojects = @project.active_children
86 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
86 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
87 @trackers = @project.trackers
87 @trackers = @project.trackers
88 @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])
88 @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])
89 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
89 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
90 @total_hours = @project.time_entries.sum(:hours)
90 @total_hours = @project.time_entries.sum(:hours)
91 @key = User.current.rss_key
91 @key = User.current.rss_key
92 end
92 end
93
93
94 def settings
94 def settings
95 @root_projects = Project.find(:all,
95 @root_projects = Project.find(:all,
96 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
96 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
97 :order => 'name')
97 :order => 'name')
98 @custom_fields = IssueCustomField.find(:all)
98 @custom_fields = IssueCustomField.find(:all)
99 @issue_category ||= IssueCategory.new
99 @issue_category ||= IssueCategory.new
100 @member ||= @project.members.new
100 @member ||= @project.members.new
101 @trackers = Tracker.all
101 @trackers = Tracker.all
102 @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) }
102 @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) }
103 @repository ||= @project.repository
103 @repository ||= @project.repository
104 @wiki ||= @project.wiki
104 @wiki ||= @project.wiki
105 end
105 end
106
106
107 # Edit @project
107 # Edit @project
108 def edit
108 def edit
109 if request.post?
109 if request.post?
110 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
110 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
111 if params[:custom_fields]
111 if params[:custom_fields]
112 @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]) }
112 @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]) }
113 @project.custom_values = @custom_values
113 @project.custom_values = @custom_values
114 end
114 end
115 @project.attributes = params[:project]
115 @project.attributes = params[:project]
116 if @project.save
116 if @project.save
117 flash[:notice] = l(:notice_successful_update)
117 flash[:notice] = l(:notice_successful_update)
118 redirect_to :action => 'settings', :id => @project
118 redirect_to :action => 'settings', :id => @project
119 else
119 else
120 settings
120 settings
121 render :action => 'settings'
121 render :action => 'settings'
122 end
122 end
123 end
123 end
124 end
124 end
125
125
126 def modules
126 def modules
127 @project.enabled_module_names = params[:enabled_modules]
127 @project.enabled_module_names = params[:enabled_modules]
128 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
128 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
129 end
129 end
130
130
131 def archive
131 def archive
132 @project.archive if request.post? && @project.active?
132 @project.archive 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 def unarchive
136 def unarchive
137 @project.unarchive if request.post? && !@project.active?
137 @project.unarchive if request.post? && !@project.active?
138 redirect_to :controller => 'admin', :action => 'projects'
138 redirect_to :controller => 'admin', :action => 'projects'
139 end
139 end
140
140
141 # Delete @project
141 # Delete @project
142 def destroy
142 def destroy
143 @project_to_destroy = @project
143 @project_to_destroy = @project
144 if request.post? and params[:confirm]
144 if request.post? and params[:confirm]
145 @project_to_destroy.destroy
145 @project_to_destroy.destroy
146 redirect_to :controller => 'admin', :action => 'projects'
146 redirect_to :controller => 'admin', :action => 'projects'
147 end
147 end
148 # hide project in layout
148 # hide project in layout
149 @project = nil
149 @project = nil
150 end
150 end
151
151
152 # Add a new issue category to @project
152 # Add a new issue category to @project
153 def add_issue_category
153 def add_issue_category
154 @category = @project.issue_categories.build(params[:category])
154 @category = @project.issue_categories.build(params[:category])
155 if request.post? and @category.save
155 if request.post? and @category.save
156 respond_to do |format|
156 respond_to do |format|
157 format.html do
157 format.html do
158 flash[:notice] = l(:notice_successful_create)
158 flash[:notice] = l(:notice_successful_create)
159 redirect_to :action => 'settings', :tab => 'categories', :id => @project
159 redirect_to :action => 'settings', :tab => 'categories', :id => @project
160 end
160 end
161 format.js do
161 format.js do
162 # IE doesn't support the replace_html rjs method for select box options
162 # IE doesn't support the replace_html rjs method for select box options
163 render(:update) {|page| page.replace "issue_category_id",
163 render(:update) {|page| page.replace "issue_category_id",
164 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]')
164 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]')
165 }
165 }
166 end
166 end
167 end
167 end
168 end
168 end
169 end
169 end
170
170
171 # Add a new version to @project
171 # Add a new version to @project
172 def add_version
172 def add_version
173 @version = @project.versions.build(params[:version])
173 @version = @project.versions.build(params[:version])
174 if request.post? and @version.save
174 if request.post? and @version.save
175 flash[:notice] = l(:notice_successful_create)
175 flash[:notice] = l(:notice_successful_create)
176 redirect_to :action => 'settings', :tab => 'versions', :id => @project
176 redirect_to :action => 'settings', :tab => 'versions', :id => @project
177 end
177 end
178 end
178 end
179
179
180 # Add a new issue to @project
180 # Add a new issue to @project
181 # The new issue will be created from an existing one if copy_from parameter is given
181 # The new issue will be created from an existing one if copy_from parameter is given
182 def add_issue
182 def add_issue
183 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
183 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
184 @issue.project = @project
184 @issue.project = @project
185 @issue.author = User.current
185 @issue.author = User.current
186 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
186 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
187
187
188 default_status = IssueStatus.default
188 default_status = IssueStatus.default
189 unless default_status
189 unless default_status
190 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
190 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
191 render :nothing => true, :layout => true
191 render :nothing => true, :layout => true
192 return
192 return
193 end
193 end
194 @issue.status = default_status
194 @issue.status = default_status
195 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
195 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
196
196
197 if request.get?
197 if request.get?
198 @issue.start_date ||= Date.today
198 @issue.start_date ||= Date.today
199 @custom_values = @issue.custom_values.empty? ?
199 @custom_values = @issue.custom_values.empty? ?
200 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
200 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
201 @issue.custom_values
201 @issue.custom_values
202 else
202 else
203 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
203 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
204 # Check that the user is allowed to apply the requested status
204 # Check that the user is allowed to apply the requested status
205 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
205 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
206 @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]) }
206 @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]) }
207 @issue.custom_values = @custom_values
207 @issue.custom_values = @custom_values
208 if @issue.save
208 if @issue.save
209 attach_files(@issue, params[:attachments])
209 attach_files(@issue, params[:attachments])
210 flash[:notice] = l(:notice_successful_create)
210 flash[:notice] = l(:notice_successful_create)
211 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
211 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
212 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
212 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
213 return
213 return
214 end
214 end
215 end
215 end
216 @priorities = Enumeration::get_values('IPRI')
216 @priorities = Enumeration::get_values('IPRI')
217 end
217 end
218
218
219 # Bulk edit issues
219 # Bulk edit issues
220 def bulk_edit_issues
220 def bulk_edit_issues
221 if request.post?
221 if request.post?
222 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
222 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
223 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
223 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
224 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
224 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
225 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
225 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
226 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
226 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
227 issues = @project.issues.find_all_by_id(params[:issue_ids])
227 issues = @project.issues.find_all_by_id(params[:issue_ids])
228 unsaved_issue_ids = []
228 unsaved_issue_ids = []
229 issues.each do |issue|
229 issues.each do |issue|
230 journal = issue.init_journal(User.current, params[:notes])
230 journal = issue.init_journal(User.current, params[:notes])
231 issue.priority = priority if priority
231 issue.priority = priority if priority
232 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
232 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
233 issue.category = category if category
233 issue.category = category if category
234 issue.fixed_version = fixed_version if fixed_version
234 issue.fixed_version = fixed_version if fixed_version
235 issue.start_date = params[:start_date] unless params[:start_date].blank?
235 issue.start_date = params[:start_date] unless params[:start_date].blank?
236 issue.due_date = params[:due_date] unless params[:due_date].blank?
236 issue.due_date = params[:due_date] unless params[:due_date].blank?
237 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
237 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
238 # Don't save any change to the issue if the user is not authorized to apply the requested status
238 # Don't save any change to the issue if the user is not authorized to apply the requested status
239 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
239 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
240 # Send notification for each issue (if changed)
240 # Send notification for each issue (if changed)
241 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
241 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
242 else
242 else
243 # Keep unsaved issue ids to display them in flash error
243 # Keep unsaved issue ids to display them in flash error
244 unsaved_issue_ids << issue.id
244 unsaved_issue_ids << issue.id
245 end
245 end
246 end
246 end
247 if unsaved_issue_ids.empty?
247 if unsaved_issue_ids.empty?
248 flash[:notice] = l(:notice_successful_update) unless issues.empty?
248 flash[:notice] = l(:notice_successful_update) unless issues.empty?
249 else
249 else
250 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
250 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
251 end
251 end
252 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
252 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
253 return
253 return
254 end
254 end
255 if current_role && User.current.allowed_to?(:change_issue_status, @project)
255 if current_role && User.current.allowed_to?(:change_issue_status, @project)
256 # Find potential statuses the user could be allowed to switch issues to
256 # Find potential statuses the user could be allowed to switch issues to
257 @available_statuses = Workflow.find(:all, :include => :new_status,
257 @available_statuses = Workflow.find(:all, :include => :new_status,
258 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
258 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
259 end
259 end
260 render :update do |page|
260 render :update do |page|
261 page.hide 'query_form'
261 page.hide 'query_form'
262 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
262 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
263 end
263 end
264 end
264 end
265
265
266 def move_issues
266 def move_issues
267 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
267 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
268 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
268 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
269
269
270 @projects = []
270 @projects = []
271 # find projects to which the user is allowed to move the issue
271 # find projects to which the user is allowed to move the issue
272 if User.current.admin?
272 if User.current.admin?
273 # admin is allowed to move issues to any active (visible) project
273 # admin is allowed to move issues to any active (visible) project
274 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
274 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
275 else
275 else
276 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
276 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
277 end
277 end
278 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
278 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
279 @target_project ||= @project
279 @target_project ||= @project
280 @trackers = @target_project.trackers
280 @trackers = @target_project.trackers
281 if request.post?
281 if request.post?
282 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
282 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
283 unsaved_issue_ids = []
283 unsaved_issue_ids = []
284 @issues.each do |issue|
284 @issues.each do |issue|
285 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
285 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
286 end
286 end
287 if unsaved_issue_ids.empty?
287 if unsaved_issue_ids.empty?
288 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
288 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
289 else
289 else
290 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
290 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
291 end
291 end
292 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
292 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
293 return
293 return
294 end
294 end
295 render :layout => false if request.xhr?
295 render :layout => false if request.xhr?
296 end
296 end
297
297
298 # Add a news to @project
298 # Add a news to @project
299 def add_news
299 def add_news
300 @news = News.new(:project => @project, :author => User.current)
300 @news = News.new(:project => @project, :author => User.current)
301 if request.post?
301 if request.post?
302 @news.attributes = params[:news]
302 @news.attributes = params[:news]
303 if @news.save
303 if @news.save
304 flash[:notice] = l(:notice_successful_create)
304 flash[:notice] = l(:notice_successful_create)
305 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
305 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
306 redirect_to :controller => 'news', :action => 'index', :project_id => @project
306 redirect_to :controller => 'news', :action => 'index', :project_id => @project
307 end
307 end
308 end
308 end
309 end
309 end
310
310
311 def add_file
311 def add_file
312 if request.post?
312 if request.post?
313 @version = @project.versions.find_by_id(params[:version_id])
313 @version = @project.versions.find_by_id(params[:version_id])
314 attachments = attach_files(@issue, params[:attachments])
314 attachments = attach_files(@version, params[:attachments])
315 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
315 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
316 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
316 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
317 end
317 end
318 @versions = @project.versions.sort
318 @versions = @project.versions.sort
319 end
319 end
320
320
321 def list_files
321 def list_files
322 @versions = @project.versions.sort
322 @versions = @project.versions.sort
323 end
323 end
324
324
325 # Show changelog for @project
325 # Show changelog for @project
326 def changelog
326 def changelog
327 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
327 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
328 retrieve_selected_tracker_ids(@trackers)
328 retrieve_selected_tracker_ids(@trackers)
329 @versions = @project.versions.sort
329 @versions = @project.versions.sort
330 end
330 end
331
331
332 def roadmap
332 def roadmap
333 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
333 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
334 retrieve_selected_tracker_ids(@trackers)
334 retrieve_selected_tracker_ids(@trackers)
335 @versions = @project.versions.sort
335 @versions = @project.versions.sort
336 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
336 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
337 end
337 end
338
338
339 def activity
339 def activity
340 if params[:year] and params[:year].to_i > 1900
340 if params[:year] and params[:year].to_i > 1900
341 @year = params[:year].to_i
341 @year = params[:year].to_i
342 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
342 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
343 @month = params[:month].to_i
343 @month = params[:month].to_i
344 end
344 end
345 end
345 end
346 @year ||= Date.today.year
346 @year ||= Date.today.year
347 @month ||= Date.today.month
347 @month ||= Date.today.month
348
348
349 case params[:format]
349 case params[:format]
350 when 'atom'
350 when 'atom'
351 # 30 last days
351 # 30 last days
352 @date_from = Date.today - 30
352 @date_from = Date.today - 30
353 @date_to = Date.today + 1
353 @date_to = Date.today + 1
354 else
354 else
355 # current month
355 # current month
356 @date_from = Date.civil(@year, @month, 1)
356 @date_from = Date.civil(@year, @month, 1)
357 @date_to = @date_from >> 1
357 @date_to = @date_from >> 1
358 end
358 end
359
359
360 @event_types = %w(issues news files documents changesets wiki_pages messages)
360 @event_types = %w(issues news files documents changesets wiki_pages messages)
361 @event_types.delete('wiki_pages') unless @project.wiki
361 @event_types.delete('wiki_pages') unless @project.wiki
362 @event_types.delete('changesets') unless @project.repository
362 @event_types.delete('changesets') unless @project.repository
363 @event_types.delete('messages') unless @project.boards.any?
363 @event_types.delete('messages') unless @project.boards.any?
364 # only show what the user is allowed to view
364 # only show what the user is allowed to view
365 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
365 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
366
366
367 @scope = @event_types.select {|t| params["show_#{t}"]}
367 @scope = @event_types.select {|t| params["show_#{t}"]}
368 # default events if none is specified in parameters
368 # default events if none is specified in parameters
369 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
369 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
370
370
371 @events = []
371 @events = []
372
372
373 if @scope.include?('issues')
373 if @scope.include?('issues')
374 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
374 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
375 @events += @project.issues_status_changes(@date_from, @date_to)
375 @events += @project.issues_status_changes(@date_from, @date_to)
376 end
376 end
377
377
378 if @scope.include?('news')
378 if @scope.include?('news')
379 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
379 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
380 end
380 end
381
381
382 if @scope.include?('files')
382 if @scope.include?('files')
383 @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 )
383 @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 )
384 end
384 end
385
385
386 if @scope.include?('documents')
386 if @scope.include?('documents')
387 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
387 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
388 @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 )
388 @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 )
389 end
389 end
390
390
391 if @scope.include?('wiki_pages')
391 if @scope.include?('wiki_pages')
392 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
392 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
393 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
393 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
394 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
394 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
395 "#{WikiContent.versioned_table_name}.id"
395 "#{WikiContent.versioned_table_name}.id"
396 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
396 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
397 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
397 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
398 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
398 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
399 @project.id, @date_from, @date_to]
399 @project.id, @date_from, @date_to]
400
400
401 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
401 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
402 end
402 end
403
403
404 if @scope.include?('changesets')
404 if @scope.include?('changesets')
405 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
405 @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
406 end
406 end
407
407
408 if @scope.include?('messages')
408 if @scope.include?('messages')
409 @events += Message.find(:all,
409 @events += Message.find(:all,
410 :include => [:board, :author],
410 :include => [:board, :author],
411 :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])
411 :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])
412 end
412 end
413
413
414 @events_by_day = @events.group_by(&:event_date)
414 @events_by_day = @events.group_by(&:event_date)
415
415
416 respond_to do |format|
416 respond_to do |format|
417 format.html { render :layout => false if request.xhr? }
417 format.html { render :layout => false if request.xhr? }
418 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
418 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
419 end
419 end
420 end
420 end
421
421
422 def calendar
422 def calendar
423 @trackers = Tracker.find(:all, :order => 'position')
423 @trackers = Tracker.find(:all, :order => 'position')
424 retrieve_selected_tracker_ids(@trackers)
424 retrieve_selected_tracker_ids(@trackers)
425
425
426 if params[:year] and params[:year].to_i > 1900
426 if params[:year] and params[:year].to_i > 1900
427 @year = params[:year].to_i
427 @year = params[:year].to_i
428 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
428 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
429 @month = params[:month].to_i
429 @month = params[:month].to_i
430 end
430 end
431 end
431 end
432 @year ||= Date.today.year
432 @year ||= Date.today.year
433 @month ||= Date.today.month
433 @month ||= Date.today.month
434 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
434 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
435
435
436 events = []
436 events = []
437 @project.issues_with_subprojects(params[:with_subprojects]) do
437 @project.issues_with_subprojects(params[:with_subprojects]) do
438 events += Issue.find(:all,
438 events += Issue.find(:all,
439 :include => [:tracker, :status, :assigned_to, :priority, :project],
439 :include => [:tracker, :status, :assigned_to, :priority, :project],
440 :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]
440 :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]
441 ) unless @selected_tracker_ids.empty?
441 ) unless @selected_tracker_ids.empty?
442 end
442 end
443 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
443 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
444 @calendar.events = events
444 @calendar.events = events
445
445
446 render :layout => false if request.xhr?
446 render :layout => false if request.xhr?
447 end
447 end
448
448
449 def gantt
449 def gantt
450 @trackers = Tracker.find(:all, :order => 'position')
450 @trackers = Tracker.find(:all, :order => 'position')
451 retrieve_selected_tracker_ids(@trackers)
451 retrieve_selected_tracker_ids(@trackers)
452
452
453 if params[:year] and params[:year].to_i >0
453 if params[:year] and params[:year].to_i >0
454 @year_from = params[:year].to_i
454 @year_from = params[:year].to_i
455 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
455 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
456 @month_from = params[:month].to_i
456 @month_from = params[:month].to_i
457 else
457 else
458 @month_from = 1
458 @month_from = 1
459 end
459 end
460 else
460 else
461 @month_from ||= Date.today.month
461 @month_from ||= Date.today.month
462 @year_from ||= Date.today.year
462 @year_from ||= Date.today.year
463 end
463 end
464
464
465 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
465 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
466 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
466 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
467 months = (params[:months] || User.current.pref[:gantt_months]).to_i
467 months = (params[:months] || User.current.pref[:gantt_months]).to_i
468 @months = (months > 0 && months < 25) ? months : 6
468 @months = (months > 0 && months < 25) ? months : 6
469
469
470 # Save gantt paramters as user preference (zoom and months count)
470 # Save gantt paramters as user preference (zoom and months count)
471 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
471 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
472 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
472 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
473 User.current.preference.save
473 User.current.preference.save
474 end
474 end
475
475
476 @date_from = Date.civil(@year_from, @month_from, 1)
476 @date_from = Date.civil(@year_from, @month_from, 1)
477 @date_to = (@date_from >> @months) - 1
477 @date_to = (@date_from >> @months) - 1
478
478
479 @events = []
479 @events = []
480 @project.issues_with_subprojects(params[:with_subprojects]) do
480 @project.issues_with_subprojects(params[:with_subprojects]) do
481 @events += Issue.find(:all,
481 @events += Issue.find(:all,
482 :order => "start_date, due_date",
482 :order => "start_date, due_date",
483 :include => [:tracker, :status, :assigned_to, :priority, :project],
483 :include => [:tracker, :status, :assigned_to, :priority, :project],
484 :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]
484 :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]
485 ) unless @selected_tracker_ids.empty?
485 ) unless @selected_tracker_ids.empty?
486 end
486 end
487 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
487 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
488 @events.sort! {|x,y| x.start_date <=> y.start_date }
488 @events.sort! {|x,y| x.start_date <=> y.start_date }
489
489
490 if params[:format]=='pdf'
490 if params[:format]=='pdf'
491 @options_for_rfpdf ||= {}
491 @options_for_rfpdf ||= {}
492 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
492 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
493 render :template => "projects/gantt.rfpdf", :layout => false
493 render :template => "projects/gantt.rfpdf", :layout => false
494 elsif params[:format]=='png' && respond_to?('gantt_image')
494 elsif params[:format]=='png' && respond_to?('gantt_image')
495 image = gantt_image(@events, @date_from, @months, @zoom)
495 image = gantt_image(@events, @date_from, @months, @zoom)
496 image.format = 'PNG'
496 image.format = 'PNG'
497 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
497 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
498 else
498 else
499 render :template => "projects/gantt.rhtml"
499 render :template => "projects/gantt.rhtml"
500 end
500 end
501 end
501 end
502
502
503 private
503 private
504 # Find project of id params[:id]
504 # Find project of id params[:id]
505 # if not found, redirect to project list
505 # if not found, redirect to project list
506 # Used as a before_filter
506 # Used as a before_filter
507 def find_project
507 def find_project
508 @project = Project.find(params[:id])
508 @project = Project.find(params[:id])
509 rescue ActiveRecord::RecordNotFound
509 rescue ActiveRecord::RecordNotFound
510 render_404
510 render_404
511 end
511 end
512
512
513 def retrieve_selected_tracker_ids(selectable_trackers)
513 def retrieve_selected_tracker_ids(selectable_trackers)
514 if ids = params[:tracker_ids]
514 if ids = params[:tracker_ids]
515 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
515 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
516 else
516 else
517 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
517 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
518 end
518 end
519 end
519 end
520 end
520 end
General Comments 0
You need to be logged in to leave comments. Login now