labimotion 1.1.4 → 1.2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labimotion/apis/generic_element_api.rb +32 -38
  3. data/lib/labimotion/collection/export.rb +45 -84
  4. data/lib/labimotion/collection/import.rb +60 -54
  5. data/lib/labimotion/entities/element_revision_entity.rb +10 -10
  6. data/lib/labimotion/entities/eln_element_entity.rb +23 -23
  7. data/lib/labimotion/entities/properties_entity.rb +18 -19
  8. data/lib/labimotion/entities/segment_revision_entity.rb +11 -11
  9. data/lib/labimotion/helpers/element_helpers.rb +14 -4
  10. data/lib/labimotion/helpers/generic_helpers.rb +9 -9
  11. data/lib/labimotion/helpers/segment_helpers.rb +1 -2
  12. data/lib/labimotion/libs/converter.rb +12 -12
  13. data/lib/labimotion/libs/export_dataset.rb +32 -6
  14. data/lib/labimotion/libs/nmr_mapper.rb +27 -27
  15. data/lib/labimotion/libs/properties_handler.rb +95 -0
  16. data/lib/labimotion/libs/sample_association.rb +15 -15
  17. data/lib/labimotion/models/concerns/generic_klass_revisions.rb +1 -1
  18. data/lib/labimotion/models/concerns/generic_revisions.rb +3 -3
  19. data/lib/labimotion/models/concerns/linked_properties.rb +18 -0
  20. data/lib/labimotion/models/concerns/segmentable.rb +17 -12
  21. data/lib/labimotion/models/element.rb +26 -17
  22. data/lib/labimotion/utils/export_utils.rb +196 -0
  23. data/lib/labimotion/utils/field_type.rb +23 -0
  24. data/lib/labimotion/utils/import_utils.rb +250 -59
  25. data/lib/labimotion/utils/prop.rb +27 -0
  26. data/lib/labimotion/utils/search.rb +2 -2
  27. data/lib/labimotion/utils/serializer.rb +22 -22
  28. data/lib/labimotion/version.rb +1 -1
  29. data/lib/labimotion.rb +4 -1
  30. metadata +7 -2
@@ -1,92 +1,283 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Labimotion
4
- ## Import Utils
5
4
  class ImportUtils
6
- def self.proc_sample(layer, key, data, properties)
7
- field_samples = layer['fields'].select { |ss| ss['type'] == 'drag_sample' }
8
- field_samples.each do |field|
9
- idx = properties['layers'][key]['fields'].index(field)
10
- id = field["value"] && field["value"]["el_id"] unless idx.nil?
5
+ class << self
6
+ private
7
+ def upload_type(element)
8
+ return nil if element.nil?
9
+
10
+ case Labimotion::Utils.element_name(element.class.name)
11
+ when Labimotion::Prop::ELEMENT
12
+ Labimotion::Prop::ELEMENTPROPS
13
+ when Labimotion::Prop::SEGMENT
14
+ Labimotion::Prop::SEGMENTPROPS
15
+ when Labimotion::Prop::DATASET
16
+ Labimotion::Prop::DATASETPROPS
17
+ end
18
+ end
19
+
20
+ def proc_assign_molecule(value, molecule)
21
+ return {} if molecule.nil?
22
+
23
+ value = {} if value.nil? || value.is_a?(String)
24
+ value['el_id'] = molecule.id
25
+ value['el_tip'] = "#{molecule.inchikey}@@#{molecule.cano_smiles}"
26
+ value['el_label'] = molecule.iupac_name
27
+ value['el_svg'] = File.join('/images', 'molecules', molecule.molecule_svg_file)
28
+ value['el_inchikey'] = molecule.inchikey
29
+ value['el_smiles'] = molecule.cano_smiles
30
+ value['el_type'] = 'molecule' if value['el_type'].nil?
31
+ value['el_iupac'] = molecule.iupac_name
32
+ value['el_molecular_weight'] = molecule.molecular_weight
33
+ value
34
+ rescue StandardError => e
35
+ Labimotion.log_exception(e)
36
+ value
37
+ end
38
+
39
+ def proc_assign_sample(value, sample, element)
40
+ return {} if sample.nil?
41
+
42
+ value = {} if value.nil? || value.is_a?(String)
43
+ value['el_id'] = sample.id
44
+ value['el_type'] = 'sample' if value['el_type'].nil?
45
+ value['el_tip'] = sample.short_label
46
+ value['el_label'] = sample.short_label
47
+ value['el_svg'] = sample.get_svg_path
48
+ if element&.class&.name == Labimotion::Prop::L_ELEMENT && sample&.class&.name == Labimotion::Prop::SAMPLE
49
+ Labimotion::ElementsSample.find_or_create_by(element_id: element.id, sample_id: sample.id)
50
+ end
51
+ value
52
+ rescue StandardError => e
53
+ Labimotion.log_exception(e)
54
+ value
55
+ end
56
+
57
+ def proc_assign_element(value, element, _parent = nil)
58
+ return {} if element.nil?
59
+
60
+ value = {} if value.nil? || value.is_a?(String)
61
+ value['el_id'] = element.id
62
+ value['el_type'] = 'element' if value['el_type'].nil?
63
+ value['el_tip'] = element.short_label
64
+ value['el_label'] = element.short_label
65
+ if _parent&.class&.name == Labimotion::Prop::L_ELEMENT && element&.class&.name == Labimotion::Prop::L_ELEMENT
66
+ Labimotion::ElementsElement.find_or_create_by(parent_id: _parent.id, element_id: element.id)
67
+ end
68
+ value
69
+ rescue StandardError => e
70
+ Labimotion.log_exception(e)
71
+ value
72
+ end
73
+
74
+ def proc_assign_upload(value, attachment)
75
+ return {} if attachment.nil?
76
+
77
+ value = {} if value.nil? || value.is_a?(String)
78
+ value['aid'] = attachment.id
79
+ value['uid'] = attachment.identifier
80
+ value['filename'] = attachment.filename
81
+ value
82
+ rescue StandardError => e
83
+ Labimotion.log_exception(e)
84
+ value
85
+ end
86
+
87
+
88
+ def proc_table_molecule(properties, data, svalue, key, tidx, vdx, col_id)
89
+ return properties unless id = svalue.fetch('el_id', nil)
90
+
91
+ molfile = data.fetch(Labimotion::Prop::MOLECULE, nil)&.fetch(id, nil)&.fetch('molfile', nil)
92
+ tmol = Molecule.find_or_create_by_molfile(molfile) if molfile.present?
93
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value']
94
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value'] = proc_assign_molecule(val, tmol)
95
+ properties
96
+ rescue StandardError => e
97
+ Labimotion.log_exception(e)
98
+ properties
99
+ end
100
+
101
+ def proc_table_sample(properties, data, instances, svalue, key, tidx, vdx, col_id, element)
102
+ return properties unless id = svalue.fetch('el_id', nil)
103
+
104
+ # orig_s = data.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(svalue['el_id'], nil)
105
+ sample = instances.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(id, nil)
106
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value']
107
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value'] = proc_assign_sample(val, sample, element)
108
+ properties
109
+ rescue StandardError => e
110
+ Labimotion.log_exception(e)
111
+ properties
112
+ end
113
+
114
+ def proc_table_prop(layer, key, data, instance, properties, field, tidx, type, element)
115
+ fields = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == type }
116
+ return properties if fields.nil?
117
+
118
+ col_ids = fields.map { |x| x.values[0] }
119
+ col_ids.each do |col_id|
120
+ next if field[Labimotion::Prop::SUBVALUES].nil?
121
+
122
+ field[Labimotion::Prop::SUBVALUES].each_with_index do |sub_value, vdx|
123
+ next unless sub_value.fetch(col_id, nil)&.fetch('value', nil).is_a?(Hash)
124
+
125
+ next if sub_value.fetch(col_id, nil)&.fetch('value', nil)&.fetch('el_id', nil).nil?
126
+
127
+ svalue = sub_value.fetch(col_id, nil)&.fetch('value', nil)
128
+ next if svalue.fetch('el_id', nil).nil? ## || svalue.fetch('el_inchikey', nil).nil? (molecule only?)
129
+
130
+ case type
131
+ when Labimotion::FieldType::DRAG_MOLECULE
132
+ properties = proc_table_molecule(properties, data, svalue, key, tidx, vdx, col_id)
133
+ when Labimotion::FieldType::DRAG_SAMPLE
134
+ properties = proc_table_sample(properties, data, instance, svalue, key, tidx, vdx, col_id, element)
135
+ end
136
+ end
137
+ end
138
+ properties
139
+ rescue StandardError => e
140
+ Labimotion.log_exception(e)
141
+ properties
142
+ end
143
+ end
11
144
 
12
- # mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
13
- # unless mol.nil?
14
- # properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
15
- # properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
16
- # properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
17
- # end
145
+ def self.proc_sample(layer, key, data, instances, properties, element)
146
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE }
147
+ fields.each do |field|
148
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
149
+ id = field["value"] && field["value"]["el_id"] unless idx.nil?
150
+ sample = instances.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(id, nil)
151
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
152
+ val = proc_assign_sample(val, sample, element)
153
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val
18
154
  end
19
155
  properties
20
156
  rescue StandardError => e
21
- Rails.logger.error(e.backtrace)
157
+ Labimotion.log_exception(e)
22
158
  raise
23
159
  end
24
160
 
25
- def self.proc_molecule(layer, key, data, properties)
26
- field_molecules = layer['fields'].select { |ss| ss['type'] == 'drag_molecule' }
27
- field_molecules.each do |field|
28
- idx = properties['layers'][key]['fields'].index(field)
161
+ def self.proc_element(layer, key, data, instances, properties, elements, element)
162
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_ELEMENT }
163
+ fields.each do |field|
164
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
29
165
  id = field["value"] && field["value"]["el_id"] unless idx.nil?
30
- mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
31
- unless mol.nil?
32
- properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
33
- properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
34
- properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
166
+ att_el = (elements && elements[id]) || instances.fetch(Labimotion::Prop::L_ELEMENT, nil)&.fetch(id, nil)
167
+ if att_el.nil?
168
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = {}
169
+ else
170
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
171
+ val = proc_assign_element(val, att_el, element)
172
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val
35
173
  end
36
174
  end
37
175
  properties
38
176
  rescue StandardError => e
39
- Rails.logger.error(e.backtrace)
177
+ Labimotion.log_exception(e)
40
178
  raise
41
179
  end
42
180
 
43
- def self.proc_table(layer, key, data, properties)
44
- field_tables = layer['fields'].select { |ss| ss['type'] == 'table' }
45
- field_tables&.each do |field|
46
- tidx = layer['fields'].index(field)
47
- next unless field['sub_values'].present? && field['sub_fields'].present?
48
-
49
- field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
50
- if field_table_molecules.present?
51
- col_ids = field_table_molecules.map { |x| x.values[0] }
52
- col_ids.each do |col_id|
53
- field['sub_values'].each_with_index do |sub_value, vdx|
54
- next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
55
-
56
- svalue = sub_value[col_id]['value']
57
- next unless svalue['el_id'].present? && svalue['el_inchikey'].present?
58
-
59
- tmol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[svalue['el_id']]['molfile']) unless svalue['el_id'].nil?
60
- unless tmol.nil?
61
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_id'] = tmol.id
62
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_tip'] = "#{tmol.inchikey}@@#{tmol.cano_smiles}"
63
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_label'] = tmol.cano_smiles
64
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_smiles'] = tmol.cano_smiles
65
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_iupac'] = tmol.iupac_name
66
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_inchikey'] = tmol.inchikey
67
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_svg'] = File.join('/images', 'molecules', tmol.molecule_svg_file)
68
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_molecular_weight'] = tmol.molecular_weight
69
- end
70
- end
71
- end
181
+ def self.proc_upload(layer, key, data, instances, attachments, element)
182
+ properties = element.properties
183
+ upload_type = upload_type(element)
184
+ return if upload_type.nil?
185
+
186
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::UPLOAD }
187
+ fields.each do |field|
188
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
189
+ next if idx.nil?
190
+
191
+ files = field["value"] && field["value"]["files"]
192
+ files&.each_with_index do |fi, fdx|
193
+ aid = properties['layers'][key]['fields'][idx]['value']['files'][fdx]['aid']
194
+ uid = properties['layers'][key]['fields'][idx]['value']['files'][fdx]['uid']
195
+ att = data.fetch('Attachment', nil)&.fetch(aid, nil)
196
+ attachment = Attachment.find_by('id IN (?) AND filename LIKE ? ', attachments, uid << '%')
197
+ next if attachment.nil? || att.nil?
198
+
199
+ attachment.update!(attachable_id: element.id, attachable_type: upload_type, transferred: true, aasm_state: att['aasm_state'], filename: att['filename'])
200
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['files'][fdx]
201
+ val = proc_assign_upload(val, attachment)
202
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['files'][fdx] = val
72
203
  end
73
204
  end
74
205
  properties
75
206
  rescue StandardError => e
76
- Rails.logger.error(e.backtrace)
207
+ Labimotion.log_exception(e)
208
+ properties
209
+ end
210
+
211
+ def self.proc_molecule(layer, key, data, properties)
212
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
213
+ fields.each do |field|
214
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
215
+ next if idx.nil? || field.fetch('value', nil).nil?
216
+
217
+ next unless field.fetch('value', nil).is_a?(Hash)
218
+
219
+ id = field.fetch('value', nil)&.fetch('el_id', nil) unless idx.nil?
220
+ molfile = data.fetch(Labimotion::Prop::MOLECULE, nil)&.fetch(id, nil)&.fetch('molfile', nil) unless id.nil?
221
+ next if molfile.nil?
222
+
223
+ mol = Molecule.find_or_create_by_molfile(molfile)
224
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
225
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = proc_assign_molecule(val, mol)
226
+ end
227
+ properties
228
+ rescue StandardError => e
229
+ Labimotion.log_exception(e)
77
230
  raise
78
231
  end
79
232
 
80
- def self.properties_handler(data, properties)
81
- properties && properties['layers'] && properties['layers'].keys&.each do |key|
82
- layer = properties['layers'][key]
233
+
234
+ def self.proc_table(layer, key, data, instance, properties, element)
235
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::TABLE }
236
+ fields&.each do |field|
237
+ tidx = layer[Labimotion::Prop::FIELDS].index(field)
238
+ next unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
239
+
240
+ proc_table_prop(layer, key, data, instance, properties, field, tidx, Labimotion::FieldType::DRAG_MOLECULE, element)
241
+ proc_table_prop(layer, key, data, instance, properties, field, tidx, Labimotion::FieldType::DRAG_SAMPLE, element)
242
+ end
243
+ properties
244
+ rescue StandardError => e
245
+ Labimotion.log_exception(e)
246
+ raise
247
+ end
248
+
249
+ def self.properties_handler(data, instances, attachments, elmenet, elements)
250
+ properties = elmenet.properties
251
+ properties.fetch(Labimotion::Prop::LAYERS, nil)&.keys&.each do |key|
252
+ layer = properties[Labimotion::Prop::LAYERS][key]
83
253
  properties = proc_molecule(layer, key, data, properties)
84
- properties = proc_table(layer, key, data, properties)
85
- # properties = proc_sample(layer, key, data, properties)
254
+ properties = proc_upload(layer, key, data, instances, attachments, elmenet)
255
+ properties = proc_sample(layer, key, data, instances, properties, elmenet)
256
+ properties = proc_element(layer, key, data, instances, properties, elements, elmenet) # unless elements.nil?
257
+ properties = proc_table(layer, key, data, instances, properties, elmenet)
86
258
  end
87
259
  properties
88
260
  rescue StandardError => e
89
- Rails.logger.error(e.backtrace)
261
+ Labimotion.log_exception(e)
262
+ raise
263
+ end
264
+
265
+ def self.process_ai(data, instances)
266
+ ai_has_changed = false
267
+ instances&.fetch(Labimotion::Prop::L_ELEMENT, nil)&.each do |uuid, element|
268
+ properties = element.properties
269
+ properties.fetch(Labimotion::Prop::LAYERS, nil)&.keys&.each do |key|
270
+ layer = properties[Labimotion::Prop::LAYERS][key]
271
+ layer.fetch('ai', nil)&.each_with_index do |ai_key, idx|
272
+ ana = instances.fetch(Labimotion::Prop::CONTAINER)&.fetch(ai_key, nil)
273
+ properties[Labimotion::Prop::LAYERS][key]['ai'][idx] = ana.id unless ana.nil?
274
+ ai_has_changed = true
275
+ end
276
+ end
277
+ element.update_columns(properties: properties) if ai_has_changed
278
+ end
279
+ rescue StandardError => e
280
+ Labimotion.log_exception(e)
90
281
  raise
91
282
  end
92
283
 
@@ -0,0 +1,27 @@
1
+ module Labimotion
2
+ ## Converter State
3
+ class Prop
4
+ LAYERS = 'layers'.freeze
5
+ FIELDS = 'fields'.freeze
6
+ SUBFIELDS = 'sub_fields'.freeze
7
+ SUBVALUES = 'sub_values'.freeze
8
+ SEL_OPTIONS = 'select_options'.freeze
9
+ L_DATASET_KLASS = 'Labimotion::DatasetKlass'.freeze
10
+ L_ELEMENT_KLASS = 'Labimotion::ElementKlass'.freeze
11
+ L_SEGMENT_KLASS = 'Labimotion::SegmentKlass'.freeze
12
+ L_ELEMENT = 'Labimotion::Element'.freeze
13
+ L_SEGMENT = 'Labimotion::Segment'.freeze
14
+ L_DATASET = 'Labimotion::Dataset'.freeze
15
+ SEGMENT = 'Segment'.freeze
16
+ ELEMENT = 'Element'.freeze
17
+ DATASET = 'Dataset'.freeze
18
+ SAMPLE = 'Sample'.freeze
19
+ MOLECULE = 'Molecule'.freeze
20
+ REACTION = 'Reaction'.freeze
21
+ CONTAINER = 'Container'.freeze
22
+ ELEMENTPROPS = 'ElementProps'.freeze
23
+ SEGMENTPROPS = 'SegmentProps'.freeze
24
+ DATASETPROPS = 'DatasetProps'.freeze
25
+ UPLOADPROPS = [ELEMENTPROPS, SEGMENTPROPS, DATASETPROPS].freeze
26
+ end
27
+ end
@@ -30,7 +30,7 @@ module Labimotion
30
30
  query_field = { "fields": [{ "field": f[:field].to_s, "sub_fields": sfs }] } unless sfs.empty?
31
31
  elsif %w[checkbox integer system-defined].include? f[:type]
32
32
  query_field = { "fields": [{ "field": f[:field].to_s, "value": f[:value] }] }
33
- elsif %w[drag_element drag_molecule drag_sample].include? f[:type]
33
+ elsif Labimotion::FieldType::DRAG_ALL.include? f[:type]
34
34
  vfs = { "el_label": f[:value] }
35
35
  query_field = { "fields": [{ "field": f[:field].to_s, "value": vfs }] } unless f[:value].empty?
36
36
  else
@@ -70,7 +70,7 @@ module Labimotion
70
70
  query_field = { "fields": [{ "field": f[:field].to_s, "sub_fields": sfs }] } unless sfs.empty?
71
71
  elsif %w[checkbox integer system-defined].include? f[:type]
72
72
  query_field = { "fields": [{ "field": f[:field].to_s, "value": f[:value] }] }
73
- elsif %w[drag_element drag_molecule drag_sample].include? f[:type]
73
+ elsif Labimotion::FieldType::DRAG_ALL.include? f[:type]
74
74
  vfs = { "el_label": f[:value] }
75
75
  query_field = { "fields": [{ "field": f[:field].to_s, "value": vfs }] } unless f[:value].empty?
76
76
  else
@@ -12,13 +12,13 @@ module Labimotion
12
12
  next unless find_obj.present?
13
13
 
14
14
  case obj
15
- when 'Molecule'
15
+ when Labimotion::Prop::MOLECULE
16
16
  sub_value[col_id]['value']['el_svg'] = File.join('/images', 'molecules', find_obj.molecule_svg_file)
17
17
  sub_value[col_id]['value']['el_inchikey'] = find_obj.inchikey
18
18
  sub_value[col_id]['value']['el_smiles'] = find_obj.cano_smiles
19
19
  sub_value[col_id]['value']['el_iupac'] = find_obj.iupac_name
20
20
  sub_value[col_id]['value']['el_molecular_weight'] = find_obj.molecular_weight
21
- when 'Sample'
21
+ when Labimotion::Prop::SAMPLE
22
22
  sub_value[col_id]['value']['el_svg'] = find_obj.get_svg_path
23
23
  sub_value[col_id]['value']['el_label'] = find_obj.short_label
24
24
  sub_value[col_id]['value']['el_short_label'] = find_obj.short_label
@@ -33,43 +33,43 @@ module Labimotion
33
33
  end
34
34
 
35
35
  def self.element_properties(object)
36
- object.properties['layers']&.keys.each do |key|
36
+ object.properties[Labimotion::Prop::LAYERS]&.keys.each do |key|
37
37
  # layer = object.properties[key]
38
- field_sample_molecules = object.properties['layers'][key]['fields'].select { |ss| %w[drag_sample drag_element drag_element].include?(ss['type']) }
38
+ field_sample_molecules = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| Labimotion::FieldType::DRAG_ALL.include?(ss['type']) }
39
39
  field_sample_molecules.each do |field|
40
- idx = object.properties['layers'][key]['fields'].index(field)
40
+ idx = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
41
41
  sid = field.dig('value') != '' && field.dig('value', 'el_id')
42
42
  next unless sid.present?
43
43
 
44
44
  case field['type']
45
- when 'drag_sample'
45
+ when Labimotion::FieldType::DRAG_SAMPLE
46
46
  el = Sample.find_by(id: sid)
47
- when 'drag_molecule'
47
+ when Labimotion::FieldType::DRAG_MOLECULE
48
48
  el = Molecule.find_by(id: sid)
49
- when 'drag_element'
49
+ when Labimotion::FieldType::DRAG_ELEMENT
50
50
  el = Labimotion::Element.find_by(id: sid)
51
51
  end
52
52
  next unless el.present?
53
- next unless object.properties.dig('layers', key, 'fields', idx, 'value').present?
53
+ next unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx, 'value').present?
54
54
 
55
- object.properties['layers'][key]['fields'][idx]['value']['el_label'] = el.short_label if %w[drag_sample drag_element].include?(field['type'])
56
- object.properties['layers'][key]['fields'][idx]['value']['el_tip'] = el.short_label if %w[drag_sample].include?(field['type'])
57
- object.properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{el.element_klass&.label}@@#{el.name}" if %w[drag_element].include?(field['type'])
58
- object.properties['layers'][key]['fields'][idx]['value']['icon_name'] = el.element_klass&.icon_name || '' if %w[drag_element].include?(field['type'])
59
- 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'])
60
- object.properties['layers'][key]['fields'][idx]['value']['el_decoupled'] = el.decoupled if %w[drag_sample].include?(field['type'])
55
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_label'] = el.short_label if %w[drag_sample drag_element].include?(field['type'])
56
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_tip'] = el.short_label if %w[drag_sample].include?(field['type'])
57
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_tip'] = "#{el.element_klass&.label}@@#{el.name}" if %w[drag_element].include?(field['type'])
58
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['icon_name'] = el.element_klass&.icon_name || '' if %w[drag_element].include?(field['type'])
59
+ 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) if Labimotion::FieldType::DRAG_MS.include?(field['type'])
60
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['el_decoupled'] = el.decoupled if %w[drag_sample].include?(field['type'])
61
61
  end
62
62
 
63
- field_tables = object.properties['layers'][key]['fields'].select { |ss| ss['type'] == 'table' }
63
+ field_tables = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::TABLE }
64
64
  field_tables.each do |field|
65
- idx = object.properties['layers'][key]['fields'].index(field)
66
- next unless field['sub_values'].present? && field['sub_fields'].present?
65
+ idx = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
66
+ next unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
67
67
 
68
- field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
69
- object.properties['layers'][key]['fields'][idx] = set_table(field, field_table_molecules, 'Molecule') if field_table_molecules.present?
68
+ field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
69
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] = set_table(field, field_table_molecules, Labimotion::Prop::MOLECULE) if field_table_molecules.present?
70
70
 
71
- field_table_samples = field['sub_fields'].select { |ss| ss['type'] == 'drag_sample' }
72
- object.properties['layers'][key]['fields'][idx] = set_table(field, field_table_samples, 'Sample') if field_table_samples.present?
71
+ field_table_samples = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE }
72
+ object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] = set_table(field, field_table_samples, Labimotion::Prop::SAMPLE) if field_table_samples.present?
73
73
  end
74
74
  end
75
75
  object.properties
@@ -3,5 +3,5 @@
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
5
  IS_RAILS5 = false
6
- VERSION = '1.1.4'
6
+ VERSION = '1.2.0.1'
7
7
  end
data/lib/labimotion.rb CHANGED
@@ -59,13 +59,15 @@ module Labimotion
59
59
  autoload :TemplateHub, 'labimotion/libs/template_hub'
60
60
  autoload :ExportDataset, 'labimotion/libs/export_dataset'
61
61
  autoload :SampleAssociation, 'labimotion/libs/sample_association'
62
+ autoload :PropertiesHandler, 'labimotion/libs/properties_handler'
62
63
 
63
64
  ######## Utils
65
+ autoload :Prop, 'labimotion/utils/prop'
64
66
  autoload :ConState, 'labimotion/utils/con_state'
67
+ autoload :FieldType, 'labimotion/utils/field_type'
65
68
  autoload :Serializer, 'labimotion/utils/serializer'
66
69
  autoload :Search, 'labimotion/utils/search'
67
70
 
68
-
69
71
  ######## Collection
70
72
  autoload :Export, 'labimotion/collection/export'
71
73
  autoload :Import, 'labimotion/collection/import'
@@ -97,6 +99,7 @@ module Labimotion
97
99
  autoload :Segmentable, 'labimotion/models/concerns/segmentable'
98
100
  autoload :Datasetable, 'labimotion/models/concerns/datasetable'
99
101
  autoload :AttachmentConverter, 'labimotion/models/concerns/attachment_converter.rb'
102
+ autoload :LinkedProperties, 'labimotion/models/concerns/linked_properties'
100
103
 
101
104
 
102
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labimotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chia-Lin Lin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-02-15 00:00:00.000000000 Z
12
+ date: 2024-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -67,6 +67,7 @@ files:
67
67
  - lib/labimotion/libs/converter.rb
68
68
  - lib/labimotion/libs/export_dataset.rb
69
69
  - lib/labimotion/libs/nmr_mapper.rb
70
+ - lib/labimotion/libs/properties_handler.rb
70
71
  - lib/labimotion/libs/sample_association.rb
71
72
  - lib/labimotion/libs/template_hub.rb
72
73
  - lib/labimotion/models/collections_element.rb
@@ -74,6 +75,7 @@ files:
74
75
  - lib/labimotion/models/concerns/datasetable.rb
75
76
  - lib/labimotion/models/concerns/generic_klass_revisions.rb
76
77
  - lib/labimotion/models/concerns/generic_revisions.rb
78
+ - lib/labimotion/models/concerns/linked_properties.rb
77
79
  - lib/labimotion/models/concerns/segmentable.rb
78
80
  - lib/labimotion/models/concerns/workflow.rb
79
81
  - lib/labimotion/models/dataset.rb
@@ -92,7 +94,10 @@ files:
92
94
  - lib/labimotion/models/segment_klasses_revision.rb
93
95
  - lib/labimotion/models/segments_revision.rb
94
96
  - lib/labimotion/utils/con_state.rb
97
+ - lib/labimotion/utils/export_utils.rb
98
+ - lib/labimotion/utils/field_type.rb
95
99
  - lib/labimotion/utils/import_utils.rb
100
+ - lib/labimotion/utils/prop.rb
96
101
  - lib/labimotion/utils/search.rb
97
102
  - lib/labimotion/utils/serializer.rb
98
103
  - lib/labimotion/utils/utils.rb