13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/models/admin_list_page.rb', line 13
def render_value(record, column)
if column.name.include?('.')
parts = column.name.split('.')
raw_value = record
until parts.empty?
raw_value = raw_value.try(parts.shift)
end
else
raw_value = record.get(column.name)
end
value = ''
case column.style
when 'Text'
value = raw_value
when 'Boolean'
raw_value = raw_value ? column.true_text : column.false_text
value = raw_value
when 'Integer'
raw_value = raw_value.to_i
value = raw_value
when 'Float'
raw_value = raw_value.to_f
value = raw_value.round(column.decimals)
when 'Currency'
raw_value = raw_value.to_f
value = "#{symbol}#{raw_value.round(column.decimals)}"
when 'Percentage'
raw_value = raw_value.to_f
value = "#{raw_value.round(column.decimals)}%"
when 'Date'
if column.format
value = raw_value.strftime(column.format)
else
value = raw_value.strftime('%F')
end
raw_value = raw_value.strftime('%F %T')
when 'Time'
if column.format
value = raw_value.strftime(column.format)
else
value = raw_value.strftime('%R')
end
raw_value = raw_value.strftime('%T')
when 'DateTime'
if column.format
value = raw_value.strftime(column.format)
else
value = raw_value.strftime('%F %R')
end
raw_value = raw_value.strftime('%F %T')
when 'Label'
label_color = column.colors.find {|label_color| label_color.label == raw_value}
value = "<span style='background-color: ##{label_color.try(:color)}'>#{raw_value}</span>"
end
"<td data-value='#{raw_value}'>#{value}</td>"
end
|