##// END OF EJS Templates
Add etag check on the activity view to avoid rendering when not modified....
Jean-Philippe Lang -
r2868:a658679d29eb
parent child
Show More
@@ -1,347 +1,349
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 menu_item :overview
19 menu_item :overview
20 menu_item :activity, :only => :activity
20 menu_item :activity, :only => :activity
21 menu_item :roadmap, :only => :roadmap
21 menu_item :roadmap, :only => :roadmap
22 menu_item :files, :only => [:list_files, :add_file]
22 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :settings, :only => :settings
23 menu_item :settings, :only => :settings
24 menu_item :issues, :only => [:changelog]
24 menu_item :issues, :only => [:changelog]
25
25
26 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
26 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
27 before_filter :find_optional_project, :only => :activity
27 before_filter :find_optional_project, :only => :activity
28 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
28 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
29 before_filter :authorize_global, :only => :add
29 before_filter :authorize_global, :only => :add
30 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
30 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
31 accept_key_auth :activity
31 accept_key_auth :activity
32
32
33 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
33 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
34 if controller.request.post?
34 if controller.request.post?
35 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
35 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
36 end
36 end
37 end
37 end
38
38
39 helper :sort
39 helper :sort
40 include SortHelper
40 include SortHelper
41 helper :custom_fields
41 helper :custom_fields
42 include CustomFieldsHelper
42 include CustomFieldsHelper
43 helper :issues
43 helper :issues
44 helper IssuesHelper
44 helper IssuesHelper
45 helper :queries
45 helper :queries
46 include QueriesHelper
46 include QueriesHelper
47 helper :repositories
47 helper :repositories
48 include RepositoriesHelper
48 include RepositoriesHelper
49 include ProjectsHelper
49 include ProjectsHelper
50
50
51 # Lists visible projects
51 # Lists visible projects
52 def index
52 def index
53 respond_to do |format|
53 respond_to do |format|
54 format.html {
54 format.html {
55 @projects = Project.visible.find(:all, :order => 'lft')
55 @projects = Project.visible.find(:all, :order => 'lft')
56 }
56 }
57 format.atom {
57 format.atom {
58 projects = Project.visible.find(:all, :order => 'created_on DESC',
58 projects = Project.visible.find(:all, :order => 'created_on DESC',
59 :limit => Setting.feeds_limit.to_i)
59 :limit => Setting.feeds_limit.to_i)
60 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
60 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
61 }
61 }
62 end
62 end
63 end
63 end
64
64
65 # Add a new project
65 # Add a new project
66 def add
66 def add
67 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
67 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
68 @trackers = Tracker.all
68 @trackers = Tracker.all
69 @project = Project.new(params[:project])
69 @project = Project.new(params[:project])
70 if request.get?
70 if request.get?
71 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
71 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
72 @project.trackers = Tracker.all
72 @project.trackers = Tracker.all
73 @project.is_public = Setting.default_projects_public?
73 @project.is_public = Setting.default_projects_public?
74 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
74 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
75 else
75 else
76 @project.enabled_module_names = params[:enabled_modules]
76 @project.enabled_module_names = params[:enabled_modules]
77 if @project.save
77 if @project.save
78 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
78 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
79 # Add current user as a project member if he is not admin
79 # Add current user as a project member if he is not admin
80 unless User.current.admin?
80 unless User.current.admin?
81 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
81 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
82 m = Member.new(:user => User.current, :roles => [r])
82 m = Member.new(:user => User.current, :roles => [r])
83 @project.members << m
83 @project.members << m
84 end
84 end
85 flash[:notice] = l(:notice_successful_create)
85 flash[:notice] = l(:notice_successful_create)
86 redirect_to :controller => 'projects', :action => 'settings', :id => @project
86 redirect_to :controller => 'projects', :action => 'settings', :id => @project
87 end
87 end
88 end
88 end
89 end
89 end
90
90
91 def copy
91 def copy
92 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
92 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
93 @trackers = Tracker.all
93 @trackers = Tracker.all
94 @root_projects = Project.find(:all,
94 @root_projects = Project.find(:all,
95 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
95 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
96 :order => 'name')
96 :order => 'name')
97 @source_project = Project.find(params[:id])
97 @source_project = Project.find(params[:id])
98 if request.get?
98 if request.get?
99 @project = Project.copy_from(@source_project)
99 @project = Project.copy_from(@source_project)
100 if @project
100 if @project
101 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
101 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
102 else
102 else
103 redirect_to :controller => 'admin', :action => 'projects'
103 redirect_to :controller => 'admin', :action => 'projects'
104 end
104 end
105 else
105 else
106 @project = Project.new(params[:project])
106 @project = Project.new(params[:project])
107 @project.enabled_module_names = params[:enabled_modules]
107 @project.enabled_module_names = params[:enabled_modules]
108 if @project.copy(@source_project, :only => params[:only])
108 if @project.copy(@source_project, :only => params[:only])
109 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
109 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
110 flash[:notice] = l(:notice_successful_create)
110 flash[:notice] = l(:notice_successful_create)
111 redirect_to :controller => 'admin', :action => 'projects'
111 redirect_to :controller => 'admin', :action => 'projects'
112 end
112 end
113 end
113 end
114 end
114 end
115
115
116
116
117 # Show @project
117 # Show @project
118 def show
118 def show
119 if params[:jump]
119 if params[:jump]
120 # try to redirect to the requested menu item
120 # try to redirect to the requested menu item
121 redirect_to_project_menu_item(@project, params[:jump]) && return
121 redirect_to_project_menu_item(@project, params[:jump]) && return
122 end
122 end
123
123
124 @users_by_role = @project.users_by_role
124 @users_by_role = @project.users_by_role
125 @subprojects = @project.children.visible
125 @subprojects = @project.children.visible
126 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
126 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
127 @trackers = @project.rolled_up_trackers
127 @trackers = @project.rolled_up_trackers
128
128
129 cond = @project.project_condition(Setting.display_subprojects_issues?)
129 cond = @project.project_condition(Setting.display_subprojects_issues?)
130
130
131 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
131 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
132 :include => [:project, :status, :tracker],
132 :include => [:project, :status, :tracker],
133 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
133 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
134 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
134 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
135 :include => [:project, :status, :tracker],
135 :include => [:project, :status, :tracker],
136 :conditions => cond)
136 :conditions => cond)
137
137
138 TimeEntry.visible_by(User.current) do
138 TimeEntry.visible_by(User.current) do
139 @total_hours = TimeEntry.sum(:hours,
139 @total_hours = TimeEntry.sum(:hours,
140 :include => :project,
140 :include => :project,
141 :conditions => cond).to_f
141 :conditions => cond).to_f
142 end
142 end
143 @key = User.current.rss_key
143 @key = User.current.rss_key
144 end
144 end
145
145
146 def settings
146 def settings
147 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
147 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
148 @issue_category ||= IssueCategory.new
148 @issue_category ||= IssueCategory.new
149 @member ||= @project.members.new
149 @member ||= @project.members.new
150 @trackers = Tracker.all
150 @trackers = Tracker.all
151 @repository ||= @project.repository
151 @repository ||= @project.repository
152 @wiki ||= @project.wiki
152 @wiki ||= @project.wiki
153 end
153 end
154
154
155 # Edit @project
155 # Edit @project
156 def edit
156 def edit
157 if request.post?
157 if request.post?
158 @project.attributes = params[:project]
158 @project.attributes = params[:project]
159 if @project.save
159 if @project.save
160 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
160 @project.set_parent!(params[:project]['parent_id']) if User.current.admin? && params[:project].has_key?('parent_id')
161 flash[:notice] = l(:notice_successful_update)
161 flash[:notice] = l(:notice_successful_update)
162 redirect_to :action => 'settings', :id => @project
162 redirect_to :action => 'settings', :id => @project
163 else
163 else
164 settings
164 settings
165 render :action => 'settings'
165 render :action => 'settings'
166 end
166 end
167 end
167 end
168 end
168 end
169
169
170 def modules
170 def modules
171 @project.enabled_module_names = params[:enabled_modules]
171 @project.enabled_module_names = params[:enabled_modules]
172 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
172 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
173 end
173 end
174
174
175 def archive
175 def archive
176 @project.archive if request.post? && @project.active?
176 @project.archive if request.post? && @project.active?
177 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
177 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
178 end
178 end
179
179
180 def unarchive
180 def unarchive
181 @project.unarchive if request.post? && !@project.active?
181 @project.unarchive if request.post? && !@project.active?
182 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
182 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
183 end
183 end
184
184
185 # Delete @project
185 # Delete @project
186 def destroy
186 def destroy
187 @project_to_destroy = @project
187 @project_to_destroy = @project
188 if request.post? and params[:confirm]
188 if request.post? and params[:confirm]
189 @project_to_destroy.destroy
189 @project_to_destroy.destroy
190 redirect_to :controller => 'admin', :action => 'projects'
190 redirect_to :controller => 'admin', :action => 'projects'
191 end
191 end
192 # hide project in layout
192 # hide project in layout
193 @project = nil
193 @project = nil
194 end
194 end
195
195
196 # Add a new issue category to @project
196 # Add a new issue category to @project
197 def add_issue_category
197 def add_issue_category
198 @category = @project.issue_categories.build(params[:category])
198 @category = @project.issue_categories.build(params[:category])
199 if request.post? and @category.save
199 if request.post? and @category.save
200 respond_to do |format|
200 respond_to do |format|
201 format.html do
201 format.html do
202 flash[:notice] = l(:notice_successful_create)
202 flash[:notice] = l(:notice_successful_create)
203 redirect_to :action => 'settings', :tab => 'categories', :id => @project
203 redirect_to :action => 'settings', :tab => 'categories', :id => @project
204 end
204 end
205 format.js do
205 format.js do
206 # IE doesn't support the replace_html rjs method for select box options
206 # IE doesn't support the replace_html rjs method for select box options
207 render(:update) {|page| page.replace "issue_category_id",
207 render(:update) {|page| page.replace "issue_category_id",
208 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]')
208 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]')
209 }
209 }
210 end
210 end
211 end
211 end
212 end
212 end
213 end
213 end
214
214
215 # Add a new version to @project
215 # Add a new version to @project
216 def add_version
216 def add_version
217 @version = @project.versions.build(params[:version])
217 @version = @project.versions.build(params[:version])
218 if request.post? and @version.save
218 if request.post? and @version.save
219 flash[:notice] = l(:notice_successful_create)
219 flash[:notice] = l(:notice_successful_create)
220 redirect_to :action => 'settings', :tab => 'versions', :id => @project
220 redirect_to :action => 'settings', :tab => 'versions', :id => @project
221 end
221 end
222 end
222 end
223
223
224 def add_file
224 def add_file
225 if request.post?
225 if request.post?
226 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
226 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
227 attachments = attach_files(container, params[:attachments])
227 attachments = attach_files(container, params[:attachments])
228 if !attachments.empty? && Setting.notified_events.include?('file_added')
228 if !attachments.empty? && Setting.notified_events.include?('file_added')
229 Mailer.deliver_attachments_added(attachments)
229 Mailer.deliver_attachments_added(attachments)
230 end
230 end
231 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
231 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
232 return
232 return
233 end
233 end
234 @versions = @project.versions.sort
234 @versions = @project.versions.sort
235 end
235 end
236
236
237 def save_activities
237 def save_activities
238 if request.post? && params[:enumerations]
238 if request.post? && params[:enumerations]
239 Project.transaction do
239 Project.transaction do
240 params[:enumerations].each do |id, activity|
240 params[:enumerations].each do |id, activity|
241 @project.update_or_create_time_entry_activity(id, activity)
241 @project.update_or_create_time_entry_activity(id, activity)
242 end
242 end
243 end
243 end
244 end
244 end
245
245
246 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
246 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
247 end
247 end
248
248
249 def reset_activities
249 def reset_activities
250 @project.time_entry_activities.each do |time_entry_activity|
250 @project.time_entry_activities.each do |time_entry_activity|
251 time_entry_activity.destroy(time_entry_activity.parent)
251 time_entry_activity.destroy(time_entry_activity.parent)
252 end
252 end
253 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
253 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
254 end
254 end
255
255
256 def list_files
256 def list_files
257 sort_init 'filename', 'asc'
257 sort_init 'filename', 'asc'
258 sort_update 'filename' => "#{Attachment.table_name}.filename",
258 sort_update 'filename' => "#{Attachment.table_name}.filename",
259 'created_on' => "#{Attachment.table_name}.created_on",
259 'created_on' => "#{Attachment.table_name}.created_on",
260 'size' => "#{Attachment.table_name}.filesize",
260 'size' => "#{Attachment.table_name}.filesize",
261 'downloads' => "#{Attachment.table_name}.downloads"
261 'downloads' => "#{Attachment.table_name}.downloads"
262
262
263 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
263 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
264 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
264 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
265 render :layout => !request.xhr?
265 render :layout => !request.xhr?
266 end
266 end
267
267
268 # Show changelog for @project
268 # Show changelog for @project
269 def changelog
269 def changelog
270 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
270 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
271 retrieve_selected_tracker_ids(@trackers)
271 retrieve_selected_tracker_ids(@trackers)
272 @versions = @project.versions.sort
272 @versions = @project.versions.sort
273 end
273 end
274
274
275 def roadmap
275 def roadmap
276 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
276 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
277 retrieve_selected_tracker_ids(@trackers)
277 retrieve_selected_tracker_ids(@trackers)
278 @versions = @project.versions.sort
278 @versions = @project.versions.sort
279 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
279 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
280 end
280 end
281
281
282 def activity
282 def activity
283 @days = Setting.activity_days_default.to_i
283 @days = Setting.activity_days_default.to_i
284
284
285 if params[:from]
285 if params[:from]
286 begin; @date_to = params[:from].to_date + 1; rescue; end
286 begin; @date_to = params[:from].to_date + 1; rescue; end
287 end
287 end
288
288
289 @date_to ||= Date.today + 1
289 @date_to ||= Date.today + 1
290 @date_from = @date_to - @days
290 @date_from = @date_to - @days
291 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
291 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
292 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
292 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
293
293
294 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
294 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
295 :with_subprojects => @with_subprojects,
295 :with_subprojects => @with_subprojects,
296 :author => @author)
296 :author => @author)
297 @activity.scope_select {|t| !params["show_#{t}"].nil?}
297 @activity.scope_select {|t| !params["show_#{t}"].nil?}
298 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
298 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
299
299
300 events = @activity.events(@date_from, @date_to)
300 events = @activity.events(@date_from, @date_to)
301
301
302 respond_to do |format|
302 if events.empty? || stale?(:etag => [events.first, User.current])
303 format.html {
303 respond_to do |format|
304 @events_by_day = events.group_by(&:event_date)
304 format.html {
305 render :layout => false if request.xhr?
305 @events_by_day = events.group_by(&:event_date)
306 }
306 render :layout => false if request.xhr?
307 format.atom {
307 }
308 title = l(:label_activity)
308 format.atom {
309 if @author
309 title = l(:label_activity)
310 title = @author.name
310 if @author
311 elsif @activity.scope.size == 1
311 title = @author.name
312 title = l("label_#{@activity.scope.first.singularize}_plural")
312 elsif @activity.scope.size == 1
313 end
313 title = l("label_#{@activity.scope.first.singularize}_plural")
314 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
314 end
315 }
315 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
316 }
317 end
316 end
318 end
317
319
318 rescue ActiveRecord::RecordNotFound
320 rescue ActiveRecord::RecordNotFound
319 render_404
321 render_404
320 end
322 end
321
323
322 private
324 private
323 # Find project of id params[:id]
325 # Find project of id params[:id]
324 # if not found, redirect to project list
326 # if not found, redirect to project list
325 # Used as a before_filter
327 # Used as a before_filter
326 def find_project
328 def find_project
327 @project = Project.find(params[:id])
329 @project = Project.find(params[:id])
328 rescue ActiveRecord::RecordNotFound
330 rescue ActiveRecord::RecordNotFound
329 render_404
331 render_404
330 end
332 end
331
333
332 def find_optional_project
334 def find_optional_project
333 return true unless params[:id]
335 return true unless params[:id]
334 @project = Project.find(params[:id])
336 @project = Project.find(params[:id])
335 authorize
337 authorize
336 rescue ActiveRecord::RecordNotFound
338 rescue ActiveRecord::RecordNotFound
337 render_404
339 render_404
338 end
340 end
339
341
340 def retrieve_selected_tracker_ids(selectable_trackers)
342 def retrieve_selected_tracker_ids(selectable_trackers)
341 if ids = params[:tracker_ids]
343 if ids = params[:tracker_ids]
342 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
344 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
343 else
345 else
344 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
346 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
345 end
347 end
346 end
348 end
347 end
349 end
@@ -1,93 +1,95
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 module Redmine
18 module Redmine
19 module Activity
19 module Activity
20 # Class used to retrieve activity events
20 # Class used to retrieve activity events
21 class Fetcher
21 class Fetcher
22 attr_reader :user, :project, :scope
22 attr_reader :user, :project, :scope
23
23
24 # Needs to be unloaded in development mode
24 # Needs to be unloaded in development mode
25 @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } }
25 @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } }
26
26
27 def initialize(user, options={})
27 def initialize(user, options={})
28 options.assert_valid_keys(:project, :with_subprojects, :author)
28 options.assert_valid_keys(:project, :with_subprojects, :author)
29 @user = user
29 @user = user
30 @project = options[:project]
30 @project = options[:project]
31 @options = options
31 @options = options
32
32
33 @scope = event_types
33 @scope = event_types
34 end
34 end
35
35
36 # Returns an array of available event types
36 # Returns an array of available event types
37 def event_types
37 def event_types
38 return @event_types unless @event_types.nil?
38 return @event_types unless @event_types.nil?
39
39
40 @event_types = Redmine::Activity.available_event_types
40 @event_types = Redmine::Activity.available_event_types
41 @event_types = @event_types.select {|o| @user.allowed_to?("view_#{o}".to_sym, @project)} if @project
41 @event_types = @event_types.select {|o| @user.allowed_to?("view_#{o}".to_sym, @project)} if @project
42 @event_types
42 @event_types
43 end
43 end
44
44
45 # Yields to filter the activity scope
45 # Yields to filter the activity scope
46 def scope_select(&block)
46 def scope_select(&block)
47 @scope = @scope.select {|t| yield t }
47 @scope = @scope.select {|t| yield t }
48 end
48 end
49
49
50 # Sets the scope
50 # Sets the scope
51 # Argument can be :all, :default or an array of event types
51 # Argument can be :all, :default or an array of event types
52 def scope=(s)
52 def scope=(s)
53 case s
53 case s
54 when :all
54 when :all
55 @scope = event_types
55 @scope = event_types
56 when :default
56 when :default
57 default_scope!
57 default_scope!
58 else
58 else
59 @scope = s & event_types
59 @scope = s & event_types
60 end
60 end
61 end
61 end
62
62
63 # Resets the scope to the default scope
63 # Resets the scope to the default scope
64 def default_scope!
64 def default_scope!
65 @scope = Redmine::Activity.default_event_types
65 @scope = Redmine::Activity.default_event_types
66 end
66 end
67
67
68 # Returns an array of events for the given date range
68 # Returns an array of events for the given date range
69 # sorted in reverse chronological order
69 def events(from = nil, to = nil, options={})
70 def events(from = nil, to = nil, options={})
70 e = []
71 e = []
71 @options[:limit] = options[:limit]
72 @options[:limit] = options[:limit]
72
73
73 @scope.each do |event_type|
74 @scope.each do |event_type|
74 constantized_providers(event_type).each do |provider|
75 constantized_providers(event_type).each do |provider|
75 e += provider.find_events(event_type, @user, from, to, @options)
76 e += provider.find_events(event_type, @user, from, to, @options)
76 end
77 end
77 end
78 end
78
79
80 e.sort! {|a,b| b.event_datetime <=> a.event_datetime}
81
79 if options[:limit]
82 if options[:limit]
80 e.sort! {|a,b| b.event_date <=> a.event_date}
81 e = e.slice(0, options[:limit])
83 e = e.slice(0, options[:limit])
82 end
84 end
83 e
85 e
84 end
86 end
85
87
86 private
88 private
87
89
88 def constantized_providers(event_type)
90 def constantized_providers(event_type)
89 @@constantized_providers[event_type]
91 @@constantized_providers[event_type]
90 end
92 end
91 end
93 end
92 end
94 end
93 end
95 end
General Comments 0
You need to be logged in to leave comments. Login now