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