Class: Labimotion::ElementRevisionEntity

Inherits:
ApplicationEntity show all
Defined in:
lib/labimotion/entities/element_revision_entity.rb

Overview

ElementRevisionEntity

Constant Summary

Constants inherited from ApplicationEntity

ApplicationEntity::CUSTOM_ENTITY_OPTIONS

Instance Method Summary collapse

Methods inherited from ApplicationEntity

expose!, expose_timestamps

Instance Method Details

#created_atObject



8
9
10
# File 'lib/labimotion/entities/element_revision_entity.rb', line 8

def created_at
  object.created_at.strftime('%d.%m.%Y, %H:%M')
end

#propertiesObject



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
# File 'lib/labimotion/entities/element_revision_entity.rb', line 12

def properties
  object.properties[Labimotion::Prop::LAYERS]&.keys.each do |key|
    field_sample_molecules = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE || ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
    field_sample_molecules.each do |field|
      idx = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
      sid = field.dig('value', 'el_id')
      next unless sid.present?

      el = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? Sample.find_by(id: sid) : Molecule.find_by(id: sid)
      next unless el.present?
      next unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx, 'value').present?

      object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_label'] = el.short_label if field['type'] == Labimotion::FieldType::DRAG_SAMPLE
      object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_tip'] = el.short_label if field['type'] == Labimotion::FieldType::DRAG_SAMPLE
      object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_svg'] = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? el.get_svg_path : File.join('/images', 'molecules', el&.molecule_svg_file || 'nosvg')
    end

    field_tables = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::TABLE }
    field_tables.each do |field|
      next unless field['sub_values'].present? && field['sub_fields'].present?

      field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
      next unless field_table_molecules.present?

      col_ids = field_table_molecules.map { |x| x.values[0] }
      col_ids.each do |col_id|
        field_table_values = field['sub_values'].each do |sub_value|
          next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?

          find_mol = Molecule.find_by(id: sub_value[col_id]['value']['el_id'])
          next unless find_mol.present?

          sub_value[col_id]['value']['el_svg'] = File.join('/images', 'molecules', find_mol.molecule_svg_file) if find_mol&.molecule_svg_file&.present?
          sub_value[col_id]['value']['el_inchikey'] = find_mol.inchikey
          sub_value[col_id]['value']['el_smiles'] = find_mol.cano_smiles
          sub_value[col_id]['value']['el_iupac'] = find_mol.iupac_name
          sub_value[col_id]['value']['el_molecular_weight'] = find_mol.molecular_weight
        end
      end
    end
  end
  object.properties['select_options'] = object.properties_release['select_options']
  object.properties
end