]> source.dussan.org Git - redmine.git/commitdiff
Adds projects association on tracker form (#2578).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 29 Jan 2009 14:22:56 +0000 (14:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 29 Jan 2009 14:22:56 +0000 (14:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2335 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/trackers_controller.rb
app/helpers/application_helper.rb
app/views/trackers/_form.rhtml
app/views/trackers/edit.rhtml
app/views/trackers/new.rhtml
public/stylesheets/application.css
test/functional/trackers_controller_test.rb [new file with mode: 0644]

index 8c02f9474d8c6dbff87b7f3880104916ff6147d9..51e70ddf411d8b4c4aa025952d39712aac1952fd 100644 (file)
@@ -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
index 3f92d8d4b342d8034e08c2a3523633c9a4b4a7fb..3bdb6e2eb381a7b922784c5c4483199f944d0df3 100644 (file)
@@ -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)
index 856b70bbcaa8a9b2bc6f6c5e9c8ea9cef31c7a1a..d8d35ba36f01bdb0341fa08cae110906e14a13a2 100644 (file)
@@ -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>
 <% 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>
index d8411099c514f953b4b334715612b37dabd8f899..038acc86e157bbf02a1814d189aa88a444fb5322 100644 (file)
@@ -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 %>
index b318a5dc40270700625865ca8db3981ea76246ad..3f8384cdd623a095f5d5469ef7e0263028da3826 100644 (file)
@@ -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 %>
index 1b453966cd968b1ff35a9aa1c3ebe994ecf88802..76add4f2564a78697caf5173771b177a8173869b 100644 (file)
@@ -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 (file)
index 0000000..89bbf22
--- /dev/null
@@ -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