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