annotate .svn/pristine/8d/8d774416d4f9f9cfc87a53af486a7209216cfa47.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # encoding: utf-8
Chris@1296 2 #
Chris@1296 3 # Redmine - project management software
Chris@1296 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 5 #
Chris@1296 6 # This program is free software; you can redistribute it and/or
Chris@1296 7 # modify it under the terms of the GNU General Public License
Chris@1296 8 # as published by the Free Software Foundation; either version 2
Chris@1296 9 # of the License, or (at your option) any later version.
Chris@1296 10 #
Chris@1296 11 # This program is distributed in the hope that it will be useful,
Chris@1296 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 14 # GNU General Public License for more details.
Chris@1296 15 #
Chris@1296 16 # You should have received a copy of the GNU General Public License
Chris@1296 17 # along with this program; if not, write to the Free Software
Chris@1296 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 19
Chris@1296 20 module QueriesHelper
Chris@1296 21 def filters_options_for_select(query)
Chris@1296 22 options_for_select(filters_options(query))
Chris@1296 23 end
Chris@1296 24
Chris@1296 25 def filters_options(query)
Chris@1296 26 options = [[]]
Chris@1296 27 sorted_options = query.available_filters.sort do |a, b|
Chris@1296 28 ord = 0
Chris@1296 29 if !(a[1][:order] == 20 && b[1][:order] == 20)
Chris@1296 30 ord = a[1][:order] <=> b[1][:order]
Chris@1296 31 else
Chris@1296 32 cn = (CustomField::CUSTOM_FIELDS_NAMES.index(a[1][:field].class.name) <=>
Chris@1296 33 CustomField::CUSTOM_FIELDS_NAMES.index(b[1][:field].class.name))
Chris@1296 34 if cn != 0
Chris@1296 35 ord = cn
Chris@1296 36 else
Chris@1296 37 f = (a[1][:field] <=> b[1][:field])
Chris@1296 38 if f != 0
Chris@1296 39 ord = f
Chris@1296 40 else
Chris@1296 41 # assigned_to or author
Chris@1296 42 ord = (a[0] <=> b[0])
Chris@1296 43 end
Chris@1296 44 end
Chris@1296 45 end
Chris@1296 46 ord
Chris@1296 47 end
Chris@1296 48 options += sorted_options.map do |field, field_options|
Chris@1296 49 [field_options[:name], field]
Chris@1296 50 end
Chris@1296 51 end
Chris@1296 52
Chris@1296 53 def available_block_columns_tags(query)
Chris@1296 54 tags = ''.html_safe
Chris@1296 55 query.available_block_columns.each do |column|
Chris@1296 56 tags << content_tag('label', check_box_tag('c[]', column.name.to_s, query.has_column?(column)) + " #{column.caption}", :class => 'inline')
Chris@1296 57 end
Chris@1296 58 tags
Chris@1296 59 end
Chris@1296 60
Chris@1296 61 def column_header(column)
Chris@1296 62 column.sortable ? sort_header_tag(column.name.to_s, :caption => column.caption,
Chris@1296 63 :default_order => column.default_order) :
Chris@1296 64 content_tag('th', h(column.caption))
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def column_content(column, issue)
Chris@1296 68 value = column.value(issue)
Chris@1296 69 if value.is_a?(Array)
Chris@1296 70 value.collect {|v| column_value(column, issue, v)}.compact.join(', ').html_safe
Chris@1296 71 else
Chris@1296 72 column_value(column, issue, value)
Chris@1296 73 end
Chris@1296 74 end
Chris@1296 75
Chris@1296 76 def column_value(column, issue, value)
Chris@1296 77 case value.class.name
Chris@1296 78 when 'String'
Chris@1296 79 if column.name == :subject
Chris@1296 80 link_to(h(value), :controller => 'issues', :action => 'show', :id => issue)
Chris@1296 81 elsif column.name == :description
Chris@1296 82 issue.description? ? content_tag('div', textilizable(issue, :description), :class => "wiki") : ''
Chris@1296 83 else
Chris@1296 84 h(value)
Chris@1296 85 end
Chris@1296 86 when 'Time'
Chris@1296 87 format_time(value)
Chris@1296 88 when 'Date'
Chris@1296 89 format_date(value)
Chris@1296 90 when 'Fixnum'
Chris@1296 91 if column.name == :done_ratio
Chris@1296 92 progress_bar(value, :width => '80px')
Chris@1296 93 else
Chris@1296 94 value.to_s
Chris@1296 95 end
Chris@1296 96 when 'Float'
Chris@1296 97 sprintf "%.2f", value
Chris@1296 98 when 'User'
Chris@1296 99 link_to_user value
Chris@1296 100 when 'Project'
Chris@1296 101 link_to_project value
Chris@1296 102 when 'Version'
Chris@1296 103 link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
Chris@1296 104 when 'TrueClass'
Chris@1296 105 l(:general_text_Yes)
Chris@1296 106 when 'FalseClass'
Chris@1296 107 l(:general_text_No)
Chris@1296 108 when 'Issue'
Chris@1296 109 link_to_issue(value, :subject => false)
Chris@1296 110 when 'IssueRelation'
Chris@1296 111 other = value.other_issue(issue)
Chris@1296 112 content_tag('span',
Chris@1296 113 (l(value.label_for(issue)) + " " + link_to_issue(other, :subject => false, :tracker => false)).html_safe,
Chris@1296 114 :class => value.css_classes_for(issue))
Chris@1296 115 else
Chris@1296 116 h(value)
Chris@1296 117 end
Chris@1296 118 end
Chris@1296 119
Chris@1296 120 # Retrieve query from session or build a new query
Chris@1296 121 def retrieve_query
Chris@1296 122 if !params[:query_id].blank?
Chris@1296 123 cond = "project_id IS NULL"
Chris@1296 124 cond << " OR project_id = #{@project.id}" if @project
Chris@1296 125 @query = Query.find(params[:query_id], :conditions => cond)
Chris@1296 126 raise ::Unauthorized unless @query.visible?
Chris@1296 127 @query.project = @project
Chris@1296 128 session[:query] = {:id => @query.id, :project_id => @query.project_id}
Chris@1296 129 sort_clear
Chris@1296 130 elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
Chris@1296 131 # Give it a name, required to be valid
Chris@1296 132 @query = Query.new(:name => "_")
Chris@1296 133 @query.project = @project
Chris@1296 134 build_query_from_params
Chris@1296 135 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
Chris@1296 136 else
Chris@1296 137 # retrieve from session
Chris@1296 138 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
Chris@1296 139 @query ||= Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
Chris@1296 140 @query.project = @project
Chris@1296 141 end
Chris@1296 142 end
Chris@1296 143
Chris@1296 144 def retrieve_query_from_session
Chris@1296 145 if session[:query]
Chris@1296 146 if session[:query][:id]
Chris@1296 147 @query = Query.find_by_id(session[:query][:id])
Chris@1296 148 return unless @query
Chris@1296 149 else
Chris@1296 150 @query = Query.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
Chris@1296 151 end
Chris@1296 152 if session[:query].has_key?(:project_id)
Chris@1296 153 @query.project_id = session[:query][:project_id]
Chris@1296 154 else
Chris@1296 155 @query.project = @project
Chris@1296 156 end
Chris@1296 157 @query
Chris@1296 158 end
Chris@1296 159 end
Chris@1296 160
Chris@1296 161 def build_query_from_params
Chris@1296 162 if params[:fields] || params[:f]
Chris@1296 163 @query.filters = {}
Chris@1296 164 @query.add_filters(params[:fields] || params[:f], params[:operators] || params[:op], params[:values] || params[:v])
Chris@1296 165 else
Chris@1296 166 @query.available_filters.keys.each do |field|
Chris@1296 167 @query.add_short_filter(field, params[field]) if params[field]
Chris@1296 168 end
Chris@1296 169 end
Chris@1296 170 @query.group_by = params[:group_by] || (params[:query] && params[:query][:group_by])
Chris@1296 171 @query.column_names = params[:c] || (params[:query] && params[:query][:column_names])
Chris@1296 172 end
Chris@1296 173 end