6
7
8
9
10
11
12
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
|
# File 'lib/labimotion/libs/vocabulary_handler.rb', line 6
def self.update_vocabularies(properties, current_user, element)
properties[Labimotion::Prop::LAYERS].keys.each do |key|
layer = properties[Labimotion::Prop::LAYERS][key]
field_vocabularies = layer[Labimotion::Prop::FIELDS].select { |ss| ss['is_vocabulary'] == true && ss['opid'] == 9}
field_vocabularies.each do |field|
idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
val = ''
orig_val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
case field['source']
when 'System'
val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.update'
val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.create' && orig_val.blank?
when 'User'
val = current_user.name if field['identifier'] == 'user.name' && current_user.present?
when 'Element'
val = element.id.to_s if field['identifier'] == 'element.id'
val = element.short_label if element.has_attribute?(:short_label) && field['identifier'] == 'element.short_label'
when 'Segment'
segments = element.segments.joins(:segment_klass).find_by('segment_klasses.identifier = ?', field['source_id'])
next if segments.nil?
seg_prop = segments.properties
fields = seg_prop[Labimotion::Prop::LAYERS][field['layer_id']][Labimotion::Prop::FIELDS].select { |ss| ss['field'] == field['field_id'] }
val = fields.first['value']
when 'Dataset'
byebug
end
properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val if val.present?
end
end
properties
rescue StandardError => e
Labimotion.log_exception(e, current_user)
properties
end
|