summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 19:18:57 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-12-09 19:18:57 +0000
commit9dc07d4790aac44b5183c8a19759512dc777f259 (patch)
treece07b6538bccea104afebfff4f3784e19e34b65c /app
parent093ecdfc730f2a35bcdb289603d8f714d5dce320 (diff)
downloadredmine-9dc07d4790aac44b5183c8a19759512dc777f259.tar.gz
redmine-9dc07d4790aac44b5183c8a19759512dc777f259.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/timelog_controller.rb4
-rw-r--r--app/models/query.rb2
-rw-r--r--app/models/time_entry_query.rb51
-rw-r--r--app/views/custom_fields/_form.html.erb1
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" %>
<p><%= f.check_box :is_required %></p>
+ <p><%= f.check_box :is_filter %></p>
<% else %>
<p><%= f.check_box :is_required %></p>