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
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
<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>
<%= 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' %>
}, :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 %>
-<% 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' %>
<% 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>
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