Defect #26023 » category_filter.patch
app/models/issue_category.rb (copie de travail) | ||
---|---|---|
28 | 28 |
safe_attributes 'name', 'assigned_to_id' |
29 | 29 | |
30 | 30 |
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} |
31 |
scope :visible, lambda {|user = User.current| |
|
32 |
joins(:project). |
|
33 |
where(Project.allowed_to_condition(user, :view_issues)) |
|
34 |
} |
|
31 | 35 | |
32 | 36 |
alias :destroy_without_reassign :destroy |
33 | 37 |
app/models/issue_query.rb (copie de travail) | ||
---|---|---|
31 | 31 |
QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement("authors")}, :groupable => true), |
32 | 32 |
QueryColumn.new(:assigned_to, :sortable => lambda {User.fields_for_order_statement}, :groupable => true), |
33 | 33 |
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'), |
34 |
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
|
|
34 |
IssueCategoryQueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => "#{IssueCategory.table_name}.name"),
|
|
35 | 35 |
QueryColumn.new(:fixed_version, :sortable => lambda {Version.fields_for_order_statement}, :groupable => true), |
36 | 36 |
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"), |
37 | 37 |
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"), |
... | ... | |
124 | 124 | |
125 | 125 |
add_available_filter "category_id", |
126 | 126 |
:type => :list_optional, |
127 |
:values => lambda { project.issue_categories.collect{|s| [s.name, s.id.to_s] } } if project
|
|
127 |
:values => lambda { issue_category_values }
|
|
128 | 128 | |
129 | 129 |
add_available_filter "subject", :type => :text |
130 | 130 |
add_available_filter "description", :type => :text |
... | ... | |
543 | 543 |
end |
544 | 544 |
end |
545 | 545 | |
546 |
def sql_for_category_id_field(field, operator, value) |
|
547 |
ids = value.select {|v| v.to_s =~ /\A\d+\z/} |
|
548 |
names = value - ids |
|
549 |
if names.any? |
|
550 |
ids += IssueCategory.where(:name => names).ids |
|
551 |
end |
|
552 |
sql_for_field(field, operator, ids.uniq, Issue.table_name, "category_id") |
|
553 |
end |
|
554 | ||
546 | 555 |
def sql_for_relations(field, operator, value, options={}) |
547 | 556 |
relation_options = IssueRelation::TYPES[field] |
548 | 557 |
return relation_options unless relation_options |
app/models/project.rb (copie de travail) | ||
---|---|---|
330 | 330 |
@users = nil |
331 | 331 |
@shared_versions = nil |
332 | 332 |
@rolled_up_versions = nil |
333 |
@rolled_up_issue_categories = nil |
|
333 | 334 |
@rolled_up_trackers = nil |
334 | 335 |
@rolled_up_statuses = nil |
335 | 336 |
@rolled_up_custom_fields = nil |
... | ... | |
482 | 483 |
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED) |
483 | 484 |
end |
484 | 485 | |
486 |
def rolled_up_issue_categories |
|
487 |
@rolled_up_issue_categories ||= |
|
488 |
IssueCategory. |
|
489 |
joins(:project). |
|
490 |
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED) |
|
491 |
end |
|
492 | ||
485 | 493 |
# Returns a scope of the Versions used by the project |
486 | 494 |
def shared_versions |
487 | 495 |
if new_record? |
app/models/query.rb (copie de travail) | ||
---|---|---|
162 | 162 |
end |
163 | 163 |
end |
164 | 164 | |
165 |
class IssueCategoryQueryColumn < QueryColumn |
|
166 |
|
|
167 |
def value_object(object) |
|
168 |
value(object) |
|
169 |
end |
|
170 |
|
|
171 |
def value(object) |
|
172 |
object.category.try(:name) |
|
173 |
end |
|
174 |
end |
|
175 | ||
165 | 176 |
class QueryFilter |
166 | 177 |
include Redmine::I18n |
167 | 178 | |
... | ... | |
569 | 580 |
watcher_values += users.sort_by(&:status).collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUS[s.status]}")] } if User.current.allowed_to?(:view_issue_watchers, self.project) |
570 | 581 |
watcher_values |
571 | 582 |
end |
583 |
|
|
584 |
def issue_category_values |
|
585 |
categories = |
|
586 |
if project |
|
587 |
project.rolled_up_issue_categories |
|
588 |
else |
|
589 |
IssueCategory |
|
590 |
end |
|
591 |
categories.visible.distinct.order(:name).pluck(:name, :name) |
|
592 |
end |
|
572 | 593 | |
594 |
def find_category_id_filter_values(values) |
|
595 |
ids = values.select {|v| v.to_s =~ /\A\d+\z/} |
|
596 |
IssueCategory.where(:id => ids).distinct.order(:name).pluck(:name, :id).map {|name, id| [name, id.to_s]} |
|
597 |
end |
|
598 | ||
573 | 599 |
# Returns a scope of issue custom fields that are available as columns or filters |
574 | 600 |
def issue_custom_fields |
575 | 601 |
if project |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »