##// END OF EJS Templates
Better naming of activity feed if only one kind of event is displayed (#1323)....
Jean-Philippe Lang -
r1628:bfba84d526f8
parent child
Show More
@@ -1,434 +1,437
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class ProjectsController < ApplicationController
19 19 layout 'base'
20 20 menu_item :overview
21 21 menu_item :activity, :only => :activity
22 22 menu_item :roadmap, :only => :roadmap
23 23 menu_item :files, :only => [:list_files, :add_file]
24 24 menu_item :settings, :only => :settings
25 25 menu_item :issues, :only => [:changelog]
26 26
27 27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 28 before_filter :find_optional_project, :only => :activity
29 29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 31 accept_key_auth :activity, :calendar
32 32
33 33 helper :sort
34 34 include SortHelper
35 35 helper :custom_fields
36 36 include CustomFieldsHelper
37 37 helper :ifpdf
38 38 include IfpdfHelper
39 39 helper :issues
40 40 helper IssuesHelper
41 41 helper :queries
42 42 include QueriesHelper
43 43 helper :repositories
44 44 include RepositoriesHelper
45 45 include ProjectsHelper
46 46
47 47 # Lists visible projects
48 48 def index
49 49 projects = Project.find :all,
50 50 :conditions => Project.visible_by(User.current),
51 51 :include => :parent
52 52 respond_to do |format|
53 53 format.html {
54 54 @project_tree = projects.group_by {|p| p.parent || p}
55 55 @project_tree.keys.each {|p| @project_tree[p] -= [p]}
56 56 }
57 57 format.atom {
58 58 render_feed(projects.sort_by(&:created_on).reverse.slice(0, Setting.feeds_limit.to_i),
59 59 :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 60 }
61 61 end
62 62 end
63 63
64 64 # Add a new project
65 65 def add
66 66 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 67 @trackers = Tracker.all
68 68 @root_projects = Project.find(:all,
69 69 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
70 70 :order => 'name')
71 71 @project = Project.new(params[:project])
72 72 if request.get?
73 73 @project.trackers = Tracker.all
74 74 @project.is_public = Setting.default_projects_public?
75 75 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
76 76 else
77 77 @project.enabled_module_names = params[:enabled_modules]
78 78 if @project.save
79 79 flash[:notice] = l(:notice_successful_create)
80 80 redirect_to :controller => 'admin', :action => 'projects'
81 81 end
82 82 end
83 83 end
84 84
85 85 # Show @project
86 86 def show
87 87 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
88 88 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
89 89 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
90 90 @trackers = @project.rolled_up_trackers
91 91
92 92 cond = @project.project_condition(Setting.display_subprojects_issues?)
93 93 Issue.visible_by(User.current) do
94 94 @open_issues_by_tracker = Issue.count(:group => :tracker,
95 95 :include => [:project, :status, :tracker],
96 96 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
97 97 @total_issues_by_tracker = Issue.count(:group => :tracker,
98 98 :include => [:project, :status, :tracker],
99 99 :conditions => cond)
100 100 end
101 101 TimeEntry.visible_by(User.current) do
102 102 @total_hours = TimeEntry.sum(:hours,
103 103 :include => :project,
104 104 :conditions => cond).to_f
105 105 end
106 106 @key = User.current.rss_key
107 107 end
108 108
109 109 def settings
110 110 @root_projects = Project.find(:all,
111 111 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
112 112 :order => 'name')
113 113 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
114 114 @issue_category ||= IssueCategory.new
115 115 @member ||= @project.members.new
116 116 @trackers = Tracker.all
117 117 @repository ||= @project.repository
118 118 @wiki ||= @project.wiki
119 119 end
120 120
121 121 # Edit @project
122 122 def edit
123 123 if request.post?
124 124 @project.attributes = params[:project]
125 125 if @project.save
126 126 flash[:notice] = l(:notice_successful_update)
127 127 redirect_to :action => 'settings', :id => @project
128 128 else
129 129 settings
130 130 render :action => 'settings'
131 131 end
132 132 end
133 133 end
134 134
135 135 def modules
136 136 @project.enabled_module_names = params[:enabled_modules]
137 137 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
138 138 end
139 139
140 140 def archive
141 141 @project.archive if request.post? && @project.active?
142 142 redirect_to :controller => 'admin', :action => 'projects'
143 143 end
144 144
145 145 def unarchive
146 146 @project.unarchive if request.post? && !@project.active?
147 147 redirect_to :controller => 'admin', :action => 'projects'
148 148 end
149 149
150 150 # Delete @project
151 151 def destroy
152 152 @project_to_destroy = @project
153 153 if request.post? and params[:confirm]
154 154 @project_to_destroy.destroy
155 155 redirect_to :controller => 'admin', :action => 'projects'
156 156 end
157 157 # hide project in layout
158 158 @project = nil
159 159 end
160 160
161 161 # Add a new issue category to @project
162 162 def add_issue_category
163 163 @category = @project.issue_categories.build(params[:category])
164 164 if request.post? and @category.save
165 165 respond_to do |format|
166 166 format.html do
167 167 flash[:notice] = l(:notice_successful_create)
168 168 redirect_to :action => 'settings', :tab => 'categories', :id => @project
169 169 end
170 170 format.js do
171 171 # IE doesn't support the replace_html rjs method for select box options
172 172 render(:update) {|page| page.replace "issue_category_id",
173 173 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]')
174 174 }
175 175 end
176 176 end
177 177 end
178 178 end
179 179
180 180 # Add a new version to @project
181 181 def add_version
182 182 @version = @project.versions.build(params[:version])
183 183 if request.post? and @version.save
184 184 flash[:notice] = l(:notice_successful_create)
185 185 redirect_to :action => 'settings', :tab => 'versions', :id => @project
186 186 end
187 187 end
188 188
189 189 def add_file
190 190 if request.post?
191 191 @version = @project.versions.find_by_id(params[:version_id])
192 192 attachments = attach_files(@version, params[:attachments])
193 193 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
194 194 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
195 195 end
196 196 @versions = @project.versions.sort
197 197 end
198 198
199 199 def list_files
200 200 sort_init "#{Attachment.table_name}.filename", "asc"
201 201 sort_update
202 202 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
203 203 render :layout => !request.xhr?
204 204 end
205 205
206 206 # Show changelog for @project
207 207 def changelog
208 208 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
209 209 retrieve_selected_tracker_ids(@trackers)
210 210 @versions = @project.versions.sort
211 211 end
212 212
213 213 def roadmap
214 214 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
215 215 retrieve_selected_tracker_ids(@trackers)
216 216 @versions = @project.versions.sort
217 217 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
218 218 end
219 219
220 220 def activity
221 221 @days = Setting.activity_days_default.to_i
222 222
223 223 if params[:from]
224 224 begin; @date_to = params[:from].to_date; rescue; end
225 225 end
226 226
227 227 @date_to ||= Date.today + 1
228 228 @date_from = @date_to - @days
229 229
230 230 @event_types = %w(issues news files documents changesets wiki_pages messages)
231 231 if @project
232 232 @event_types.delete('wiki_pages') unless @project.wiki
233 233 @event_types.delete('changesets') unless @project.repository
234 234 @event_types.delete('messages') unless @project.boards.any?
235 235 # only show what the user is allowed to view
236 236 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
237 237 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
238 238 end
239 239 @scope = @event_types.select {|t| params["show_#{t}"]}
240 240 # default events if none is specified in parameters
241 241 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
242 242
243 243 @events = []
244 244
245 245 if @scope.include?('issues')
246 246 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
247 247 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
248 248 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
249 249
250 250 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
251 251 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
252 252 cond.add("#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> ''")
253 253 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
254 254 end
255 255
256 256 if @scope.include?('news')
257 257 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
258 258 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
259 259 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
260 260 end
261 261
262 262 if @scope.include?('files')
263 263 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
264 264 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
265 265 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
266 266 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
267 267 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
268 268 :conditions => cond.conditions)
269 269 end
270 270
271 271 if @scope.include?('documents')
272 272 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
273 273 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
274 274 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
275 275
276 276 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
277 277 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
278 278 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
279 279 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
280 280 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
281 281 :conditions => cond.conditions)
282 282 end
283 283
284 284 if @scope.include?('wiki_pages')
285 285 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
286 286 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
287 287 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
288 288 "#{WikiContent.versioned_table_name}.id"
289 289 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
290 290 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
291 291 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
292 292
293 293 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
294 294 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
295 295 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
296 296 end
297 297
298 298 if @scope.include?('changesets')
299 299 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
300 300 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
301 301 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
302 302 end
303 303
304 304 if @scope.include?('messages')
305 305 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
306 306 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
307 307 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
308 308 end
309 309
310 310 @events_by_day = @events.group_by(&:event_date)
311 311
312 312 respond_to do |format|
313 313 format.html { render :layout => false if request.xhr? }
314 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
314 format.atom {
315 title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity)
316 render_feed(@events, :title => "#{@project || Setting.app_title}: #{title}")
317 }
315 318 end
316 319 end
317 320
318 321 def calendar
319 322 @trackers = @project.rolled_up_trackers
320 323 retrieve_selected_tracker_ids(@trackers)
321 324
322 325 if params[:year] and params[:year].to_i > 1900
323 326 @year = params[:year].to_i
324 327 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
325 328 @month = params[:month].to_i
326 329 end
327 330 end
328 331 @year ||= Date.today.year
329 332 @month ||= Date.today.month
330 333 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
331 334 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
332 335 events = []
333 336 @project.issues_with_subprojects(@with_subprojects) do
334 337 events += Issue.find(:all,
335 338 :include => [:tracker, :status, :assigned_to, :priority, :project],
336 339 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
337 340 ) unless @selected_tracker_ids.empty?
338 341 events += Version.find(:all, :include => :project,
339 342 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
340 343 end
341 344 @calendar.events = events
342 345
343 346 render :layout => false if request.xhr?
344 347 end
345 348
346 349 def gantt
347 350 @trackers = @project.rolled_up_trackers
348 351 retrieve_selected_tracker_ids(@trackers)
349 352
350 353 if params[:year] and params[:year].to_i >0
351 354 @year_from = params[:year].to_i
352 355 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
353 356 @month_from = params[:month].to_i
354 357 else
355 358 @month_from = 1
356 359 end
357 360 else
358 361 @month_from ||= Date.today.month
359 362 @year_from ||= Date.today.year
360 363 end
361 364
362 365 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
363 366 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
364 367 months = (params[:months] || User.current.pref[:gantt_months]).to_i
365 368 @months = (months > 0 && months < 25) ? months : 6
366 369
367 370 # Save gantt paramters as user preference (zoom and months count)
368 371 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
369 372 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
370 373 User.current.preference.save
371 374 end
372 375
373 376 @date_from = Date.civil(@year_from, @month_from, 1)
374 377 @date_to = (@date_from >> @months) - 1
375 378 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
376 379
377 380 @events = []
378 381 @project.issues_with_subprojects(@with_subprojects) do
379 382 # Issues that have start and due dates
380 383 @events += Issue.find(:all,
381 384 :order => "start_date, due_date",
382 385 :include => [:tracker, :status, :assigned_to, :priority, :project],
383 386 :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]
384 387 ) unless @selected_tracker_ids.empty?
385 388 # Issues that don't have a due date but that are assigned to a version with a date
386 389 @events += Issue.find(:all,
387 390 :order => "start_date, effective_date",
388 391 :include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
389 392 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_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]
390 393 ) unless @selected_tracker_ids.empty?
391 394 @events += Version.find(:all, :include => :project,
392 395 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
393 396 end
394 397 @events.sort! {|x,y| x.start_date <=> y.start_date }
395 398
396 399 if params[:format]=='pdf'
397 400 @options_for_rfpdf ||= {}
398 401 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
399 402 render :template => "projects/gantt.rfpdf", :layout => false
400 403 elsif params[:format]=='png' && respond_to?('gantt_image')
401 404 image = gantt_image(@events, @date_from, @months, @zoom)
402 405 image.format = 'PNG'
403 406 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
404 407 else
405 408 render :template => "projects/gantt.rhtml"
406 409 end
407 410 end
408 411
409 412 private
410 413 # Find project of id params[:id]
411 414 # if not found, redirect to project list
412 415 # Used as a before_filter
413 416 def find_project
414 417 @project = Project.find(params[:id])
415 418 rescue ActiveRecord::RecordNotFound
416 419 render_404
417 420 end
418 421
419 422 def find_optional_project
420 423 return true unless params[:id]
421 424 @project = Project.find(params[:id])
422 425 authorize
423 426 rescue ActiveRecord::RecordNotFound
424 427 render_404
425 428 end
426 429
427 430 def retrieve_selected_tracker_ids(selectable_trackers)
428 431 if ids = params[:tracker_ids]
429 432 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
430 433 else
431 434 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
432 435 end
433 436 end
434 437 end
General Comments 0
You need to be logged in to leave comments. Login now