labimotion 1.3.0.rc3 → 1.3.0.rc5
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.
- checksums.yaml +4 -4
- data/lib/labimotion/apis/generic_element_api.rb +57 -58
- data/lib/labimotion/apis/generic_klass_api.rb +34 -0
- data/lib/labimotion/apis/segment_api.rb +25 -10
- data/lib/labimotion/helpers/element_helpers.rb +22 -20
- data/lib/labimotion/helpers/param_helpers.rb +97 -0
- data/lib/labimotion/helpers/segment_helpers.rb +26 -18
- data/lib/labimotion/libs/converter.rb +8 -27
- data/lib/labimotion/libs/export_dataset.rb +3 -12
- data/lib/labimotion/libs/export_element.rb +89 -25
- data/lib/labimotion/libs/nmr_mapper.rb +2 -15
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +6 -0
- data/lib/labimotion/utils/field_type.rb +2 -0
- data/lib/labimotion/utils/units.rb +465 -0
- data/lib/labimotion/version.rb +1 -2
- data/lib/labimotion.rb +2 -0
- metadata +5 -2
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'export_table'
|
3
3
|
require 'labimotion/version'
|
4
|
+
require 'labimotion/utils/units'
|
4
5
|
require 'sablon'
|
5
6
|
|
6
7
|
module Labimotion
|
@@ -8,6 +9,25 @@ module Labimotion
|
|
8
9
|
def initialize(current_user, element, export_format)
|
9
10
|
@current_user = current_user
|
10
11
|
@element = element
|
12
|
+
@parent =
|
13
|
+
case element.class.name
|
14
|
+
when 'Labimotion::Segment'
|
15
|
+
element&.element
|
16
|
+
when 'Labimotion::Dataset'
|
17
|
+
element&.element&.root_element
|
18
|
+
end
|
19
|
+
@element_klass =
|
20
|
+
case element.class.name
|
21
|
+
when 'Labimotion::Element'
|
22
|
+
element.element_klass
|
23
|
+
when 'Labimotion::Segment'
|
24
|
+
element.segment_klass
|
25
|
+
when 'Labimotion::Dataset'
|
26
|
+
element.dataset_klass
|
27
|
+
end
|
28
|
+
@name = @element.instance_of?(Labimotion::Element) ? element.name : @parent&.name
|
29
|
+
@short_label = @element.instance_of?(Labimotion::Element) ? element.short_label : @parent&.short_label
|
30
|
+
@element_name = "#{@element_klass.label}_#{@short_label}".gsub(/\s+/, '')
|
11
31
|
@properties = element.properties
|
12
32
|
@options = element.properties_release[Labimotion::Prop::SEL_OPTIONS]
|
13
33
|
@export_format = export_format
|
@@ -17,7 +37,12 @@ module Labimotion
|
|
17
37
|
|
18
38
|
def build_layers
|
19
39
|
objs = []
|
20
|
-
@properties[Labimotion::Prop::LAYERS]&.keys&.sort_by
|
40
|
+
@properties[Labimotion::Prop::LAYERS]&.keys&.sort_by do |key|
|
41
|
+
[
|
42
|
+
@properties[Labimotion::Prop::LAYERS].fetch(key, nil)&.fetch('position', 0) || 0,
|
43
|
+
@properties[Labimotion::Prop::LAYERS].fetch(key, nil)&.fetch('wf_position', 0) || 0
|
44
|
+
]
|
45
|
+
end&.each do |key|
|
21
46
|
layer = @properties[Labimotion::Prop::LAYERS][key] || {}
|
22
47
|
|
23
48
|
## Build fields html
|
@@ -53,23 +78,25 @@ module Labimotion
|
|
53
78
|
field_obj[:value] = (field['value'] && field['value']['el_label']) || ''
|
54
79
|
field_obj[:obj] = field['value'] ### change to object
|
55
80
|
when Labimotion::FieldType::DRAG_SAMPLE
|
56
|
-
val = field.fetch('value',
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
81
|
+
val = field.fetch('value', nil)
|
82
|
+
if val.present?
|
83
|
+
instance = Sample.find_by(id: val['el_id'])
|
84
|
+
field_obj[:value] = val['el_label']
|
85
|
+
field_obj[:has_structure] = true
|
86
|
+
obj_os = Entities::SampleReportEntity.new(
|
87
|
+
instance,
|
88
|
+
current_user: @current_user,
|
89
|
+
detail_levels: ElementDetailLevelCalculator.new(user: @current_user, element: instance).detail_levels,
|
90
|
+
).serializable_hash
|
91
|
+
obj_final = OpenStruct.new(obj_os)
|
92
|
+
field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj_final, format: 'png').generate
|
93
|
+
end
|
67
94
|
when Labimotion::FieldType::DRAG_MOLECULE
|
68
|
-
val = field.fetch('value',
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
95
|
+
val = field.fetch('value', nil)
|
96
|
+
if val.present?
|
97
|
+
obj = Molecule.find_by(id: val['el_id'])
|
98
|
+
field_obj[:value] = val['el_label']
|
99
|
+
end
|
73
100
|
when Labimotion::FieldType::SELECT
|
74
101
|
field_obj[:value] = @options.fetch(field['option_layers'], nil)&.fetch('options', nil)&.find { |ss| ss['key'] == field['value'] }&.fetch('label', nil) || field['value']
|
75
102
|
when Labimotion::FieldType::UPLOAD
|
@@ -82,7 +109,6 @@ module Labimotion
|
|
82
109
|
tbl = []
|
83
110
|
## tbl_idx = []
|
84
111
|
header = {}
|
85
|
-
|
86
112
|
sub_fields = field.fetch('sub_fields', [])
|
87
113
|
sub_fields.each_with_index do |sub_field, idx|
|
88
114
|
header["col#{idx}"] = sub_field['col_name']
|
@@ -107,6 +133,25 @@ module Labimotion
|
|
107
133
|
end
|
108
134
|
end
|
109
135
|
field_obj[:value] = val.join(' ')
|
136
|
+
when Labimotion::FieldType::WF_NEXT
|
137
|
+
if field['value'].present? && field['wf_options'].present?
|
138
|
+
field_obj[:value] = field['wf_options'].find { |ss| ss['key'] == field['value'] }&.fetch('label', nil)&.split('(')&.first&.strip
|
139
|
+
end
|
140
|
+
when Labimotion::FieldType::SYSTEM_DEFINED
|
141
|
+
_field = field
|
142
|
+
unit = Labimotion::Units::FIELDS.find { |o| o[:field] == _field['option_layers'] }&.fetch(:units, []).find { |u| u[:key] == _field['value_system'] }&.fetch(:label, '')
|
143
|
+
val = _field['value'].to_s + ' ' + unit
|
144
|
+
val = Sablon.content(:html, "<div>" + val + "</div>") if val.include? '<'
|
145
|
+
field_obj[:value] = val
|
146
|
+
when Labimotion::FieldType::TEXT_FORMULA
|
147
|
+
field.fetch('text_sub_fields', []).each do |sub_field|
|
148
|
+
va = @properties['layers'][sub_field.fetch('layer','')]['fields'].find { |f| f['field'] == sub_field.fetch('field','') }&.fetch('value',nil)
|
149
|
+
field_obj[:value] = (field_obj[:value] || '') + va.to_s + sub_field.fetch('separator','') if va.present?
|
150
|
+
end
|
151
|
+
# field_obj[:value] = (field['value'] && field['value']['el_label']) || ''
|
152
|
+
# field_obj[:obj] = field['value'] ### change to object
|
153
|
+
else
|
154
|
+
field_obj[:value] = field['value']
|
110
155
|
end
|
111
156
|
field_obj
|
112
157
|
rescue StandardError => e
|
@@ -117,10 +162,27 @@ module Labimotion
|
|
117
162
|
return '' if sub_field.fetch('id', nil).nil? || sub_val[sub_field['id']].nil?
|
118
163
|
|
119
164
|
case sub_field['type']
|
165
|
+
when Labimotion::FieldType::DRAG_SAMPLE
|
166
|
+
val = sub_val[sub_field['id']]['value'] || {}
|
167
|
+
label = val['el_label'].present? ? "Short Label: [#{val['el_label']}] \n" : ''
|
168
|
+
name = val['el_name'].present? ? "Name: [#{val['el_name']}] \n" : ''
|
169
|
+
ext = val['el_external_label'].present? ? "Ext. Label: [#{val['el_external_label']}] \n" : ''
|
170
|
+
mass = val['el_molecular_weight'].present? ? "Mass: [#{val['el_molecular_weight']}] \n" : ''
|
171
|
+
"#{label}#{name}#{ext}#{mass}"
|
172
|
+
when Labimotion::FieldType::DRAG_MOLECULE
|
173
|
+
val = sub_val[sub_field['id']]['value'] || {}
|
174
|
+
smile = val['el_smiles'].present? ? "SMILES: [#{val['el_smiles']}] \n" : ''
|
175
|
+
inchikey = val['el_inchikey'].present? ? "InChiKey:[#{val['el_inchikey']}] \n" : ''
|
176
|
+
iupac = val['el_iupac'].present? ? "IUPAC:[#{val['el_iupac']}] \n" : ''
|
177
|
+
mass = val['el_molecular_weight'].present? ? "MASS: [#{val['el_molecular_weight']}] \n" : ''
|
178
|
+
"#{smile}#{inchikey}#{iupac}#{mass}"
|
120
179
|
when Labimotion::FieldType::SELECT
|
121
180
|
sub_val[sub_field['id']]['value']
|
122
181
|
when Labimotion::FieldType::SYSTEM_DEFINED
|
123
|
-
|
182
|
+
unit = Labimotion::Units::FIELDS.find { |o| o[:field] == sub_field['option_layers'] }&.fetch(:units, [])&.find { |u| u[:key] == sub_field['value_system'] }&.fetch(:label, '')
|
183
|
+
val = sub_val[sub_field['id']]['value'].to_s + ' ' + unit
|
184
|
+
val = Sablon.content(:html, "<div>" + val + "</div>") if val.include? '<'
|
185
|
+
val
|
124
186
|
else
|
125
187
|
sub_val[sub_field['id']]
|
126
188
|
end
|
@@ -148,8 +210,11 @@ module Labimotion
|
|
148
210
|
template = Sablon.template(location)
|
149
211
|
layers = build_layers
|
150
212
|
context = {
|
151
|
-
|
152
|
-
|
213
|
+
label: @element_klass.label,
|
214
|
+
desc: @element_klass.desc,
|
215
|
+
name: @name,
|
216
|
+
parent_klass: @parent.present? ? "#{@parent&.class&.name&.split('::')&.last}: " : '',
|
217
|
+
short_label: @short_label,
|
153
218
|
date: Time.now.strftime('%d/%m/%Y'),
|
154
219
|
author: @current_user.name,
|
155
220
|
layers: layers
|
@@ -162,14 +227,13 @@ module Labimotion
|
|
162
227
|
Labimotion.log_exception(e)
|
163
228
|
ensure
|
164
229
|
# Close and delete the temporary file
|
165
|
-
tempfile
|
166
|
-
tempfile
|
230
|
+
tempfile&.close
|
231
|
+
tempfile&.unlink
|
167
232
|
end
|
168
233
|
|
169
234
|
|
170
235
|
def res_name
|
171
|
-
element_name
|
172
|
-
"#{element_name}_#{Time.now.strftime('%Y%m%d%H%M')}.docx"
|
236
|
+
"#{@element_name}_#{Time.now.strftime('%Y%m%d%H%M')}.docx"
|
173
237
|
rescue StandardError => e
|
174
238
|
Labimotion.log_exception(e)
|
175
239
|
end
|
@@ -28,8 +28,8 @@ module Labimotion
|
|
28
28
|
att = Attachment.find_by(id: id, con_state: Labimotion::ConState::NMR)
|
29
29
|
return if att.nil?
|
30
30
|
|
31
|
-
if
|
32
|
-
Zip::File.open(att.
|
31
|
+
if att&.attachment_attacher&.file&.url
|
32
|
+
Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
|
33
33
|
zip_file.each do |entry|
|
34
34
|
if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
|
35
35
|
metadata = entry.get_input_stream.read.force_encoding('UTF-8')
|
@@ -39,19 +39,6 @@ module Labimotion
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
else
|
43
|
-
if att&.attachment_attacher&.file&.url
|
44
|
-
Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
|
45
|
-
zip_file.each do |entry|
|
46
|
-
if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
|
47
|
-
metadata = entry.get_input_stream.read.force_encoding('UTF-8')
|
48
|
-
return { is_bagit: false, metadata: metadata }
|
49
|
-
elsif entry.name.include?('metadata/') && entry.name.include?('converter.json')
|
50
|
-
return { is_bagit: true, metadata: nil }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
42
|
end
|
56
43
|
{ is_bagit: false, metadata: nil }
|
57
44
|
end
|
@@ -6,6 +6,12 @@ module Labimotion
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
included do
|
8
8
|
# has_many :element_klasses_revisions, dependent: :destroy
|
9
|
+
before_save :check_identifier
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def check_identifier
|
14
|
+
self.identifier = identifier || SecureRandom.uuid
|
9
15
|
end
|
10
16
|
|
11
17
|
def create_klasses_revision(current_user)
|
@@ -8,6 +8,8 @@ module Labimotion
|
|
8
8
|
SELECT = 'select'.freeze
|
9
9
|
INTEGER = 'integer'.freeze
|
10
10
|
INPUT_GROUP = 'input-group'.freeze
|
11
|
+
WF_NEXT = 'wf-next'.freeze
|
12
|
+
TEXT_FORMULA = 'text-formula'.freeze
|
11
13
|
SYSTEM_DEFINED = 'system-defined'.freeze
|
12
14
|
DRAG = 'drag'.freeze
|
13
15
|
DRAG_ELEMENT = 'drag_element'.freeze
|