From 176288d92d05c8c3e5d0a1ff5fde843ea357abc6 Mon Sep 17 00:00:00 2001 From: Robert Kranz Date: Mon, 30 Nov 2015 14:12:37 +0100 Subject: [PATCH] * fixed sidebars for loglist, booking list and report --- app/concerns/tt_query_concern.rb | 7 ++++--- app/helpers/report_sidebar_helper.rb | 15 +++++---------- app/helpers/time_bookings_sidebar_helper.rb | 15 +++++---------- app/helpers/time_logs_sidebar_helper.rb | 14 +++++--------- app/helpers/time_trackers_helper.rb | 2 +- app/views/tt_bookings_list/index.html.erb | 4 ++++ app/views/tt_logs_list/index.html.erb | 4 ++++ app/views/tt_reporting/index.html.erb | 2 +- 8 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/concerns/tt_query_concern.rb b/app/concerns/tt_query_concern.rb index 9c2f839d..bacf0841 100644 --- a/app/concerns/tt_query_concern.rb +++ b/app/concerns/tt_query_concern.rb @@ -3,10 +3,11 @@ module TtQueryConcern included do class_eval do - scope :visible, lambda { |*args| + scope :visible, lambda {|*args| user = args.shift || User.current - base = Project.allowed_to_condition(user, @visibile_permission, *args) - scope = joins(:project).where("#{table_name}.project_id IS NULL OR (#{base})") + base = Project.allowed_to_condition(user, @visible_permission, *args) + scope = joins("LEFT OUTER JOIN #{Project.table_name} ON #{table_name}.project_id = #{Project.table_name}.id"). + where("#{table_name}.project_id IS NULL OR (#{base})") if user.admin? scope.where("#{table_name}.visibility <> ? OR #{table_name}.user_id = ?", Query::VISIBILITY_PRIVATE, user.id) diff --git a/app/helpers/report_sidebar_helper.rb b/app/helpers/report_sidebar_helper.rb index f09a6a63..dfe43f48 100644 --- a/app/helpers/report_sidebar_helper.rb +++ b/app/helpers/report_sidebar_helper.rb @@ -1,13 +1,8 @@ module ReportSidebarHelper def sidebar_queries - unless @sidebar_queries - @sidebar_queries = ReportQuery.visible.all( - :order => "#{Query.table_name}.name ASC", - # Project specific queries and global queries - :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) - ) - end - @sidebar_queries + return @sidebar_queries if @sidebar_queries + @sidebar_queries = ReportQuery.visible + @project.nil? ? @sidebar_queries.where(project_id: nil) : @sidebar_queries.where(project_id: [nil, @project.id]) + @sidebar_queries.order(name: :asc) end - -end \ No newline at end of file +end diff --git a/app/helpers/time_bookings_sidebar_helper.rb b/app/helpers/time_bookings_sidebar_helper.rb index 6e5c14e5..83b86c3c 100644 --- a/app/helpers/time_bookings_sidebar_helper.rb +++ b/app/helpers/time_bookings_sidebar_helper.rb @@ -1,13 +1,8 @@ module TimeBookingsSidebarHelper def sidebar_queries - unless @sidebar_queries - @sidebar_queries = TimeBookingQuery.visible.all( - :order => "#{Query.table_name}.name ASC", - # Project specific queries and global queries - :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) - ) - end - @sidebar_queries + return @sidebar_queries if @sidebar_queries + @sidebar_queries = TimeBookingQuery.visible + @project.nil? ? @sidebar_queries.where(project_id: nil) : @sidebar_queries.where(project_id: [nil, @project.id]) + @sidebar_queries.order(name: :asc) end - -end \ No newline at end of file +end diff --git a/app/helpers/time_logs_sidebar_helper.rb b/app/helpers/time_logs_sidebar_helper.rb index de277002..cf287ee5 100644 --- a/app/helpers/time_logs_sidebar_helper.rb +++ b/app/helpers/time_logs_sidebar_helper.rb @@ -1,12 +1,8 @@ module TimeLogsSidebarHelper def sidebar_queries - unless @sidebar_queries - @sidebar_queries = TimeLogQuery.visible.all( - :order => "#{Query.table_name}.name ASC", - # Project specific queries and global queries - :conditions => (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) - ) - end - @sidebar_queries + return @sidebar_queries if @sidebar_queries + @sidebar_queries = TimeLogQuery.visible + @project.nil? ? @sidebar_queries.where(project_id: nil) : @sidebar_queries.where(project_id: [nil, @project.id]) + @sidebar_queries.order(name: :asc) end -end \ No newline at end of file +end diff --git a/app/helpers/time_trackers_helper.rb b/app/helpers/time_trackers_helper.rb index 8b933487..5a66bc88 100644 --- a/app/helpers/time_trackers_helper.rb +++ b/app/helpers/time_trackers_helper.rb @@ -159,7 +159,7 @@ def time_string2hour(str) def query_from_id unless params[:query_id].blank? - query = Query.find(params[:query_id], :conditions => "project_id IS NULL") + query = Query.find(params[:query_id]) raise ::Unauthorized unless query.visible? sess_info = {:filters => query.filters, :group_by => query.group_by, :column_names => query.column_names} case query.class.name diff --git a/app/views/tt_bookings_list/index.html.erb b/app/views/tt_bookings_list/index.html.erb index 65cb0c10..6add2563 100644 --- a/app/views/tt_bookings_list/index.html.erb +++ b/app/views/tt_bookings_list/index.html.erb @@ -69,4 +69,8 @@ <% end %> <% end %> +<% content_for :sidebar do %> + <%= render_sidebar_queries %> +<% end %> + <%= context_menu tt_bookings_list_context_menu_path %> diff --git a/app/views/tt_logs_list/index.html.erb b/app/views/tt_logs_list/index.html.erb index 7ad395f0..707a23da 100644 --- a/app/views/tt_logs_list/index.html.erb +++ b/app/views/tt_logs_list/index.html.erb @@ -69,4 +69,8 @@ <% end %> <% end %> +<% content_for :sidebar do %> + <%= render_sidebar_queries %> +<% end %> + <%= context_menu tt_logs_list_context_menu_path %> diff --git a/app/views/tt_reporting/index.html.erb b/app/views/tt_reporting/index.html.erb index 86ed678f..dc0352d0 100644 --- a/app/views/tt_reporting/index.html.erb +++ b/app/views/tt_reporting/index.html.erb @@ -72,7 +72,7 @@ <% end %> <% content_for :sidebar do %> - + <%= render_sidebar_queries %>

<%=l(:time_tracker_label_menu_tab_reports)%>