From 9dc07d4790aac44b5183c8a19759512dc777f259 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 9 Dec 2012 19:18:57 +0000 Subject: [PATCH] Adds filters for regular/custom fields to the time entries list/report (#10191). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10970 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/timelog_controller.rb | 4 +- app/models/query.rb | 2 +- app/models/time_entry_query.rb | 51 +++++++++++++++++++++++++- app/views/custom_fields/_form.html.erb | 1 + 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index a2dcfac7d..ab4897d2c 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -39,7 +39,7 @@ class TimelogController < ApplicationController helper :queries def index - @query = TimeEntryQuery.build_from_params(params, :name => '_') + @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') scope = time_entry_scope sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) @@ -90,7 +90,7 @@ class TimelogController < ApplicationController end def report - @query = TimeEntryQuery.build_from_params(params, :name => '_') + @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') scope = time_entry_scope @report = Redmine::Helpers::TimeReport.new(@project, @issue, params[:criteria], params[:columns], scope) diff --git a/app/models/query.rb b/app/models/query.rb index ff7758c71..9681a2339 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -456,7 +456,7 @@ class Query < ActiveRecord::Base operator = operator_for(field) # "me" value subsitution - if %w(assigned_to_id author_id watcher_id).include?(field) + if %w(assigned_to_id author_id user_id watcher_id).include?(field) if v.delete("me") if User.current.logged? v.push(User.current.id.to_s) diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index c2fea35fe..4cb9932ec 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -38,8 +38,57 @@ class TimeEntryQuery < Query def available_filters return @available_filters if @available_filters @available_filters = { - "spent_on" => { :type => :date_past, :order => 0 } + "spent_on" => { :type => :date_past, :order => 0 }, + "comments" => { :type => :text, :order => 5 }, + "hours" => { :type => :float, :order => 6 } } + + principals = [] + if project + principals += project.principals.sort + unless project.leaf? + subprojects = project.descendants.visible.all + if subprojects.any? + @available_filters["subproject_id"] = { + :type => :list_subprojects, :order => 1, + :values => subprojects.collect{|s| [s.name, s.id.to_s] } + } + principals += Principal.member_of(subprojects) + end + end + else + if all_projects.any? + # members of visible projects + principals += Principal.member_of(all_projects) + # project filter + project_values = [] + if User.current.logged? && User.current.memberships.any? + project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"] + end + project_values += all_projects_values + @available_filters["project_id"] = { + :type => :list, :order => 1, :values => project_values + } unless project_values.empty? + end + end + principals.uniq! + principals.sort! + users = principals.select {|p| p.is_a?(User)} + + users_values = [] + users_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged? + users_values += users.collect{|s| [s.name, s.id.to_s] } + @available_filters["user_id"] = { + :type => :list_optional, :order => 2, :values => users_values + } unless users_values.empty? + + activities = (project ? project.activities : TimeEntryActivity.shared.active) + @available_filters["activity_id"] = { + :type => :list, :order => 3, :values => activities.map {|a| [a.name, a.id.to_s]} + } unless activities.empty? + + add_custom_fields_filters(TimeEntryCustomField.where(:is_filter => true).all) + @available_filters.each do |field, options| options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, '')) end diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb index beaa78b2f..d3fd1de69 100644 --- a/app/views/custom_fields/_form.html.erb +++ b/app/views/custom_fields/_form.html.erb @@ -73,6 +73,7 @@ when "IssueCustomField" %> <% when "TimeEntryCustomField" %>

<%= f.check_box :is_required %>

+

<%= f.check_box :is_filter %>

<% else %>

<%= f.check_box :is_required %>