@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -22,9 +22,8 class TrackersController < ApplicationController | |||||
22 | list |
|
22 | list | |
23 | render :action => 'list' unless request.xhr? |
|
23 | render :action => 'list' unless request.xhr? | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
26 | verify :method => :post, :only => :destroy, :redirect_to => { :action => :list } | |
27 | verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list } |
|
|||
28 |
|
27 | |||
29 | def list |
|
28 | def list | |
30 | @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position' |
|
29 | @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position' | |
@@ -55,21 +54,6 class TrackersController < ApplicationController | |||||
55 | end |
|
54 | end | |
56 | @projects = Project.find(:all) |
|
55 | @projects = Project.find(:all) | |
57 | end |
|
56 | end | |
58 |
|
||||
59 | def move |
|
|||
60 | @tracker = Tracker.find(params[:id]) |
|
|||
61 | case params[:position] |
|
|||
62 | when 'highest' |
|
|||
63 | @tracker.move_to_top |
|
|||
64 | when 'higher' |
|
|||
65 | @tracker.move_higher |
|
|||
66 | when 'lower' |
|
|||
67 | @tracker.move_lower |
|
|||
68 | when 'lowest' |
|
|||
69 | @tracker.move_to_bottom |
|
|||
70 | end if params[:position] |
|
|||
71 | redirect_to :action => 'list' |
|
|||
72 | end |
|
|||
73 |
|
57 | |||
74 | def destroy |
|
58 | def destroy | |
75 | @tracker = Tracker.find(params[:id]) |
|
59 | @tracker = Tracker.find(params[:id]) |
@@ -265,6 +265,13 module ApplicationHelper | |||||
265 | end |
|
265 | end | |
266 | links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil |
|
266 | links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil | |
267 | end |
|
267 | end | |
|
268 | ||||
|
269 | def reorder_links(name, url) | |||
|
270 | link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) + | |||
|
271 | link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) + | |||
|
272 | link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :title => l(:label_sort_lower)) + | |||
|
273 | link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), :method => :post, :title => l(:label_sort_lowest)) | |||
|
274 | end | |||
268 |
|
275 | |||
269 | def breadcrumb(*args) |
|
276 | def breadcrumb(*args) | |
270 | elements = args.flatten |
|
277 | elements = args.flatten |
@@ -16,12 +16,7 | |||||
16 | <tr class="<%= cycle("odd", "even") %>"> |
|
16 | <tr class="<%= cycle("odd", "even") %>"> | |
17 | <td><%= link_to tracker.name, :action => 'edit', :id => tracker %></td> |
|
17 | <td><%= link_to tracker.name, :action => 'edit', :id => tracker %></td> | |
18 | <td align="center"><% unless tracker.workflows.count > 0 %><span class="icon icon-warning"><%= l(:text_tracker_no_workflow) %> (<%= link_to l(:button_edit), {:controller => 'workflows', :action => 'edit', :tracker_id => tracker} %>)</span><% end %></td> |
|
18 | <td align="center"><% unless tracker.workflows.count > 0 %><span class="icon icon-warning"><%= l(:text_tracker_no_workflow) %> (<%= link_to l(:button_edit), {:controller => 'workflows', :action => 'edit', :tracker_id => tracker} %>)</span><% end %></td> | |
19 | <td align="center" style="width:15%;"> |
|
19 | <td align="center" style="width:15%;"><%= reorder_links('tracker', {:action => 'edit', :id => tracker}) %></td> | |
20 | <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => tracker, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %> |
|
|||
21 | <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => tracker, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> - |
|
|||
22 | <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => tracker, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %> |
|
|||
23 | <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => tracker, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %> |
|
|||
24 | </td> |
|
|||
25 | <td align="center" style="width:10%;"> |
|
20 | <td align="center" style="width:10%;"> | |
26 | <%= button_to l(:button_delete), { :action => 'destroy', :id => tracker }, :confirm => l(:text_are_you_sure), :class => "button-small" %> |
|
21 | <%= button_to l(:button_delete), { :action => 'destroy', :id => tracker }, :confirm => l(:text_are_you_sure), :class => "button-small" %> | |
27 | </td> |
|
22 | </td> |
@@ -22,7 +22,7 require 'trackers_controller' | |||||
22 | class TrackersController; def rescue_action(e) raise e end; end |
|
22 | class TrackersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class TrackersControllerTest < Test::Unit::TestCase |
|
24 | class TrackersControllerTest < Test::Unit::TestCase | |
25 | fixtures :trackers, :projects, :projects_trackers, :users |
|
25 | fixtures :trackers, :projects, :projects_trackers, :users, :issues | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = TrackersController.new |
|
28 | @controller = TrackersController.new | |
@@ -32,6 +32,34 class TrackersControllerTest < Test::Unit::TestCase | |||||
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
|
35 | def test_index | |||
|
36 | get :index | |||
|
37 | assert_response :success | |||
|
38 | assert_template 'list' | |||
|
39 | end | |||
|
40 | ||||
|
41 | def test_get_new | |||
|
42 | get :new | |||
|
43 | assert_response :success | |||
|
44 | assert_template 'new' | |||
|
45 | end | |||
|
46 | ||||
|
47 | def test_post_new | |||
|
48 | post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''] } | |||
|
49 | assert_redirected_to '/trackers/list' | |||
|
50 | tracker = Tracker.find_by_name('New tracker') | |||
|
51 | assert_equal [1], tracker.project_ids.sort | |||
|
52 | assert_equal 0, tracker.workflows.count | |||
|
53 | end | |||
|
54 | ||||
|
55 | def test_post_new_with_workflow_copy | |||
|
56 | post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 | |||
|
57 | assert_redirected_to '/trackers/list' | |||
|
58 | tracker = Tracker.find_by_name('New tracker') | |||
|
59 | assert_equal 0, tracker.projects.count | |||
|
60 | assert_equal Tracker.find(1).workflows.count, tracker.workflows.count | |||
|
61 | end | |||
|
62 | ||||
35 | def test_get_edit |
|
63 | def test_get_edit | |
36 | Tracker.find(1).project_ids = [1, 3] |
|
64 | Tracker.find(1).project_ids = [1, 3] | |
37 |
|
65 | |||
@@ -65,4 +93,27 class TrackersControllerTest < Test::Unit::TestCase | |||||
65 | assert_redirected_to '/trackers/list' |
|
93 | assert_redirected_to '/trackers/list' | |
66 | assert Tracker.find(1).project_ids.empty? |
|
94 | assert Tracker.find(1).project_ids.empty? | |
67 | end |
|
95 | end | |
|
96 | ||||
|
97 | def test_move_lower | |||
|
98 | tracker = Tracker.find_by_position(1) | |||
|
99 | post :edit, :id => 1, :tracker => { :move_to => 'lower' } | |||
|
100 | assert_equal 2, tracker.reload.position | |||
|
101 | end | |||
|
102 | ||||
|
103 | def test_destroy | |||
|
104 | tracker = Tracker.create!(:name => 'Destroyable') | |||
|
105 | assert_difference 'Tracker.count', -1 do | |||
|
106 | post :destroy, :id => tracker.id | |||
|
107 | end | |||
|
108 | assert_redirected_to '/trackers/list' | |||
|
109 | assert_nil flash[:error] | |||
|
110 | end | |||
|
111 | ||||
|
112 | def test_destroy_tracker_in_use | |||
|
113 | assert_no_difference 'Tracker.count' do | |||
|
114 | post :destroy, :id => 1 | |||
|
115 | end | |||
|
116 | assert_redirected_to '/trackers/list' | |||
|
117 | assert_not_nil flash[:error] | |||
|
118 | end | |||
68 | end |
|
119 | end |
@@ -118,6 +118,20 module ActiveRecord | |||||
118 | assume_top_position |
|
118 | assume_top_position | |
119 | end |
|
119 | end | |
120 | end |
|
120 | end | |
|
121 | ||||
|
122 | # Move to the given position | |||
|
123 | def move_to=(pos) | |||
|
124 | case pos.to_s | |||
|
125 | when 'highest' | |||
|
126 | move_to_top | |||
|
127 | when 'higher' | |||
|
128 | move_higher | |||
|
129 | when 'lower' | |||
|
130 | move_lower | |||
|
131 | when 'lowest' | |||
|
132 | move_to_bottom | |||
|
133 | end | |||
|
134 | end | |||
121 |
|
135 | |||
122 | # Removes the item from the list. |
|
136 | # Removes the item from the list. | |
123 | def remove_from_list |
|
137 | def remove_from_list |
General Comments 0
You need to be logged in to leave comments.
Login now