##// END OF EJS Templates
Added parent project name (if it exists) on project list and project overview....
Jean-Philippe Lang -
r401:6e1b9326e44b
parent child
Show More
@@ -1,677 +1,678
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, :authorize, :except => [ :index, :list, :add ]
22 before_filter :find_project, :authorize, :except => [ :index, :list, :add ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
23 before_filter :require_admin, :only => [ :add, :destroy ]
24
24
25 helper :sort
25 helper :sort
26 include SortHelper
26 include SortHelper
27 helper :custom_fields
27 helper :custom_fields
28 include CustomFieldsHelper
28 include CustomFieldsHelper
29 helper :ifpdf
29 helper :ifpdf
30 include IfpdfHelper
30 include IfpdfHelper
31 helper IssuesHelper
31 helper IssuesHelper
32 helper :queries
32 helper :queries
33 include QueriesHelper
33 include QueriesHelper
34
34
35 def index
35 def index
36 list
36 list
37 render :action => 'list' unless request.xhr?
37 render :action => 'list' unless request.xhr?
38 end
38 end
39
39
40 # Lists public projects
40 # Lists public projects
41 def list
41 def list
42 sort_init 'name', 'asc'
42 sort_init "#{Project.table_name}.name", "asc"
43 sort_update
43 sort_update
44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
44 @project_count = Project.count(:all, :conditions => ["is_public=?", true])
45 @project_pages = Paginator.new self, @project_count,
45 @project_pages = Paginator.new self, @project_count,
46 15,
46 15,
47 params['page']
47 params['page']
48 @projects = Project.find :all, :order => sort_clause,
48 @projects = Project.find :all, :order => sort_clause,
49 :conditions => ["is_public=?", true],
49 :conditions => ["#{Project.table_name}.is_public=?", true],
50 :include => :parent,
50 :limit => @project_pages.items_per_page,
51 :limit => @project_pages.items_per_page,
51 :offset => @project_pages.current.offset
52 :offset => @project_pages.current.offset
52
53
53 render :action => "list", :layout => false if request.xhr?
54 render :action => "list", :layout => false if request.xhr?
54 end
55 end
55
56
56 # Add a new project
57 # Add a new project
57 def add
58 def add
58 @custom_fields = IssueCustomField.find(:all)
59 @custom_fields = IssueCustomField.find(:all)
59 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 @root_projects = Project.find(:all, :conditions => "parent_id is null")
60 @project = Project.new(params[:project])
61 @project = Project.new(params[:project])
61 if request.get?
62 if request.get?
62 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
63 else
64 else
64 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
65 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
66 @project.custom_values = @custom_values
67 @project.custom_values = @custom_values
67 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 if params[:repository_enabled] && params[:repository_enabled] == "1"
68 @project.repository = Repository.new
69 @project.repository = Repository.new
69 @project.repository.attributes = params[:repository]
70 @project.repository.attributes = params[:repository]
70 end
71 end
71 if "1" == params[:wiki_enabled]
72 if "1" == params[:wiki_enabled]
72 @project.wiki = Wiki.new
73 @project.wiki = Wiki.new
73 @project.wiki.attributes = params[:wiki]
74 @project.wiki.attributes = params[:wiki]
74 end
75 end
75 if @project.save
76 if @project.save
76 flash[:notice] = l(:notice_successful_create)
77 flash[:notice] = l(:notice_successful_create)
77 redirect_to :controller => 'admin', :action => 'projects'
78 redirect_to :controller => 'admin', :action => 'projects'
78 end
79 end
79 end
80 end
80 end
81 end
81
82
82 # Show @project
83 # Show @project
83 def show
84 def show
84 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
85 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
85 @members = @project.members.find(:all, :include => [:user, :role], :order => 'position')
86 @members = @project.members.find(:all, :include => [:user, :role], :order => 'position')
86 @subprojects = @project.children if @project.children.size > 0
87 @subprojects = @project.children if @project.children.size > 0
87 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
88 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
88 @trackers = Tracker.find(:all, :order => 'position')
89 @trackers = Tracker.find(:all, :order => 'position')
89 @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])
90 @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])
90 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
91 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
91 end
92 end
92
93
93 def settings
94 def settings
94 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
95 @root_projects = Project::find(:all, :conditions => ["parent_id is null and id <> ?", @project.id])
95 @custom_fields = IssueCustomField.find(:all)
96 @custom_fields = IssueCustomField.find(:all)
96 @issue_category ||= IssueCategory.new
97 @issue_category ||= IssueCategory.new
97 @member ||= @project.members.new
98 @member ||= @project.members.new
98 @roles = Role.find(:all, :order => 'position')
99 @roles = Role.find(:all, :order => 'position')
99 @users = User.find_active(:all) - @project.users
100 @users = User.find_active(:all) - @project.users
100 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
101 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
101 end
102 end
102
103
103 # Edit @project
104 # Edit @project
104 def edit
105 def edit
105 if request.post?
106 if request.post?
106 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
107 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
107 if params[:custom_fields]
108 if params[:custom_fields]
108 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
109 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
109 @project.custom_values = @custom_values
110 @project.custom_values = @custom_values
110 end
111 end
111 if params[:repository_enabled]
112 if params[:repository_enabled]
112 case params[:repository_enabled]
113 case params[:repository_enabled]
113 when "0"
114 when "0"
114 @project.repository = nil
115 @project.repository = nil
115 when "1"
116 when "1"
116 @project.repository ||= Repository.new
117 @project.repository ||= Repository.new
117 @project.repository.update_attributes params[:repository]
118 @project.repository.update_attributes params[:repository]
118 end
119 end
119 end
120 end
120 if params[:wiki_enabled]
121 if params[:wiki_enabled]
121 case params[:wiki_enabled]
122 case params[:wiki_enabled]
122 when "0"
123 when "0"
123 @project.wiki.destroy if @project.wiki
124 @project.wiki.destroy if @project.wiki
124 when "1"
125 when "1"
125 @project.wiki ||= Wiki.new
126 @project.wiki ||= Wiki.new
126 @project.wiki.update_attributes params[:wiki]
127 @project.wiki.update_attributes params[:wiki]
127 end
128 end
128 end
129 end
129 @project.attributes = params[:project]
130 @project.attributes = params[:project]
130 if @project.save
131 if @project.save
131 flash[:notice] = l(:notice_successful_update)
132 flash[:notice] = l(:notice_successful_update)
132 redirect_to :action => 'settings', :id => @project
133 redirect_to :action => 'settings', :id => @project
133 else
134 else
134 settings
135 settings
135 render :action => 'settings'
136 render :action => 'settings'
136 end
137 end
137 end
138 end
138 end
139 end
139
140
140 # Delete @project
141 # Delete @project
141 def destroy
142 def destroy
142 if request.post? and params[:confirm]
143 if request.post? and params[:confirm]
143 @project.destroy
144 @project.destroy
144 redirect_to :controller => 'admin', :action => 'projects'
145 redirect_to :controller => 'admin', :action => 'projects'
145 end
146 end
146 end
147 end
147
148
148 # Add a new issue category to @project
149 # Add a new issue category to @project
149 def add_issue_category
150 def add_issue_category
150 if request.post?
151 if request.post?
151 @issue_category = @project.issue_categories.build(params[:issue_category])
152 @issue_category = @project.issue_categories.build(params[:issue_category])
152 if @issue_category.save
153 if @issue_category.save
153 flash[:notice] = l(:notice_successful_create)
154 flash[:notice] = l(:notice_successful_create)
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 else
156 else
156 settings
157 settings
157 render :action => 'settings'
158 render :action => 'settings'
158 end
159 end
159 end
160 end
160 end
161 end
161
162
162 # Add a new version to @project
163 # Add a new version to @project
163 def add_version
164 def add_version
164 @version = @project.versions.build(params[:version])
165 @version = @project.versions.build(params[:version])
165 if request.post? and @version.save
166 if request.post? and @version.save
166 flash[:notice] = l(:notice_successful_create)
167 flash[:notice] = l(:notice_successful_create)
167 redirect_to :action => 'settings', :tab => 'versions', :id => @project
168 redirect_to :action => 'settings', :tab => 'versions', :id => @project
168 end
169 end
169 end
170 end
170
171
171 # Add a new member to @project
172 # Add a new member to @project
172 def add_member
173 def add_member
173 @member = @project.members.build(params[:member])
174 @member = @project.members.build(params[:member])
174 if request.post?
175 if request.post?
175 if @member.save
176 if @member.save
176 flash[:notice] = l(:notice_successful_create)
177 flash[:notice] = l(:notice_successful_create)
177 redirect_to :action => 'settings', :tab => 'members', :id => @project
178 redirect_to :action => 'settings', :tab => 'members', :id => @project
178 else
179 else
179 settings
180 settings
180 render :action => 'settings'
181 render :action => 'settings'
181 end
182 end
182 end
183 end
183 end
184 end
184
185
185 # Show members list of @project
186 # Show members list of @project
186 def list_members
187 def list_members
187 @members = @project.members.find(:all)
188 @members = @project.members.find(:all)
188 end
189 end
189
190
190 # Add a new document to @project
191 # Add a new document to @project
191 def add_document
192 def add_document
192 @categories = Enumeration::get_values('DCAT')
193 @categories = Enumeration::get_values('DCAT')
193 @document = @project.documents.build(params[:document])
194 @document = @project.documents.build(params[:document])
194 if request.post? and @document.save
195 if request.post? and @document.save
195 # Save the attachments
196 # Save the attachments
196 params[:attachments].each { |a|
197 params[:attachments].each { |a|
197 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
198 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
198 } if params[:attachments] and params[:attachments].is_a? Array
199 } if params[:attachments] and params[:attachments].is_a? Array
199 flash[:notice] = l(:notice_successful_create)
200 flash[:notice] = l(:notice_successful_create)
200 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
201 Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
201 redirect_to :action => 'list_documents', :id => @project
202 redirect_to :action => 'list_documents', :id => @project
202 end
203 end
203 end
204 end
204
205
205 # Show documents list of @project
206 # Show documents list of @project
206 def list_documents
207 def list_documents
207 @documents = @project.documents.find :all, :include => :category
208 @documents = @project.documents.find :all, :include => :category
208 end
209 end
209
210
210 # Add a new issue to @project
211 # Add a new issue to @project
211 def add_issue
212 def add_issue
212 @tracker = Tracker.find(params[:tracker_id])
213 @tracker = Tracker.find(params[:tracker_id])
213 @priorities = Enumeration::get_values('IPRI')
214 @priorities = Enumeration::get_values('IPRI')
214 @issue = Issue.new(:project => @project, :tracker => @tracker)
215 @issue = Issue.new(:project => @project, :tracker => @tracker)
215 if request.get?
216 if request.get?
216 @issue.start_date = Date.today
217 @issue.start_date = Date.today
217 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
218 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
218 else
219 else
219 @issue.attributes = params[:issue]
220 @issue.attributes = params[:issue]
220 @issue.author_id = self.logged_in_user.id if self.logged_in_user
221 @issue.author_id = self.logged_in_user.id if self.logged_in_user
221 # Multiple file upload
222 # Multiple file upload
222 @attachments = []
223 @attachments = []
223 params[:attachments].each { |a|
224 params[:attachments].each { |a|
224 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
225 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
225 } if params[:attachments] and params[:attachments].is_a? Array
226 } if params[:attachments] and params[:attachments].is_a? Array
226 @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]) }
227 @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]) }
227 @issue.custom_values = @custom_values
228 @issue.custom_values = @custom_values
228 if @issue.save
229 if @issue.save
229 @attachments.each(&:save)
230 @attachments.each(&:save)
230 flash[:notice] = l(:notice_successful_create)
231 flash[:notice] = l(:notice_successful_create)
231 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
232 Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
232 redirect_to :action => 'list_issues', :id => @project
233 redirect_to :action => 'list_issues', :id => @project
233 end
234 end
234 end
235 end
235 end
236 end
236
237
237 # Show filtered/sorted issues list of @project
238 # Show filtered/sorted issues list of @project
238 def list_issues
239 def list_issues
239 sort_init "#{Issue.table_name}.id", "desc"
240 sort_init "#{Issue.table_name}.id", "desc"
240 sort_update
241 sort_update
241
242
242 retrieve_query
243 retrieve_query
243
244
244 @results_per_page_options = [ 15, 25, 50, 100 ]
245 @results_per_page_options = [ 15, 25, 50, 100 ]
245 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
246 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
246 @results_per_page = params[:per_page].to_i
247 @results_per_page = params[:per_page].to_i
247 session[:results_per_page] = @results_per_page
248 session[:results_per_page] = @results_per_page
248 else
249 else
249 @results_per_page = session[:results_per_page] || 25
250 @results_per_page = session[:results_per_page] || 25
250 end
251 end
251
252
252 if @query.valid?
253 if @query.valid?
253 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
254 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
254 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
255 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
255 @issues = Issue.find :all, :order => sort_clause,
256 @issues = Issue.find :all, :order => sort_clause,
256 :include => [ :author, :status, :tracker, :project, :priority ],
257 :include => [ :author, :status, :tracker, :project, :priority ],
257 :conditions => @query.statement,
258 :conditions => @query.statement,
258 :limit => @issue_pages.items_per_page,
259 :limit => @issue_pages.items_per_page,
259 :offset => @issue_pages.current.offset
260 :offset => @issue_pages.current.offset
260 end
261 end
261 @trackers = Tracker.find :all, :order => 'position'
262 @trackers = Tracker.find :all, :order => 'position'
262 render :layout => false if request.xhr?
263 render :layout => false if request.xhr?
263 end
264 end
264
265
265 # Export filtered/sorted issues list to CSV
266 # Export filtered/sorted issues list to CSV
266 def export_issues_csv
267 def export_issues_csv
267 sort_init "#{Issue.table_name}.id", "desc"
268 sort_init "#{Issue.table_name}.id", "desc"
268 sort_update
269 sort_update
269
270
270 retrieve_query
271 retrieve_query
271 render :action => 'list_issues' and return unless @query.valid?
272 render :action => 'list_issues' and return unless @query.valid?
272
273
273 @issues = Issue.find :all, :order => sort_clause,
274 @issues = Issue.find :all, :order => sort_clause,
274 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
275 :include => [ :author, :status, :tracker, :priority, {:custom_values => :custom_field} ],
275 :conditions => @query.statement,
276 :conditions => @query.statement,
276 :limit => Setting.issues_export_limit
277 :limit => Setting.issues_export_limit
277
278
278 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
279 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
279 export = StringIO.new
280 export = StringIO.new
280 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
281 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
281 # csv header fields
282 # csv header fields
282 headers = [ "#", l(:field_status),
283 headers = [ "#", l(:field_status),
283 l(:field_tracker),
284 l(:field_tracker),
284 l(:field_priority),
285 l(:field_priority),
285 l(:field_subject),
286 l(:field_subject),
286 l(:field_author),
287 l(:field_author),
287 l(:field_start_date),
288 l(:field_start_date),
288 l(:field_due_date),
289 l(:field_due_date),
289 l(:field_done_ratio),
290 l(:field_done_ratio),
290 l(:field_created_on),
291 l(:field_created_on),
291 l(:field_updated_on)
292 l(:field_updated_on)
292 ]
293 ]
293 for custom_field in @project.all_custom_fields
294 for custom_field in @project.all_custom_fields
294 headers << custom_field.name
295 headers << custom_field.name
295 end
296 end
296 csv << headers.collect {|c| ic.iconv(c) }
297 csv << headers.collect {|c| ic.iconv(c) }
297 # csv lines
298 # csv lines
298 @issues.each do |issue|
299 @issues.each do |issue|
299 fields = [issue.id, issue.status.name,
300 fields = [issue.id, issue.status.name,
300 issue.tracker.name,
301 issue.tracker.name,
301 issue.priority.name,
302 issue.priority.name,
302 issue.subject,
303 issue.subject,
303 issue.author.display_name,
304 issue.author.display_name,
304 issue.start_date ? l_date(issue.start_date) : nil,
305 issue.start_date ? l_date(issue.start_date) : nil,
305 issue.due_date ? l_date(issue.due_date) : nil,
306 issue.due_date ? l_date(issue.due_date) : nil,
306 issue.done_ratio,
307 issue.done_ratio,
307 l_datetime(issue.created_on),
308 l_datetime(issue.created_on),
308 l_datetime(issue.updated_on)
309 l_datetime(issue.updated_on)
309 ]
310 ]
310 for custom_field in @project.all_custom_fields
311 for custom_field in @project.all_custom_fields
311 fields << (show_value issue.custom_value_for(custom_field))
312 fields << (show_value issue.custom_value_for(custom_field))
312 end
313 end
313 csv << fields.collect {|c| ic.iconv(c.to_s) }
314 csv << fields.collect {|c| ic.iconv(c.to_s) }
314 end
315 end
315 end
316 end
316 export.rewind
317 export.rewind
317 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
318 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
318 end
319 end
319
320
320 # Export filtered/sorted issues to PDF
321 # Export filtered/sorted issues to PDF
321 def export_issues_pdf
322 def export_issues_pdf
322 sort_init "#{Issue.table_name}.id", "desc"
323 sort_init "#{Issue.table_name}.id", "desc"
323 sort_update
324 sort_update
324
325
325 retrieve_query
326 retrieve_query
326 render :action => 'list_issues' and return unless @query.valid?
327 render :action => 'list_issues' and return unless @query.valid?
327
328
328 @issues = Issue.find :all, :order => sort_clause,
329 @issues = Issue.find :all, :order => sort_clause,
329 :include => [ :author, :status, :tracker, :priority ],
330 :include => [ :author, :status, :tracker, :priority ],
330 :conditions => @query.statement,
331 :conditions => @query.statement,
331 :limit => Setting.issues_export_limit
332 :limit => Setting.issues_export_limit
332
333
333 @options_for_rfpdf ||= {}
334 @options_for_rfpdf ||= {}
334 @options_for_rfpdf[:file_name] = "export.pdf"
335 @options_for_rfpdf[:file_name] = "export.pdf"
335 render :layout => false
336 render :layout => false
336 end
337 end
337
338
338 def move_issues
339 def move_issues
339 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
340 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
340 redirect_to :action => 'list_issues', :id => @project and return unless @issues
341 redirect_to :action => 'list_issues', :id => @project and return unless @issues
341 @projects = []
342 @projects = []
342 # find projects to which the user is allowed to move the issue
343 # find projects to which the user is allowed to move the issue
343 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
344 @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role_id)}
344 # issue can be moved to any tracker
345 # issue can be moved to any tracker
345 @trackers = Tracker.find(:all)
346 @trackers = Tracker.find(:all)
346 if request.post? and params[:new_project_id] and params[:new_tracker_id]
347 if request.post? and params[:new_project_id] and params[:new_tracker_id]
347 new_project = Project.find(params[:new_project_id])
348 new_project = Project.find(params[:new_project_id])
348 new_tracker = Tracker.find(params[:new_tracker_id])
349 new_tracker = Tracker.find(params[:new_tracker_id])
349 @issues.each { |i|
350 @issues.each { |i|
350 # project dependent properties
351 # project dependent properties
351 unless i.project_id == new_project.id
352 unless i.project_id == new_project.id
352 i.category = nil
353 i.category = nil
353 i.fixed_version = nil
354 i.fixed_version = nil
354 end
355 end
355 # move the issue
356 # move the issue
356 i.project = new_project
357 i.project = new_project
357 i.tracker = new_tracker
358 i.tracker = new_tracker
358 i.save
359 i.save
359 }
360 }
360 flash[:notice] = l(:notice_successful_update)
361 flash[:notice] = l(:notice_successful_update)
361 redirect_to :action => 'list_issues', :id => @project
362 redirect_to :action => 'list_issues', :id => @project
362 end
363 end
363 end
364 end
364
365
365 def add_query
366 def add_query
366 @query = Query.new(params[:query])
367 @query = Query.new(params[:query])
367 @query.project = @project
368 @query.project = @project
368 @query.user = logged_in_user
369 @query.user = logged_in_user
369
370
370 params[:fields].each do |field|
371 params[:fields].each do |field|
371 @query.add_filter(field, params[:operators][field], params[:values][field])
372 @query.add_filter(field, params[:operators][field], params[:values][field])
372 end if params[:fields]
373 end if params[:fields]
373
374
374 if request.post? and @query.save
375 if request.post? and @query.save
375 flash[:notice] = l(:notice_successful_create)
376 flash[:notice] = l(:notice_successful_create)
376 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
377 redirect_to :controller => 'reports', :action => 'issue_report', :id => @project
377 end
378 end
378 render :layout => false if request.xhr?
379 render :layout => false if request.xhr?
379 end
380 end
380
381
381 # Add a news to @project
382 # Add a news to @project
382 def add_news
383 def add_news
383 @news = News.new(:project => @project)
384 @news = News.new(:project => @project)
384 if request.post?
385 if request.post?
385 @news.attributes = params[:news]
386 @news.attributes = params[:news]
386 @news.author_id = self.logged_in_user.id if self.logged_in_user
387 @news.author_id = self.logged_in_user.id if self.logged_in_user
387 if @news.save
388 if @news.save
388 flash[:notice] = l(:notice_successful_create)
389 flash[:notice] = l(:notice_successful_create)
389 redirect_to :action => 'list_news', :id => @project
390 redirect_to :action => 'list_news', :id => @project
390 end
391 end
391 end
392 end
392 end
393 end
393
394
394 # Show news list of @project
395 # Show news list of @project
395 def list_news
396 def list_news
396 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
397 @news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
397 render :action => "list_news", :layout => false if request.xhr?
398 render :action => "list_news", :layout => false if request.xhr?
398 end
399 end
399
400
400 def add_file
401 def add_file
401 if request.post?
402 if request.post?
402 @version = @project.versions.find_by_id(params[:version_id])
403 @version = @project.versions.find_by_id(params[:version_id])
403 # Save the attachments
404 # Save the attachments
404 @attachments = []
405 @attachments = []
405 params[:attachments].each { |file|
406 params[:attachments].each { |file|
406 next unless file.size > 0
407 next unless file.size > 0
407 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
408 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
408 @attachments << a unless a.new_record?
409 @attachments << a unless a.new_record?
409 } if params[:attachments] and params[:attachments].is_a? Array
410 } if params[:attachments] and params[:attachments].is_a? Array
410 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
411 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
411 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
412 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
412 end
413 end
413 @versions = @project.versions
414 @versions = @project.versions
414 end
415 end
415
416
416 def list_files
417 def list_files
417 @versions = @project.versions
418 @versions = @project.versions
418 end
419 end
419
420
420 # Show changelog for @project
421 # Show changelog for @project
421 def changelog
422 def changelog
422 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
423 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
423 retrieve_selected_tracker_ids(@trackers)
424 retrieve_selected_tracker_ids(@trackers)
424
425
425 @fixed_issues = @project.issues.find(:all,
426 @fixed_issues = @project.issues.find(:all,
426 :include => [ :fixed_version, :status, :tracker ],
427 :include => [ :fixed_version, :status, :tracker ],
427 :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true],
428 :conditions => [ "#{IssueStatus.table_name}.is_closed=? and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}) and #{Issue.table_name}.fixed_version_id is not null", true],
428 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
429 :order => "#{Version.table_name}.effective_date DESC, #{Issue.table_name}.id DESC"
429 ) unless @selected_tracker_ids.empty?
430 ) unless @selected_tracker_ids.empty?
430 @fixed_issues ||= []
431 @fixed_issues ||= []
431 end
432 end
432
433
433 def roadmap
434 def roadmap
434 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
435 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
435 retrieve_selected_tracker_ids(@trackers)
436 retrieve_selected_tracker_ids(@trackers)
436
437
437 @versions = @project.versions.find(:all,
438 @versions = @project.versions.find(:all,
438 :conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
439 :conditions => [ "#{Version.table_name}.effective_date>?", Date.today],
439 :order => "#{Version.table_name}.effective_date ASC"
440 :order => "#{Version.table_name}.effective_date ASC"
440 )
441 )
441 end
442 end
442
443
443 def activity
444 def activity
444 if params[:year] and params[:year].to_i > 1900
445 if params[:year] and params[:year].to_i > 1900
445 @year = params[:year].to_i
446 @year = params[:year].to_i
446 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
447 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
447 @month = params[:month].to_i
448 @month = params[:month].to_i
448 end
449 end
449 end
450 end
450 @year ||= Date.today.year
451 @year ||= Date.today.year
451 @month ||= Date.today.month
452 @month ||= Date.today.month
452
453
453 @date_from = Date.civil(@year, @month, 1)
454 @date_from = Date.civil(@year, @month, 1)
454 @date_to = (@date_from >> 1)-1
455 @date_to = (@date_from >> 1)-1
455
456
456 @events_by_day = {}
457 @events_by_day = {}
457
458
458 unless params[:show_issues] == "0"
459 unless params[:show_issues] == "0"
459 @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
460 @project.issues.find(:all, :include => [:author, :status], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
460 @events_by_day[i.created_on.to_date] ||= []
461 @events_by_day[i.created_on.to_date] ||= []
461 @events_by_day[i.created_on.to_date] << i
462 @events_by_day[i.created_on.to_date] << i
462 }
463 }
463 @show_issues = 1
464 @show_issues = 1
464 end
465 end
465
466
466 unless params[:show_news] == "0"
467 unless params[:show_news] == "0"
467 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
468 @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ).each { |i|
468 @events_by_day[i.created_on.to_date] ||= []
469 @events_by_day[i.created_on.to_date] ||= []
469 @events_by_day[i.created_on.to_date] << i
470 @events_by_day[i.created_on.to_date] << i
470 }
471 }
471 @show_news = 1
472 @show_news = 1
472 end
473 end
473
474
474 unless params[:show_files] == "0"
475 unless params[:show_files] == "0"
475 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 ).each { |i|
476 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 ).each { |i|
476 @events_by_day[i.created_on.to_date] ||= []
477 @events_by_day[i.created_on.to_date] ||= []
477 @events_by_day[i.created_on.to_date] << i
478 @events_by_day[i.created_on.to_date] << i
478 }
479 }
479 @show_files = 1
480 @show_files = 1
480 end
481 end
481
482
482 unless params[:show_documents] == "0"
483 unless params[:show_documents] == "0"
483 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
484 @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ).each { |i|
484 @events_by_day[i.created_on.to_date] ||= []
485 @events_by_day[i.created_on.to_date] ||= []
485 @events_by_day[i.created_on.to_date] << i
486 @events_by_day[i.created_on.to_date] << i
486 }
487 }
487 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 ).each { |i|
488 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 ).each { |i|
488 @events_by_day[i.created_on.to_date] ||= []
489 @events_by_day[i.created_on.to_date] ||= []
489 @events_by_day[i.created_on.to_date] << i
490 @events_by_day[i.created_on.to_date] << i
490 }
491 }
491 @show_documents = 1
492 @show_documents = 1
492 end
493 end
493
494
494 unless params[:show_wiki_edits] == "0"
495 unless params[:show_wiki_edits] == "0"
495 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " +
496 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comment, " +
496 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
497 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title"
497 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
498 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
498 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
499 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
499 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
500 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
500 @project.id, @date_from, @date_to]
501 @project.id, @date_from, @date_to]
501
502
502 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
503 WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
503 # We provide this alias so all events can be treated in the same manner
504 # We provide this alias so all events can be treated in the same manner
504 def i.created_on
505 def i.created_on
505 self.updated_on
506 self.updated_on
506 end
507 end
507
508
508 @events_by_day[i.created_on.to_date] ||= []
509 @events_by_day[i.created_on.to_date] ||= []
509 @events_by_day[i.created_on.to_date] << i
510 @events_by_day[i.created_on.to_date] << i
510 }
511 }
511 @show_wiki_edits = 1
512 @show_wiki_edits = 1
512 end
513 end
513
514
514 unless @project.repository.nil? || params[:show_changesets] == "0"
515 unless @project.repository.nil? || params[:show_changesets] == "0"
515 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
516 @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
516 def i.created_on
517 def i.created_on
517 self.committed_on
518 self.committed_on
518 end
519 end
519 @events_by_day[i.created_on.to_date] ||= []
520 @events_by_day[i.created_on.to_date] ||= []
520 @events_by_day[i.created_on.to_date] << i
521 @events_by_day[i.created_on.to_date] << i
521 }
522 }
522 @show_changesets = 1
523 @show_changesets = 1
523 end
524 end
524
525
525 render :layout => false if request.xhr?
526 render :layout => false if request.xhr?
526 end
527 end
527
528
528 def calendar
529 def calendar
529 @trackers = Tracker.find(:all, :order => 'position')
530 @trackers = Tracker.find(:all, :order => 'position')
530 retrieve_selected_tracker_ids(@trackers)
531 retrieve_selected_tracker_ids(@trackers)
531
532
532 if params[:year] and params[:year].to_i > 1900
533 if params[:year] and params[:year].to_i > 1900
533 @year = params[:year].to_i
534 @year = params[:year].to_i
534 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
535 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
535 @month = params[:month].to_i
536 @month = params[:month].to_i
536 end
537 end
537 end
538 end
538 @year ||= Date.today.year
539 @year ||= Date.today.year
539 @month ||= Date.today.month
540 @month ||= Date.today.month
540
541
541 @date_from = Date.civil(@year, @month, 1)
542 @date_from = Date.civil(@year, @month, 1)
542 @date_to = (@date_from >> 1)-1
543 @date_to = (@date_from >> 1)-1
543 # start on monday
544 # start on monday
544 @date_from = @date_from - (@date_from.cwday-1)
545 @date_from = @date_from - (@date_from.cwday-1)
545 # finish on sunday
546 # finish on sunday
546 @date_to = @date_to + (7-@date_to.cwday)
547 @date_to = @date_to + (7-@date_to.cwday)
547
548
548 @project.issues_with_subprojects(params[:with_subprojects]) do
549 @project.issues_with_subprojects(params[:with_subprojects]) do
549 @issues = Issue.find(:all,
550 @issues = Issue.find(:all,
550 :include => [:tracker, :status, :assigned_to, :priority],
551 :include => [:tracker, :status, :assigned_to, :priority],
551 :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]
552 :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]
552 ) unless @selected_tracker_ids.empty?
553 ) unless @selected_tracker_ids.empty?
553 end
554 end
554 @issues ||=[]
555 @issues ||=[]
555
556
556 @ending_issues_by_days = @issues.group_by {|issue| issue.due_date}
557 @ending_issues_by_days = @issues.group_by {|issue| issue.due_date}
557 @starting_issues_by_days = @issues.group_by {|issue| issue.start_date}
558 @starting_issues_by_days = @issues.group_by {|issue| issue.start_date}
558
559
559 render :layout => false if request.xhr?
560 render :layout => false if request.xhr?
560 end
561 end
561
562
562 def gantt
563 def gantt
563 @trackers = Tracker.find(:all, :order => 'position')
564 @trackers = Tracker.find(:all, :order => 'position')
564 retrieve_selected_tracker_ids(@trackers)
565 retrieve_selected_tracker_ids(@trackers)
565
566
566 if params[:year] and params[:year].to_i >0
567 if params[:year] and params[:year].to_i >0
567 @year_from = params[:year].to_i
568 @year_from = params[:year].to_i
568 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
569 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
569 @month_from = params[:month].to_i
570 @month_from = params[:month].to_i
570 else
571 else
571 @month_from = 1
572 @month_from = 1
572 end
573 end
573 else
574 else
574 @month_from ||= (Date.today << 1).month
575 @month_from ||= (Date.today << 1).month
575 @year_from ||= (Date.today << 1).year
576 @year_from ||= (Date.today << 1).year
576 end
577 end
577
578
578 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
579 @zoom = (params[:zoom].to_i > 0 and params[:zoom].to_i < 5) ? params[:zoom].to_i : 2
579 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
580 @months = (params[:months].to_i > 0 and params[:months].to_i < 25) ? params[:months].to_i : 6
580
581
581 @date_from = Date.civil(@year_from, @month_from, 1)
582 @date_from = Date.civil(@year_from, @month_from, 1)
582 @date_to = (@date_from >> @months) - 1
583 @date_to = (@date_from >> @months) - 1
583
584
584 @project.issues_with_subprojects(params[:with_subprojects]) do
585 @project.issues_with_subprojects(params[:with_subprojects]) do
585 @issues = Issue.find(:all,
586 @issues = Issue.find(:all,
586 :order => "start_date, due_date",
587 :order => "start_date, due_date",
587 :include => [:tracker, :status, :assigned_to, :priority],
588 :include => [:tracker, :status, :assigned_to, :priority],
588 :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]
589 :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]
589 ) unless @selected_tracker_ids.empty?
590 ) unless @selected_tracker_ids.empty?
590 end
591 end
591 @issues ||=[]
592 @issues ||=[]
592
593
593 if params[:output]=='pdf'
594 if params[:output]=='pdf'
594 @options_for_rfpdf ||= {}
595 @options_for_rfpdf ||= {}
595 @options_for_rfpdf[:file_name] = "gantt.pdf"
596 @options_for_rfpdf[:file_name] = "gantt.pdf"
596 render :template => "projects/gantt.rfpdf", :layout => false
597 render :template => "projects/gantt.rfpdf", :layout => false
597 else
598 else
598 render :template => "projects/gantt.rhtml"
599 render :template => "projects/gantt.rhtml"
599 end
600 end
600 end
601 end
601
602
602 def search
603 def search
603 @question = params[:q] || ""
604 @question = params[:q] || ""
604 @question.strip!
605 @question.strip!
605 @all_words = params[:all_words] || (params[:submit] ? false : true)
606 @all_words = params[:all_words] || (params[:submit] ? false : true)
606 @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) )
607 @scope = params[:scope] || (params[:submit] ? [] : %w(issues changesets news documents wiki) )
607 # tokens must be at least 3 character long
608 # tokens must be at least 3 character long
608 @tokens = @question.split.uniq.select {|w| w.length > 2 }
609 @tokens = @question.split.uniq.select {|w| w.length > 2 }
609 if !@tokens.empty?
610 if !@tokens.empty?
610 # no more than 5 tokens to search for
611 # no more than 5 tokens to search for
611 @tokens.slice! 5..-1 if @tokens.size > 5
612 @tokens.slice! 5..-1 if @tokens.size > 5
612 # strings used in sql like statement
613 # strings used in sql like statement
613 like_tokens = @tokens.collect {|w| "%#{w}%"}
614 like_tokens = @tokens.collect {|w| "%#{w}%"}
614 operator = @all_words ? " AND " : " OR "
615 operator = @all_words ? " AND " : " OR "
615 limit = 10
616 limit = 10
616 @results = []
617 @results = []
617 @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues'
618 @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues'
618 @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news'
619 @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news'
619 @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents'
620 @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents'
620 @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki')
621 @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki')
621 @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets')
622 @results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comment) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets')
622 @question = @tokens.join(" ")
623 @question = @tokens.join(" ")
623 else
624 else
624 @question = ""
625 @question = ""
625 end
626 end
626 end
627 end
627
628
628 def feeds
629 def feeds
629 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
630 @queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
630 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
631 @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
631 end
632 end
632
633
633 private
634 private
634 # Find project of id params[:id]
635 # Find project of id params[:id]
635 # if not found, redirect to project list
636 # if not found, redirect to project list
636 # Used as a before_filter
637 # Used as a before_filter
637 def find_project
638 def find_project
638 @project = Project.find(params[:id])
639 @project = Project.find(params[:id])
639 @html_title = @project.name
640 @html_title = @project.name
640 rescue ActiveRecord::RecordNotFound
641 rescue ActiveRecord::RecordNotFound
641 render_404
642 render_404
642 end
643 end
643
644
644 def retrieve_selected_tracker_ids(selectable_trackers)
645 def retrieve_selected_tracker_ids(selectable_trackers)
645 if ids = params[:tracker_ids]
646 if ids = params[:tracker_ids]
646 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
647 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
647 else
648 else
648 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
649 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
649 end
650 end
650 end
651 end
651
652
652 # Retrieve query from session or build a new query
653 # Retrieve query from session or build a new query
653 def retrieve_query
654 def retrieve_query
654 if params[:query_id]
655 if params[:query_id]
655 @query = @project.queries.find(params[:query_id])
656 @query = @project.queries.find(params[:query_id])
656 session[:query] = @query
657 session[:query] = @query
657 else
658 else
658 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
659 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
659 # Give it a name, required to be valid
660 # Give it a name, required to be valid
660 @query = Query.new(:name => "_")
661 @query = Query.new(:name => "_")
661 @query.project = @project
662 @query.project = @project
662 if params[:fields] and params[:fields].is_a? Array
663 if params[:fields] and params[:fields].is_a? Array
663 params[:fields].each do |field|
664 params[:fields].each do |field|
664 @query.add_filter(field, params[:operators][field], params[:values][field])
665 @query.add_filter(field, params[:operators][field], params[:values][field])
665 end
666 end
666 else
667 else
667 @query.available_filters.keys.each do |field|
668 @query.available_filters.keys.each do |field|
668 @query.add_short_filter(field, params[field]) if params[field]
669 @query.add_short_filter(field, params[field]) if params[field]
669 end
670 end
670 end
671 end
671 session[:query] = @query
672 session[:query] = @query
672 else
673 else
673 @query = session[:query]
674 @query = session[:query]
674 end
675 end
675 end
676 end
676 end
677 end
677 end
678 end
@@ -1,21 +1,23
1 <h2><%=l(:label_public_projects)%></h2>
1 <h2><%=l(:label_public_projects)%></h2>
2
2
3 <table class="list">
3 <table class="list">
4 <thead><tr>
4 <thead><tr>
5 <%= sort_header_tag('name', :caption => l(:label_project)) %>
5 <%= sort_header_tag("#{Project.table_name}.name", :caption => l(:label_project)) %>
6 <th><%=l(:field_description)%></th>
6 <th><%=l(:field_description)%></th>
7 <%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
7 <th><%=l(:field_parent)%></th>
8 <%= sort_header_tag("#{Project.table_name}.created_on", :caption => l(:field_created_on)) %>
8 </tr></thead>
9 </tr></thead>
9 <tbody>
10 <tbody>
10 <% for project in @projects %>
11 <% for project in @projects %>
11 <tr class="<%= cycle("odd", "even") %>">
12 <tr class="<%= cycle("odd", "even") %>">
12 <td><%= link_to project.name, :action => 'show', :id => project %></td>
13 <td><%= link_to project.name, :action => 'show', :id => project %></td>
13 <td><%=h project.description %></td>
14 <td><%=h project.description %></td>
15 <td><%= link_to(project.parent.name, :action => 'show', :id => project.parent) unless project.parent.nil? %></td>
14 <td align="center"><%= format_date(project.created_on) %></td>
16 <td align="center"><%= format_date(project.created_on) %></td>
15 </tr>
17 </tr>
16 <% end %>
18 <% end %>
17 </tbody>
19 </tbody>
18 </table>
20 </table>
19
21
20 <%= pagination_links_full @project_pages %>
22 <%= pagination_links_full @project_pages %>
21 [ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ] No newline at end of file
23 [ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ]
@@ -1,59 +1,62
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to l(:label_feed_plural), {:action => 'feeds', :id => @project}, :class => 'icon icon-feed' %>
2 <%= link_to l(:label_feed_plural), {:action => 'feeds', :id => @project}, :class => 'icon icon-feed' %>
3 </div>
3 </div>
4
4
5 <h2><%=l(:label_overview)%></h2>
5 <h2><%=l(:label_overview)%></h2>
6
6
7 <div class="splitcontentleft">
7 <div class="splitcontentleft">
8 <%= simple_format(auto_link(h(@project.description))) %>
8 <%= simple_format(auto_link(h(@project.description))) %>
9 <ul>
9 <ul>
10 <% unless @project.homepage.empty? %><li><%=l(:field_homepage)%>: <%= auto_link @project.homepage %></li><% end %>
10 <% unless @project.homepage.empty? %><li><%=l(:field_homepage)%>: <%= auto_link @project.homepage %></li><% end %>
11 <li><%=l(:field_created_on)%>: <%= format_date(@project.created_on) %></li>
11 <li><%=l(:field_created_on)%>: <%= format_date(@project.created_on) %></li>
12 <% unless @project.parent.nil? %>
13 <li><%=l(:field_parent)%>: <%= link_to @project.parent.name, :controller => 'projects', :action => 'show', :id => @project.parent %></li>
14 <% end %>
12 <% for custom_value in @custom_values %>
15 <% for custom_value in @custom_values %>
13 <% if !custom_value.value.empty? %>
16 <% if !custom_value.value.empty? %>
14 <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
17 <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
15 <% end %>
18 <% end %>
16 <% end %>
19 <% end %>
17 </ul>
20 </ul>
18
21
19 <div class="box">
22 <div class="box">
20 <div class="contextual">
23 <div class="contextual">
21 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
24 <%= render :partial => 'issues/add_shortcut', :locals => {:trackers => @trackers } %>
22 </div>
25 </div>
23 <h3 class="icon22 icon22-tracker"><%=l(:label_issue_tracking)%></h3>
26 <h3 class="icon22 icon22-tracker"><%=l(:label_issue_tracking)%></h3>
24 <ul>
27 <ul>
25 <% for tracker in @trackers %>
28 <% for tracker in @trackers %>
26 <li><%= link_to tracker.name, :controller => 'projects', :action => 'list_issues', :id => @project,
29 <li><%= link_to tracker.name, :controller => 'projects', :action => 'list_issues', :id => @project,
27 :set_filter => 1,
30 :set_filter => 1,
28 "tracker_id" => tracker.id %>:
31 "tracker_id" => tracker.id %>:
29 <%= @open_issues_by_tracker[tracker] || 0 %> <%= lwr(:label_open_issues, @open_issues_by_tracker[tracker] || 0) %>
32 <%= @open_issues_by_tracker[tracker] || 0 %> <%= lwr(:label_open_issues, @open_issues_by_tracker[tracker] || 0) %>
30 <%= l(:label_on) %> <%= @total_issues_by_tracker[tracker] || 0 %></li>
33 <%= l(:label_on) %> <%= @total_issues_by_tracker[tracker] || 0 %></li>
31 <% end %>
34 <% end %>
32 </ul>
35 </ul>
33 <p class="textcenter"><small><%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %></small></p>
36 <p class="textcenter"><small><%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %></small></p>
34 </div>
37 </div>
35 </div>
38 </div>
36
39
37 <div class="splitcontentright">
40 <div class="splitcontentright">
38 <div class="box">
41 <div class="box">
39 <h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>
42 <h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>
40 <% for member in @members %>
43 <% for member in @members %>
41 <%= link_to_user member.user %> (<%= member.role.name %>)<br />
44 <%= link_to_user member.user %> (<%= member.role.name %>)<br />
42 <% end %>
45 <% end %>
43 </div>
46 </div>
44
47
45 <% if @subprojects %>
48 <% if @subprojects %>
46 <div class="box">
49 <div class="box">
47 <h3 class="icon22 icon22-projects"><%=l(:label_subproject_plural)%></h3>
50 <h3 class="icon22 icon22-projects"><%=l(:label_subproject_plural)%></h3>
48 <% for subproject in @subprojects %>
51 <% for subproject in @subprojects %>
49 <%= link_to subproject.name, :action => 'show', :id => subproject %><br />
52 <%= link_to subproject.name, :action => 'show', :id => subproject %><br />
50 <% end %>
53 <% end %>
51 </div>
54 </div>
52 <% end %>
55 <% end %>
53
56
54 <div class="box">
57 <div class="box">
55 <h3><%=l(:label_news_latest)%></h3>
58 <h3><%=l(:label_news_latest)%></h3>
56 <%= render :partial => 'news/news', :collection => @news %>
59 <%= render :partial => 'news/news', :collection => @news %>
57 <p class="textcenter"><small><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></small></p>
60 <p class="textcenter"><small><%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %></small></p>
58 </div>
61 </div>
59 </div> No newline at end of file
62 </div>
General Comments 0
You need to be logged in to leave comments. Login now