diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 8c02f947..51e70ddf 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 3f92d8d4..3bdb6e2e 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 << "\n" + end + end + s << "
  • " + s << yield(project).to_s + ancestors << project + end + s << ("
  • \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 856b70bb..d8d35ba3 100644 --- a/app/views/trackers/_form.rhtml +++ b/app/views/trackers/_form.rhtml @@ -1,5 +1,7 @@ <%= error_messages_for 'tracker' %> -
    + +
    +

    <%= f.text_field :name, :required => true %>

    <%= f.check_box :is_in_chlog %>

    @@ -10,3 +12,16 @@ <% end %>
    +
    + +
    +<% if @projects.any? %> +
    <%= l(:label_project_plural) %> +<%= 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) %> +

    <%= check_all_links 'tracker_project_ids' %>

    +
    +<% end %> +
    diff --git a/app/views/trackers/edit.rhtml b/app/views/trackers/edit.rhtml index d8411099..038acc86 100644 --- a/app/views/trackers/edit.rhtml +++ b/app/views/trackers/edit.rhtml @@ -1,6 +1,6 @@

    <%=l(:label_tracker)%>

    -<% 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 b318a5dc..3f8384cd 100644 --- a/app/views/trackers/new.rhtml +++ b/app/views/trackers/new.rhtml @@ -1,6 +1,6 @@

    <%=l(:label_tracker_new)%>

    -<% 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 1b453966..76add4f2 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 00000000..89bbf228 --- /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