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 @ 969:e632838adb35

History | View | Annotate | Download (3.82 KB)

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

    
20
module QueriesHelper
21

    
22
  def operators_for_select(filter_type)
23
    Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]}
24
  end
25

    
26
  def column_header(column)
27
    column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
28
                                                        :default_order => column.default_order) :
29
                      content_tag('th', h(column.caption))
30
  end
31

    
32
  def column_content(column, issue)
33
    value = column.value(issue)
34

    
35
    case value.class.name
36
    when 'String'
37
      if column.name == :subject
38
        link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
39
      else
40
        h(value)
41
      end
42
    when 'Time'
43
      format_time(value)
44
    when 'Date'
45
      format_date(value)
46
    when 'Fixnum', 'Float'
47
      if column.name == :done_ratio
48
        progress_bar(value, :width => '80px')
49
      else
50
        h(value.to_s)
51
      end
52
    when 'User'
53
      link_to_user value
54
    when 'Project'
55
      link_to_project value
56
    when 'Version'
57
      link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
58
    when 'TrueClass'
59
      l(:general_text_Yes)
60
    when 'FalseClass'
61
      l(:general_text_No)
62
    when 'Issue'
63
      link_to_issue(value, :subject => false)
64
    else
65
      h(value)
66
    end
67
  end
68

    
69
  # Retrieve query from session or build a new query
70
  def retrieve_query
71
    if !params[:query_id].blank?
72
      cond = "project_id IS NULL"
73
      cond << " OR project_id = #{@project.id}" if @project
74
      @query = Query.find(params[:query_id], :conditions => cond)
75
      raise ::Unauthorized unless @query.visible?
76
      @query.project = @project
77
      session[:query] = {:id => @query.id, :project_id => @query.project_id}
78
      sort_clear
79
    elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
80
      # Give it a name, required to be valid
81
      @query = Query.new(:name => "_")
82
      @query.project = @project
83
      build_query_from_params
84
      session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
85
    else
86
      # retrieve from session
87
      @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
88
      @query ||= Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
89
      @query.project = @project
90
    end
91
  end
92

    
93
  def build_query_from_params
94
    if params[:fields] || params[:f]
95
      @query.filters = {}
96
      @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
97
    else
98
      @query.available_filters.keys.each do |field|
99
        @query.add_short_filter(field, params[field]) if params[field]
100
      end
101
    end
102
    @query.group_by = params[:group_by] || (params[:query] && params[:query][:group_by])
103
    @query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
104
  end
105
end