Class: QueryCustomFieldColumn

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

Direct Known Subclasses

QueryAssociationCustomFieldColumn

Instance Attribute Summary

Attributes inherited from QueryColumn

#default_order, #groupable, #name, #sortable

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_time, included, #l, #l_hours, #l_or_humanize, #languages_options, #ll, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(custom_field) ⇒ QueryCustomFieldColumn

Returns a new instance of QueryCustomFieldColumn.


78
79
80
81
82
83
84
# File 'app/models/query.rb', line 78

def initialize(custom_field)
  self.name = "cf_#{custom_field.id}".to_sym
  self.sortable = custom_field.order_statement || false
  self.groupable = custom_field.group_statement || false
  @inline = true
  @cf = custom_field
end

Instance Method Details

#captionObject


86
87
88
# File 'app/models/query.rb', line 86

def caption
  @cf.name
end

#css_classesObject


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

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

#custom_fieldObject


90
91
92
# File 'app/models/query.rb', line 90

def custom_field
  @cf
end

#value(object) ⇒ Object


103
104
105
106
107
108
109
110
111
112
# File 'app/models/query.rb', line 103

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


94
95
96
97
98
99
100
101
# File 'app/models/query.rb', line 94

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 {|a,b| a.value.to_s <=> b.value.to_s} : cv.first
  else
    nil
  end
end