@@ -1,485 +1,484 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class ProjectsController < ApplicationController |
|
19 | 19 | layout 'base' |
|
20 | 20 | menu_item :overview |
|
21 | 21 | menu_item :activity, :only => :activity |
|
22 | 22 | menu_item :roadmap, :only => :roadmap |
|
23 | 23 | menu_item :files, :only => [:list_files, :add_file] |
|
24 | 24 | menu_item :settings, :only => :settings |
|
25 | 25 | menu_item :issues, :only => [:bulk_edit_issues, :changelog, :move_issues] |
|
26 | 26 | |
|
27 | 27 | before_filter :find_project, :except => [ :index, :list, :add ] |
|
28 | 28 | before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ] |
|
29 | 29 | before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ] |
|
30 | 30 | accept_key_auth :activity, :calendar |
|
31 | 31 | |
|
32 | 32 | cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ] |
|
33 | 33 | cache_sweeper :version_sweeper, :only => [ :add_version ] |
|
34 | 34 | |
|
35 | 35 | helper :sort |
|
36 | 36 | include SortHelper |
|
37 | 37 | helper :custom_fields |
|
38 | 38 | include CustomFieldsHelper |
|
39 | 39 | helper :ifpdf |
|
40 | 40 | include IfpdfHelper |
|
41 | 41 | helper :issues |
|
42 | 42 | helper IssuesHelper |
|
43 | 43 | helper :queries |
|
44 | 44 | include QueriesHelper |
|
45 | 45 | helper :repositories |
|
46 | 46 | include RepositoriesHelper |
|
47 | 47 | include ProjectsHelper |
|
48 | 48 | |
|
49 | 49 | def index |
|
50 | 50 | list |
|
51 | 51 | render :action => 'list' unless request.xhr? |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | # Lists visible projects |
|
55 | 55 | def list |
|
56 | 56 | projects = Project.find :all, |
|
57 | 57 | :conditions => Project.visible_by(User.current), |
|
58 | 58 | :include => :parent |
|
59 | 59 | @project_tree = projects.group_by {|p| p.parent || p} |
|
60 | 60 | @project_tree.each_key {|p| @project_tree[p] -= [p]} |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | # Add a new project |
|
64 | 64 | def add |
|
65 | 65 | @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
|
66 | 66 | @trackers = Tracker.all |
|
67 | 67 | @root_projects = Project.find(:all, |
|
68 | 68 | :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", |
|
69 | 69 | :order => 'name') |
|
70 | 70 | @project = Project.new(params[:project]) |
|
71 | 71 | @project.enabled_module_names = Redmine::AccessControl.available_project_modules |
|
72 | 72 | if request.get? |
|
73 | 73 | @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) } |
|
74 | 74 | @project.trackers = Tracker.all |
|
75 | 75 | else |
|
76 | 76 | @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] |
|
77 | 77 | @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)) } |
|
78 | 78 | @project.custom_values = @custom_values |
|
79 | 79 | if @project.save |
|
80 | 80 | @project.enabled_module_names = params[:enabled_modules] |
|
81 | 81 | flash[:notice] = l(:notice_successful_create) |
|
82 | 82 | redirect_to :controller => 'admin', :action => 'projects' |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | # Show @project |
|
88 | 88 | def show |
|
89 | 89 | @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position") |
|
90 | 90 | @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role} |
|
91 | 91 | @subprojects = @project.active_children |
|
92 | 92 | @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
93 | 93 | @trackers = @project.trackers |
|
94 | 94 | @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false]) |
|
95 | 95 | @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id]) |
|
96 | 96 | @total_hours = @project.time_entries.sum(:hours) |
|
97 | 97 | @key = User.current.rss_key |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def settings |
|
101 | 101 | @root_projects = Project.find(:all, |
|
102 | 102 | :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], |
|
103 | 103 | :order => 'name') |
|
104 | 104 | @custom_fields = IssueCustomField.find(:all) |
|
105 | 105 | @issue_category ||= IssueCategory.new |
|
106 | 106 | @member ||= @project.members.new |
|
107 | 107 | @trackers = Tracker.all |
|
108 | 108 | @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) } |
|
109 | 109 | @repository ||= @project.repository |
|
110 | 110 | @wiki ||= @project.wiki |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | # Edit @project |
|
114 | 114 | def edit |
|
115 | 115 | if request.post? |
|
116 | @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids] | |
|
117 | 116 | if params[:custom_fields] |
|
118 | 117 | @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]) } |
|
119 | 118 | @project.custom_values = @custom_values |
|
120 | 119 | end |
|
121 | 120 | @project.attributes = params[:project] |
|
122 | 121 | if @project.save |
|
123 | 122 | flash[:notice] = l(:notice_successful_update) |
|
124 | 123 | redirect_to :action => 'settings', :id => @project |
|
125 | 124 | else |
|
126 | 125 | settings |
|
127 | 126 | render :action => 'settings' |
|
128 | 127 | end |
|
129 | 128 | end |
|
130 | 129 | end |
|
131 | 130 | |
|
132 | 131 | def modules |
|
133 | 132 | @project.enabled_module_names = params[:enabled_modules] |
|
134 | 133 | redirect_to :action => 'settings', :id => @project, :tab => 'modules' |
|
135 | 134 | end |
|
136 | 135 | |
|
137 | 136 | def archive |
|
138 | 137 | @project.archive if request.post? && @project.active? |
|
139 | 138 | redirect_to :controller => 'admin', :action => 'projects' |
|
140 | 139 | end |
|
141 | 140 | |
|
142 | 141 | def unarchive |
|
143 | 142 | @project.unarchive if request.post? && !@project.active? |
|
144 | 143 | redirect_to :controller => 'admin', :action => 'projects' |
|
145 | 144 | end |
|
146 | 145 | |
|
147 | 146 | # Delete @project |
|
148 | 147 | def destroy |
|
149 | 148 | @project_to_destroy = @project |
|
150 | 149 | if request.post? and params[:confirm] |
|
151 | 150 | @project_to_destroy.destroy |
|
152 | 151 | redirect_to :controller => 'admin', :action => 'projects' |
|
153 | 152 | end |
|
154 | 153 | # hide project in layout |
|
155 | 154 | @project = nil |
|
156 | 155 | end |
|
157 | 156 | |
|
158 | 157 | # Add a new issue category to @project |
|
159 | 158 | def add_issue_category |
|
160 | 159 | @category = @project.issue_categories.build(params[:category]) |
|
161 | 160 | if request.post? and @category.save |
|
162 | 161 | respond_to do |format| |
|
163 | 162 | format.html do |
|
164 | 163 | flash[:notice] = l(:notice_successful_create) |
|
165 | 164 | redirect_to :action => 'settings', :tab => 'categories', :id => @project |
|
166 | 165 | end |
|
167 | 166 | format.js do |
|
168 | 167 | # IE doesn't support the replace_html rjs method for select box options |
|
169 | 168 | render(:update) {|page| page.replace "issue_category_id", |
|
170 | 169 | 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]') |
|
171 | 170 | } |
|
172 | 171 | end |
|
173 | 172 | end |
|
174 | 173 | end |
|
175 | 174 | end |
|
176 | 175 | |
|
177 | 176 | # Add a new version to @project |
|
178 | 177 | def add_version |
|
179 | 178 | @version = @project.versions.build(params[:version]) |
|
180 | 179 | if request.post? and @version.save |
|
181 | 180 | flash[:notice] = l(:notice_successful_create) |
|
182 | 181 | redirect_to :action => 'settings', :tab => 'versions', :id => @project |
|
183 | 182 | end |
|
184 | 183 | end |
|
185 | 184 | |
|
186 | 185 | # Bulk edit issues |
|
187 | 186 | def bulk_edit_issues |
|
188 | 187 | if request.post? |
|
189 | 188 | status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id]) |
|
190 | 189 | priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id]) |
|
191 | 190 | assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id]) |
|
192 | 191 | category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id]) |
|
193 | 192 | fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id]) |
|
194 | 193 | issues = @project.issues.find_all_by_id(params[:issue_ids]) |
|
195 | 194 | unsaved_issue_ids = [] |
|
196 | 195 | issues.each do |issue| |
|
197 | 196 | journal = issue.init_journal(User.current, params[:notes]) |
|
198 | 197 | issue.priority = priority if priority |
|
199 | 198 | issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none' |
|
200 | 199 | issue.category = category if category |
|
201 | 200 | issue.fixed_version = fixed_version if fixed_version |
|
202 | 201 | issue.start_date = params[:start_date] unless params[:start_date].blank? |
|
203 | 202 | issue.due_date = params[:due_date] unless params[:due_date].blank? |
|
204 | 203 | issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? |
|
205 | 204 | # Don't save any change to the issue if the user is not authorized to apply the requested status |
|
206 | 205 | if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save |
|
207 | 206 | # Send notification for each issue (if changed) |
|
208 | 207 | Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated') |
|
209 | 208 | else |
|
210 | 209 | # Keep unsaved issue ids to display them in flash error |
|
211 | 210 | unsaved_issue_ids << issue.id |
|
212 | 211 | end |
|
213 | 212 | end |
|
214 | 213 | if unsaved_issue_ids.empty? |
|
215 | 214 | flash[:notice] = l(:notice_successful_update) unless issues.empty? |
|
216 | 215 | else |
|
217 | 216 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
218 | 217 | end |
|
219 | 218 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
220 | 219 | return |
|
221 | 220 | end |
|
222 | 221 | # Find potential statuses the user could be allowed to switch issues to |
|
223 | 222 | @available_statuses = Workflow.find(:all, :include => :new_status, |
|
224 | 223 | :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq |
|
225 | 224 | render :update do |page| |
|
226 | 225 | page.hide 'query_form' |
|
227 | 226 | page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form' |
|
228 | 227 | end |
|
229 | 228 | end |
|
230 | 229 | |
|
231 | 230 | def move_issues |
|
232 | 231 | @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids] |
|
233 | 232 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues |
|
234 | 233 | |
|
235 | 234 | @projects = [] |
|
236 | 235 | # find projects to which the user is allowed to move the issue |
|
237 | 236 | if User.current.admin? |
|
238 | 237 | # admin is allowed to move issues to any active (visible) project |
|
239 | 238 | @projects = Project.find(:all, :conditions => Project.visible_by(User.current), :order => 'name') |
|
240 | 239 | else |
|
241 | 240 | User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:move_issues)} |
|
242 | 241 | end |
|
243 | 242 | @target_project = @projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id] |
|
244 | 243 | @target_project ||= @project |
|
245 | 244 | @trackers = @target_project.trackers |
|
246 | 245 | if request.post? |
|
247 | 246 | new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
|
248 | 247 | unsaved_issue_ids = [] |
|
249 | 248 | @issues.each do |issue| |
|
250 | 249 | unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) |
|
251 | 250 | end |
|
252 | 251 | if unsaved_issue_ids.empty? |
|
253 | 252 | flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
254 | 253 | else |
|
255 | 254 | flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
256 | 255 | end |
|
257 | 256 | redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
258 | 257 | return |
|
259 | 258 | end |
|
260 | 259 | render :layout => false if request.xhr? |
|
261 | 260 | end |
|
262 | 261 | |
|
263 | 262 | # Add a news to @project |
|
264 | 263 | def add_news |
|
265 | 264 | @news = News.new(:project => @project, :author => User.current) |
|
266 | 265 | if request.post? |
|
267 | 266 | @news.attributes = params[:news] |
|
268 | 267 | if @news.save |
|
269 | 268 | flash[:notice] = l(:notice_successful_create) |
|
270 | 269 | Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added') |
|
271 | 270 | redirect_to :controller => 'news', :action => 'index', :project_id => @project |
|
272 | 271 | end |
|
273 | 272 | end |
|
274 | 273 | end |
|
275 | 274 | |
|
276 | 275 | def add_file |
|
277 | 276 | if request.post? |
|
278 | 277 | @version = @project.versions.find_by_id(params[:version_id]) |
|
279 | 278 | attachments = attach_files(@version, params[:attachments]) |
|
280 | 279 | Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added') |
|
281 | 280 | redirect_to :controller => 'projects', :action => 'list_files', :id => @project |
|
282 | 281 | end |
|
283 | 282 | @versions = @project.versions.sort |
|
284 | 283 | end |
|
285 | 284 | |
|
286 | 285 | def list_files |
|
287 | 286 | @versions = @project.versions.sort |
|
288 | 287 | end |
|
289 | 288 | |
|
290 | 289 | # Show changelog for @project |
|
291 | 290 | def changelog |
|
292 | 291 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position') |
|
293 | 292 | retrieve_selected_tracker_ids(@trackers) |
|
294 | 293 | @versions = @project.versions.sort |
|
295 | 294 | end |
|
296 | 295 | |
|
297 | 296 | def roadmap |
|
298 | 297 | @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) |
|
299 | 298 | retrieve_selected_tracker_ids(@trackers) |
|
300 | 299 | @versions = @project.versions.sort |
|
301 | 300 | @versions = @versions.select {|v| !v.completed? } unless params[:completed] |
|
302 | 301 | end |
|
303 | 302 | |
|
304 | 303 | def activity |
|
305 | 304 | if params[:year] and params[:year].to_i > 1900 |
|
306 | 305 | @year = params[:year].to_i |
|
307 | 306 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
308 | 307 | @month = params[:month].to_i |
|
309 | 308 | end |
|
310 | 309 | end |
|
311 | 310 | @year ||= Date.today.year |
|
312 | 311 | @month ||= Date.today.month |
|
313 | 312 | |
|
314 | 313 | case params[:format] |
|
315 | 314 | when 'atom' |
|
316 | 315 | # 30 last days |
|
317 | 316 | @date_from = Date.today - 30 |
|
318 | 317 | @date_to = Date.today + 1 |
|
319 | 318 | else |
|
320 | 319 | # current month |
|
321 | 320 | @date_from = Date.civil(@year, @month, 1) |
|
322 | 321 | @date_to = @date_from >> 1 |
|
323 | 322 | end |
|
324 | 323 | |
|
325 | 324 | @event_types = %w(issues news files documents changesets wiki_pages messages) |
|
326 | 325 | @event_types.delete('wiki_pages') unless @project.wiki |
|
327 | 326 | @event_types.delete('changesets') unless @project.repository |
|
328 | 327 | @event_types.delete('messages') unless @project.boards.any? |
|
329 | 328 | # only show what the user is allowed to view |
|
330 | 329 | @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)} |
|
331 | 330 | |
|
332 | 331 | @scope = @event_types.select {|t| params["show_#{t}"]} |
|
333 | 332 | # default events if none is specified in parameters |
|
334 | 333 | @scope = (@event_types - %w(wiki_pages messages))if @scope.empty? |
|
335 | 334 | |
|
336 | 335 | @events = [] |
|
337 | 336 | |
|
338 | 337 | if @scope.include?('issues') |
|
339 | 338 | @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] ) |
|
340 | 339 | @events += @project.issues_status_changes(@date_from, @date_to) |
|
341 | 340 | end |
|
342 | 341 | |
|
343 | 342 | if @scope.include?('news') |
|
344 | 343 | @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author ) |
|
345 | 344 | end |
|
346 | 345 | |
|
347 | 346 | if @scope.include?('files') |
|
348 | 347 | @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 ) |
|
349 | 348 | end |
|
350 | 349 | |
|
351 | 350 | if @scope.include?('documents') |
|
352 | 351 | @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] ) |
|
353 | 352 | @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 ) |
|
354 | 353 | end |
|
355 | 354 | |
|
356 | 355 | if @scope.include?('wiki_pages') |
|
357 | 356 | select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " + |
|
358 | 357 | "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " + |
|
359 | 358 | "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " + |
|
360 | 359 | "#{WikiContent.versioned_table_name}.id" |
|
361 | 360 | joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " + |
|
362 | 361 | "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " |
|
363 | 362 | conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", |
|
364 | 363 | @project.id, @date_from, @date_to] |
|
365 | 364 | |
|
366 | 365 | @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions) |
|
367 | 366 | end |
|
368 | 367 | |
|
369 | 368 | if @scope.include?('changesets') |
|
370 | 369 | @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]) |
|
371 | 370 | end |
|
372 | 371 | |
|
373 | 372 | if @scope.include?('messages') |
|
374 | 373 | @events += Message.find(:all, |
|
375 | 374 | :include => [:board, :author], |
|
376 | 375 | :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to]) |
|
377 | 376 | end |
|
378 | 377 | |
|
379 | 378 | @events_by_day = @events.group_by(&:event_date) |
|
380 | 379 | |
|
381 | 380 | respond_to do |format| |
|
382 | 381 | format.html { render :layout => false if request.xhr? } |
|
383 | 382 | format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") } |
|
384 | 383 | end |
|
385 | 384 | end |
|
386 | 385 | |
|
387 | 386 | def calendar |
|
388 | 387 | @trackers = @project.rolled_up_trackers |
|
389 | 388 | retrieve_selected_tracker_ids(@trackers) |
|
390 | 389 | |
|
391 | 390 | if params[:year] and params[:year].to_i > 1900 |
|
392 | 391 | @year = params[:year].to_i |
|
393 | 392 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
394 | 393 | @month = params[:month].to_i |
|
395 | 394 | end |
|
396 | 395 | end |
|
397 | 396 | @year ||= Date.today.year |
|
398 | 397 | @month ||= Date.today.month |
|
399 | 398 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
400 | 399 | |
|
401 | 400 | events = [] |
|
402 | 401 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
403 | 402 | events += Issue.find(:all, |
|
404 | 403 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
405 | 404 | :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] |
|
406 | 405 | ) unless @selected_tracker_ids.empty? |
|
407 | 406 | end |
|
408 | 407 | events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
409 | 408 | @calendar.events = events |
|
410 | 409 | |
|
411 | 410 | render :layout => false if request.xhr? |
|
412 | 411 | end |
|
413 | 412 | |
|
414 | 413 | def gantt |
|
415 | 414 | @trackers = @project.rolled_up_trackers |
|
416 | 415 | retrieve_selected_tracker_ids(@trackers) |
|
417 | 416 | |
|
418 | 417 | if params[:year] and params[:year].to_i >0 |
|
419 | 418 | @year_from = params[:year].to_i |
|
420 | 419 | if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12 |
|
421 | 420 | @month_from = params[:month].to_i |
|
422 | 421 | else |
|
423 | 422 | @month_from = 1 |
|
424 | 423 | end |
|
425 | 424 | else |
|
426 | 425 | @month_from ||= Date.today.month |
|
427 | 426 | @year_from ||= Date.today.year |
|
428 | 427 | end |
|
429 | 428 | |
|
430 | 429 | zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i |
|
431 | 430 | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
|
432 | 431 | months = (params[:months] || User.current.pref[:gantt_months]).to_i |
|
433 | 432 | @months = (months > 0 && months < 25) ? months : 6 |
|
434 | 433 | |
|
435 | 434 | # Save gantt paramters as user preference (zoom and months count) |
|
436 | 435 | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) |
|
437 | 436 | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
|
438 | 437 | User.current.preference.save |
|
439 | 438 | end |
|
440 | 439 | |
|
441 | 440 | @date_from = Date.civil(@year_from, @month_from, 1) |
|
442 | 441 | @date_to = (@date_from >> @months) - 1 |
|
443 | 442 | |
|
444 | 443 | @events = [] |
|
445 | 444 | @project.issues_with_subprojects(params[:with_subprojects]) do |
|
446 | 445 | @events += Issue.find(:all, |
|
447 | 446 | :order => "start_date, due_date", |
|
448 | 447 | :include => [:tracker, :status, :assigned_to, :priority, :project], |
|
449 | 448 | :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] |
|
450 | 449 | ) unless @selected_tracker_ids.empty? |
|
451 | 450 | end |
|
452 | 451 | @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
453 | 452 | @events.sort! {|x,y| x.start_date <=> y.start_date } |
|
454 | 453 | |
|
455 | 454 | if params[:format]=='pdf' |
|
456 | 455 | @options_for_rfpdf ||= {} |
|
457 | 456 | @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf" |
|
458 | 457 | render :template => "projects/gantt.rfpdf", :layout => false |
|
459 | 458 | elsif params[:format]=='png' && respond_to?('gantt_image') |
|
460 | 459 | image = gantt_image(@events, @date_from, @months, @zoom) |
|
461 | 460 | image.format = 'PNG' |
|
462 | 461 | send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") |
|
463 | 462 | else |
|
464 | 463 | render :template => "projects/gantt.rhtml" |
|
465 | 464 | end |
|
466 | 465 | end |
|
467 | 466 | |
|
468 | 467 | private |
|
469 | 468 | # Find project of id params[:id] |
|
470 | 469 | # if not found, redirect to project list |
|
471 | 470 | # Used as a before_filter |
|
472 | 471 | def find_project |
|
473 | 472 | @project = Project.find(params[:id]) |
|
474 | 473 | rescue ActiveRecord::RecordNotFound |
|
475 | 474 | render_404 |
|
476 | 475 | end |
|
477 | 476 | |
|
478 | 477 | def retrieve_selected_tracker_ids(selectable_trackers) |
|
479 | 478 | if ids = params[:tracker_ids] |
|
480 | 479 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
481 | 480 | else |
|
482 | 481 | @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s } |
|
483 | 482 | end |
|
484 | 483 | end |
|
485 | 484 | end |
@@ -1,52 +1,53 | |||
|
1 | 1 | <%= error_messages_for 'project' %> |
|
2 | 2 | |
|
3 | 3 | <div class="box"> |
|
4 | 4 | <!--[form:project]--> |
|
5 | 5 | <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p> |
|
6 | 6 | |
|
7 | 7 | <% if User.current.admin? and !@root_projects.empty? %> |
|
8 | 8 | <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p> |
|
9 | 9 | <% end %> |
|
10 | 10 | |
|
11 | 11 | <p><%= f.text_area :description, :required => true, :cols => 60, :rows => 5 %><em><%= l(:text_caracters_maximum, 255) %></em></p> |
|
12 | 12 | <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %><br /><em><%= l(:text_length_between, 3, 20) %> <%= l(:text_project_identifier_info) unless @project.identifier_frozen? %></em></p> |
|
13 | 13 | <p><%= f.text_field :homepage, :size => 40 %></p> |
|
14 | 14 | <p><%= f.check_box :is_public %></p> |
|
15 | 15 | <%= wikitoolbar_for 'project_description' %> |
|
16 | 16 | |
|
17 | 17 | <% for @custom_value in @custom_values %> |
|
18 | 18 | <p><%= custom_field_tag_with_label @custom_value %></p> |
|
19 | 19 | <% end %> |
|
20 | 20 | </div> |
|
21 | 21 | |
|
22 | 22 | <% unless @trackers.empty? %> |
|
23 | 23 | <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend> |
|
24 | 24 | <% @trackers.each do |tracker| %> |
|
25 | 25 | <label class="floating"> |
|
26 | 26 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> |
|
27 | 27 | <%= tracker %> |
|
28 | 28 | </label> |
|
29 | 29 | <% end %> |
|
30 | 30 | <%= hidden_field_tag 'project[tracker_ids][]', '' %> |
|
31 | 31 | </fieldset> |
|
32 | 32 | <% end %> |
|
33 | 33 | |
|
34 | 34 | <% unless @custom_fields.empty? %> |
|
35 | 35 | <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend> |
|
36 | 36 | <% for custom_field in @custom_fields %> |
|
37 | 37 | <label class="floating"> |
|
38 |
<%= check_box_tag |
|
|
38 | <%= check_box_tag 'project[custom_field_ids][]', custom_field.id, ((@project.custom_fields.include? custom_field) or custom_field.is_for_all?), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %> | |
|
39 | 39 | <%= custom_field.name %> |
|
40 | 40 | </label> |
|
41 | 41 | <% end %> |
|
42 | <%= hidden_field_tag 'project[custom_field_ids][]', '' %> | |
|
42 | 43 | </fieldset> |
|
43 | 44 | <% end %> |
|
44 | 45 | <!--[eoform:project]--> |
|
45 | 46 | |
|
46 | 47 | |
|
47 | 48 | <% content_for :header_tags do %> |
|
48 | 49 | <%= javascript_include_tag 'calendar/calendar' %> |
|
49 | 50 | <%= javascript_include_tag "calendar/lang/calendar-#{current_language}.js" %> |
|
50 | 51 | <%= javascript_include_tag 'calendar/calendar-setup' %> |
|
51 | 52 | <%= stylesheet_link_tag 'calendar' %> |
|
52 | 53 | <% end %> |
@@ -1,239 +1,240 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'projects_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = ProjectsController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_index |
|
34 | 34 | get :index |
|
35 | 35 | assert_response :success |
|
36 | 36 | assert_template 'list' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def test_list |
|
40 | 40 | get :list |
|
41 | 41 | assert_response :success |
|
42 | 42 | assert_template 'list' |
|
43 | 43 | assert_not_nil assigns(:project_tree) |
|
44 | 44 | # Root project as hash key |
|
45 | 45 | assert assigns(:project_tree).has_key?(Project.find(1)) |
|
46 | 46 | # Subproject in corresponding value |
|
47 | 47 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def test_show_by_id |
|
51 | 51 | get :show, :id => 1 |
|
52 | 52 | assert_response :success |
|
53 | 53 | assert_template 'show' |
|
54 | 54 | assert_not_nil assigns(:project) |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def test_show_by_identifier |
|
58 | 58 | get :show, :id => 'ecookbook' |
|
59 | 59 | assert_response :success |
|
60 | 60 | assert_template 'show' |
|
61 | 61 | assert_not_nil assigns(:project) |
|
62 | 62 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_settings |
|
66 | 66 | @request.session[:user_id] = 2 # manager |
|
67 | 67 | get :settings, :id => 1 |
|
68 | 68 | assert_response :success |
|
69 | 69 | assert_template 'settings' |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def test_edit |
|
73 | 73 | @request.session[:user_id] = 2 # manager |
|
74 |
post :edit, :id => 1, :project => {:name => 'Test changed name' |
|
|
74 | post :edit, :id => 1, :project => {:name => 'Test changed name', | |
|
75 | :custom_field_ids => ['']} | |
|
75 | 76 | assert_redirected_to 'projects/settings/ecookbook' |
|
76 | 77 | project = Project.find(1) |
|
77 | 78 | assert_equal 'Test changed name', project.name |
|
78 | 79 | end |
|
79 | 80 | |
|
80 | 81 | def test_get_destroy |
|
81 | 82 | @request.session[:user_id] = 1 # admin |
|
82 | 83 | get :destroy, :id => 1 |
|
83 | 84 | assert_response :success |
|
84 | 85 | assert_template 'destroy' |
|
85 | 86 | assert_not_nil Project.find_by_id(1) |
|
86 | 87 | end |
|
87 | 88 | |
|
88 | 89 | def test_post_destroy |
|
89 | 90 | @request.session[:user_id] = 1 # admin |
|
90 | 91 | post :destroy, :id => 1, :confirm => 1 |
|
91 | 92 | assert_redirected_to 'admin/projects' |
|
92 | 93 | assert_nil Project.find_by_id(1) |
|
93 | 94 | end |
|
94 | 95 | |
|
95 | 96 | def test_bulk_edit_issues |
|
96 | 97 | @request.session[:user_id] = 2 |
|
97 | 98 | # update issues priority |
|
98 | 99 | post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' |
|
99 | 100 | assert_response 302 |
|
100 | 101 | # check that the issues were updated |
|
101 | 102 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
102 | 103 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
103 | 104 | end |
|
104 | 105 | |
|
105 | 106 | def test_move_issues_to_another_project |
|
106 | 107 | @request.session[:user_id] = 1 |
|
107 | 108 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 |
|
108 | 109 | assert_redirected_to 'projects/ecookbook/issues' |
|
109 | 110 | assert_equal 2, Issue.find(1).project_id |
|
110 | 111 | assert_equal 2, Issue.find(2).project_id |
|
111 | 112 | end |
|
112 | 113 | |
|
113 | 114 | def test_move_issues_to_another_tracker |
|
114 | 115 | @request.session[:user_id] = 1 |
|
115 | 116 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 2 |
|
116 | 117 | assert_redirected_to 'projects/ecookbook/issues' |
|
117 | 118 | assert_equal 2, Issue.find(1).tracker_id |
|
118 | 119 | assert_equal 2, Issue.find(2).tracker_id |
|
119 | 120 | end |
|
120 | 121 | |
|
121 | 122 | def test_list_files |
|
122 | 123 | get :list_files, :id => 1 |
|
123 | 124 | assert_response :success |
|
124 | 125 | assert_template 'list_files' |
|
125 | 126 | assert_not_nil assigns(:versions) |
|
126 | 127 | end |
|
127 | 128 | |
|
128 | 129 | def test_changelog |
|
129 | 130 | get :changelog, :id => 1 |
|
130 | 131 | assert_response :success |
|
131 | 132 | assert_template 'changelog' |
|
132 | 133 | assert_not_nil assigns(:versions) |
|
133 | 134 | end |
|
134 | 135 | |
|
135 | 136 | def test_roadmap |
|
136 | 137 | get :roadmap, :id => 1 |
|
137 | 138 | assert_response :success |
|
138 | 139 | assert_template 'roadmap' |
|
139 | 140 | assert_not_nil assigns(:versions) |
|
140 | 141 | # Version with no date set appears |
|
141 | 142 | assert assigns(:versions).include?(Version.find(3)) |
|
142 | 143 | # Completed version doesn't appear |
|
143 | 144 | assert !assigns(:versions).include?(Version.find(1)) |
|
144 | 145 | end |
|
145 | 146 | |
|
146 | 147 | def test_roadmap_with_completed_versions |
|
147 | 148 | get :roadmap, :id => 1, :completed => 1 |
|
148 | 149 | assert_response :success |
|
149 | 150 | assert_template 'roadmap' |
|
150 | 151 | assert_not_nil assigns(:versions) |
|
151 | 152 | # Version with no date set appears |
|
152 | 153 | assert assigns(:versions).include?(Version.find(3)) |
|
153 | 154 | # Completed version appears |
|
154 | 155 | assert assigns(:versions).include?(Version.find(1)) |
|
155 | 156 | end |
|
156 | 157 | |
|
157 | 158 | def test_activity |
|
158 | 159 | get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month |
|
159 | 160 | assert_response :success |
|
160 | 161 | assert_template 'activity' |
|
161 | 162 | assert_not_nil assigns(:events_by_day) |
|
162 | 163 | |
|
163 | 164 | assert_tag :tag => "h3", |
|
164 | 165 | :content => /#{2.days.ago.to_date.day}/, |
|
165 | 166 | :sibling => { :tag => "ul", |
|
166 | 167 | :child => { :tag => "li", |
|
167 | 168 | :child => { :tag => "p", |
|
168 | 169 | :content => /(#{IssueStatus.find(2).name})/, |
|
169 | 170 | } |
|
170 | 171 | } |
|
171 | 172 | } |
|
172 | 173 | |
|
173 | 174 | get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month |
|
174 | 175 | assert_response :success |
|
175 | 176 | assert_template 'activity' |
|
176 | 177 | assert_not_nil assigns(:events_by_day) |
|
177 | 178 | |
|
178 | 179 | assert_tag :tag => "h3", |
|
179 | 180 | :content => /#{3.day.ago.to_date.day}/, |
|
180 | 181 | :sibling => { :tag => "ul", |
|
181 | 182 | :child => { :tag => "li", |
|
182 | 183 | :child => { :tag => "p", |
|
183 | 184 | :content => /#{Issue.find(1).subject}/, |
|
184 | 185 | } |
|
185 | 186 | } |
|
186 | 187 | } |
|
187 | 188 | end |
|
188 | 189 | |
|
189 | 190 | def test_calendar |
|
190 | 191 | get :calendar, :id => 1 |
|
191 | 192 | assert_response :success |
|
192 | 193 | assert_template 'calendar' |
|
193 | 194 | assert_not_nil assigns(:calendar) |
|
194 | 195 | end |
|
195 | 196 | |
|
196 | 197 | def test_calendar_with_subprojects |
|
197 | 198 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
198 | 199 | assert_response :success |
|
199 | 200 | assert_template 'calendar' |
|
200 | 201 | assert_not_nil assigns(:calendar) |
|
201 | 202 | end |
|
202 | 203 | |
|
203 | 204 | def test_gantt |
|
204 | 205 | get :gantt, :id => 1 |
|
205 | 206 | assert_response :success |
|
206 | 207 | assert_template 'gantt.rhtml' |
|
207 | 208 | assert_not_nil assigns(:events) |
|
208 | 209 | end |
|
209 | 210 | |
|
210 | 211 | def test_gantt_with_subprojects |
|
211 | 212 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
212 | 213 | assert_response :success |
|
213 | 214 | assert_template 'gantt.rhtml' |
|
214 | 215 | assert_not_nil assigns(:events) |
|
215 | 216 | end |
|
216 | 217 | |
|
217 | 218 | def test_gantt_export_to_pdf |
|
218 | 219 | get :gantt, :id => 1, :format => 'pdf' |
|
219 | 220 | assert_response :success |
|
220 | 221 | assert_template 'gantt.rfpdf' |
|
221 | 222 | assert_equal 'application/pdf', @response.content_type |
|
222 | 223 | assert_not_nil assigns(:events) |
|
223 | 224 | end |
|
224 | 225 | |
|
225 | 226 | def test_archive |
|
226 | 227 | @request.session[:user_id] = 1 # admin |
|
227 | 228 | post :archive, :id => 1 |
|
228 | 229 | assert_redirected_to 'admin/projects' |
|
229 | 230 | assert !Project.find(1).active? |
|
230 | 231 | end |
|
231 | 232 | |
|
232 | 233 | def test_unarchive |
|
233 | 234 | @request.session[:user_id] = 1 # admin |
|
234 | 235 | Project.find(1).archive |
|
235 | 236 | post :unarchive, :id => 1 |
|
236 | 237 | assert_redirected_to 'admin/projects' |
|
237 | 238 | assert Project.find(1).active? |
|
238 | 239 | end |
|
239 | 240 | end |
General Comments 0
You need to be logged in to leave comments.
Login now