@@ -0,0 +1,68 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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 | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | require 'trackers_controller' | |||
|
20 | ||||
|
21 | # Re-raise errors caught by the controller. | |||
|
22 | class TrackersController; def rescue_action(e) raise e end; end | |||
|
23 | ||||
|
24 | class TrackersControllerTest < Test::Unit::TestCase | |||
|
25 | fixtures :trackers, :projects, :projects_trackers, :users | |||
|
26 | ||||
|
27 | def setup | |||
|
28 | @controller = TrackersController.new | |||
|
29 | @request = ActionController::TestRequest.new | |||
|
30 | @response = ActionController::TestResponse.new | |||
|
31 | User.current = nil | |||
|
32 | @request.session[:user_id] = 1 # admin | |||
|
33 | end | |||
|
34 | ||||
|
35 | def test_get_edit | |||
|
36 | Tracker.find(1).project_ids = [1, 3] | |||
|
37 | ||||
|
38 | get :edit, :id => 1 | |||
|
39 | assert_response :success | |||
|
40 | assert_template 'edit' | |||
|
41 | ||||
|
42 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | |||
|
43 | :value => '1', | |||
|
44 | :checked => 'checked' } | |||
|
45 | ||||
|
46 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | |||
|
47 | :value => '2', | |||
|
48 | :checked => nil } | |||
|
49 | ||||
|
50 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', | |||
|
51 | :value => '', | |||
|
52 | :type => 'hidden'} | |||
|
53 | end | |||
|
54 | ||||
|
55 | def test_post_edit | |||
|
56 | post :edit, :id => 1, :tracker => { :name => 'Renamed', | |||
|
57 | :project_ids => ['1', '2', ''] } | |||
|
58 | assert_redirected_to '/trackers/list' | |||
|
59 | assert_equal [1, 2], Tracker.find(1).project_ids.sort | |||
|
60 | end | |||
|
61 | ||||
|
62 | def test_post_edit_without_projects | |||
|
63 | post :edit, :id => 1, :tracker => { :name => 'Renamed', | |||
|
64 | :project_ids => [''] } | |||
|
65 | assert_redirected_to '/trackers/list' | |||
|
66 | assert Tracker.find(1).project_ids.empty? | |||
|
67 | end | |||
|
68 | end |
@@ -40,8 +40,10 class TrackersController < ApplicationController | |||||
40 | end |
|
40 | end | |
41 | flash[:notice] = l(:notice_successful_create) |
|
41 | flash[:notice] = l(:notice_successful_create) | |
42 | redirect_to :action => 'list' |
|
42 | redirect_to :action => 'list' | |
|
43 | return | |||
43 | end |
|
44 | end | |
44 | @trackers = Tracker.find :all, :order => 'position' |
|
45 | @trackers = Tracker.find :all, :order => 'position' | |
|
46 | @projects = Project.find(:all) | |||
45 | end |
|
47 | end | |
46 |
|
48 | |||
47 | def edit |
|
49 | def edit | |
@@ -49,7 +51,9 class TrackersController < ApplicationController | |||||
49 | if request.post? and @tracker.update_attributes(params[:tracker]) |
|
51 | if request.post? and @tracker.update_attributes(params[:tracker]) | |
50 | flash[:notice] = l(:notice_successful_update) |
|
52 | flash[:notice] = l(:notice_successful_update) | |
51 | redirect_to :action => 'list' |
|
53 | redirect_to :action => 'list' | |
|
54 | return | |||
52 | end |
|
55 | end | |
|
56 | @projects = Project.find(:all) | |||
53 | end |
|
57 | end | |
54 |
|
58 | |||
55 | def move |
|
59 | def move |
@@ -195,6 +195,30 module ApplicationHelper | |||||
195 | ancestors << project |
|
195 | ancestors << project | |
196 | end |
|
196 | end | |
197 | end |
|
197 | end | |
|
198 | ||||
|
199 | def project_nested_ul(projects, &block) | |||
|
200 | s = '' | |||
|
201 | if projects.any? | |||
|
202 | ancestors = [] | |||
|
203 | projects.sort_by(&:lft).each do |project| | |||
|
204 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) | |||
|
205 | s << "<ul>\n" | |||
|
206 | else | |||
|
207 | ancestors.pop | |||
|
208 | s << "</li>" | |||
|
209 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) | |||
|
210 | ancestors.pop | |||
|
211 | s << "</ul></li>\n" | |||
|
212 | end | |||
|
213 | end | |||
|
214 | s << "<li>" | |||
|
215 | s << yield(project).to_s | |||
|
216 | ancestors << project | |||
|
217 | end | |||
|
218 | s << ("</li></ul>\n" * ancestors.size) | |||
|
219 | end | |||
|
220 | s | |||
|
221 | end | |||
198 |
|
222 | |||
199 | # Truncates and returns the string as a single line |
|
223 | # Truncates and returns the string as a single line | |
200 | def truncate_single_line(string, *args) |
|
224 | def truncate_single_line(string, *args) |
@@ -1,5 +1,7 | |||||
1 | <%= error_messages_for 'tracker' %> |
|
1 | <%= error_messages_for 'tracker' %> | |
2 | <div class="box"> |
|
2 | ||
|
3 | <div class="splitcontentleft"> | |||
|
4 | <div class="box tabular"> | |||
3 | <!--[form:tracker]--> |
|
5 | <!--[form:tracker]--> | |
4 | <p><%= f.text_field :name, :required => true %></p> |
|
6 | <p><%= f.text_field :name, :required => true %></p> | |
5 | <p><%= f.check_box :is_in_chlog %></p> |
|
7 | <p><%= f.check_box :is_in_chlog %></p> | |
@@ -10,3 +12,16 | |||||
10 | <% end %> |
|
12 | <% end %> | |
11 | <!--[eoform:tracker]--> |
|
13 | <!--[eoform:tracker]--> | |
12 | </div> |
|
14 | </div> | |
|
15 | </div> | |||
|
16 | ||||
|
17 | <div class="splitcontentright"> | |||
|
18 | <% if @projects.any? %> | |||
|
19 | <fieldset class="box" id="tracker_project_ids"><legend><%= l(:label_project_plural) %></legend> | |||
|
20 | <%= project_nested_ul(@projects) do |p| | |||
|
21 | content_tag('label', check_box_tag('tracker[project_ids][]', p.id, @tracker.projects.include?(p), :id => nil) + ' ' + h(p)) | |||
|
22 | end %> | |||
|
23 | <%= hidden_field_tag('tracker[project_ids][]', '', :id => nil) %> | |||
|
24 | <p><%= check_all_links 'tracker_project_ids' %></p> | |||
|
25 | </fieldset> | |||
|
26 | <% end %> | |||
|
27 | </div> |
@@ -1,6 +1,6 | |||||
1 | <h2><%=l(:label_tracker)%></h2> |
|
1 | <h2><%=l(:label_tracker)%></h2> | |
2 |
|
2 | |||
3 |
<% |
|
3 | <% form_for :tracker, @tracker, :url => { :action => 'edit' }, :builder => TabularFormBuilder do |f| %> | |
4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
4 | <%= render :partial => 'form', :locals => { :f => f } %> | |
5 | <%= submit_tag l(:button_save) %> |
|
5 | <%= submit_tag l(:button_save) %> | |
6 | <% end %> No newline at end of file |
|
6 | <% end %> |
@@ -1,6 +1,6 | |||||
1 | <h2><%=l(:label_tracker_new)%></h2> |
|
1 | <h2><%=l(:label_tracker_new)%></h2> | |
2 |
|
2 | |||
3 |
<% |
|
3 | <% form_for :tracker, @tracker, :url => { :action => 'new' }, :builder => TabularFormBuilder do |f| %> | |
4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
4 | <%= render :partial => 'form', :locals => { :f => f } %> | |
5 | <%= submit_tag l(:button_create) %> |
|
5 | <%= submit_tag l(:button_create) %> | |
6 | <% end %> No newline at end of file |
|
6 | <% end %> |
@@ -247,6 +247,9 ul.projects li.child { margin-top: 1em;} | |||||
247 | ul.projects div.root a.project { font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold; font-size: 16px; margin: 0 0 10px 0; } |
|
247 | ul.projects div.root a.project { font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold; font-size: 16px; margin: 0 0 10px 0; } | |
248 | .my-project { padding-left: 18px; background: url(../images/fav.png) no-repeat 0 50%; } |
|
248 | .my-project { padding-left: 18px; background: url(../images/fav.png) no-repeat 0 50%; } | |
249 |
|
249 | |||
|
250 | #tracker_project_ids ul { margin: 0; padding-left: 1em; } | |||
|
251 | #tracker_project_ids li { list-style-type:none; } | |||
|
252 | ||||
250 | ul.properties {padding:0; font-size: 0.9em; color: #777;} |
|
253 | ul.properties {padding:0; font-size: 0.9em; color: #777;} | |
251 | ul.properties li {list-style-type:none;} |
|
254 | ul.properties li {list-style-type:none;} | |
252 | ul.properties li span {font-style:italic;} |
|
255 | ul.properties li span {font-style:italic;} |
General Comments 0
You need to be logged in to leave comments.
Login now