Project

General

Profile

Patch #2002 » dividing_public_and_private_queries.patch

patch vs. trunk - Mariusz Olejnik, 2008-10-07 12:47

View differences:

app/helpers/issues_helper.rb (working copy)
32 32
      "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
33 33
      "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
34 34
  end
35

  
36
  def sidebar_queries_custom(visible)
37
    # Project specific queries and global queries
38
    visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
39
    @sidebar_queries_custom = Query.find(:all, 
40
                                  :order => "name ASC",
41
                                  :conditions => visible.conditions)
42
    @sidebar_queries_custom
43
  end
35 44
  
36 45
  def sidebar_queries
37 46
    unless @sidebar_queries
38 47
      # User can see public queries and his own queries
39 48
      visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
40
      # Project specific queries and global queries
41
      visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
42
      @sidebar_queries = Query.find(:all, 
43
                                    :order => "name ASC",
44
                                    :conditions => visible.conditions)
49
      @sidebar_queries = sidebar_queries_custom(visible)
45 50
    end
46 51
    @sidebar_queries
47 52
  end
48 53

  
54
  def sidebar_queries_public
55
    unless @sidebar_queries_public
56
      # User can see public queries
57
      visible = ARCondition.new(["is_public = ?", true])
58
      @sidebar_queries_public = sidebar_queries_custom(visible)
59
    end
60
    @sidebar_queries_public
61
  end
62

  
63
  def sidebar_queries_private
64
    unless @sidebar_queries_private
65
      # User can see private queries
66
      visible = ARCondition.new(["is_public = ? AND user_id = ?", false, (User.current.logged? ? User.current.id : 0)])
67
      @sidebar_queries_private = sidebar_queries_custom(visible)
68
    end
69
    @sidebar_queries_private
70
  end
71

  
49 72
  def show_detail(detail, no_html=false)
50 73
    case detail.property
51 74
    when 'attr'
app/views/issues/_sidebar.rhtml (working copy)
15 15

  
16 16
<% end %>
17 17

  
18
<% unless sidebar_queries.empty? -%>
19 18
<h3><%= l(:label_query_plural) %></h3>
19
<% unless sidebar_queries_public.empty? -%>
20
<% sidebar_queries_public.each do |query| -%>
21
<%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %><br />
22
<% end -%>
23
<% end -%>
20 24

  
21
<% sidebar_queries.each do |query| -%>
25
<% unless sidebar_queries_private.empty? -%>
26
<br />
27
<% sidebar_queries_private.each do |query| -%>
22 28
<%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %><br />
23 29
<% end -%>
24 30
<% end -%>
(2-2/2)