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
This commit is contained in:
parent
093ecdfc73
commit
9dc07d4790
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue