summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-29 14:22:56 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-29 14:22:56 +0000
commit945ec8942a4c43ed41aa4302cbe74ad45f1ff08c (patch)
tree2e2f45b48ee4277e6e1920d094c337a7b7191738
parent32d4378198b83a10bab53c8e7cee2e4ec8adb818 (diff)
downloadredmine-945ec8942a4c43ed41aa4302cbe74ad45f1ff08c.tar.gz
redmine-945ec8942a4c43ed41aa4302cbe74ad45f1ff08c.zip
Adds projects association on tracker form (#2578).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2335 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/trackers_controller.rb4
-rw-r--r--app/helpers/application_helper.rb24
-rw-r--r--app/views/trackers/_form.rhtml17
-rw-r--r--app/views/trackers/edit.rhtml4
-rw-r--r--app/views/trackers/new.rhtml4
-rw-r--r--public/stylesheets/application.css3
-rw-r--r--test/functional/trackers_controller_test.rb68
7 files changed, 119 insertions, 5 deletions
diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb
index 8c02f9474..51e70ddf4 100644
--- a/app/controllers/trackers_controller.rb
+++ b/app/controllers/trackers_controller.rb
@@ -40,8 +40,10 @@ class TrackersController < ApplicationController
end
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list'
+ return
end
@trackers = Tracker.find :all, :order => 'position'
+ @projects = Project.find(:all)
end
def edit
@@ -49,7 +51,9 @@ class TrackersController < ApplicationController
if request.post? and @tracker.update_attributes(params[:tracker])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'list'
+ return
end
+ @projects = Project.find(:all)
end
def move
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3f92d8d4b..3bdb6e2eb 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -195,6 +195,30 @@ module ApplicationHelper
ancestors << project
end
end
+
+ def project_nested_ul(projects, &block)
+ s = ''
+ if projects.any?
+ ancestors = []
+ projects.sort_by(&:lft).each do |project|
+ if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
+ s << "<ul>\n"
+ else
+ ancestors.pop
+ s << "</li>"
+ while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
+ ancestors.pop
+ s << "</ul></li>\n"
+ end
+ end
+ s << "<li>"
+ s << yield(project).to_s
+ ancestors << project
+ end
+ s << ("</li></ul>\n" * ancestors.size)
+ end
+ s
+ end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
diff --git a/app/views/trackers/_form.rhtml b/app/views/trackers/_form.rhtml
index 856b70bbc..d8d35ba36 100644
--- a/app/views/trackers/_form.rhtml
+++ b/app/views/trackers/_form.rhtml
@@ -1,5 +1,7 @@
<%= error_messages_for 'tracker' %>
-<div class="box">
+
+<div class="splitcontentleft">
+<div class="box tabular">
<!--[form:tracker]-->
<p><%= f.text_field :name, :required => true %></p>
<p><%= f.check_box :is_in_chlog %></p>
@@ -10,3 +12,16 @@
<% end %>
<!--[eoform:tracker]-->
</div>
+</div>
+
+<div class="splitcontentright">
+<% if @projects.any? %>
+<fieldset class="box" id="tracker_project_ids"><legend><%= l(:label_project_plural) %></legend>
+<%= project_nested_ul(@projects) do |p|
+ content_tag('label', check_box_tag('tracker[project_ids][]', p.id, @tracker.projects.include?(p), :id => nil) + ' ' + h(p))
+end %>
+<%= hidden_field_tag('tracker[project_ids][]', '', :id => nil) %>
+<p><%= check_all_links 'tracker_project_ids' %></p>
+</fieldset>
+<% end %>
+</div>
diff --git a/app/views/trackers/edit.rhtml b/app/views/trackers/edit.rhtml
index d8411099c..038acc86e 100644
--- a/app/views/trackers/edit.rhtml
+++ b/app/views/trackers/edit.rhtml
@@ -1,6 +1,6 @@
<h2><%=l(:label_tracker)%></h2>
-<% labelled_tabular_form_for :tracker, @tracker, :url => { :action => 'edit' } do |f| %>
+<% form_for :tracker, @tracker, :url => { :action => 'edit' }, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/app/views/trackers/new.rhtml b/app/views/trackers/new.rhtml
index b318a5dc4..3f8384cdd 100644
--- a/app/views/trackers/new.rhtml
+++ b/app/views/trackers/new.rhtml
@@ -1,6 +1,6 @@
<h2><%=l(:label_tracker_new)%></h2>
-<% labelled_tabular_form_for :tracker, @tracker, :url => { :action => 'new' } do |f| %>
+<% form_for :tracker, @tracker, :url => { :action => 'new' }, :builder => TabularFormBuilder do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
-<% end %> \ No newline at end of file
+<% end %>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 1b453966c..76add4f25 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -247,6 +247,9 @@ ul.projects li.child { margin-top: 1em;}
ul.projects div.root a.project { font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold; font-size: 16px; margin: 0 0 10px 0; }
.my-project { padding-left: 18px; background: url(../images/fav.png) no-repeat 0 50%; }
+#tracker_project_ids ul { margin: 0; padding-left: 1em; }
+#tracker_project_ids li { list-style-type:none; }
+
ul.properties {padding:0; font-size: 0.9em; color: #777;}
ul.properties li {list-style-type:none;}
ul.properties li span {font-style:italic;}
diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb
new file mode 100644
index 000000000..89bbf228f
--- /dev/null
+++ b/test/functional/trackers_controller_test.rb
@@ -0,0 +1,68 @@
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../test_helper'
+require 'trackers_controller'
+
+# Re-raise errors caught by the controller.
+class TrackersController; def rescue_action(e) raise e end; end
+
+class TrackersControllerTest < Test::Unit::TestCase
+ fixtures :trackers, :projects, :projects_trackers, :users
+
+ def setup
+ @controller = TrackersController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ User.current = nil
+ @request.session[:user_id] = 1 # admin
+ end
+
+ def test_get_edit
+ Tracker.find(1).project_ids = [1, 3]
+
+ get :edit, :id => 1
+ assert_response :success
+ assert_template 'edit'
+
+ assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
+ :value => '1',
+ :checked => 'checked' }
+
+ assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
+ :value => '2',
+ :checked => nil }
+
+ assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
+ :value => '',
+ :type => 'hidden'}
+ end
+
+ def test_post_edit
+ post :edit, :id => 1, :tracker => { :name => 'Renamed',
+ :project_ids => ['1', '2', ''] }
+ assert_redirected_to '/trackers/list'
+ assert_equal [1, 2], Tracker.find(1).project_ids.sort
+ end
+
+ def test_post_edit_without_projects
+ post :edit, :id => 1, :tracker => { :name => 'Renamed',
+ :project_ids => [''] }
+ assert_redirected_to '/trackers/list'
+ assert Tracker.find(1).project_ids.empty?
+ end
+end