]> source.dussan.org Git - redmine.git/commitdiff
Adds a view for editing all trackers fields.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Sep 2012 16:55:16 +0000 (16:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Sep 2012 16:55:16 +0000 (16:55 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10283 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/trackers_controller.rb
app/views/trackers/fields.html.erb [new file with mode: 0644]
app/views/trackers/index.html.erb
config/routes.rb
test/functional/trackers_controller_test.rb
test/integration/routing/trackers_test.rb

index 5d4bfcaf1bcd57112d4d08ed75bdb9b9a3377495..074514d9674a6c6b477cd99b07feab368f9d34c4 100644 (file)
@@ -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 (file)
index 0000000..a487211
--- /dev/null
@@ -0,0 +1,77 @@
+<h2><%= link_to l(:label_tracker_plural), trackers_path %> &#187; <%= l(:field_summary) %></h2>
+
+<% if @trackers.any? %>
+  <%= form_tag({}) do %>
+    <div class="autoscroll">
+    <table class="list">
+    <thead>
+      <tr>
+        <th></th>
+        <% @trackers.each do |tracker| %>
+        <th>
+          <%= tracker.name %>
+          <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.tracker-#{tracker.id}')",
+                                                              :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
+        </th>
+        <% end %>
+      </tr>
+    </thead>
+    <tbody>
+      <tr class="group open">
+        <td colspan="<%= @trackers.size + 1 %>">
+          <span class="expander" onclick="toggleRowGroup(this);">&nbsp;</span>
+          <%= l(:field_core_fields) %>
+        </td>
+      </tr>
+      <% Tracker::CORE_FIELDS.each do |field| %>
+      <tr class="<%= cycle("odd", "even") %>">
+        <td>
+          <%= 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$/, '')) %>
+        </td>
+        <% @trackers.each do |tracker| %>
+        <td align="center">
+          <%= check_box_tag "trackers[#{tracker.id}][core_fields][]", field, tracker.core_fields.include?(field),
+                            :class => "tracker-#{tracker.id} core-field-#{field}" %>
+        </td>
+        <% end %>
+      </tr>
+      <% end %>
+      <% if @custom_fields.any? %>
+        <tr class="group open">
+          <td colspan="<%= @trackers.size + 1 %>">
+            <span class="expander" onclick="toggleRowGroup(this);">&nbsp;</span>
+            <%= l(:label_custom_field_plural) %>
+          </td>
+        </tr>
+        <% @custom_fields.each do |field| %>
+        <tr class="<%= cycle("odd", "even") %>">
+          <td>
+            <%= 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 %>
+          </td>
+          <% @trackers.each do |tracker| %>
+          <td align="center">
+            <%= check_box_tag "trackers[#{tracker.id}][custom_field_ids][]", field.id, tracker.custom_fields.include?(field),
+                              :class => "tracker-#{tracker.id} custom-field-#{field.id}" %>
+          </td>
+          <% end %>
+        </tr>
+        <% end %>
+      <% end %>
+    </tbody>
+    </table>
+    </div>
+    <p><%= submit_tag l(:button_save) %></p>
+    <% @trackers.each do |tracker| %>
+      <%= hidden_field_tag "trackers[#{tracker.id}][core_fields][]", '' %>
+      <%= hidden_field_tag "trackers[#{tracker.id}][custom_field_ids][]", '' %>
+    <% end %>
+  <% end %>
+<% else %>
+  <p class="nodata"><%= l(:label_no_data) %></p>
+<% end %>
+
+<% html_title l(:field_summary) %>
index 4d10d857e71a6dd2d38f5c376f7964e7eacd6566..b3840dba703944305014a8e53ccd514d43877c93 100644 (file)
@@ -1,5 +1,6 @@
 <div class="contextual">
 <%= link_to l(:label_tracker_new), new_tracker_path, :class => 'icon icon-add' %>
+<%= link_to l(:field_summary), {:action => 'fields'}, :class => 'icon icon-summary' %>
 </div>
 
 <h2><%=l(:label_tracker_plural)%></h2>
index d904c9b9ef84b10c321d9801fe9449e65c7529a7..a7e0bdc568d6607bc3d65972b4c90653fc3309b0 100644 (file)
@@ -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'
index caa1ec9ebb87723b23c02b76f179d9187786b545..9a8ec54b0aebcfdcd0a27a709508681f65124432 100644 (file)
@@ -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
index 4b75bf52ebd0adfe96e6553aec38929271388599..42bb574a9f1d83840a6fc6f65e1b6e5d76e21572 100644 (file)
@@ -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