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
|
# File 'lib/labimotion/utils/serializer.rb', line 35
def self.element_properties(object)
object.properties['layers']&.keys.each do |key|
field_sample_molecules = object.properties['layers'][key]['fields'].select { |ss| %w[drag_sample drag_element drag_element].include?(ss['type']) }
field_sample_molecules.each do |field|
idx = object.properties['layers'][key]['fields'].index(field)
sid = field.dig('value') != '' && field.dig('value', 'el_id')
next unless sid.present?
case field['type']
when 'drag_sample'
el = Sample.find_by(id: sid)
when 'drag_molecule'
el = Molecule.find_by(id: sid)
when 'drag_element'
el = Labimotion::Element.find_by(id: sid)
end
next unless el.present?
next unless object.properties.dig('layers', key, 'fields', idx, 'value').present?
object.properties['layers'][key]['fields'][idx]['value']['el_label'] = el.short_label if %w[drag_sample drag_element].include?(field['type'])
object.properties['layers'][key]['fields'][idx]['value']['el_tip'] = el.short_label if %w[drag_sample].include?(field['type'])
object.properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{el.element_klass&.label}@@#{el.name}" if %w[drag_element].include?(field['type'])
object.properties['layers'][key]['fields'][idx]['value']['icon_name'] = el.element_klass&.icon_name || '' if %w[drag_element].include?(field['type'])
object.properties['layers'][key]['fields'][idx]['value']['el_svg'] = field['type'] == 'drag_sample' ? el.get_svg_path : File.join('/images', 'molecules', el.molecule_svg_file) if %w[drag_sample drag_molecule].include?(field['type'])
object.properties['layers'][key]['fields'][idx]['value']['el_decoupled'] = el.decoupled if %w[drag_sample].include?(field['type'])
end
field_tables = object.properties['layers'][key]['fields'].select { |ss| ss['type'] == 'table' }
field_tables.each do |field|
idx = object.properties['layers'][key]['fields'].index(field)
next unless field['sub_values'].present? && field['sub_fields'].present?
field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
object.properties['layers'][key]['fields'][idx] = set_table(field, field_table_molecules, 'Molecule') if field_table_molecules.present?
field_table_samples = field['sub_fields'].select { |ss| ss['type'] == 'drag_sample' }
object.properties['layers'][key]['fields'][idx] = set_table(field, field_table_samples, 'Sample') if field_table_samples.present?
end
end
object.properties
end
|