diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 5d4bfcaf1..074514d96 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -80,4 +80,22 @@ class TrackersController < ApplicationController end redirect_to :action => 'index' end + + def fields + if request.post? && params[:trackers] + params[:trackers].each do |tracker_id, tracker_params| + tracker = Tracker.find_by_id(tracker_id) + if tracker + tracker.core_fields = tracker_params[:core_fields] + tracker.custom_field_ids = tracker_params[:custom_field_ids] + tracker.save + end + end + flash[:notice] = l(:notice_successful_update) + redirect_to :action => 'fields' + return + end + @trackers = Tracker.sorted.all + @custom_fields = IssueCustomField.all.sort + end end diff --git a/app/views/trackers/fields.html.erb b/app/views/trackers/fields.html.erb new file mode 100644 index 000000000..a4872112f --- /dev/null +++ b/app/views/trackers/fields.html.erb @@ -0,0 +1,77 @@ +

<%= link_to l(:label_tracker_plural), trackers_path %> » <%= l(:field_summary) %>

+ +<% if @trackers.any? %> + <%= form_tag({}) do %> +
+ + + + + <% @trackers.each do |tracker| %> + + <% end %> + + + + + + + <% Tracker::CORE_FIELDS.each do |field| %> + "> + + <% @trackers.each do |tracker| %> + + <% end %> + + <% end %> + <% if @custom_fields.any? %> + + + + <% @custom_fields.each do |field| %> + "> + + <% @trackers.each do |tracker| %> + + <% end %> + + <% end %> + <% end %> + +
+ <%= tracker.name %> + <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.tracker-#{tracker.id}')", + :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %> +
+   + <%= l(:field_core_fields) %> +
+ <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.core-field-#{field}')", + :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %> + <%= l("field_#{field}".sub(/_id$/, '')) %> + + <%= check_box_tag "trackers[#{tracker.id}][core_fields][]", field, tracker.core_fields.include?(field), + :class => "tracker-#{tracker.id} core-field-#{field}" %> +
+   + <%= l(:label_custom_field_plural) %> +
+ <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.custom-field-#{field.id}')", + :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %> + <%= field.name %> + + <%= check_box_tag "trackers[#{tracker.id}][custom_field_ids][]", field.id, tracker.custom_fields.include?(field), + :class => "tracker-#{tracker.id} custom-field-#{field.id}" %> +
+
+

<%= submit_tag l(:button_save) %>

+ <% @trackers.each do |tracker| %> + <%= hidden_field_tag "trackers[#{tracker.id}][core_fields][]", '' %> + <%= hidden_field_tag "trackers[#{tracker.id}][custom_field_ids][]", '' %> + <% end %> + <% end %> +<% else %> +

<%= l(:label_no_data) %>

+<% end %> + +<% html_title l(:field_summary) %> diff --git a/app/views/trackers/index.html.erb b/app/views/trackers/index.html.erb index 4d10d857e..b3840dba7 100644 --- a/app/views/trackers/index.html.erb +++ b/app/views/trackers/index.html.erb @@ -1,5 +1,6 @@
<%= link_to l(:label_tracker_new), new_tracker_path, :class => 'icon icon-add' %> +<%= link_to l(:field_summary), {:action => 'fields'}, :class => 'icon icon-summary' %>

<%=l(:label_tracker_plural)%>

diff --git a/config/routes.rb b/config/routes.rb index d904c9b9e..a7e0bdc56 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -278,7 +278,11 @@ RedmineApp::Application.routes.draw do match 'groups/destroy_membership/:id', :controller => 'groups', :action => 'destroy_membership', :id => /\d+/, :via => :post match 'groups/edit_membership/:id', :controller => 'groups', :action => 'edit_membership', :id => /\d+/, :via => :post - resources :trackers, :except => :show + resources :trackers, :except => :show do + collection do + match 'fields', :via => [:get, :post] + end + end resources :issue_statuses, :except => :show do collection do post 'update_issue_done_ratio' diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index caa1ec9eb..9a8ec54b0 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -185,4 +185,34 @@ class TrackersControllerTest < ActionController::TestCase assert_redirected_to :action => 'index' assert_not_nil flash[:error] end + + def test_get_fields + get :fields + assert_response :success + assert_template 'fields' + + assert_select 'form' do + assert_select 'input[type=checkbox][name=?][value=assigned_to_id]', 'trackers[1][core_fields][]' + assert_select 'input[type=checkbox][name=?][value=2]', 'trackers[1][custom_field_ids][]' + + assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][core_fields][]' + assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][custom_field_ids][]' + end + end + + def test_post_fields + post :fields, :trackers => { + '1' => {'core_fields' => ['assigned_to_id', 'due_date', ''], 'custom_field_ids' => ['1', '2']}, + '2' => {'core_fields' => [''], 'custom_field_ids' => ['']} + } + assert_redirected_to '/trackers/fields' + + tracker = Tracker.find(1) + assert_equal %w(assigned_to_id due_date), tracker.core_fields + assert_equal [1, 2], tracker.custom_field_ids.sort + + tracker = Tracker.find(2) + assert_equal [], tracker.core_fields + assert_equal [], tracker.custom_field_ids.sort + end end diff --git a/test/integration/routing/trackers_test.rb b/test/integration/routing/trackers_test.rb index 4b75bf52e..42bb574a9 100644 --- a/test/integration/routing/trackers_test.rb +++ b/test/integration/routing/trackers_test.rb @@ -67,5 +67,13 @@ class RoutingTrackersTest < ActionController::IntegrationTest { :controller => 'trackers', :action => 'destroy', :format => 'xml', :id => '1' } ) + assert_routing( + { :method => 'get', :path => "/trackers/fields" }, + { :controller => 'trackers', :action => 'fields' } + ) + assert_routing( + { :method => 'post', :path => "/trackers/fields" }, + { :controller => 'trackers', :action => 'fields' } + ) end end