Revision 2335
Added by Jean-Philippe Lang over 16 years ago
trunk/app/controllers/trackers_controller.rb | ||
---|---|---|
40 | 40 |
end |
41 | 41 |
flash[:notice] = l(:notice_successful_create) |
42 | 42 |
redirect_to :action => 'list' |
43 |
return |
|
43 | 44 |
end |
44 | 45 |
@trackers = Tracker.find :all, :order => 'position' |
46 |
@projects = Project.find(:all) |
|
45 | 47 |
end |
46 | 48 |
|
47 | 49 |
def edit |
... | ... | |
49 | 51 |
if request.post? and @tracker.update_attributes(params[:tracker]) |
50 | 52 |
flash[:notice] = l(:notice_successful_update) |
51 | 53 |
redirect_to :action => 'list' |
54 |
return |
|
52 | 55 |
end |
56 |
@projects = Project.find(:all) |
|
53 | 57 |
end |
54 | 58 |
|
55 | 59 |
def move |
trunk/app/helpers/application_helper.rb | ||
---|---|---|
195 | 195 |
ancestors << project |
196 | 196 |
end |
197 | 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 | 223 |
# Truncates and returns the string as a single line |
200 | 224 |
def truncate_single_line(string, *args) |
trunk/app/views/trackers/_form.rhtml | ||
---|---|---|
1 | 1 |
<%= error_messages_for 'tracker' %> |
2 |
<div class="box"> |
|
2 |
|
|
3 |
<div class="splitcontentleft"> |
|
4 |
<div class="box tabular"> |
|
3 | 5 |
<!--[form:tracker]--> |
4 | 6 |
<p><%= f.text_field :name, :required => true %></p> |
5 | 7 |
<p><%= f.check_box :is_in_chlog %></p> |
... | ... | |
10 | 12 |
<% end %> |
11 | 13 |
<!--[eoform:tracker]--> |
12 | 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> |
trunk/app/views/trackers/edit.rhtml | ||
---|---|---|
1 | 1 |
<h2><%=l(:label_tracker)%></h2> |
2 | 2 |
|
3 |
<% labelled_tabular_form_for :tracker, @tracker, :url => { :action => 'edit' } do |f| %>
|
|
3 |
<% form_for :tracker, @tracker, :url => { :action => 'edit' }, :builder => TabularFormBuilder do |f| %>
|
|
4 | 4 |
<%= render :partial => 'form', :locals => { :f => f } %> |
5 | 5 |
<%= submit_tag l(:button_save) %> |
6 |
<% end %> |
|
6 |
<% end %> |
trunk/app/views/trackers/new.rhtml | ||
---|---|---|
1 | 1 |
<h2><%=l(:label_tracker_new)%></h2> |
2 | 2 |
|
3 |
<% labelled_tabular_form_for :tracker, @tracker, :url => { :action => 'new' } do |f| %>
|
|
3 |
<% form_for :tracker, @tracker, :url => { :action => 'new' }, :builder => TabularFormBuilder do |f| %>
|
|
4 | 4 |
<%= render :partial => 'form', :locals => { :f => f } %> |
5 | 5 |
<%= submit_tag l(:button_create) %> |
6 |
<% end %> |
|
6 |
<% end %> |
trunk/public/stylesheets/application.css | ||
---|---|---|
247 | 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 | 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 | 253 |
ul.properties {padding:0; font-size: 0.9em; color: #777;} |
251 | 254 |
ul.properties li {list-style-type:none;} |
252 | 255 |
ul.properties li span {font-style:italic;} |
trunk/test/functional/trackers_controller_test.rb | ||
---|---|---|
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 |
|
0 | 69 |
Also available in: Unified diff
Adds projects association on tracker form (#2578).