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, #totalable

Instance Method Summary collapse

Methods inherited from QueryColumn

#frozen?, #group_value, #inline?, #sortable?

Methods included from Redmine::I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #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.


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

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

Instance Method Details

#captionObject


145
146
147
# File 'app/models/query.rb', line 145

def caption
  @cf.name
end

#css_classesObject


173
174
175
# File 'app/models/query.rb', line 173

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

#custom_fieldObject


149
150
151
# File 'app/models/query.rb', line 149

def custom_field
  @cf
end

#group_by_statementObject


141
142
143
# File 'app/models/query.rb', line 141

def group_by_statement
  @cf.group_statement
end

#groupable?Boolean

Returns:

  • (Boolean)

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

def groupable?
  group_by_statement.present?
end

#value(object) ⇒ Object


162
163
164
165
166
167
168
169
170
171
# File 'app/models/query.rb', line 162

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


153
154
155
156
157
158
159
160
# File 'app/models/query.rb', line 153

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