labimotion 1.1.3 → 1.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 -13
  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 +244 -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,277 @@
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)
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
+ value
49
+ rescue StandardError => e
50
+ Labimotion.log_exception(e)
51
+ value
52
+ end
53
+
54
+ def proc_assign_element(value, element)
55
+ return {} if element.nil?
56
+
57
+ value = {} if value.nil? || value.is_a?(String)
58
+ value['el_id'] = element.id
59
+ value['el_type'] = 'element' if value['el_type'].nil?
60
+ value['el_tip'] = element.short_label
61
+ value['el_label'] = element.short_label
62
+ value
63
+ rescue StandardError => e
64
+ Labimotion.log_exception(e)
65
+ value
66
+ end
67
+
68
+ def proc_assign_upload(value, attachment)
69
+ return {} if attachment.nil?
70
+
71
+ value = {} if value.nil? || value.is_a?(String)
72
+ value['aid'] = attachment.id
73
+ value['uid'] = attachment.identifier
74
+ value['filename'] = attachment.filename
75
+ value
76
+ rescue StandardError => e
77
+ Labimotion.log_exception(e)
78
+ value
79
+ end
80
+
81
+
82
+ def proc_table_molecule(properties, data, svalue, key, tidx, vdx, col_id)
83
+ return properties unless id = svalue.fetch('el_id', nil)
84
+
85
+ molfile = data.fetch(Labimotion::Prop::MOLECULE, nil)&.fetch(id, nil)&.fetch('molfile', nil)
86
+ tmol = Molecule.find_or_create_by_molfile(molfile) if molfile.present?
87
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value']
88
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value'] = proc_assign_molecule(val, tmol)
89
+ properties
90
+ rescue StandardError => e
91
+ Labimotion.log_exception(e)
92
+ properties
93
+ end
94
+
95
+ def proc_table_sample(properties, data, instances, svalue, key, tidx, vdx, col_id)
96
+ return properties unless id = svalue.fetch('el_id', nil)
97
+
98
+ # orig_s = data.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(svalue['el_id'], nil)
99
+ sample = instances.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(id, nil)
100
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value']
101
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][tidx]['sub_values'][vdx][col_id]['value'] = proc_assign_sample(val, sample)
102
+ properties
103
+ rescue StandardError => e
104
+ Labimotion.log_exception(e)
105
+ properties
106
+ end
107
+
108
+ def proc_table_prop(layer, key, data, instance, properties, field, tidx, type)
109
+ fields = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == type }
110
+ return properties if fields.nil?
111
+
112
+ col_ids = fields.map { |x| x.values[0] }
113
+ col_ids.each do |col_id|
114
+ next if field[Labimotion::Prop::SUBVALUES].nil?
115
+
116
+ field[Labimotion::Prop::SUBVALUES].each_with_index do |sub_value, vdx|
117
+ next unless sub_value.fetch(col_id, nil)&.fetch('value', nil).is_a?(Hash)
118
+
119
+ next if sub_value.fetch(col_id, nil)&.fetch('value', nil)&.fetch('el_id', nil).nil?
120
+
121
+ svalue = sub_value.fetch(col_id, nil)&.fetch('value', nil)
122
+ next if svalue.fetch('el_id', nil).nil? ## || svalue.fetch('el_inchikey', nil).nil? (molecule only?)
123
+
124
+ case type
125
+ when Labimotion::FieldType::DRAG_MOLECULE
126
+ properties = proc_table_molecule(properties, data, svalue, key, tidx, vdx, col_id)
127
+ when Labimotion::FieldType::DRAG_SAMPLE
128
+ properties = proc_table_sample(properties, data, instance, svalue, key, tidx, vdx, col_id)
129
+ end
130
+ end
131
+ end
132
+ properties
133
+ rescue StandardError => e
134
+ Labimotion.log_exception(e)
135
+ properties
136
+ end
137
+ end
11
138
 
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
139
+ def self.proc_sample(layer, key, data, instances, properties)
140
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE }
141
+ fields.each do |field|
142
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
143
+ id = field["value"] && field["value"]["el_id"] unless idx.nil?
144
+ sample = instances.fetch(Labimotion::Prop::SAMPLE, nil)&.fetch(id, nil)
145
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
146
+ val = proc_assign_sample(val, sample)
147
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val
18
148
  end
19
149
  properties
20
150
  rescue StandardError => e
21
- Rails.logger.error(e.backtrace)
151
+ Labimotion.log_exception(e)
22
152
  raise
23
153
  end
24
154
 
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)
155
+ def self.proc_element(layer, key, data, instances, properties, elements)
156
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_ELEMENT }
157
+ fields.each do |field|
158
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
29
159
  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
160
+ att_el = (elements && elements[id]) || instances.fetch(Labimotion::Prop::L_ELEMENT, nil)&.fetch(id, nil)
161
+ if att_el.nil?
162
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = {}
163
+ else
164
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
165
+ val = proc_assign_element(val, att_el)
166
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val
35
167
  end
36
168
  end
37
169
  properties
38
170
  rescue StandardError => e
39
- Rails.logger.error(e.backtrace)
171
+ Labimotion.log_exception(e)
40
172
  raise
41
173
  end
42
174
 
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
175
+ def self.proc_upload(layer, key, data, instances, attachments, element)
176
+ properties = element.properties
177
+ upload_type = upload_type(element)
178
+ return if upload_type.nil?
179
+
180
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::UPLOAD }
181
+ fields.each do |field|
182
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
183
+ next if idx.nil?
184
+
185
+ files = field["value"] && field["value"]["files"]
186
+ files&.each_with_index do |fi, fdx|
187
+ aid = properties['layers'][key]['fields'][idx]['value']['files'][fdx]['aid']
188
+ uid = properties['layers'][key]['fields'][idx]['value']['files'][fdx]['uid']
189
+ att = data.fetch('Attachment', nil)&.fetch(aid, nil)
190
+ attachment = Attachment.find_by('id IN (?) AND filename LIKE ? ', attachments, uid << '%')
191
+ next if attachment.nil? || att.nil?
192
+
193
+ attachment.update!(attachable_id: element.id, attachable_type: upload_type, transferred: true, aasm_state: att['aasm_state'], filename: att['filename'])
194
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['files'][fdx]
195
+ val = proc_assign_upload(val, attachment)
196
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']['files'][fdx] = val
72
197
  end
73
198
  end
74
199
  properties
75
200
  rescue StandardError => e
76
- Rails.logger.error(e.backtrace)
201
+ Labimotion.log_exception(e)
202
+ properties
203
+ end
204
+
205
+ def self.proc_molecule(layer, key, data, properties)
206
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
207
+ fields.each do |field|
208
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
209
+ next if idx.nil? || field.fetch('value', nil).nil?
210
+
211
+ next unless field.fetch('value', nil).is_a?(Hash)
212
+
213
+ id = field.fetch('value', nil)&.fetch('el_id', nil) unless idx.nil?
214
+ molfile = data.fetch(Labimotion::Prop::MOLECULE, nil)&.fetch(id, nil)&.fetch('molfile', nil) unless id.nil?
215
+ next if molfile.nil?
216
+
217
+ mol = Molecule.find_or_create_by_molfile(molfile)
218
+ val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
219
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = proc_assign_molecule(val, mol)
220
+ end
221
+ properties
222
+ rescue StandardError => e
223
+ Labimotion.log_exception(e)
224
+ raise
225
+ end
226
+
227
+
228
+ def self.proc_table(layer, key, data, instance, properties)
229
+ fields = layer[Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::TABLE }
230
+ fields&.each do |field|
231
+ tidx = layer[Labimotion::Prop::FIELDS].index(field)
232
+ next unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
233
+
234
+ proc_table_prop(layer, key, data, instance, properties, field, tidx, Labimotion::FieldType::DRAG_MOLECULE)
235
+ proc_table_prop(layer, key, data, instance, properties, field, tidx, Labimotion::FieldType::DRAG_SAMPLE)
236
+ end
237
+ properties
238
+ rescue StandardError => e
239
+ Labimotion.log_exception(e)
77
240
  raise
78
241
  end
79
242
 
80
- def self.properties_handler(data, properties)
81
- properties && properties['layers'] && properties['layers'].keys&.each do |key|
82
- layer = properties['layers'][key]
243
+ def self.properties_handler(data, instances, attachments, elmenet, elements)
244
+ properties = elmenet.properties
245
+ properties.fetch(Labimotion::Prop::LAYERS, nil)&.keys&.each do |key|
246
+ layer = properties[Labimotion::Prop::LAYERS][key]
83
247
  properties = proc_molecule(layer, key, data, properties)
84
- properties = proc_table(layer, key, data, properties)
85
- # properties = proc_sample(layer, key, data, properties)
248
+ properties = proc_upload(layer, key, data, instances, attachments, elmenet)
249
+ properties = proc_sample(layer, key, data, instances, properties)
250
+ properties = proc_element(layer, key, data, instances, properties, elements) # unless elements.nil?
251
+ properties = proc_table(layer, key, data, instances, properties)
86
252
  end
87
253
  properties
88
254
  rescue StandardError => e
89
- Rails.logger.error(e.backtrace)
255
+ Labimotion.log_exception(e)
256
+ raise
257
+ end
258
+
259
+ def self.process_ai(data, instances)
260
+ ai_has_changed = false
261
+ instances&.fetch(Labimotion::Prop::L_ELEMENT, nil)&.each do |uuid, element|
262
+ properties = element.properties
263
+ properties.fetch(Labimotion::Prop::LAYERS, nil)&.keys&.each do |key|
264
+ layer = properties[Labimotion::Prop::LAYERS][key]
265
+ layer.fetch('ai', nil)&.each_with_index do |ai_key, idx|
266
+ ana = instances.fetch(Labimotion::Prop::CONTAINER)&.fetch(ai_key, nil)
267
+ properties[Labimotion::Prop::LAYERS][key]['ai'][idx] = ana.id unless ana.nil?
268
+ ai_has_changed = true
269
+ end
270
+ end
271
+ element.update_columns(properties: properties) if ai_has_changed
272
+ end
273
+ rescue StandardError => e
274
+ Labimotion.log_exception(e)
90
275
  raise
91
276
  end
92
277
 
@@ -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.3'
6
+ VERSION = '1.2.0.0'
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.3
4
+ version: 1.2.0.0
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-01-31 00:00:00.000000000 Z
12
+ date: 2024-03-15 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