##// END OF EJS Templates
Introduce virtual MenuNodes (#15880)....
Introduce virtual MenuNodes (#15880). They are characterized by having a blank url. they will only be rendered if the user is authorized to see at least one of its children. they render as links which do nothing when clicked. Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@15501 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r14856:cda9c63d9c21
r15119:53710d80fc88
Show More
time_entry_query.rb
141 lines | 5.5 KiB | text/x-ruby | RubyLexer
/ app / models / time_entry_query.rb
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class TimeEntryQuery < Query
self.queried_class = TimeEntry
self.available_columns = [
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
Jean-Philippe Lang
Makes time entry custom fields available for display on the time entries list (#1766)....
r10745 QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true),
Jean-Philippe Lang
Adds week column to time entries list (#20221)....
r14341 QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => l(:label_week)),
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 QueryColumn.new(:user, :sortable => lambda {User.fields_for_order_statement}, :groupable => true),
QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true),
QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"),
QueryColumn.new(:comments),
QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours"),
]
def initialize(attributes=nil, *args)
super attributes
self.filters ||= {}
add_filter('spent_on', '*') unless filters.present?
end
Jean-Philippe Lang
Refactor: use an ordered hash to store available filters and remove :order option (#13154)....
r11142 def initialize_available_filters
add_available_filter "spent_on", :type => :date_past
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743
principals = []
if project
Jean-Philippe Lang
Adds a role setting for controlling visibility of users: all or members of visible projects (#11724)....
r13202 principals += project.principals.visible.sort
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 unless project.leaf?
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 subprojects = project.descendants.visible.to_a
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 if subprojects.any?
Jean-Philippe Lang
Refactor: use an ordered hash to store available filters and remove :order option (#13154)....
r11142 add_available_filter "subproject_id",
:type => :list_subprojects,
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 :values => subprojects.collect{|s| [s.name, s.id.to_s] }
Jean-Philippe Lang
Adds a role setting for controlling visibility of users: all or members of visible projects (#11724)....
r13202 principals += Principal.member_of(subprojects).visible
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 end
end
else
if all_projects.any?
# members of visible projects
Jean-Philippe Lang
Adds a role setting for controlling visibility of users: all or members of visible projects (#11724)....
r13202 principals += Principal.member_of(all_projects).visible
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 # 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
Jean-Philippe Lang
Refactor: use an ordered hash to store available filters and remove :order option (#13154)....
r11142 add_available_filter("project_id",
:type => :list, :values => project_values
) unless project_values.empty?
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743 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] }
Jean-Philippe Lang
Refactor: use an ordered hash to store available filters and remove :order option (#13154)....
r11142 add_available_filter("user_id",
:type => :list_optional, :values => users_values
) unless users_values.empty?
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743
Jean-Philippe Lang
Include inactive activities in time entries filter (#20117)....
r14244 activities = (project ? project.activities : TimeEntryActivity.shared)
Jean-Philippe Lang
Refactor: use an ordered hash to store available filters and remove :order option (#13154)....
r11142 add_available_filter("activity_id",
:type => :list, :values => activities.map {|a| [a.name, a.id.to_s]}
) unless activities.empty?
add_available_filter "comments", :type => :text
add_available_filter "hours", :type => :float
Jean-Philippe Lang
Adds filters for regular/custom fields to the time entries list/report (#10191)....
r10743
Jean-Philippe Lang
Query#add_custom_fields_filters now takes a custom fields scope....
r11687 add_custom_fields_filters(TimeEntryCustomField)
Jean-Philippe Lang
Adds issue custom fields to time entries filters (#10191)....
r10941 add_associations_custom_fields_filters :project, :issue, :user
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 end
Jean-Philippe Lang
Makes time entry custom fields available for display on the time entries list (#1766)....
r10745 def available_columns
return @available_columns if @available_columns
@available_columns = self.class.available_columns.dup
Toshi MARUYAMA
remove unneeded Relation#all from TimeEntryQuery model...
r12457 @available_columns += TimeEntryCustomField.visible.
map {|cf| QueryCustomFieldColumn.new(cf) }
@available_columns += IssueCustomField.visible.
map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf) }
Jean-Philippe Lang
Makes time entry custom fields available for display on the time entries list (#1766)....
r10745 @available_columns
end
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 def default_columns_names
@default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours]
end
Jean-Philippe Lang
Fixed that sorting time entries by custom field raises a SQL error (#14366)....
r11812 def results_scope(options={})
order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
TimeEntry.visible.
where(statement).
order(order_option).
Jean-Philippe Lang
Fixed that filtering time entries on activity does not take care of activity overrides (#15623)....
r12139 joins(joins_for_order_statement(order_option.join(','))).
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 includes(:activity).
references(:activity)
Jean-Philippe Lang
Fixed that filtering time entries on activity does not take care of activity overrides (#15623)....
r12139 end
def sql_for_activity_id_field(field, operator, value)
condition_on_id = sql_for_field(field, operator, value, Enumeration.table_name, 'id')
condition_on_parent_id = sql_for_field(field, operator, value, Enumeration.table_name, 'parent_id')
ids = value.map(&:to_i).join(',')
table_name = Enumeration.table_name
if operator == '='
"(#{table_name}.id IN (#{ids}) OR #{table_name}.parent_id IN (#{ids}))"
else
"(#{table_name}.id NOT IN (#{ids}) AND (#{table_name}.parent_id IS NULL OR #{table_name}.parent_id NOT IN (#{ids})))"
end
Jean-Philippe Lang
Fixed that sorting time entries by custom field raises a SQL error (#14366)....
r11812 end
Jean-Philippe Lang
Adds TimeEntryQuery for listing time entries....
r10740 # Accepts :from/:to params as shortcut filters
def build_from_params(params)
super
if params[:from].present? && params[:to].present?
add_filter('spent_on', '><', [params[:from], params[:to]])
elsif params[:from].present?
add_filter('spent_on', '>=', [params[:from]])
elsif params[:to].present?
add_filter('spent_on', '<=', [params[:to]])
end
self
end
end