##// END OF EJS Templates
Refactor: move method, ProjectsController#roadmap to VersionsController#index....
Eric Davis -
r3936:a188abbe2813
parent child
Show More
@@ -287,30 +287,6 class ProjectsController < ApplicationController
287 287 render :layout => !request.xhr?
288 288 end
289 289
290 def roadmap
291 @trackers = @project.trackers.find(:all, :order => 'position')
292 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
293 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
294 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
295
296 @versions = @project.shared_versions || []
297 @versions += @project.rolled_up_versions.visible if @with_subprojects
298 @versions = @versions.uniq.sort
299 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
300
301 @issues_by_version = {}
302 unless @selected_tracker_ids.empty?
303 @versions.each do |version|
304 issues = version.fixed_issues.visible.find(:all,
305 :include => [:project, :status, :tracker, :priority],
306 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
307 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
308 @issues_by_version[version] = issues
309 end
310 end
311 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
312 end
313
314 290 private
315 291 def find_optional_project
316 292 return true unless params[:id]
@@ -320,14 +296,6 private
320 296 render_404
321 297 end
322 298
323 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
324 if ids = params[:tracker_ids]
325 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
326 else
327 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
328 end
329 end
330
331 299 # Validates parent_id param according to user's permissions
332 300 # TODO: move it to Project model in a validation that depends on User.current
333 301 def validate_parent_id
@@ -18,13 +18,37
18 18 class VersionsController < ApplicationController
19 19 menu_item :roadmap
20 20 model_object Version
21 before_filter :find_model_object, :except => [:new, :close_completed]
22 before_filter :find_project_from_association, :except => [:new, :close_completed]
23 before_filter :find_project, :only => [:new, :close_completed]
21 before_filter :find_model_object, :except => [:index, :new, :close_completed]
22 before_filter :find_project_from_association, :except => [:index, :new, :close_completed]
23 before_filter :find_project, :only => [:index, :new, :close_completed]
24 24 before_filter :authorize
25 25
26 26 helper :custom_fields
27 27 helper :projects
28
29 def index
30 @trackers = @project.trackers.find(:all, :order => 'position')
31 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
32 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
33 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
34
35 @versions = @project.shared_versions || []
36 @versions += @project.rolled_up_versions.visible if @with_subprojects
37 @versions = @versions.uniq.sort
38 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
39
40 @issues_by_version = {}
41 unless @selected_tracker_ids.empty?
42 @versions.each do |version|
43 issues = version.fixed_issues.visible.find(:all,
44 :include => [:project, :status, :tracker, :priority],
45 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
46 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
47 @issues_by_version[version] = issues
48 end
49 end
50 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
51 end
28 52
29 53 def show
30 54 @issues = @version.fixed_issues.visible.find(:all,
@@ -105,4 +129,13 private
105 129 rescue ActiveRecord::RecordNotFound
106 130 render_404
107 131 end
132
133 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
134 if ids = params[:tracker_ids]
135 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
136 else
137 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
138 end
139 end
140
108 141 end
1 NO CONTENT: file renamed from app/views/projects/roadmap.rhtml to app/views/versions/index.html.erb
@@ -180,7 +180,7 ActionController::Routing::Routes.draw do |map|
180 180 project_views.connect 'projects/new', :action => 'add'
181 181 project_views.connect 'projects/:id', :action => 'show'
182 182 project_views.connect 'projects/:id.:format', :action => 'show'
183 project_views.connect 'projects/:id/:action', :action => /roadmap|destroy|settings/
183 project_views.connect 'projects/:id/:action', :action => /destroy|settings/
184 184 project_views.connect 'projects/:id/files', :action => 'list_files'
185 185 project_views.connect 'projects/:id/files/new', :action => 'add_file'
186 186 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
@@ -215,6 +215,7 ActionController::Routing::Routes.draw do |map|
215 215
216 216 map.with_options :controller => 'versions' do |versions|
217 217 versions.connect 'projects/:project_id/versions/new', :action => 'new'
218 versions.connect 'projects/:project_id/roadmap', :action => 'index'
218 219 versions.with_options :conditions => {:method => :post} do |version_actions|
219 220 version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed'
220 221 end
@@ -57,11 +57,10 Redmine::AccessControl.map do |map|
57 57 # Issue categories
58 58 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
59 59 # Issues
60 map.permission :view_issues, {:projects => :roadmap,
61 :issues => [:index, :show],
60 map.permission :view_issues, {:issues => [:index, :show],
62 61 :auto_complete => [:issues],
63 62 :context_menus => [:issues],
64 :versions => [:show, :status_by],
63 :versions => [:index, :show, :status_by],
65 64 :journals => :index,
66 65 :queries => :index,
67 66 :reports => [:issue_report, :issue_report_details]}
@@ -186,7 +185,7 end
186 185 Redmine::MenuManager.map :project_menu do |menu|
187 186 menu.push :overview, { :controller => 'projects', :action => 'show' }
188 187 menu.push :activity, { :controller => 'activities', :action => 'index' }
189 menu.push :roadmap, { :controller => 'projects', :action => 'roadmap' },
188 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
190 189 :if => Proc.new { |p| p.shared_versions.any? }
191 190 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
192 191 menu.push :new_issue, { :controller => 'issues', :action => 'new' }, :param => :project_id, :caption => :label_issue_new,
@@ -368,38 +368,6 class ProjectsControllerTest < ActionController::TestCase
368 368 :attributes => { :href => '/attachments/download/9/version_file.zip' }
369 369 end
370 370
371 def test_roadmap
372 get :roadmap, :id => 1
373 assert_response :success
374 assert_template 'roadmap'
375 assert_not_nil assigns(:versions)
376 # Version with no date set appears
377 assert assigns(:versions).include?(Version.find(3))
378 # Completed version doesn't appear
379 assert !assigns(:versions).include?(Version.find(1))
380 end
381
382 def test_roadmap_with_completed_versions
383 get :roadmap, :id => 1, :completed => 1
384 assert_response :success
385 assert_template 'roadmap'
386 assert_not_nil assigns(:versions)
387 # Version with no date set appears
388 assert assigns(:versions).include?(Version.find(3))
389 # Completed version appears
390 assert assigns(:versions).include?(Version.find(1))
391 end
392
393 def test_roadmap_showing_subprojects_versions
394 @subproject_version = Version.generate!(:project => Project.find(3))
395 get :roadmap, :id => 1, :with_subprojects => 1
396 assert_response :success
397 assert_template 'roadmap'
398 assert_not_nil assigns(:versions)
399
400 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
401 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
402 end
403 371 def test_archive
404 372 @request.session[:user_id] = 1 # admin
405 373 post :archive, :id => 1
@@ -31,6 +31,39 class VersionsControllerTest < ActionController::TestCase
31 31 User.current = nil
32 32 end
33 33
34 def test_index
35 get :index, :project_id => 1
36 assert_response :success
37 assert_template 'index'
38 assert_not_nil assigns(:versions)
39 # Version with no date set appears
40 assert assigns(:versions).include?(Version.find(3))
41 # Completed version doesn't appear
42 assert !assigns(:versions).include?(Version.find(1))
43 end
44
45 def test_index_with_completed_versions
46 get :index, :project_id => 1, :completed => 1
47 assert_response :success
48 assert_template 'index'
49 assert_not_nil assigns(:versions)
50 # Version with no date set appears
51 assert assigns(:versions).include?(Version.find(3))
52 # Completed version appears
53 assert assigns(:versions).include?(Version.find(1))
54 end
55
56 def test_index_showing_subprojects_versions
57 @subproject_version = Version.generate!(:project => Project.find(3))
58 get :index, :project_id => 1, :with_subprojects => 1
59 assert_response :success
60 assert_template 'index'
61 assert_not_nil assigns(:versions)
62
63 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
64 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
65 end
66
34 67 def test_show
35 68 get :show, :id => 2
36 69 assert_response :success
@@ -174,7 +174,7 class RoutingTest < ActionController::IntegrationTest
174 174 should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
175 175 should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33'
176 176 should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
177 should_route :get, "/projects/33/roadmap", :controller => 'projects', :action => 'roadmap', :id => '33'
177 should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
178 178 should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
179 179 should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom'
180 180
General Comments 0
You need to be logged in to leave comments. Login now