@@ -1,391 +1,391 | |||||
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 ] |
|
27 | before_filter :find_project, :except => [ :index, :list, :add ] | |
28 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
28 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] | |
29 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
29 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] | |
30 | accept_key_auth :activity, :calendar |
|
30 | accept_key_auth :activity, :calendar | |
31 |
|
31 | |||
32 | helper :sort |
|
32 | helper :sort | |
33 | include SortHelper |
|
33 | include SortHelper | |
34 | helper :custom_fields |
|
34 | helper :custom_fields | |
35 | include CustomFieldsHelper |
|
35 | include CustomFieldsHelper | |
36 | helper :ifpdf |
|
36 | helper :ifpdf | |
37 | include IfpdfHelper |
|
37 | include IfpdfHelper | |
38 | helper :issues |
|
38 | helper :issues | |
39 | helper IssuesHelper |
|
39 | helper IssuesHelper | |
40 | helper :queries |
|
40 | helper :queries | |
41 | include QueriesHelper |
|
41 | include QueriesHelper | |
42 | helper :repositories |
|
42 | helper :repositories | |
43 | include RepositoriesHelper |
|
43 | include RepositoriesHelper | |
44 | include ProjectsHelper |
|
44 | include ProjectsHelper | |
45 |
|
45 | |||
46 | def index |
|
46 | def index | |
47 | list |
|
47 | list | |
48 | render :action => 'list' unless request.xhr? |
|
48 | render :action => 'list' unless request.xhr? | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | # Lists visible projects |
|
51 | # Lists visible projects | |
52 | def list |
|
52 | def list | |
53 | projects = Project.find :all, |
|
53 | projects = Project.find :all, | |
54 | :conditions => Project.visible_by(User.current), |
|
54 | :conditions => Project.visible_by(User.current), | |
55 | :include => :parent |
|
55 | :include => :parent | |
56 | @project_tree = projects.group_by {|p| p.parent || p} |
|
56 | @project_tree = projects.group_by {|p| p.parent || p} | |
57 | @project_tree.each_key {|p| @project_tree[p] -= [p]} |
|
57 | @project_tree.each_key {|p| @project_tree[p] -= [p]} | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | # Add a new project |
|
60 | # Add a new project | |
61 | def add |
|
61 | def add | |
62 | @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
62 | @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") | |
63 | @trackers = Tracker.all |
|
63 | @trackers = Tracker.all | |
64 | @root_projects = Project.find(:all, |
|
64 | @root_projects = Project.find(:all, | |
65 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
65 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", | |
66 | :order => 'name') |
|
66 | :order => 'name') | |
67 | @project = Project.new(params[:project]) |
|
67 | @project = Project.new(params[:project]) | |
68 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
68 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules | |
69 | if request.get? |
|
69 | if request.get? | |
70 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
70 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } | |
71 | @project.trackers = Tracker.all |
|
71 | @project.trackers = Tracker.all | |
72 | else |
|
72 | else | |
73 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
73 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
74 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } |
|
74 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) } | |
75 | @project.custom_values = @custom_values |
|
75 | @project.custom_values = @custom_values | |
76 | if @project.save |
|
76 | if @project.save | |
77 | @project.enabled_module_names = params[:enabled_modules] |
|
77 | @project.enabled_module_names = params[:enabled_modules] | |
78 | flash[:notice] = l(:notice_successful_create) |
|
78 | flash[:notice] = l(:notice_successful_create) | |
79 | redirect_to :controller => 'admin', :action => 'projects' |
|
79 | redirect_to :controller => 'admin', :action => 'projects' | |
80 | end |
|
80 | end | |
81 | end |
|
81 | end | |
82 | end |
|
82 | end | |
83 |
|
83 | |||
84 | # Show @project |
|
84 | # Show @project | |
85 | def show |
|
85 | def show | |
86 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") |
|
86 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") | |
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.active_children |
|
88 | @subprojects = @project.active_children | |
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 | Issue.visible_by(User.current) do |
|
91 | Issue.visible_by(User.current) do | |
92 | @open_issues_by_tracker = Issue.count(:group => :tracker, |
|
92 | @open_issues_by_tracker = Issue.count(:group => :tracker, | |
93 | :include => [:project, :status, :tracker], |
|
93 | :include => [:project, :status, :tracker], | |
94 | :conditions => ["(#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?) and #{IssueStatus.table_name}.is_closed=?", @project.id, @project.id, false]) |
|
94 | :conditions => ["(#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?) and #{IssueStatus.table_name}.is_closed=?", @project.id, @project.id, false]) | |
95 | @total_issues_by_tracker = Issue.count(:group => :tracker, |
|
95 | @total_issues_by_tracker = Issue.count(:group => :tracker, | |
96 | :include => [:project, :status, :tracker], |
|
96 | :include => [:project, :status, :tracker], | |
97 | :conditions => ["#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?", @project.id, @project.id]) |
|
97 | :conditions => ["#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?", @project.id, @project.id]) | |
98 | end |
|
98 | end | |
99 | TimeEntry.visible_by(User.current) do |
|
99 | TimeEntry.visible_by(User.current) do | |
100 | @total_hours = TimeEntry.sum(:hours, |
|
100 | @total_hours = TimeEntry.sum(:hours, | |
101 | :include => :project, |
|
101 | :include => :project, | |
102 | :conditions => ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id]).to_f |
|
102 | :conditions => ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id]).to_f | |
103 | end |
|
103 | end | |
104 | @key = User.current.rss_key |
|
104 | @key = User.current.rss_key | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def settings |
|
107 | def settings | |
108 | @root_projects = Project.find(:all, |
|
108 | @root_projects = Project.find(:all, | |
109 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], |
|
109 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], | |
110 | :order => 'name') |
|
110 | :order => 'name') | |
111 | @custom_fields = IssueCustomField.find(:all) |
|
111 | @custom_fields = IssueCustomField.find(:all) | |
112 | @issue_category ||= IssueCategory.new |
|
112 | @issue_category ||= IssueCategory.new | |
113 | @member ||= @project.members.new |
|
113 | @member ||= @project.members.new | |
114 | @trackers = Tracker.all |
|
114 | @trackers = Tracker.all | |
115 | @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } |
|
115 | @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } | |
116 | @repository ||= @project.repository |
|
116 | @repository ||= @project.repository | |
117 | @wiki ||= @project.wiki |
|
117 | @wiki ||= @project.wiki | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | # Edit @project |
|
120 | # Edit @project | |
121 | def edit |
|
121 | def edit | |
122 | if request.post? |
|
122 | if request.post? | |
123 | if params[:custom_fields] |
|
123 | if params[:custom_fields] | |
124 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } |
|
124 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) } | |
125 | @project.custom_values = @custom_values |
|
125 | @project.custom_values = @custom_values | |
126 | end |
|
126 | end | |
127 | @project.attributes = params[:project] |
|
127 | @project.attributes = params[:project] | |
128 | if @project.save |
|
128 | if @project.save | |
129 | flash[:notice] = l(:notice_successful_update) |
|
129 | flash[:notice] = l(:notice_successful_update) | |
130 | redirect_to :action => 'settings', :id => @project |
|
130 | redirect_to :action => 'settings', :id => @project | |
131 | else |
|
131 | else | |
132 | settings |
|
132 | settings | |
133 | render :action => 'settings' |
|
133 | render :action => 'settings' | |
134 | end |
|
134 | end | |
135 | end |
|
135 | end | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def modules |
|
138 | def modules | |
139 | @project.enabled_module_names = params[:enabled_modules] |
|
139 | @project.enabled_module_names = params[:enabled_modules] | |
140 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
140 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def archive |
|
143 | def archive | |
144 | @project.archive if request.post? && @project.active? |
|
144 | @project.archive if request.post? && @project.active? | |
145 | redirect_to :controller => 'admin', :action => 'projects' |
|
145 | redirect_to :controller => 'admin', :action => 'projects' | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def unarchive |
|
148 | def unarchive | |
149 | @project.unarchive if request.post? && !@project.active? |
|
149 | @project.unarchive if request.post? && !@project.active? | |
150 | redirect_to :controller => 'admin', :action => 'projects' |
|
150 | redirect_to :controller => 'admin', :action => 'projects' | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | # Delete @project |
|
153 | # Delete @project | |
154 | def destroy |
|
154 | def destroy | |
155 | @project_to_destroy = @project |
|
155 | @project_to_destroy = @project | |
156 | if request.post? and params[:confirm] |
|
156 | if request.post? and params[:confirm] | |
157 | @project_to_destroy.destroy |
|
157 | @project_to_destroy.destroy | |
158 | redirect_to :controller => 'admin', :action => 'projects' |
|
158 | redirect_to :controller => 'admin', :action => 'projects' | |
159 | end |
|
159 | end | |
160 | # hide project in layout |
|
160 | # hide project in layout | |
161 | @project = nil |
|
161 | @project = nil | |
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | # Add a new issue category to @project |
|
164 | # Add a new issue category to @project | |
165 | def add_issue_category |
|
165 | def add_issue_category | |
166 | @category = @project.issue_categories.build(params[:category]) |
|
166 | @category = @project.issue_categories.build(params[:category]) | |
167 | if request.post? and @category.save |
|
167 | if request.post? and @category.save | |
168 | respond_to do |format| |
|
168 | respond_to do |format| | |
169 | format.html do |
|
169 | format.html do | |
170 | flash[:notice] = l(:notice_successful_create) |
|
170 | flash[:notice] = l(:notice_successful_create) | |
171 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
171 | redirect_to :action => 'settings', :tab => 'categories', :id => @project | |
172 | end |
|
172 | end | |
173 | format.js do |
|
173 | format.js do | |
174 | # IE doesn't support the replace_html rjs method for select box options |
|
174 | # IE doesn't support the replace_html rjs method for select box options | |
175 | render(:update) {|page| page.replace "issue_category_id", |
|
175 | render(:update) {|page| page.replace "issue_category_id", | |
176 | 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]') |
|
176 | 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]') | |
177 | } |
|
177 | } | |
178 | end |
|
178 | end | |
179 | end |
|
179 | end | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | # Add a new version to @project |
|
183 | # Add a new version to @project | |
184 | def add_version |
|
184 | def add_version | |
185 | @version = @project.versions.build(params[:version]) |
|
185 | @version = @project.versions.build(params[:version]) | |
186 | if request.post? and @version.save |
|
186 | if request.post? and @version.save | |
187 | flash[:notice] = l(:notice_successful_create) |
|
187 | flash[:notice] = l(:notice_successful_create) | |
188 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
188 | redirect_to :action => 'settings', :tab => 'versions', :id => @project | |
189 | end |
|
189 | end | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | def add_file |
|
192 | def add_file | |
193 | if request.post? |
|
193 | if request.post? | |
194 | @version = @project.versions.find_by_id(params[:version_id]) |
|
194 | @version = @project.versions.find_by_id(params[:version_id]) | |
195 | attachments = attach_files(@version, params[:attachments]) |
|
195 | attachments = attach_files(@version, params[:attachments]) | |
196 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
196 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') | |
197 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
197 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project | |
198 | end |
|
198 | end | |
199 | @versions = @project.versions.sort |
|
199 | @versions = @project.versions.sort | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | def list_files |
|
202 | def list_files | |
203 | @versions = @project.versions.sort.reverse |
|
203 | @versions = @project.versions.sort.reverse | |
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 | @event_types.delete('wiki_pages') unless @project.wiki |
|
231 | @event_types.delete('wiki_pages') unless @project.wiki | |
232 | @event_types.delete('changesets') unless @project.repository |
|
232 | @event_types.delete('changesets') unless @project.repository | |
233 | @event_types.delete('messages') unless @project.boards.any? |
|
233 | @event_types.delete('messages') unless @project.boards.any? | |
234 | # only show what the user is allowed to view |
|
234 | # only show what the user is allowed to view | |
235 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} |
|
235 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} | |
236 |
|
236 | |||
237 | @scope = @event_types.select {|t| params["show_#{t}"]} |
|
237 | @scope = @event_types.select {|t| params["show_#{t}"]} | |
238 | # default events if none is specified in parameters |
|
238 | # default events if none is specified in parameters | |
239 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? |
|
239 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? | |
240 |
|
240 | |||
241 | @events = [] |
|
241 | @events = [] | |
242 |
|
242 | |||
243 | if @scope.include?('issues') |
|
243 | if @scope.include?('issues') | |
244 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) |
|
244 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) | |
245 | @events += @project.issues_status_changes(@date_from, @date_to) |
|
245 | @events += @project.issues_status_changes(@date_from, @date_to) | |
246 | end |
|
246 | end | |
247 |
|
247 | |||
248 | if @scope.include?('news') |
|
248 | if @scope.include?('news') | |
249 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) |
|
249 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | if @scope.include?('files') |
|
252 | if @scope.include?('files') | |
253 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
253 | @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | if @scope.include?('documents') |
|
256 | if @scope.include?('documents') | |
257 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) |
|
257 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) | |
258 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) |
|
258 | @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author ) | |
259 | end |
|
259 | end | |
260 |
|
260 | |||
261 | if @scope.include?('wiki_pages') |
|
261 | if @scope.include?('wiki_pages') | |
262 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
262 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + | |
263 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
263 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + | |
264 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
264 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + | |
265 | "#{WikiContent.versioned_table_name}.id" |
|
265 | "#{WikiContent.versioned_table_name}.id" | |
266 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
266 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + | |
267 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
267 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " | |
268 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
268 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", | |
269 | @project.id, @date_from, @date_to] |
|
269 | @project.id, @date_from, @date_to] | |
270 |
|
270 | |||
271 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) |
|
271 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) | |
272 | end |
|
272 | end | |
273 |
|
273 | |||
274 | if @scope.include?('changesets') |
|
274 | if @scope.include?('changesets') | |
275 | @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) |
|
275 | @events += Changeset.find(:all, :include => :repository, :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) | |
276 | end |
|
276 | end | |
277 |
|
277 | |||
278 | if @scope.include?('messages') |
|
278 | if @scope.include?('messages') | |
279 | @events += Message.find(:all, |
|
279 | @events += Message.find(:all, | |
280 | :include => [:board, :author], |
|
280 | :include => [:board, :author], | |
281 |
:conditions => ["#{Board.table_name}.project_id=? AND |
|
281 | :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) | |
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | @events_by_day = @events.group_by(&:event_date) |
|
284 | @events_by_day = @events.group_by(&:event_date) | |
285 |
|
285 | |||
286 | respond_to do |format| |
|
286 | respond_to do |format| | |
287 | format.html { render :layout => false if request.xhr? } |
|
287 | format.html { render :layout => false if request.xhr? } | |
288 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } |
|
288 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } | |
289 | end |
|
289 | end | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | def calendar |
|
292 | def calendar | |
293 | @trackers = @project.rolled_up_trackers |
|
293 | @trackers = @project.rolled_up_trackers | |
294 | retrieve_selected_tracker_ids(@trackers) |
|
294 | retrieve_selected_tracker_ids(@trackers) | |
295 |
|
295 | |||
296 | if params[:year] and params[:year].to_i > 1900 |
|
296 | if params[:year] and params[:year].to_i > 1900 | |
297 | @year = params[:year].to_i |
|
297 | @year = params[:year].to_i | |
298 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
298 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
299 | @month = params[:month].to_i |
|
299 | @month = params[:month].to_i | |
300 | end |
|
300 | end | |
301 | end |
|
301 | end | |
302 | @year ||= Date.today.year |
|
302 | @year ||= Date.today.year | |
303 | @month ||= Date.today.month |
|
303 | @month ||= Date.today.month | |
304 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
304 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
305 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
305 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') | |
306 | events = [] |
|
306 | events = [] | |
307 | @project.issues_with_subprojects(@with_subprojects) do |
|
307 | @project.issues_with_subprojects(@with_subprojects) do | |
308 | events += Issue.find(:all, |
|
308 | events += Issue.find(:all, | |
309 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
309 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
310 | :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] |
|
310 | :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] | |
311 | ) unless @selected_tracker_ids.empty? |
|
311 | ) unless @selected_tracker_ids.empty? | |
312 | end |
|
312 | end | |
313 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
313 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
314 | @calendar.events = events |
|
314 | @calendar.events = events | |
315 |
|
315 | |||
316 | render :layout => false if request.xhr? |
|
316 | render :layout => false if request.xhr? | |
317 | end |
|
317 | end | |
318 |
|
318 | |||
319 | def gantt |
|
319 | def gantt | |
320 | @trackers = @project.rolled_up_trackers |
|
320 | @trackers = @project.rolled_up_trackers | |
321 | retrieve_selected_tracker_ids(@trackers) |
|
321 | retrieve_selected_tracker_ids(@trackers) | |
322 |
|
322 | |||
323 | if params[:year] and params[:year].to_i >0 |
|
323 | if params[:year] and params[:year].to_i >0 | |
324 | @year_from = params[:year].to_i |
|
324 | @year_from = params[:year].to_i | |
325 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
325 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 | |
326 | @month_from = params[:month].to_i |
|
326 | @month_from = params[:month].to_i | |
327 | else |
|
327 | else | |
328 | @month_from = 1 |
|
328 | @month_from = 1 | |
329 | end |
|
329 | end | |
330 | else |
|
330 | else | |
331 | @month_from ||= Date.today.month |
|
331 | @month_from ||= Date.today.month | |
332 | @year_from ||= Date.today.year |
|
332 | @year_from ||= Date.today.year | |
333 | end |
|
333 | end | |
334 |
|
334 | |||
335 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
335 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i | |
336 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
336 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 | |
337 | months = (params[:months] || User.current.pref[:gantt_months]).to_i |
|
337 | months = (params[:months] || User.current.pref[:gantt_months]).to_i | |
338 | @months = (months > 0 && months < 25) ? months : 6 |
|
338 | @months = (months > 0 && months < 25) ? months : 6 | |
339 |
|
339 | |||
340 | # Save gantt paramters as user preference (zoom and months count) |
|
340 | # Save gantt paramters as user preference (zoom and months count) | |
341 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) |
|
341 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) | |
342 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
342 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months | |
343 | User.current.preference.save |
|
343 | User.current.preference.save | |
344 | end |
|
344 | end | |
345 |
|
345 | |||
346 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
346 | @date_from = Date.civil(@year_from, @month_from, 1) | |
347 | @date_to = (@date_from >> @months) - 1 |
|
347 | @date_to = (@date_from >> @months) - 1 | |
348 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
348 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') | |
349 |
|
349 | |||
350 | @events = [] |
|
350 | @events = [] | |
351 | @project.issues_with_subprojects(@with_subprojects) do |
|
351 | @project.issues_with_subprojects(@with_subprojects) do | |
352 | @events += Issue.find(:all, |
|
352 | @events += Issue.find(:all, | |
353 | :order => "start_date, due_date", |
|
353 | :order => "start_date, due_date", | |
354 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
354 | :include => [:tracker, :status, :assigned_to, :priority, :project], | |
355 | :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] |
|
355 | :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] | |
356 | ) unless @selected_tracker_ids.empty? |
|
356 | ) unless @selected_tracker_ids.empty? | |
357 | end |
|
357 | end | |
358 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
358 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) | |
359 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
359 | @events.sort! {|x,y| x.start_date <=> y.start_date } | |
360 |
|
360 | |||
361 | if params[:format]=='pdf' |
|
361 | if params[:format]=='pdf' | |
362 | @options_for_rfpdf ||= {} |
|
362 | @options_for_rfpdf ||= {} | |
363 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
363 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" | |
364 | render :template => "projects/gantt.rfpdf", :layout => false |
|
364 | render :template => "projects/gantt.rfpdf", :layout => false | |
365 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
365 | elsif params[:format]=='png' && respond_to?('gantt_image') | |
366 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
366 | image = gantt_image(@events, @date_from, @months, @zoom) | |
367 | image.format = 'PNG' |
|
367 | image.format = 'PNG' | |
368 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
368 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") | |
369 | else |
|
369 | else | |
370 | render :template => "projects/gantt.rhtml" |
|
370 | render :template => "projects/gantt.rhtml" | |
371 | end |
|
371 | end | |
372 | end |
|
372 | end | |
373 |
|
373 | |||
374 | private |
|
374 | private | |
375 | # Find project of id params[:id] |
|
375 | # Find project of id params[:id] | |
376 | # if not found, redirect to project list |
|
376 | # if not found, redirect to project list | |
377 | # Used as a before_filter |
|
377 | # Used as a before_filter | |
378 | def find_project |
|
378 | def find_project | |
379 | @project = Project.find(params[:id]) |
|
379 | @project = Project.find(params[:id]) | |
380 | rescue ActiveRecord::RecordNotFound |
|
380 | rescue ActiveRecord::RecordNotFound | |
381 | render_404 |
|
381 | render_404 | |
382 | end |
|
382 | end | |
383 |
|
383 | |||
384 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
384 | def retrieve_selected_tracker_ids(selectable_trackers) | |
385 | if ids = params[:tracker_ids] |
|
385 | if ids = params[:tracker_ids] | |
386 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
386 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
387 | else |
|
387 | else | |
388 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
388 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } | |
389 | end |
|
389 | end | |
390 | end |
|
390 | end | |
391 | end |
|
391 | end |
General Comments 0
You need to be logged in to leave comments.
Login now