From 66540afc08209939dd4b9a6d9969b99a6ffecfc9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 28 Nov 2009 11:34:12 +0000 Subject: [PATCH] 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 --- app/controllers/issues_controller.rb | 5 +++-- app/models/query.rb | 10 ++++++++-- app/views/issues/index.rhtml | 15 ++++++++++++--- app/views/queries/_columns.rhtml | 11 +++-------- app/views/queries/_form.rhtml | 4 ++++ test/functional/issues_controller_test.rb | 16 ++++++++++++++++ 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bbd0f801c..d0a34d7bf 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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 diff --git a/app/models/query.rb b/app/models/query.rb index 2e0ddc489..c691736e9 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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 diff --git a/app/views/issues/index.rhtml b/app/views/issues/index.rhtml index 5eddb7052..5b8fa05a7 100644 --- a/app/views/issues/index.rhtml +++ b/app/views/issues/index.rhtml @@ -20,8 +20,16 @@ @@ -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 %>

<% end %> diff --git a/app/views/queries/_columns.rhtml b/app/views/queries/_columns.rhtml index 1a481adae..e11b286b6 100644 --- a/app/views/queries/_columns.rhtml +++ b/app/views/queries/_columns.rhtml @@ -1,10 +1,6 @@ -<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> -<%= l(:field_column_names) %> - -<%= hidden_field_tag 'query[column_names][]', '', :id => nil %> - +
- @@ -15,12 +11,11 @@ onclick="moveOptions(this.form.selected_columns, this.form.available_columns);" />
<%= select_tag 'available_columns', + <%= 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" %> <%= 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" %>
-<% end %> <% content_for :header_tags do %> <%= javascript_include_tag 'select_list_move' %> diff --git a/app/views/queries/_form.rhtml b/app/views/queries/_form.rhtml index 577699d70..dcafe9f60 100644 --- a/app/views/queries/_form.rhtml +++ b/app/views/queries/_form.rhtml @@ -37,5 +37,9 @@ <% end %> +<% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> +<%= l(:field_column_names) %> <%= render :partial => 'queries/columns', :locals => {:query => query}%> +<% end %> + diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 3ece848b7..9555db4ea 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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 -- 2.39.5