##// END OF EJS Templates
Changesets retrieval optimization on the activity view. Prevents additional query from being executed for each displayed changeset....
Jean-Philippe Lang -
r939:d00014221ed1
parent child
Show More
@@ -1,560 +1,560
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 document to @project
180 # Add a new document to @project
181 def add_document
181 def add_document
182 @document = @project.documents.build(params[:document])
182 @document = @project.documents.build(params[:document])
183 if request.post? and @document.save
183 if request.post? and @document.save
184 # Save the attachments
184 # Save the attachments
185 params[:attachments].each { |a|
185 params[:attachments].each { |a|
186 Attachment.create(:container => @document, :file => a, :author => User.current) unless a.size == 0
186 Attachment.create(:container => @document, :file => a, :author => User.current) unless a.size == 0
187 } if params[:attachments] and params[:attachments].is_a? Array
187 } if params[:attachments] and params[:attachments].is_a? Array
188 flash[:notice] = l(:notice_successful_create)
188 flash[:notice] = l(:notice_successful_create)
189 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
189 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
190 redirect_to :action => 'list_documents', :id => @project
190 redirect_to :action => 'list_documents', :id => @project
191 end
191 end
192 end
192 end
193
193
194 # Show documents list of @project
194 # Show documents list of @project
195 def list_documents
195 def list_documents
196 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
196 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
197 documents = @project.documents.find :all, :include => [:attachments, :category]
197 documents = @project.documents.find :all, :include => [:attachments, :category]
198 case @sort_by
198 case @sort_by
199 when 'date'
199 when 'date'
200 @grouped = documents.group_by {|d| d.created_on.to_date }
200 @grouped = documents.group_by {|d| d.created_on.to_date }
201 when 'title'
201 when 'title'
202 @grouped = documents.group_by {|d| d.title.first.upcase}
202 @grouped = documents.group_by {|d| d.title.first.upcase}
203 when 'author'
203 when 'author'
204 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
204 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
205 else
205 else
206 @grouped = documents.group_by(&:category)
206 @grouped = documents.group_by(&:category)
207 end
207 end
208 render :layout => false if request.xhr?
208 render :layout => false if request.xhr?
209 end
209 end
210
210
211 # Add a new issue to @project
211 # Add a new issue to @project
212 # The new issue will be created from an existing one if copy_from parameter is given
212 # The new issue will be created from an existing one if copy_from parameter is given
213 def add_issue
213 def add_issue
214 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
214 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
215 @issue.project = @project
215 @issue.project = @project
216 @issue.author = User.current
216 @issue.author = User.current
217 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
217 @issue.tracker ||= @project.trackers.find(params[:tracker_id])
218
218
219 default_status = IssueStatus.default
219 default_status = IssueStatus.default
220 unless default_status
220 unless default_status
221 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
221 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
222 render :nothing => true, :layout => true
222 render :nothing => true, :layout => true
223 return
223 return
224 end
224 end
225 @issue.status = default_status
225 @issue.status = default_status
226 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
226 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.role_for_project(@project), @issue.tracker))
227
227
228 if request.get?
228 if request.get?
229 @issue.start_date ||= Date.today
229 @issue.start_date ||= Date.today
230 @custom_values = @issue.custom_values.empty? ?
230 @custom_values = @issue.custom_values.empty? ?
231 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
231 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
232 @issue.custom_values
232 @issue.custom_values
233 else
233 else
234 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
234 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
235 # Check that the user is allowed to apply the requested status
235 # Check that the user is allowed to apply the requested status
236 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
236 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
237 @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]) }
237 @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]) }
238 @issue.custom_values = @custom_values
238 @issue.custom_values = @custom_values
239 if @issue.save
239 if @issue.save
240 if params[:attachments] && params[:attachments].is_a?(Array)
240 if params[:attachments] && params[:attachments].is_a?(Array)
241 # Save attachments
241 # Save attachments
242 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
242 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
243 end
243 end
244 flash[:notice] = l(:notice_successful_create)
244 flash[:notice] = l(:notice_successful_create)
245 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
245 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
246 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
246 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
247 return
247 return
248 end
248 end
249 end
249 end
250 @priorities = Enumeration::get_values('IPRI')
250 @priorities = Enumeration::get_values('IPRI')
251 end
251 end
252
252
253 # Bulk edit issues
253 # Bulk edit issues
254 def bulk_edit_issues
254 def bulk_edit_issues
255 if request.post?
255 if request.post?
256 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
256 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
257 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
257 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
258 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
258 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
259 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
259 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
260 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
260 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
261 issues = @project.issues.find_all_by_id(params[:issue_ids])
261 issues = @project.issues.find_all_by_id(params[:issue_ids])
262 unsaved_issue_ids = []
262 unsaved_issue_ids = []
263 issues.each do |issue|
263 issues.each do |issue|
264 journal = issue.init_journal(User.current, params[:notes])
264 journal = issue.init_journal(User.current, params[:notes])
265 issue.priority = priority if priority
265 issue.priority = priority if priority
266 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
266 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
267 issue.category = category if category
267 issue.category = category if category
268 issue.fixed_version = fixed_version if fixed_version
268 issue.fixed_version = fixed_version if fixed_version
269 issue.start_date = params[:start_date] unless params[:start_date].blank?
269 issue.start_date = params[:start_date] unless params[:start_date].blank?
270 issue.due_date = params[:due_date] unless params[:due_date].blank?
270 issue.due_date = params[:due_date] unless params[:due_date].blank?
271 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
271 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
272 # Don't save any change to the issue if the user is not authorized to apply the requested status
272 # Don't save any change to the issue if the user is not authorized to apply the requested status
273 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
273 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
274 # Send notification for each issue (if changed)
274 # Send notification for each issue (if changed)
275 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
275 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
276 else
276 else
277 # Keep unsaved issue ids to display them in flash error
277 # Keep unsaved issue ids to display them in flash error
278 unsaved_issue_ids << issue.id
278 unsaved_issue_ids << issue.id
279 end
279 end
280 end
280 end
281 if unsaved_issue_ids.empty?
281 if unsaved_issue_ids.empty?
282 flash[:notice] = l(:notice_successful_update) unless issues.empty?
282 flash[:notice] = l(:notice_successful_update) unless issues.empty?
283 else
283 else
284 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
284 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
285 end
285 end
286 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
286 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
287 return
287 return
288 end
288 end
289 if current_role && User.current.allowed_to?(:change_issue_status, @project)
289 if current_role && User.current.allowed_to?(:change_issue_status, @project)
290 # Find potential statuses the user could be allowed to switch issues to
290 # Find potential statuses the user could be allowed to switch issues to
291 @available_statuses = Workflow.find(:all, :include => :new_status,
291 @available_statuses = Workflow.find(:all, :include => :new_status,
292 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
292 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
293 end
293 end
294 render :update do |page|
294 render :update do |page|
295 page.hide 'query_form'
295 page.hide 'query_form'
296 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
296 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
297 end
297 end
298 end
298 end
299
299
300 def move_issues
300 def move_issues
301 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
301 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
302 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
302 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
303
303
304 @projects = []
304 @projects = []
305 # find projects to which the user is allowed to move the issue
305 # find projects to which the user is allowed to move the issue
306 if User.current.admin?
306 if User.current.admin?
307 # admin is allowed to move issues to any active (visible) project
307 # admin is allowed to move issues to any active (visible) project
308 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
308 @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name')
309 else
309 else
310 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
310 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)}
311 end
311 end
312 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
312 @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
313 @target_project ||= @project
313 @target_project ||= @project
314 @trackers = @target_project.trackers
314 @trackers = @target_project.trackers
315 if request.post?
315 if request.post?
316 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
316 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
317 unsaved_issue_ids = []
317 unsaved_issue_ids = []
318 @issues.each do |issue|
318 @issues.each do |issue|
319 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
319 unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
320 end
320 end
321 if unsaved_issue_ids.empty?
321 if unsaved_issue_ids.empty?
322 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
322 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
323 else
323 else
324 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
324 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
325 end
325 end
326 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
326 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
327 return
327 return
328 end
328 end
329 render :layout => false if request.xhr?
329 render :layout => false if request.xhr?
330 end
330 end
331
331
332 # Add a news to @project
332 # Add a news to @project
333 def add_news
333 def add_news
334 @news = News.new(:project => @project, :author => User.current)
334 @news = News.new(:project => @project, :author => User.current)
335 if request.post?
335 if request.post?
336 @news.attributes = params[:news]
336 @news.attributes = params[:news]
337 if @news.save
337 if @news.save
338 flash[:notice] = l(:notice_successful_create)
338 flash[:notice] = l(:notice_successful_create)
339 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
339 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
340 redirect_to :controller => 'news', :action => 'index', :project_id => @project
340 redirect_to :controller => 'news', :action => 'index', :project_id => @project
341 end
341 end
342 end
342 end
343 end
343 end
344
344
345 def add_file
345 def add_file
346 if request.post?
346 if request.post?
347 @version = @project.versions.find_by_id(params[:version_id])
347 @version = @project.versions.find_by_id(params[:version_id])
348 # Save the attachments
348 # Save the attachments
349 @attachments = []
349 @attachments = []
350 params[:attachments].each { |file|
350 params[:attachments].each { |file|
351 next unless file.size > 0
351 next unless file.size > 0
352 a = Attachment.create(:container => @version, :file => file, :author => User.current)
352 a = Attachment.create(:container => @version, :file => file, :author => User.current)
353 @attachments << a unless a.new_record?
353 @attachments << a unless a.new_record?
354 } if params[:attachments] and params[:attachments].is_a? Array
354 } if params[:attachments] and params[:attachments].is_a? Array
355 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
355 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
356 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
356 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
357 end
357 end
358 @versions = @project.versions.sort
358 @versions = @project.versions.sort
359 end
359 end
360
360
361 def list_files
361 def list_files
362 @versions = @project.versions.sort
362 @versions = @project.versions.sort
363 end
363 end
364
364
365 # Show changelog for @project
365 # Show changelog for @project
366 def changelog
366 def changelog
367 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
367 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
368 retrieve_selected_tracker_ids(@trackers)
368 retrieve_selected_tracker_ids(@trackers)
369 @versions = @project.versions.sort
369 @versions = @project.versions.sort
370 end
370 end
371
371
372 def roadmap
372 def roadmap
373 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
373 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
374 retrieve_selected_tracker_ids(@trackers)
374 retrieve_selected_tracker_ids(@trackers)
375 @versions = @project.versions.sort
375 @versions = @project.versions.sort
376 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
376 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
377 end
377 end
378
378
379 def activity
379 def activity
380 if params[:year] and params[:year].to_i > 1900
380 if params[:year] and params[:year].to_i > 1900
381 @year = params[:year].to_i
381 @year = params[:year].to_i
382 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
382 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
383 @month = params[:month].to_i
383 @month = params[:month].to_i
384 end
384 end
385 end
385 end
386 @year ||= Date.today.year
386 @year ||= Date.today.year
387 @month ||= Date.today.month
387 @month ||= Date.today.month
388
388
389 case params[:format]
389 case params[:format]
390 when 'atom'
390 when 'atom'
391 # 30 last days
391 # 30 last days
392 @date_from = Date.today - 30
392 @date_from = Date.today - 30
393 @date_to = Date.today + 1
393 @date_to = Date.today + 1
394 else
394 else
395 # current month
395 # current month
396 @date_from = Date.civil(@year, @month, 1)
396 @date_from = Date.civil(@year, @month, 1)
397 @date_to = @date_from >> 1
397 @date_to = @date_from >> 1
398 end
398 end
399
399
400 @event_types = %w(issues news files documents changesets wiki_pages messages)
400 @event_types = %w(issues news files documents changesets wiki_pages messages)
401 @event_types.delete('wiki_pages') unless @project.wiki
401 @event_types.delete('wiki_pages') unless @project.wiki
402 @event_types.delete('changesets') unless @project.repository
402 @event_types.delete('changesets') unless @project.repository
403 @event_types.delete('messages') unless @project.boards.any?
403 @event_types.delete('messages') unless @project.boards.any?
404 # only show what the user is allowed to view
404 # only show what the user is allowed to view
405 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
405 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
406
406
407 @scope = @event_types.select {|t| params["show_#{t}"]}
407 @scope = @event_types.select {|t| params["show_#{t}"]}
408 # default events if none is specified in parameters
408 # default events if none is specified in parameters
409 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
409 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
410
410
411 @events = []
411 @events = []
412
412
413 if @scope.include?('issues')
413 if @scope.include?('issues')
414 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
414 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
415 @events += @project.issues_status_changes(@date_from, @date_to)
415 @events += @project.issues_status_changes(@date_from, @date_to)
416 end
416 end
417
417
418 if @scope.include?('news')
418 if @scope.include?('news')
419 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
419 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
420 end
420 end
421
421
422 if @scope.include?('files')
422 if @scope.include?('files')
423 @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 )
423 @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 )
424 end
424 end
425
425
426 if @scope.include?('documents')
426 if @scope.include?('documents')
427 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
427 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
428 @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 )
428 @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 )
429 end
429 end
430
430
431 if @scope.include?('wiki_pages')
431 if @scope.include?('wiki_pages')
432 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
432 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
433 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
433 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
434 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
434 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
435 "#{WikiContent.versioned_table_name}.id"
435 "#{WikiContent.versioned_table_name}.id"
436 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
436 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
437 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
437 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
438 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
438 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
439 @project.id, @date_from, @date_to]
439 @project.id, @date_from, @date_to]
440
440
441 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
441 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
442 end
442 end
443
443
444 if @scope.include?('changesets')
444 if @scope.include?('changesets')
445 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
445 @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])
446 end
446 end
447
447
448 if @scope.include?('messages')
448 if @scope.include?('messages')
449 @events += Message.find(:all,
449 @events += Message.find(:all,
450 :include => [:board, :author],
450 :include => [:board, :author],
451 :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])
451 :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])
452 end
452 end
453
453
454 @events_by_day = @events.group_by(&:event_date)
454 @events_by_day = @events.group_by(&:event_date)
455
455
456 respond_to do |format|
456 respond_to do |format|
457 format.html { render :layout => false if request.xhr? }
457 format.html { render :layout => false if request.xhr? }
458 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
458 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
459 end
459 end
460 end
460 end
461
461
462 def calendar
462 def calendar
463 @trackers = Tracker.find(:all, :order => 'position')
463 @trackers = Tracker.find(:all, :order => 'position')
464 retrieve_selected_tracker_ids(@trackers)
464 retrieve_selected_tracker_ids(@trackers)
465
465
466 if params[:year] and params[:year].to_i > 1900
466 if params[:year] and params[:year].to_i > 1900
467 @year = params[:year].to_i
467 @year = params[:year].to_i
468 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
468 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
469 @month = params[:month].to_i
469 @month = params[:month].to_i
470 end
470 end
471 end
471 end
472 @year ||= Date.today.year
472 @year ||= Date.today.year
473 @month ||= Date.today.month
473 @month ||= Date.today.month
474 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
474 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
475
475
476 events = []
476 events = []
477 @project.issues_with_subprojects(params[:with_subprojects]) do
477 @project.issues_with_subprojects(params[:with_subprojects]) do
478 events += Issue.find(:all,
478 events += Issue.find(:all,
479 :include => [:tracker, :status, :assigned_to, :priority, :project],
479 :include => [:tracker, :status, :assigned_to, :priority, :project],
480 :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]
480 :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]
481 ) unless @selected_tracker_ids.empty?
481 ) unless @selected_tracker_ids.empty?
482 end
482 end
483 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
483 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
484 @calendar.events = events
484 @calendar.events = events
485
485
486 render :layout => false if request.xhr?
486 render :layout => false if request.xhr?
487 end
487 end
488
488
489 def gantt
489 def gantt
490 @trackers = Tracker.find(:all, :order => 'position')
490 @trackers = Tracker.find(:all, :order => 'position')
491 retrieve_selected_tracker_ids(@trackers)
491 retrieve_selected_tracker_ids(@trackers)
492
492
493 if params[:year] and params[:year].to_i >0
493 if params[:year] and params[:year].to_i >0
494 @year_from = params[:year].to_i
494 @year_from = params[:year].to_i
495 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
495 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
496 @month_from = params[:month].to_i
496 @month_from = params[:month].to_i
497 else
497 else
498 @month_from = 1
498 @month_from = 1
499 end
499 end
500 else
500 else
501 @month_from ||= Date.today.month
501 @month_from ||= Date.today.month
502 @year_from ||= Date.today.year
502 @year_from ||= Date.today.year
503 end
503 end
504
504
505 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
505 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
506 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
506 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
507 months = (params[:months] || User.current.pref[:gantt_months]).to_i
507 months = (params[:months] || User.current.pref[:gantt_months]).to_i
508 @months = (months > 0 && months < 25) ? months : 6
508 @months = (months > 0 && months < 25) ? months : 6
509
509
510 # Save gantt paramters as user preference (zoom and months count)
510 # Save gantt paramters as user preference (zoom and months count)
511 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
511 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
512 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
512 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
513 User.current.preference.save
513 User.current.preference.save
514 end
514 end
515
515
516 @date_from = Date.civil(@year_from, @month_from, 1)
516 @date_from = Date.civil(@year_from, @month_from, 1)
517 @date_to = (@date_from >> @months) - 1
517 @date_to = (@date_from >> @months) - 1
518
518
519 @events = []
519 @events = []
520 @project.issues_with_subprojects(params[:with_subprojects]) do
520 @project.issues_with_subprojects(params[:with_subprojects]) do
521 @events += Issue.find(:all,
521 @events += Issue.find(:all,
522 :order => "start_date, due_date",
522 :order => "start_date, due_date",
523 :include => [:tracker, :status, :assigned_to, :priority, :project],
523 :include => [:tracker, :status, :assigned_to, :priority, :project],
524 :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]
524 :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]
525 ) unless @selected_tracker_ids.empty?
525 ) unless @selected_tracker_ids.empty?
526 end
526 end
527 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
527 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
528 @events.sort! {|x,y| x.start_date <=> y.start_date }
528 @events.sort! {|x,y| x.start_date <=> y.start_date }
529
529
530 if params[:format]=='pdf'
530 if params[:format]=='pdf'
531 @options_for_rfpdf ||= {}
531 @options_for_rfpdf ||= {}
532 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
532 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
533 render :template => "projects/gantt.rfpdf", :layout => false
533 render :template => "projects/gantt.rfpdf", :layout => false
534 elsif params[:format]=='png' && respond_to?('gantt_image')
534 elsif params[:format]=='png' && respond_to?('gantt_image')
535 image = gantt_image(@events, @date_from, @months, @zoom)
535 image = gantt_image(@events, @date_from, @months, @zoom)
536 image.format = 'PNG'
536 image.format = 'PNG'
537 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
537 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
538 else
538 else
539 render :template => "projects/gantt.rhtml"
539 render :template => "projects/gantt.rhtml"
540 end
540 end
541 end
541 end
542
542
543 private
543 private
544 # Find project of id params[:id]
544 # Find project of id params[:id]
545 # if not found, redirect to project list
545 # if not found, redirect to project list
546 # Used as a before_filter
546 # Used as a before_filter
547 def find_project
547 def find_project
548 @project = Project.find(params[:id])
548 @project = Project.find(params[:id])
549 rescue ActiveRecord::RecordNotFound
549 rescue ActiveRecord::RecordNotFound
550 render_404
550 render_404
551 end
551 end
552
552
553 def retrieve_selected_tracker_ids(selectable_trackers)
553 def retrieve_selected_tracker_ids(selectable_trackers)
554 if ids = params[:tracker_ids]
554 if ids = params[:tracker_ids]
555 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
555 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
556 else
556 else
557 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
557 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
558 end
558 end
559 end
559 end
560 end
560 end
General Comments 0
You need to be logged in to leave comments. Login now