From a00538e602d7ca0a4d3fb3c4053514ef1fc620e0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 12 Jul 2016 17:54:46 +0000 Subject: Display the list of saved queries in the sidebar (#14790). git-svn-id: http://svn.redmine.org/redmine/trunk@15642 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/queries_helper.rb | 15 ++++++++++----- app/views/issues/_sidebar.html.erb | 2 +- app/views/timelog/index.html.erb | 4 ++++ app/views/timelog/report.html.erb | 4 ++++ test/functional/timelog_controller_test.rb | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 52da20e84..d457593d5 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -278,10 +278,12 @@ module QueriesHelper tags end - def sidebar_queries - @sidebar_queries ||= IssueQuery.visible.global_or_on_project(@project).sorted.to_a + # Returns the queries that are rendered in the sidebar + def sidebar_queries(klass, project) + klass.visible.global_or_on_project(@project).sorted.to_a end + # Renders a group of queries def query_links(title, queries) return '' if queries.empty? # links to #index on issues/show @@ -298,10 +300,13 @@ module QueriesHelper ) + "\n" end - def render_sidebar_queries + # Renders the list of queries for the sidebar + def render_sidebar_queries(klass, project) + queries = sidebar_queries(klass, project) + out = ''.html_safe - out << query_links(l(:label_my_queries), sidebar_queries.select(&:is_private?)) - out << query_links(l(:label_query_plural), sidebar_queries.reject(&:is_private?)) + out << query_links(l(:label_my_queries), queries.select(&:is_private?)) + out << query_links(l(:label_query_plural), queries.reject(&:is_private?)) out end end diff --git a/app/views/issues/_sidebar.html.erb b/app/views/issues/_sidebar.html.erb index df9f43b72..7e97c0911 100644 --- a/app/views/issues/_sidebar.html.erb +++ b/app/views/issues/_sidebar.html.erb @@ -21,5 +21,5 @@ <%= call_hook(:view_issues_sidebar_issues_bottom) %> <%= call_hook(:view_issues_sidebar_planning_bottom) %> -<%= render_sidebar_queries %> +<%= render_sidebar_queries(IssueQuery, @project) %> <%= call_hook(:view_issues_sidebar_queries_bottom) %> diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb index 6f2c92f4e..02d5dbf9b 100644 --- a/app/views/timelog/index.html.erb +++ b/app/views/timelog/index.html.erb @@ -41,6 +41,10 @@ <% end %> +<% content_for :sidebar do %> + <%= render_sidebar_queries(TimeEntryQuery, @project) %> +<% end %> + <% html_title(@query.new_record? ? l(:label_spent_time) : @query.name, l(:label_details)) %> <% content_for :header_tags do %> diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb index d1d215542..f3cd6dc60 100644 --- a/app/views/timelog/report.html.erb +++ b/app/views/timelog/report.html.erb @@ -70,5 +70,9 @@ <% end %> <% end %> +<% content_for :sidebar do %> + <%= render_sidebar_queries(TimeEntryQuery, @project) %> +<% end %> + <% html_title(@query.new_record? ? l(:label_spent_time) : @query.name, l(:label_report)) %> diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 5ee683f4c..eafea27c7 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -767,6 +767,7 @@ class TimelogControllerTest < ActionController::TestCase get :index, :project_id => 'ecookbook', :query_id => query.id assert_response :success assert_select 'h2', :text => query.name + assert_select '#sidebar a.selected', :text => query.name end def test_index_atom_feed -- cgit v1.2.3