]> source.dussan.org Git - redmine.git/commitdiff
Adds dynamic columns selection on the issue list (#4272).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Nov 2009 11:34:12 +0000 (11:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Nov 2009 11:34:12 +0000 (11:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3105 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/query.rb
app/views/issues/index.rhtml
app/views/queries/_columns.rhtml
app/views/queries/_form.rhtml
test/functional/issues_controller_test.rb

index bbd0f801cf370886d3a0a562a8efa7dbadf9157e..d0a34d7bfd9ecd5386b5c606e382c9c32e466f2f 100644 (file)
@@ -501,10 +501,11 @@ private
           end
         end
         @query.group_by = params[:group_by]
-        session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by}
+        @query.column_names = params[:query] && params[:query][:column_names]
+        session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
       else
         @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
-        @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by])
+        @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
         @query.project = @project
       end
     end
index 2e0ddc48996d66611acd320df89f3acb9698b4ac..c691736e90cf2f5d5a5fc1acec3a94a4e4b7a55e 100644 (file)
@@ -270,8 +270,14 @@ class Query < ActiveRecord::Base
   end
   
   def column_names=(names)
-    names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names
-    names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } if names
+    if names
+      names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
+      names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym }
+      # Set column_names to nil if default columns
+      if names.map(&:to_s) == Setting.issue_list_default_columns
+        names = nil
+      end
+    end
     write_attribute(:column_names, names)
   end
   
index 5eddb7052d06e1f68bb54ac4f7c4ed134528d8ae..5b8fa05a7585fefcc5b04652671040185feed1e2 100644 (file)
     <fieldset class="collapsible collapsed">
        <legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
        <div style="display: none;">
-                               <%= l(:field_group_by) %>
-                               <%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %>
+               <table>
+                       <tr>
+                               <td><%= l(:field_column_names) %></td>
+                                               <td><%= render :partial => 'queries/columns', :locals => {:query => @query} %></td>
+                                       </tr>
+                                       <tr>
+                                               <td><%= l(:field_group_by) %></td>
+                                               <td><%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %></td>
+                                       </tr>
+                               </table>
                        </div>
                </fieldset>
                </div>
@@ -29,6 +37,7 @@
 
     <%= link_to_remote l(:button_apply), 
                        { :url => { :set_filter => 1 },
+                         :before => 'selectAllOptions("selected_columns");',
                          :update => "content",
                          :with => "Form.serialize('query_form')"
                        }, :class => 'icon icon-checked' %>
@@ -40,7 +49,7 @@
                        }, :class => 'icon icon-reload'  %>
                        
     <% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %>
-    <%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
+    <%= link_to l(:button_save), {}, :onclick => "selectAllOptions('selected_columns'); $('query_form').submit(); return false;", :class => 'icon icon-save' %>
     <% end %>
     </p>
 <% end %>
index 1a481adae65fd5b3fb2bf9510574873a735c79a2..e11b286b62028b10927963bb5149367efe867287 100644 (file)
@@ -1,10 +1,6 @@
-<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
-<legend><%= l(:field_column_names) %></legend>
-
-<%= hidden_field_tag 'query[column_names][]', '', :id => nil %>
-<table>
+<table style="border-collapse: collapse; border:0;">
        <tr>
-               <td><%= select_tag 'available_columns',
+               <td style="padding-left:0"><%= select_tag 'available_columns',
                          options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
                          :multiple => true, :size => 10, :style => "width:150px" %>
                </td>
                         onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
                </td>
                <td><%= select_tag 'query[column_names][]',
-                         options_for_select(@query.columns.collect {|column| [column.caption, column.name]}),
+                         options_for_select(query.columns.collect {|column| [column.caption, column.name]}),
                          :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
                </td>
        </tr>
 </table>
-<% end %>
 
 <% content_for :header_tags do %>
 <%= javascript_include_tag 'select_list_move' %>
index 577699d70d9af81a11c95f151e6c75c5763dc5a3..dcafe9f604118e442b2d01292ae072d5d8f8784f 100644 (file)
@@ -37,5 +37,9 @@
 <% end %>
 </fieldset>
 
+<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %>
+<legend><%= l(:field_column_names) %></legend>
 <%= render :partial => 'queries/columns', :locals => {:query => query}%>
+<% end %>
+
 </div>
index 3ece848b703c39c9d044ca5e9588bd4f52acfe12..9555db4ea7fd485446afb86e363950f4c44ccd8b 100644 (file)
@@ -255,6 +255,22 @@ class IssuesControllerTest < ActionController::TestCase
     assert !issues.empty?
     assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
   end
+  
+  def test_index_with_columns
+    columns = ['tracker', 'subject', 'assigned_to']
+    get :index, :set_filter => 1, :query => { 'column_names' => columns}
+    assert_response :success
+    
+    # query should use specified columns
+    query = assigns(:query)
+    assert_kind_of Query, query
+    assert_equal columns, query.column_names.map(&:to_s)
+    
+    # columns should be stored in session
+    assert_kind_of Hash, session[:query]
+    assert_kind_of Array, session[:query][:column_names]
+    assert_equal columns, session[:query][:column_names].map(&:to_s)
+  end
 
   def test_gantt
     get :gantt, :project_id => 1