Adds dynamic columns selection on the issue list (#4272).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3105 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-11-28 11:34:12 +00:00
parent 99b52c8796
commit 66540afc08
6 changed files with 46 additions and 15 deletions

View File

@ -501,10 +501,11 @@ private
end end
end end
@query.group_by = params[:group_by] @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 else
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id] @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 @query.project = @project
end end
end end

View File

@ -270,8 +270,14 @@ class Query < ActiveRecord::Base
end end
def column_names=(names) def column_names=(names)
names = names.select {|n| n.is_a?(Symbol) || !n.blank? } if names if names
names = names.collect {|n| n.is_a?(Symbol) ? n : n.to_sym } 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) write_attribute(:column_names, names)
end end

View File

@ -20,8 +20,16 @@
<fieldset class="collapsible collapsed"> <fieldset class="collapsible collapsed">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend> <legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div style="display: none;"> <div style="display: none;">
<%= l(:field_group_by) %> <table>
<%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %> <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> </div>
</fieldset> </fieldset>
</div> </div>
@ -29,6 +37,7 @@
<%= link_to_remote l(:button_apply), <%= link_to_remote l(:button_apply),
{ :url => { :set_filter => 1 }, { :url => { :set_filter => 1 },
:before => 'selectAllOptions("selected_columns");',
:update => "content", :update => "content",
:with => "Form.serialize('query_form')" :with => "Form.serialize('query_form')"
}, :class => 'icon icon-checked' %> }, :class => 'icon icon-checked' %>
@ -40,7 +49,7 @@
}, :class => 'icon icon-reload' %> }, :class => 'icon icon-reload' %>
<% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %> <% 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 %> <% end %>
</p> </p>
<% end %> <% end %>

View File

@ -1,10 +1,6 @@
<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> <table style="border-collapse: collapse; border:0;">
<legend><%= l(:field_column_names) %></legend>
<%= hidden_field_tag 'query[column_names][]', '', :id => nil %>
<table>
<tr> <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]}), options_for_select((query.available_columns - query.columns).collect {|column| [column.caption, column.name]}),
:multiple => true, :size => 10, :style => "width:150px" %> :multiple => true, :size => 10, :style => "width:150px" %>
</td> </td>
@ -15,12 +11,11 @@
onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" /> onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
</td> </td>
<td><%= select_tag 'query[column_names][]', <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" %> :id => 'selected_columns', :multiple => true, :size => 10, :style => "width:150px" %>
</td> </td>
</tr> </tr>
</table> </table>
<% end %>
<% content_for :header_tags do %> <% content_for :header_tags do %>
<%= javascript_include_tag 'select_list_move' %> <%= javascript_include_tag 'select_list_move' %>

View File

@ -37,5 +37,9 @@
<% end %> <% end %>
</fieldset> </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}%> <%= render :partial => 'queries/columns', :locals => {:query => query}%>
<% end %>
</div> </div>

View File

@ -256,6 +256,22 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
end 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 def test_gantt
get :gantt, :project_id => 1 get :gantt, :project_id => 1
assert_response :success assert_response :success