To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / queries_helper.rb @ 415:405dd646a6cc

History | View | Annotate | Download (3.63 KB)

1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
module QueriesHelper
19
  
20
  def operators_for_select(filter_type)
21
    Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
22
  end
23
  
24
  def column_header(column)
25
    column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
26
                                                        :default_order => column.default_order) : 
27
                      content_tag('th', column.caption)
28
  end
29
  
30
  def column_content(column, issue)
31
    value = column.value(issue)
32
    
33
    case value.class.name
34
    when 'String'
35
      if column.name == :subject
36
        link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
37
      else
38
        h(value)
39
      end
40
    when 'Time'
41
      format_time(value)
42
    when 'Date'
43
      format_date(value)
44
    when 'Fixnum', 'Float'
45
      if column.name == :done_ratio
46
        progress_bar(value, :width => '80px')
47
      else
48
        value.to_s
49
      end
50
    when 'User'
51
      link_to_user value
52
    when 'Project'
53
      link_to_project value
54
    when 'Version'
55
      link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
56
    when 'TrueClass'
57
      l(:general_text_Yes)
58
    when 'FalseClass'
59
      l(:general_text_No)
60
    when 'Issue'
61
      link_to_issue(value, :subject => false)
62
    else
63
      h(value)
64
    end
65
  end
66

    
67
  # Retrieve query from session or build a new query
68
  def retrieve_query
69
    if !params[:query_id].blank?
70
      cond = "project_id IS NULL"
71
      cond << " OR project_id = #{@project.id}" if @project
72
      @query = Query.find(params[:query_id], :conditions => cond)
73
      @query.project = @project
74
      session[:query] = {:id => @query.id, :project_id => @query.project_id}
75
      sort_clear
76
    else
77
      if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
78
        # Give it a name, required to be valid
79
        @query = Query.new(:name => "_")
80
        @query.project = @project
81
        if params[:fields]
82
          @query.filters = {}
83
          @query.add_filters(params[:fields], params[:operators], params[:values])
84
        else
85
          @query.available_filters.keys.each do |field|
86
            @query.add_short_filter(field, params[field]) if params[field]
87
          end
88
        end
89
        @query.group_by = params[:group_by]
90
        @query.column_names = params[:query] && params[:query][:column_names]
91
        session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
92
      else
93
        @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
94
        @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
95
        @query.project = @project
96
      end
97
    end
98
  end
99
end