Adds projects association on tracker form (#2578).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2335 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
32d4378198
commit
945ec8942a
|
@ -40,8 +40,10 @@ class TrackersController < ApplicationController
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'list'
|
||||||
|
return
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find :all, :order => 'position'
|
@trackers = Tracker.find :all, :order => 'position'
|
||||||
|
@projects = Project.find(:all)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@ -49,7 +51,9 @@ class TrackersController < ApplicationController
|
||||||
if request.post? and @tracker.update_attributes(params[:tracker])
|
if request.post? and @tracker.update_attributes(params[:tracker])
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'list'
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
@projects = Project.find(:all)
|
||||||
end
|
end
|
||||||
|
|
||||||
def move
|
def move
|
||||||
|
|
|
@ -195,6 +195,30 @@ module ApplicationHelper
|
||||||
ancestors << project
|
ancestors << project
|
||||||
end
|
end
|
||||||
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
|
# Truncates and returns the string as a single line
|
||||||
def truncate_single_line(string, *args)
|
def truncate_single_line(string, *args)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<%= error_messages_for 'tracker' %>
|
<%= error_messages_for 'tracker' %>
|
||||||
<div class="box">
|
|
||||||
|
<div class="splitcontentleft">
|
||||||
|
<div class="box tabular">
|
||||||
<!--[form:tracker]-->
|
<!--[form:tracker]-->
|
||||||
<p><%= f.text_field :name, :required => true %></p>
|
<p><%= f.text_field :name, :required => true %></p>
|
||||||
<p><%= f.check_box :is_in_chlog %></p>
|
<p><%= f.check_box :is_in_chlog %></p>
|
||||||
|
@ -10,3 +12,16 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<!--[eoform:tracker]-->
|
<!--[eoform:tracker]-->
|
||||||
</div>
|
</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>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2><%=l(:label_tracker)%></h2>
|
<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 } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_save) %>
|
<%= submit_tag l(:button_save) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2><%=l(:label_tracker_new)%></h2>
|
<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 } %>
|
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||||
<%= submit_tag l(:button_create) %>
|
<%= submit_tag l(:button_create) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -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; }
|
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%; }
|
.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 {padding:0; font-size: 0.9em; color: #777;}
|
||||||
ul.properties li {list-style-type:none;}
|
ul.properties li {list-style-type:none;}
|
||||||
ul.properties li span {font-style:italic;}
|
ul.properties li span {font-style:italic;}
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue