]> source.dussan.org Git - redmine.git/commitdiff
Fix link to issues when displaying a project query (#1565).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 18:14:58 +0000 (18:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 18:14:58 +0000 (18:14 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16409 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
app/views/my/blocks/_issues.erb
test/functional/my_controller_test.rb

index 23eca02781617222c99bb53e601ad434ebd5fa82..a0f1969e3735bed71032ca0591548d2fc763c730 100644 (file)
@@ -387,19 +387,23 @@ class Query < ActiveRecord::Base
   end
 
   def as_params
-    params = {}
-    filters.each do |field, options|
-      params[:f] ||= []
-      params[:f] << field
-      params[:op] ||= {}
-      params[:op][field] = options[:operator]
-      params[:v] ||= {}
-      params[:v][field] = options[:values]
+    if new_record?
+      params = {}
+      filters.each do |field, options|
+        params[:f] ||= []
+        params[:f] << field
+        params[:op] ||= {}
+        params[:op][field] = options[:operator]
+        params[:v] ||= {}
+        params[:v][field] = options[:values]
+      end
+      params[:c] = column_names
+      params[:sort] = sort_criteria.to_param
+      params[:set_filter] = 1
+      params
+    else
+      {:query_id => id}
     end
-    params[:c] = column_names
-    params[:sort] = sort_criteria.to_param
-    params[:set_filter] = 1
-    params
   end
 
   def validate_query_filters
index 0174bac2e6e3472c844385891418e7dccaa2d782..47fb28136a931e4a712abb09893a0b6d7b044fd1 100644 (file)
@@ -6,7 +6,8 @@
 </div>
 
 <h3>
-  <%= link_to query.name, issues_path(query.as_params) %>
+  <%= "#{query.project} |" if query.project %>
+  <%= link_to query.name, _project_issues_path(query.project, query.as_params) %>
   (<%= query.issue_count %>)
 </h3>
 
@@ -38,7 +39,7 @@
 
 <% content_for :header_tags do %>
 <%= auto_discovery_link_tag(:atom,
-                            issues_path(query.as_params.merge(:format => 'atom', :key => User.current.rss_key)),
+                            _project_issues_path(query.project, query.as_params.merge(:format => 'atom', :key => User.current.rss_key)),
                             {:title => query.name}) %>
 <% end %>
 
index f6771a1f58dc465240250bf24a31f3b0b9c35cbb..09cb1a834dae7995453363a8b5720a34edc667a9 100644 (file)
@@ -108,7 +108,7 @@ class MyControllerTest < Redmine::ControllerTest
     end
   end
 
-  def test_page_with_issuequery_block_and_selected_query
+  def test_page_with_issuequery_block_and_global_query
     user = User.find(2)
     query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
     user.pref.my_page_layout = {'top' => ['issuequery']}
@@ -119,6 +119,7 @@ class MyControllerTest < Redmine::ControllerTest
     assert_response :success
 
     assert_select '#block-issuequery' do
+      assert_select 'a[href=?]', "/issues?query_id=#{query.id}"
       # assert number of columns (columns from query + id column + checkbox column)
       assert_select 'table.issues th', 6
       # assert results limit
@@ -127,7 +128,27 @@ class MyControllerTest < Redmine::ControllerTest
     end
   end
 
-  def test_page_with_issuequery_block_and_selected_query_and_custom_columns
+  def test_page_with_issuequery_block_and_project_query
+    user = User.find(2)
+    query = IssueQuery.create!(:name => 'All issues', :project => Project.find(1), :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
+    user.pref.my_page_layout = {'top' => ['issuequery']}
+    user.pref.my_page_settings = {'issuequery' => {:query_id => query.id}}
+    user.pref.save!
+
+    get :page
+    assert_response :success
+
+    assert_select '#block-issuequery' do
+      assert_select 'a[href=?]', "/projects/ecookbook/issues?query_id=#{query.id}"
+      # assert number of columns (columns from query + id column + checkbox column)
+      assert_select 'table.issues th', 6
+      # assert results limit
+      assert_select 'table.issues tr.issue', 10
+      assert_select 'table.issues td.assigned_to'
+    end
+  end
+
+  def test_page_with_issuequery_block_and_query_should_display_custom_columns
     user = User.find(2)
     query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
     user.pref.my_page_layout = {'top' => ['issuequery']}