Class: QueryCustomFieldColumn
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?
#abbr_day_name, #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
Returns a new instance of QueryCustomFieldColumn.
128
129
130
131
132
133
134
135
136
137
|
# File 'app/models/query.rb', line 128
def initialize(custom_field, options={})
name = "cf_#{custom_field.id}".to_sym
super(
name,
:sortable => custom_field.order_statement || false,
:totalable => options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable?,
:inline => custom_field.full_width_layout? ? false : true
)
@cf = custom_field
end
|
Instance Method Details
#caption ⇒ Object
147
148
149
|
# File 'app/models/query.rb', line 147
def caption
@cf.name
end
|
#css_classes ⇒ Object
176
177
178
|
# File 'app/models/query.rb', line 176
def css_classes
@css_classes ||= "#{name} #{@cf.field_format}"
end
|
#custom_field ⇒ Object
151
152
153
|
# File 'app/models/query.rb', line 151
def custom_field
@cf
end
|
#group_by_statement ⇒ Object
143
144
145
|
# File 'app/models/query.rb', line 143
def group_by_statement
@cf.group_statement
end
|
#groupable? ⇒ Boolean
139
140
141
|
# File 'app/models/query.rb', line 139
def groupable?
group_by_statement.present?
end
|
#value(object) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'app/models/query.rb', line 165
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
155
156
157
158
159
160
161
162
163
|
# File 'app/models/query.rb', line 155
def value_object(object)
project = object.project if object.respond_to?(:project)
if custom_field.visible_by?(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
|