(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
end
- def available_filters
- return @available_filters if @available_filters
- @available_filters = {
- "status_id" => {
- :type => :list_status, :order => 0,
- :values => IssueStatus.sorted.all.collect{|s| [s.name, s.id.to_s] }
- },
- "tracker_id" => {
- :type => :list, :order => 2, :values => trackers.collect{|s| [s.name, s.id.to_s] }
- },
- "priority_id" => {
- :type => :list, :order => 3, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] }
- },
- "subject" => { :type => :text, :order => 8 },
- "created_on" => { :type => :date_past, :order => 9 },
- "updated_on" => { :type => :date_past, :order => 10 },
- "start_date" => { :type => :date, :order => 11 },
- "due_date" => { :type => :date, :order => 12 },
- "estimated_hours" => { :type => :float, :order => 13 },
- "done_ratio" => { :type => :integer, :order => 14 }
- }
- IssueRelation::TYPES.each do |relation_type, options|
- @available_filters[relation_type] = {
- :type => :relation, :order => @available_filters.size + 100,
- :label => options[:name]
- }
- end
+ def initialize_available_filters
principals = []
+ subprojects = []
+ versions = []
+ categories = []
+ issue_custom_fields = []
+
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 => 13,
- :values => subprojects.collect{|s| [s.name, s.id.to_s] }
- }
- principals += Principal.member_of(subprojects)
- end
+ principals += Principal.member_of(subprojects)
end
+ versions = project.shared_versions.all
+ categories = project.issue_categories.all
+ issue_custom_fields = project.all_issue_custom_fields
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
+ versions = Version.visible.find_all_by_sharing('system')
+ issue_custom_fields = IssueCustomField.where(:is_filter => true, :is_for_all => true).all
end
principals.uniq!
principals.sort!
users = principals.select {|p| p.is_a?(User)}
- assigned_to_values = []
- assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
- assigned_to_values += (Setting.issue_group_assignment? ?
- principals : users).collect{|s| [s.name, s.id.to_s] }
- @available_filters["assigned_to_id"] = {
- :type => :list_optional, :order => 4, :values => assigned_to_values
- } unless assigned_to_values.empty?
+
+ add_available_filter "status_id",
+ :type => :list_status, :values => IssueStatus.sorted.all.collect{|s| [s.name, s.id.to_s] }
+
+ if project.nil?
+ project_values = []
+ if User.current.logged? && User.current.memberships.any?
+ project_values << ["<< #{l(:label_my_projects).downcase} >>", "mine"]
+ end
+ project_values += all_projects_values
+ add_available_filter("project_id",
+ :type => :list, :values => project_values
+ ) unless project_values.empty?
+ end
+
+ add_available_filter "tracker_id",
+ :type => :list, :values => trackers.collect{|s| [s.name, s.id.to_s] }
+ add_available_filter "priority_id",
+ :type => :list, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s] }
author_values = []
author_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
author_values += users.collect{|s| [s.name, s.id.to_s] }
- @available_filters["author_id"] = {
- :type => :list, :order => 5, :values => author_values
- } unless author_values.empty?
+ add_available_filter("author_id",
+ :type => :list, :values => author_values
+ ) unless author_values.empty?
+
+ assigned_to_values = []
+ assigned_to_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
+ assigned_to_values += (Setting.issue_group_assignment? ?
+ principals : users).collect{|s| [s.name, s.id.to_s] }
+ add_available_filter("assigned_to_id",
+ :type => :list_optional, :values => assigned_to_values
+ ) unless assigned_to_values.empty?
group_values = Group.all.collect {|g| [g.name, g.id.to_s] }
- @available_filters["member_of_group"] = {
- :type => :list_optional, :order => 6, :values => group_values
- } unless group_values.empty?
+ add_available_filter("member_of_group",
+ :type => :list_optional, :values => group_values
+ ) unless group_values.empty?
role_values = Role.givable.collect {|r| [r.name, r.id.to_s] }
- @available_filters["assigned_to_role"] = {
- :type => :list_optional, :order => 7, :values => role_values
- } unless role_values.empty?
-
- if User.current.logged?
- @available_filters["watcher_id"] = {
- :type => :list, :order => 15, :values => [["<< #{l(:label_me)} >>", "me"]]
- }
+ add_available_filter("assigned_to_role",
+ :type => :list_optional, :values => role_values
+ ) unless role_values.empty?
+
+ if versions.any?
+ add_available_filter "fixed_version_id",
+ :type => :list_optional,
+ :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] }
end
- if project
- # project specific filters
- categories = project.issue_categories.all
- unless categories.empty?
- @available_filters["category_id"] = {
- :type => :list_optional, :order => 6,
- :values => categories.collect{|s| [s.name, s.id.to_s] }
- }
- end
- versions = project.shared_versions.all
- unless versions.empty?
- @available_filters["fixed_version_id"] = {
- :type => :list_optional, :order => 7,
- :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] }
- }
- end
- add_custom_fields_filters(project.all_issue_custom_fields)
- else
- # global filters for cross project issue list
- system_shared_versions = Version.visible.find_all_by_sharing('system')
- unless system_shared_versions.empty?
- @available_filters["fixed_version_id"] = {
- :type => :list_optional, :order => 7,
- :values => system_shared_versions.sort.collect{|s|
- ["#{s.project.name} - #{s.name}", s.id.to_s]
- }
- }
- end
- add_custom_fields_filters(IssueCustomField.where(:is_filter => true, :is_for_all => true).all)
+ if categories.any?
+ add_available_filter "category_id",
+ :type => :list_optional,
+ :values => categories.collect{|s| [s.name, s.id.to_s] }
end
- add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
+
+ add_available_filter "subject", :type => :text
+ add_available_filter "created_on", :type => :date_past
+ add_available_filter "updated_on", :type => :date_past
+ add_available_filter "start_date", :type => :date
+ add_available_filter "due_date", :type => :date
+ add_available_filter "estimated_hours", :type => :float
+ add_available_filter "done_ratio", :type => :integer
+
if User.current.allowed_to?(:set_issues_private, nil, :global => true) ||
User.current.allowed_to?(:set_own_issues_private, nil, :global => true)
- @available_filters["is_private"] = {
- :type => :list, :order => 16,
+ add_available_filter "is_private",
+ :type => :list,
:values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]]
- }
end
+
+ if User.current.logged?
+ add_available_filter "watcher_id",
+ :type => :list, :values => [["<< #{l(:label_me)} >>", "me"]]
+ end
+
+ if subprojects.any?
+ add_available_filter "subproject_id",
+ :type => :list_subprojects,
+ :values => subprojects.collect{|s| [s.name, s.id.to_s] }
+ end
+
+ add_custom_fields_filters(issue_custom_fields)
+
+ add_associations_custom_fields_filters :project, :author, :assigned_to, :fixed_version
+
+ IssueRelation::TYPES.each do |relation_type, options|
+ add_available_filter relation_type, :type => :relation, :label => options[:name]
+ end
+
Tracker.disabled_core_fields(trackers).each {|field|
- @available_filters.delete field
+ delete_available_filter field
}
- @available_filters.each do |field, options|
- options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
- end
- @available_filters
end
def available_columns
@all_projects_values = values
end
+ # Adds available filters
+ def initialize_available_filters
+ # implemented by sub-classes
+ end
+ protected :initialize_available_filters
+
+ # Adds an available filter
+ def add_available_filter(field, options)
+ @available_filters ||= ActiveSupport::OrderedHash.new
+ @available_filters[field] = options
+ @available_filters
+ end
+
+ # Removes an available filter
+ def delete_available_filter(field)
+ if @available_filters
+ @available_filters.delete(field)
+ end
+ end
+
+ # Return a hash of available filters
+ def available_filters
+ unless @available_filters
+ initialize_available_filters
+ @available_filters.each do |field, options|
+ options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
+ end
+ end
+ @available_filters
+ end
+
def add_filter(field, operator, values=nil)
# values must be an array
return unless values.nil? || values.is_a?(Array)
def add_custom_fields_filters(custom_fields, assoc=nil)
return unless custom_fields.present?
- @available_filters ||= {}
- custom_fields.select(&:is_filter?).each do |field|
+ custom_fields.select(&:is_filter?).sort.each do |field|
case field.field_format
when "text"
- options = { :type => :text, :order => 20 }
+ options = { :type => :text }
when "list"
- options = { :type => :list_optional, :values => field.possible_values, :order => 20}
+ options = { :type => :list_optional, :values => field.possible_values }
when "date"
- options = { :type => :date, :order => 20 }
+ options = { :type => :date }
when "bool"
- options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], :order => 20 }
+ options = { :type => :list, :values => [[l(:general_text_yes), "1"], [l(:general_text_no), "0"]] }
when "int"
- options = { :type => :integer, :order => 20 }
+ options = { :type => :integer }
when "float"
- options = { :type => :float, :order => 20 }
+ options = { :type => :float }
when "user", "version"
next unless project
values = field.possible_values_options(project)
if User.current.logged? && field.field_format == 'user'
values.unshift ["<< #{l(:label_me)} >>", "me"]
end
- options = { :type => :list_optional, :values => values, :order => 20}
+ options = { :type => :list_optional, :values => values }
else
- options = { :type => :string, :order => 20 }
+ options = { :type => :string }
end
filter_id = "cf_#{field.id}"
filter_name = field.name
filter_id = "#{assoc}.#{filter_id}"
filter_name = l("label_attribute_of_#{assoc}", :name => filter_name)
end
- @available_filters[filter_id] = options.merge({
+ add_available_filter filter_id, options.merge({
:name => filter_name,
:format => field.field_format,
:field => field
add_filter('spent_on', '*') unless filters.present?
end
- def available_filters
- return @available_filters if @available_filters
- @available_filters = {
- "spent_on" => { :type => :date_past, :order => 0 },
- "comments" => { :type => :text, :order => 5 },
- "hours" => { :type => :float, :order => 6 }
- }
+ def initialize_available_filters
+ add_available_filter "spent_on", :type => :date_past
principals = []
if project
unless project.leaf?
subprojects = project.descendants.visible.all
if subprojects.any?
- @available_filters["subproject_id"] = {
- :type => :list_subprojects, :order => 1,
+ add_available_filter "subproject_id",
+ :type => :list_subprojects,
:values => subprojects.collect{|s| [s.name, s.id.to_s] }
- }
principals += Principal.member_of(subprojects)
end
end
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?
+ add_available_filter("project_id",
+ :type => :list, :values => project_values
+ ) unless project_values.empty?
end
end
principals.uniq!
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?
+ add_available_filter("user_id",
+ :type => :list_optional, :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_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
add_custom_fields_filters(TimeEntryCustomField.where(:is_filter => true).all)
add_associations_custom_fields_filters :project, :issue, :user
-
- @available_filters.each do |field, options|
- options[:name] ||= l(options[:label] || "field_#{field}".gsub(/_id$/, ''))
- end
- @available_filters
end
def available_columns