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