end
def sidebar_queries
- unless @sidebar_queries
- @sidebar_queries = IssueQuery.visible.
- order("#{Query.table_name}.name ASC").
- # Project specific queries and global queries
- where(@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]).
- to_a
- end
- @sidebar_queries
+ @sidebar_queries ||= IssueQuery.visible.global_or_on_project(@project).sorted.to_a
end
def query_links(title, queries)
# Permission required to view the queries, set on subclasses.
class_attribute :view_permission
+ # Scope of queries that are global or on the given project
+ scope :global_or_on_project, lambda {|project|
+ where(:project_id => (project.nil? ? nil : [nil, project.id]))
+ }
+
+ scope :sorted, lambda {order(:name, :id)}
+
# Scope of visible queries, can be used from subclasses only.
# Unlike other visible scopes, a class methods is used as it
# let handle inheritance more nicely than scope DSL.