Class: QueryCustomFieldColumn

Inherits:
QueryColumn show all
Defined in:
app/models/query.rb

Overview

Since:

  • 0.6.1

Direct Known Subclasses

QueryAssociationCustomFieldColumn

Instance Attribute Summary

Attributes inherited from QueryColumn

#default_order, #groupable, #name, #sortable, #totalable

Instance Method Summary collapse

Methods inherited from QueryColumn

#frozen?, #inline?, #sortable?

Methods included from Redmine::I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(custom_field, options = {}) ⇒ QueryCustomFieldColumn

Returns a new instance of QueryCustomFieldColumn



101
102
103
104
105
106
107
108
# File 'app/models/query.rb', line 101

def initialize(custom_field, options={})
  self.name = "cf_#{custom_field.id}".to_sym
  self.sortable = custom_field.order_statement || false
  self.groupable = custom_field.group_statement || false
  self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable?
  @inline = true
  @cf = custom_field
end

Instance Method Details

#captionObject



110
111
112
# File 'app/models/query.rb', line 110

def caption
  @cf.name
end

#css_classesObject

Since:

  • 1.2.0



138
139
140
# File 'app/models/query.rb', line 138

def css_classes
  @css_classes ||= "#{name} #{@cf.field_format}"
end

#custom_fieldObject



114
115
116
# File 'app/models/query.rb', line 114

def custom_field
  @cf
end

#value(object) ⇒ Object

Since:

  • 0.9.0



127
128
129
130
131
132
133
134
135
136
# File 'app/models/query.rb', line 127

def value(object)
  raw = value_object(object)
  if raw.is_a?(Array)
    raw.map {|r| @cf.cast_value(r.value)}
  elsif raw
    @cf.cast_value(raw.value)
  else
    nil
  end
end

#value_object(object) ⇒ Object

Since:

  • 2.6.0



118
119
120
121
122
123
124
125
# File 'app/models/query.rb', line 118

def value_object(object)
  if custom_field.visible_by?(object.project, User.current)
    cv = object.custom_values.select {|v| v.custom_field_id == @cf.id}
    cv.size > 1 ? cv.sort_by {|e| e.value.to_s} : cv.first
  else
    nil
  end
end