labimotion 1.2.0.0 → 1.3.0.rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7724683d3271fa68ecdf774518cc4d10a4d51ee1431c957e0538c5a00e4f689d
4
- data.tar.gz: b9cc8b469761e732707c0b272c2e814a8215c3c22a7d7ca077d7f5ddca9ed877
3
+ metadata.gz: f43e928ba8d3a20237af9a587380be1a674074d8323f1b41ecedff3d3416c12b
4
+ data.tar.gz: 344ae75f2cee3560d9f18e2f167e2321310ae539735cfc74666182868db369fa
5
5
  SHA512:
6
- metadata.gz: dd7aaa2347333c05e09eb5e9d0628a8079e2fd4819e46b37e7a45fc40577fae12d2f731a5f1eddd601065c35aa333f312f724bd46b59d93f35f3639f8e34d53b
7
- data.tar.gz: f222c51a55a96c1d87c1d79a1fb965b8fb6315a2b182a6767b01222eeae665de248f7bdfdc6ca3789e1f2623faf7a1b69b03bcbc1527f51f6b9c03ba99183d56
6
+ metadata.gz: 9cfe38fdd248d4fb4f32be1c607605a0a35c6f262dc0e0cb33bd7575895aea6cd177b752f9b888458af7d75dffe45acf05f08a44a352389b0bd9f93a0cc27fc9
7
+ data.tar.gz: b7cfc290285914a6b4afddbb604718d5aeace21b8cbda8fa08aa8557e7513c5efa24829a79d39d71e59a937b9ce104623b30afea85c7f70191304b33d68e4a42
@@ -89,7 +89,7 @@ module Labimotion
89
89
  sk_id = sk_obj["identifier"]
90
90
  ek_obj = data.fetch(Labimotion::Prop::L_ELEMENT_KLASS).fetch(sk_obj["element_klass_id"])
91
91
  element_klass = Labimotion::ElementKlass.find_by(name: ek_obj['name']) if ek_obj.present?
92
- next if element_klass.nil? || ek_obj.nil? || ek_obj['is_generic'] == true
92
+ next if element_klass.nil? || ek_obj.nil? # || ek_obj['is_generic'] == true
93
93
 
94
94
  element_uuid = fields.fetch('element_id')
95
95
  element_type = fields.fetch('element_type')
@@ -99,7 +99,7 @@ module Labimotion
99
99
 
100
100
  if segment_klass.nil?
101
101
  skr = Labimotion::SegmentKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
102
- segment_klass = skr.segment_klass if segment_klass.nil? && skr.present?
102
+ segment_klass = Labimotion::SegmentKlass.find_by(id: skr.segment_klass_id) if skr.present?
103
103
  end
104
104
 
105
105
  next if segment_klass.nil? || element.nil?
@@ -133,7 +133,7 @@ module Labimotion
133
133
  data.fetch('Labimotion::Element', {}).each do |uuid, fields|
134
134
  klass_id = fields["element_klass_id"]
135
135
  ek_obj = data.fetch('Labimotion::ElementKlass', {})[klass_id]
136
- ek_id = ek_obj["identifier"]
136
+ ek_id = ek_obj["identifier"] if ek_obj.present?
137
137
  element_klass = Labimotion::ElementKlass.find_by(identifier: ek_id) if ek_id.present?
138
138
  element_klass = Labimotion::ElementKlass.find_by(uuid: fields.fetch('klass_uuid')) if element_klass.nil?
139
139
 
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+ require 'export_table'
3
+ require 'labimotion/version'
4
+ require 'sablon'
5
+
6
+ module Labimotion
7
+ class ExportElement
8
+ def initialize(current_user, element, export_format)
9
+ @current_user = current_user
10
+ @element = element
11
+ @properties = element.properties
12
+ @options = element.properties_release[Labimotion::Prop::SEL_OPTIONS]
13
+ @export_format = export_format
14
+ rescue StandardError => e
15
+ Labimotion.log_exception(e)
16
+ byebug
17
+ end
18
+
19
+ def build_layers
20
+ objs = []
21
+ @properties[Labimotion::Prop::LAYERS]&.keys&.sort_by { |key| @properties[Labimotion::Prop::LAYERS][key]['position'] }&.each do |key|
22
+ layer = @properties[Labimotion::Prop::LAYERS][key] || {}
23
+
24
+ ## Build fields html
25
+ # field_objs = build_fields_html(layer) if layer[Labimotion::Prop::FIELDS]&.length&.positive?
26
+ # field_html = Sablon.content(:html, field_objs) if field_objs.present?
27
+ field_objs = build_fields(layer)
28
+
29
+ layer_info = {
30
+ label: layer['label'],
31
+ layer: layer['layer'],
32
+ cols: layer['cols'],
33
+ timeRecord: layer['timeRecord'],
34
+ fields: field_objs
35
+ }
36
+ objs.push(layer_info)
37
+ end
38
+ objs
39
+ rescue StandardError => e
40
+ Labimotion.log_exception(e)
41
+ byebug
42
+ end
43
+
44
+ def build_field(layer, field)
45
+ field_obj = {}
46
+ field_obj[:label] = field['label']
47
+ field_obj[:field] = field['field']
48
+ field_obj[:type] = field['type']
49
+
50
+ field_obj.merge!(field.slice('value', 'value_system'))
51
+
52
+ case field['type']
53
+ when Labimotion::FieldType::DRAG_ELEMENT
54
+ field_obj[:value] = (field['value'] && field['value']['el_label']) || ''
55
+ field_obj[:obj] = field['value'] ### change to object
56
+ when Labimotion::FieldType::DRAG_SAMPLE
57
+ val = field.fetch('value', {})
58
+ sample = Sample.find_by(id: val['el_id'])
59
+ field_obj[:value] = val['el_label']
60
+ field_obj[:has_structure] = true
61
+ obj_os = OpenStruct.new(sample)
62
+ field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj_os, format: 'png').generate
63
+ when Labimotion::FieldType::DRAG_MOLECULE
64
+ val = field.fetch('value', {})
65
+ obj = Molecule.find_by(id: val['el_id'])
66
+ field_obj[:value] = val['el_label']
67
+ # field_obj[:has_structure] = true
68
+ # field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj, format: 'png').generate
69
+ when Labimotion::FieldType::SELECT
70
+ field_obj[:value] = @options.fetch(field['option_layers'], nil)&.fetch('options', nil)&.find { |ss| ss['key'] == field['value'] }&.fetch('label', nil) || field['value']
71
+ when Labimotion::FieldType::UPLOAD
72
+ files = field.fetch('value', nil)&.fetch('files', [])
73
+ val = files&.map { |file| "#{file['filename']} #{file['label']}" }&.join('\n')
74
+ field_obj[:value] = val
75
+ when Labimotion::FieldType::TABLE
76
+ field_obj[:value] = 'this is a table' ## to be handled
77
+ when Labimotion::FieldType::INPUT_GROUP
78
+ field_obj[:value] = 'this is a input group' ## to be handled
79
+ end
80
+ field_obj
81
+ rescue StandardError => e
82
+ Labimotion.log_exception(e)
83
+ byebug
84
+ end
85
+
86
+ def build_fields(layer)
87
+ fields = layer[Labimotion::Prop::FIELDS] || []
88
+ field_objs = []
89
+ fields.each do |field|
90
+ field_obj = build_field(layer, field)
91
+ field_objs.push(field_obj)
92
+ end
93
+ field_objs
94
+ rescue StandardError => e
95
+ Labimotion.log_exception(e)
96
+ byebug
97
+ end
98
+
99
+ def to_docx
100
+ # location = Rails.root.join('lib', 'template', 'Labimotion.docx')
101
+ location = Rails.root.join('lib', 'template', 'Labimotion_lines.docx')
102
+ File.exist?(location)
103
+ template = Sablon.template(location)
104
+ layers = build_layers
105
+ context = {
106
+ name: @element.name,
107
+ short_label: @element.short_label,
108
+ date: Time.now.strftime('%d/%m/%Y'),
109
+ author: @current_user.name,
110
+ layers: layers
111
+ }
112
+ output = "Labimotion1.docx"
113
+ template.render_to_file File.expand_path(output), context
114
+ File.read(output)
115
+ rescue StandardError => e
116
+ Labimotion.log_exception(e)
117
+ byebug
118
+ end
119
+
120
+
121
+ def build_field_html(layer, field, cols)
122
+ case field['type']
123
+ when Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_ELEMENT, Labimotion::FieldType::DRAG_MOLECULE
124
+ val = (field['value'] && field['value']['el_label']) || ''
125
+ when Labimotion::FieldType::UPLOAD
126
+ val = (field['value'] && field['value']['files'] && field['value']['files'].first && field['value']['files'].first['filename'] ) || ''
127
+ else
128
+ val = field['value']
129
+ end
130
+ htd = field['hasOwnRow'] == true ? "<td colspan=#{cols}>" : '<td>'
131
+ "#{htd}<b>#{field['label']}: </b><br />#{val}</td>"
132
+ rescue StandardError => e
133
+ Labimotion.log_exception(e)
134
+ byebug
135
+ end
136
+
137
+ def build_fields_html(layer)
138
+ fields = layer[Labimotion::Prop::FIELDS] || []
139
+ field_objs = []
140
+ cols = layer['cols'] || 0
141
+ field_objs.push('<table style="width: 4000dxa"><tr>')
142
+ fields.each do |field|
143
+ if cols&.zero? || field['hasOwnRow'] == true
144
+ field_objs.push('</tr><tr>')
145
+ cols = layer['cols']
146
+ end
147
+ field_obj = build_field_html(layer, field, layer['cols'])
148
+ field_objs.push(field_obj)
149
+ cols -= 1
150
+ cols = 0 if field['hasOwnRow'] == true
151
+ end
152
+ field_objs.push('</tr></table>')
153
+ field_objs&.join("")&.gsub('<tr></tr>', '')
154
+ rescue StandardError => e
155
+ Labimotion.log_exception(e)
156
+ byebug
157
+ end
158
+
159
+
160
+ def build_layers_html
161
+ layer_html = []
162
+ first_line = true
163
+ @properties[Labimotion::Prop::LAYERS]&.keys&.each do |key|
164
+ layer_html.push('</tr></table>') if first_line == false
165
+ layer = @properties[Labimotion::Prop::LAYERS][key] || {}
166
+ fields = layer[Labimotion::Prop::FIELDS] || []
167
+ layer_html.push("<h2><b>Layer:#{layer['label']}</b></h2>")
168
+ layer_html.push('<table><tr>')
169
+ cols = layer['cols']
170
+ fields.each do |field|
171
+ if (cols === 0)
172
+ layer_html.push('</tr><tr>')
173
+ end
174
+
175
+ val = field['value'].is_a?(Hash) ? field['value']['el_label'] : field['value']
176
+ layer_html.push("<td>#{field['label']}: <br />#{val}</td>")
177
+ cols -= 1
178
+ end
179
+ first_line = false
180
+ end
181
+ layer_html.push('</tr></table>')
182
+ byebug
183
+ layer_html.join('')
184
+ rescue StandardError => e
185
+ Labimotion.log_exception(e)
186
+ byebug
187
+ end
188
+
189
+ def html_labimotion
190
+ layers_html = build_layers_html
191
+ html_body = <<-HTML.strip
192
+ #{layers_html}
193
+ HTML
194
+ html_body
195
+ rescue StandardError => e
196
+ Labimotion.log_exception(e)
197
+ byebug
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+ require 'export_table'
3
+ require 'labimotion/version'
4
+ require 'sablon'
5
+
6
+ module Labimotion
7
+ class ExportElementBak1
8
+ def initialize(current_user, element, export_format)
9
+ @current_user = current_user
10
+ @element = element
11
+ @properties = element.properties
12
+ @export_format = export_format
13
+ rescue StandardError => e
14
+ Labimotion.log_exception(e)
15
+ byebug
16
+ end
17
+
18
+ def build_field(layer, field)
19
+ field_obj = {}
20
+ field_obj[:label] = field['label']
21
+ field_obj[:field] = field['field']
22
+ field_obj[:type] = field['type']
23
+
24
+ case field['type']
25
+ when Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_ELEMENT, Labimotion::FieldType::DRAG_MOLECULE
26
+ field_obj[:value] = field['value']['el_label']
27
+ else
28
+ field_obj[:value] = field['value']
29
+ end
30
+ field_obj
31
+ rescue StandardError => e
32
+ Labimotion.log_exception(e)
33
+ byebug
34
+ end
35
+
36
+ def build_fields(layer, fields)
37
+ field_objs = []
38
+ fields.each do |field|
39
+ field_obj = build_field(layer, field)
40
+ field_objs.push(field_obj)
41
+ end
42
+ field_objs
43
+ rescue StandardError => e
44
+ Labimotion.log_exception(e)
45
+ byebug
46
+ end
47
+ def build_layers
48
+ objs = []
49
+ @properties[Labimotion::Prop::LAYERS]&.keys&.each do |key|
50
+ layer = @properties[Labimotion::Prop::LAYERS][key] || {}
51
+ fields = layer[Labimotion::Prop::FIELDS] || []
52
+ field_objs = build_fields(layer, fields)
53
+
54
+ layer_info = {
55
+ label: layer['label'],
56
+ layer: layer['layer'],
57
+ cols: layer['cols'],
58
+ fields: field_objs
59
+ }
60
+ objs.push(layer_info)
61
+ end
62
+ objs
63
+ rescue StandardError => e
64
+ Labimotion.log_exception(e)
65
+ byebug
66
+ end
67
+
68
+ def html_sample
69
+ html_body = <<-HTML.strip
70
+ <p style="text-align: right; background-color: #FFFF00">
71
+ Right aligned content with a yellow background color.
72
+ </p>
73
+ <div>
74
+ <span style="color: #123456">Inline styles</span> are possible as well
75
+ </div>
76
+ <table>
77
+ <tr>
78
+ <th>Company</th>
79
+ <th>Contact</th>
80
+ <th>Country</th>
81
+ </tr>
82
+ <tr>
83
+ <td>Alfreds Futterkiste</td>
84
+ <td>Maria Anders</td>
85
+ <td>Germany</td>
86
+ </tr>
87
+ </table>
88
+
89
+ HTML
90
+ html_body
91
+ rescue StandardError => e
92
+ Labimotion.log_exception(e)
93
+ byebug
94
+ end
95
+
96
+ def to_docx
97
+ location = Rails.root.join('lib', 'template', 'Labimotion.docx')
98
+ File.exist?(location)
99
+ template = Sablon.template(location)
100
+ layers = build_layers
101
+ byebug
102
+ html_body = html_sample
103
+ html_content = Sablon.content(:html, html_body)
104
+ context = {
105
+ name: @element.name,
106
+ short_label: @element.short_label,
107
+ layers: layers,
108
+ html_sample: html_content
109
+ }
110
+ output = "Labimotion1.docx"
111
+ template.render_to_file File.expand_path(output), context
112
+ File.read(output)
113
+ rescue StandardError => e
114
+ Labimotion.log_exception(e)
115
+ byebug
116
+ end
117
+ end
118
+ end
@@ -7,6 +7,7 @@ module Labimotion
7
7
  DATETIME_RANGE = 'datetime-range'.freeze
8
8
  SELECT = 'select'.freeze
9
9
  INTEGER = 'integer'.freeze
10
+ INPUT_GROUP = 'input-group'.freeze
10
11
  SYSTEM_DEFINED = 'system-defined'.freeze
11
12
  DRAG = 'drag'.freeze
12
13
  DRAG_ELEMENT = 'drag_element'.freeze
@@ -3,5 +3,5 @@
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
5
  IS_RAILS5 = false
6
- VERSION = '1.2.0.0'
6
+ VERSION = '1.3.0.rc1'
7
7
  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.2.0.0
4
+ version: 1.3.0.rc1
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-03-15 00:00:00.000000000 Z
12
+ date: 2024-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -66,6 +66,8 @@ files:
66
66
  - lib/labimotion/helpers/segment_helpers.rb
67
67
  - lib/labimotion/libs/converter.rb
68
68
  - lib/labimotion/libs/export_dataset.rb
69
+ - lib/labimotion/libs/export_element1.rb
70
+ - lib/labimotion/libs/export_element_bak1.rb
69
71
  - lib/labimotion/libs/nmr_mapper.rb
70
72
  - lib/labimotion/libs/properties_handler.rb
71
73
  - lib/labimotion/libs/sample_association.rb
@@ -102,7 +104,7 @@ files:
102
104
  - lib/labimotion/utils/serializer.rb
103
105
  - lib/labimotion/utils/utils.rb
104
106
  - lib/labimotion/version.rb
105
- homepage: https://gitlab.kit.edu/kit/labimotion/labimotion
107
+ homepage: https://github.com/LabIMotion/labimotion
106
108
  licenses:
107
109
  - AGPL-3.0
108
110
  metadata: {}
@@ -117,9 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  requirements:
120
- - - ">="
122
+ - - ">"
121
123
  - !ruby/object:Gem::Version
122
- version: '0'
124
+ version: 1.3.1
123
125
  requirements: []
124
126
  rubygems_version: 3.1.6
125
127
  signing_key: