labimotion 0.2.0 → 0.2.2
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 +2 -2
- data/lib/labimotion/helpers/dataset_helpers.rb +5 -3
- data/lib/labimotion/helpers/element_helpers.rb +49 -20
- data/lib/labimotion/helpers/generic_helpers.rb +11 -35
- data/lib/labimotion/helpers/segment_helpers.rb +9 -6
- data/lib/labimotion/libs/converter.rb +2 -3
- data/lib/labimotion/libs/nmr_mapper.rb +3 -2
- data/lib/labimotion/libs/nmr_mapper_repo.rb +2 -2
- data/lib/labimotion/libs/template_hub.rb +9 -3
- data/lib/labimotion/models/concerns/datasetable.rb +6 -10
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +17 -10
- data/lib/labimotion/models/concerns/segmentable.rb +6 -11
- data/lib/labimotion/models/element_klass.rb +0 -4
- data/lib/labimotion/utils/utils.rb +32 -0
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 327103b60af0374bdfd4fa53653b2f314c3395f3a7e0277022caa9b8a5e865a3
|
4
|
+
data.tar.gz: 118586faba049e9b0db78533e912c1ea1143a27314e4d13395dca19469c9cecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5efea48afcc6d27d8619039fde17de1d66db7d371f547f05a61ace9a763e7eee539dc79f4c3ff947df497233d4cca74a572d9277cc869bcaa5bae310f16ae1c
|
7
|
+
data.tar.gz: 3be73cae26b84356fdd1d316391552c6e82d4b63b467705d9faad843c2d706c464bf50b1ff3335255e43c76ecffb708e17748dfe659bb23a2c9c4f1ffd9e0668
|
@@ -225,7 +225,7 @@ module Labimotion
|
|
225
225
|
@klz = fetch_klass(params[:klass], params[:id])
|
226
226
|
end
|
227
227
|
post do
|
228
|
-
update_template(params)
|
228
|
+
update_template(params, current_user)
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -237,10 +237,10 @@ module Labimotion
|
|
237
237
|
optional :from_date, type: Integer, desc: 'created_date from in ms'
|
238
238
|
optional :to_date, type: Integer, desc: 'created_date to in ms'
|
239
239
|
optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
|
240
|
+
optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
|
240
241
|
end
|
241
242
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
242
243
|
get do
|
243
|
-
|
244
244
|
scope = list_serialized_elements(params, current_user)
|
245
245
|
|
246
246
|
reset_pagination_page(scope)
|
@@ -15,8 +15,9 @@ module Labimotion
|
|
15
15
|
|
16
16
|
def create_repo_klass(params, current_user)
|
17
17
|
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
|
18
|
-
attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
|
19
|
-
attributes['
|
18
|
+
attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
|
19
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
20
|
+
attributes['properties_template'] = attributes['properties_release']
|
20
21
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
21
22
|
attributes['is_active'] = false
|
22
23
|
attributes['updated_by'] = current_user.id
|
@@ -27,8 +28,9 @@ module Labimotion
|
|
27
28
|
ds.update!(attributes)
|
28
29
|
else
|
29
30
|
attributes['created_by'] = current_user.id
|
30
|
-
Labimotion::DatasetKlass.create!(attributes)
|
31
|
+
ds = Labimotion::DatasetKlass.create!(attributes)
|
31
32
|
end
|
33
|
+
ds.create_klasses_revision(current_user)
|
32
34
|
rescue StandardError => e
|
33
35
|
Labimotion.log_exception(e, current_user)
|
34
36
|
# { error: e.message }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'grape'
|
4
|
-
require 'labimotion/
|
4
|
+
require 'labimotion/utils/utils'
|
5
5
|
# require 'labimotion/models/element_klass'
|
6
6
|
module Labimotion
|
7
7
|
## ElementHelpers
|
@@ -20,11 +20,12 @@ module Labimotion
|
|
20
20
|
uuid = SecureRandom.uuid
|
21
21
|
template = { uuid: uuid, layers: {}, select_options: {} }
|
22
22
|
attributes = declared(params, include_missing: false)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
if attributes[:properties_template].present?
|
24
|
+
attributes[:properties_template]['uuid'] = uuid
|
25
|
+
attributes[:properties_template] = template
|
26
|
+
attributes[:properties_template]['pkg'] = Labimotion::Utils.pkg(attributes[:properties_template]['pkg'])
|
27
|
+
attributes[:properties_template]['klass'] = 'ElementKlass'
|
28
|
+
end
|
28
29
|
attributes[:is_active] = false
|
29
30
|
attributes[:uuid] = uuid
|
30
31
|
attributes[:released_at] = DateTime.now
|
@@ -33,8 +34,8 @@ module Labimotion
|
|
33
34
|
|
34
35
|
new_klass = Labimotion::ElementKlass.create!(attributes)
|
35
36
|
new_klass.reload
|
36
|
-
new_klass.create_klasses_revision(current_user
|
37
|
-
klass_names_file = Rails.root.join('
|
37
|
+
new_klass.create_klasses_revision(current_user)
|
38
|
+
klass_names_file = Rails.root.join('app/packs/klasses.json')
|
38
39
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
39
40
|
File.write(klass_names_file, klasses)
|
40
41
|
klasses
|
@@ -68,11 +69,12 @@ module Labimotion
|
|
68
69
|
uuid = SecureRandom.uuid
|
69
70
|
params[:properties]['uuid'] = uuid
|
70
71
|
params[:properties]['klass_uuid'] = klass[:uuid]
|
71
|
-
params[:properties]['
|
72
|
-
params[:properties]['labimotion'] = Labimotion::VERSION
|
72
|
+
params[:properties]['pkg'] = Labimotion::Utils.pkg(params[:properties]['pkg'])
|
73
73
|
params[:properties]['klass'] = 'Element'
|
74
|
+
params[:properties]['identifier'] = klass[:identifier]
|
74
75
|
properties = params[:properties]
|
75
76
|
properties.delete('flow') unless properties['flow'].nil?
|
77
|
+
properties.delete('flowObject') unless properties['flowObject'].nil?
|
76
78
|
properties.delete('select_options') unless properties['select_options'].nil?
|
77
79
|
attributes = {
|
78
80
|
name: params[:name],
|
@@ -109,14 +111,14 @@ module Labimotion
|
|
109
111
|
params.delete(:container)
|
110
112
|
params.delete(:properties)
|
111
113
|
attributes = declared(params.except(:segments), include_missing: false)
|
112
|
-
properties['
|
113
|
-
properties['labimotion'] = Labimotion::VERSION
|
114
|
+
properties['pkg'] = Labimotion::Utils.pkg(properties['pkg'])
|
114
115
|
if element.klass_uuid != properties['klass_uuid'] || element.properties != properties || element.name != params[:name]
|
115
116
|
properties['klass'] = 'Element'
|
116
117
|
uuid = SecureRandom.uuid
|
117
118
|
properties['uuid'] = uuid
|
118
119
|
|
119
120
|
properties.delete('flow') unless properties['flow'].nil?
|
121
|
+
properties.delete('flowObject') unless properties['flowObject'].nil?
|
120
122
|
properties.delete('select_options') unless properties['select_options'].nil?
|
121
123
|
|
122
124
|
attributes['properties'] = properties
|
@@ -246,7 +248,7 @@ module Labimotion
|
|
246
248
|
.where(
|
247
249
|
element_klasses: { name: params[:el_type] },
|
248
250
|
collections_elements: { collection_id: collection_id },
|
249
|
-
).includes(:tag, collections: :sync_collections_users)
|
251
|
+
).includes(:tag, collections: :sync_collections_users)
|
250
252
|
else
|
251
253
|
Labimotion::Element.none
|
252
254
|
end
|
@@ -255,10 +257,35 @@ module Labimotion
|
|
255
257
|
from = params[:from_date]
|
256
258
|
to = params[:to_date]
|
257
259
|
by_created_at = params[:filter_created_at] || false
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
260
|
+
if params[:sort_column]&.include?('.')
|
261
|
+
layer, field = params[:sort_column].split('.')
|
262
|
+
|
263
|
+
element_klass = Labimotion::ElementKlass.find_by(name: params[:el_type])
|
264
|
+
allowed_fields = element_klass.properties_release.dig('layers', layer, 'fields')&.pluck('field') || []
|
265
|
+
|
266
|
+
if field.in?(allowed_fields)
|
267
|
+
query = ActiveRecord::Base.sanitize_sql(
|
268
|
+
[
|
269
|
+
"LEFT JOIN LATERAL(
|
270
|
+
SELECT field->'value' AS value
|
271
|
+
FROM jsonb_array_elements(properties->'layers'->:layer->'fields') a(field)
|
272
|
+
WHERE field->>'field' = :field
|
273
|
+
) a ON true",
|
274
|
+
{ layer: layer, field: field },
|
275
|
+
],
|
276
|
+
)
|
277
|
+
scope = scope.joins(query).order('value ASC NULLS FIRST')
|
278
|
+
else
|
279
|
+
scope = scope.order(updated_at: :desc)
|
280
|
+
end
|
281
|
+
else
|
282
|
+
scope = scope.order(updated_at: :desc)
|
283
|
+
end
|
284
|
+
|
285
|
+
scope = scope.elements_created_time_from(Time.at(from)) if from && by_created_at
|
286
|
+
scope = scope.elements_created_time_to(Time.at(to) + 1.day) if to && by_created_at
|
287
|
+
scope = scope.elements_updated_time_from(Time.at(from)) if from && !by_created_at
|
288
|
+
scope = scope.elements_updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
|
262
289
|
scope
|
263
290
|
rescue StandardError => e
|
264
291
|
Labimotion.log_exception(e, current_user)
|
@@ -267,8 +294,9 @@ module Labimotion
|
|
267
294
|
|
268
295
|
def create_repo_klass(params, current_user)
|
269
296
|
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
|
270
|
-
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier'
|
271
|
-
attributes['
|
297
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
298
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
299
|
+
attributes['properties_template'] = attributes['properties_release']
|
272
300
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
273
301
|
attributes['is_active'] = false
|
274
302
|
attributes['updated_by'] = current_user.id
|
@@ -280,8 +308,9 @@ module Labimotion
|
|
280
308
|
element_klass.update!(attributes)
|
281
309
|
else
|
282
310
|
attributes['created_by'] = current_user.id
|
283
|
-
Labimotion::ElementKlass.create!(attributes)
|
311
|
+
element_klass = Labimotion::ElementKlass.create!(attributes)
|
284
312
|
end
|
313
|
+
element_klass.create_klasses_revision(current_user)
|
285
314
|
rescue StandardError => e
|
286
315
|
Labimotion.log_exception(e, current_user)
|
287
316
|
# { error: e.message }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'grape'
|
3
|
-
require 'labimotion/
|
3
|
+
require 'labimotion/utils/utils'
|
4
4
|
# Helper for associated sample
|
5
5
|
module Labimotion
|
6
6
|
## Generic Helpers
|
@@ -41,43 +41,23 @@ module Labimotion
|
|
41
41
|
raise e
|
42
42
|
end
|
43
43
|
|
44
|
-
def update_template(params)
|
44
|
+
def update_template(params, current_user)
|
45
45
|
klz = fetch_klass(params[:klass], params[:id])
|
46
46
|
uuid = SecureRandom.uuid
|
47
47
|
properties = params[:properties_template]
|
48
|
-
|
49
|
-
properties['uuid'] = uuid unless params[:release] != 'draft' && @klz.identifier.present?
|
50
|
-
else
|
51
|
-
properties['uuid'] = uuid
|
52
|
-
end
|
53
|
-
|
54
|
-
klz.version =
|
55
|
-
case params[:release]
|
56
|
-
when 'draft'
|
57
|
-
klz.version
|
58
|
-
when 'major'
|
59
|
-
if klz.version.nil? || klz.version&.split('.').length < 2
|
60
|
-
'1.0'
|
61
|
-
else
|
62
|
-
"#{klz.version&.split('.').first.to_i + 1}.0"
|
63
|
-
end
|
64
|
-
when 'minor'
|
65
|
-
if klz.version.nil? || klz.version&.split('.').length < 2
|
66
|
-
'0.1'
|
67
|
-
else
|
68
|
-
"#{klz.version.split('.').first.to_i.to_s}.#{klz.version.split('.').last.to_i + 1}"
|
69
|
-
end
|
70
|
-
end
|
48
|
+
properties['uuid'] = uuid
|
71
49
|
|
50
|
+
klz.version = Labimotion::Utils.next_version(params[:release], klz.version)
|
72
51
|
properties['version'] = klz.version
|
73
|
-
properties['
|
74
|
-
properties['
|
75
|
-
properties['
|
52
|
+
properties['pkg'] = Labimotion::Utils.pkg(params['pkg'] || klz.properties_template['pkg'])
|
53
|
+
properties['klass'] = klz.class.name.split('::').last
|
54
|
+
properties['identifier'] = klz.identifier
|
55
|
+
properties.delete('eln') if properties['eln'].present?
|
76
56
|
klz.updated_by = current_user.id
|
77
57
|
klz.properties_template = properties
|
78
58
|
klz.save!
|
79
59
|
klz.reload
|
80
|
-
klz.create_klasses_revision(current_user
|
60
|
+
klz.create_klasses_revision(current_user) if params[:release] != 'draft'
|
81
61
|
klz
|
82
62
|
rescue StandardError => e
|
83
63
|
Labimotion.log_exception(e, current_user)
|
@@ -117,12 +97,8 @@ module Labimotion
|
|
117
97
|
|
118
98
|
|
119
99
|
###############
|
120
|
-
|
121
|
-
|
122
100
|
def generate_klass_file
|
123
|
-
|
124
|
-
!File.directory?(klass_dir) && FileUtils.mkdir_p(klass_dir)
|
125
|
-
klass_names_file = File.join(klass_dir, 'klasses.json')
|
101
|
+
klass_names_file = Rails.root.join('app/packs/klasses.json')
|
126
102
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
127
103
|
File.write(klass_names_file, klasses)
|
128
104
|
rescue StandardError => e
|
@@ -266,7 +242,7 @@ module Labimotion
|
|
266
242
|
filter_list || []
|
267
243
|
rescue StandardError => e
|
268
244
|
Labimotion.log_exception(e, current_user)
|
269
|
-
|
245
|
+
{ error: 'Cannot connect to Chemotion Repository' }
|
270
246
|
end
|
271
247
|
end
|
272
248
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'grape'
|
3
3
|
require 'labimotion/models/segment_klass'
|
4
|
+
require 'labimotion/utils/utils'
|
5
|
+
|
4
6
|
module Labimotion
|
5
7
|
## ElementHelpers
|
6
8
|
module SegmentHelpers
|
@@ -26,8 +28,7 @@ module Labimotion
|
|
26
28
|
attributes = declared(params, include_missing: false)
|
27
29
|
attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present?
|
28
30
|
template = (attributes[:properties_template].presence || template)
|
29
|
-
template['
|
30
|
-
template['labimotion'] = Labimotion::VERSION
|
31
|
+
template['pkg'] = Labimotion::Utils.pkg(template['pkg'])
|
31
32
|
template['klass'] = 'SegmentKlass'
|
32
33
|
attributes.merge!(properties_template: template, element_klass: @klass, created_by: current_user.id,
|
33
34
|
place: place)
|
@@ -37,7 +38,7 @@ module Labimotion
|
|
37
38
|
attributes[:properties_release] = attributes[:properties_template]
|
38
39
|
klass = Labimotion::SegmentKlass.create!(attributes)
|
39
40
|
klass.reload
|
40
|
-
klass.create_klasses_revision(current_user
|
41
|
+
klass.create_klasses_revision(current_user)
|
41
42
|
klass
|
42
43
|
rescue StandardError => e
|
43
44
|
Labimotion.log_exception(e, current_user)
|
@@ -64,8 +65,9 @@ module Labimotion
|
|
64
65
|
|
65
66
|
def create_repo_klass(params, current_user)
|
66
67
|
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
|
67
|
-
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at'
|
68
|
-
attributes['
|
68
|
+
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
|
69
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
70
|
+
attributes['properties_template'] = attributes['properties_release']
|
69
71
|
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
70
72
|
attributes['is_active'] = false
|
71
73
|
attributes['updated_by'] = current_user.id
|
@@ -86,8 +88,9 @@ module Labimotion
|
|
86
88
|
segment_klass.update!(attributes)
|
87
89
|
else
|
88
90
|
attributes['created_by'] = current_user.id
|
89
|
-
Labimotion::SegmentKlass.create!(attributes)
|
91
|
+
segment_klass = Labimotion::SegmentKlass.create!(attributes)
|
90
92
|
end
|
93
|
+
segment_klass.create_klasses_revision(current_user)
|
91
94
|
rescue StandardError => e
|
92
95
|
Labimotion.log_exception(e, current_user)
|
93
96
|
raise e
|
@@ -4,7 +4,7 @@ require 'net/http'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'json'
|
6
6
|
require 'date'
|
7
|
-
require 'labimotion/
|
7
|
+
require 'labimotion/utils/utils'
|
8
8
|
|
9
9
|
# rubocop: disable Metrics/AbcSize
|
10
10
|
# rubocop: disable Metrics/MethodLength
|
@@ -209,8 +209,7 @@ module Labimotion
|
|
209
209
|
uuid = SecureRandom.uuid
|
210
210
|
props = klass.properties_release
|
211
211
|
props['uuid'] = uuid
|
212
|
-
props['
|
213
|
-
props['labimotion'] = Labimotion::VERSION
|
212
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
214
213
|
props['klass'] = 'Dataset'
|
215
214
|
Labimotion::Dataset.create!(
|
216
215
|
uuid: uuid,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'labimotion/utils/utils'
|
4
|
+
|
3
5
|
module Labimotion
|
4
6
|
## NmrMapper
|
5
7
|
class NmrMapper
|
@@ -247,8 +249,7 @@ module Labimotion
|
|
247
249
|
uuid = SecureRandom.uuid
|
248
250
|
props = klass.properties_release
|
249
251
|
props['uuid'] = uuid
|
250
|
-
props['
|
251
|
-
props['labimotion'] = Labimotion::VERSION
|
252
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
252
253
|
props['klass'] = 'Dataset'
|
253
254
|
dataset = Labimotion::Dataset.create!(
|
254
255
|
uuid: uuid,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'labimotion/utils/utils'
|
2
3
|
|
3
4
|
module Labimotion
|
4
5
|
class NmrMapperRepo
|
@@ -245,8 +246,7 @@ module Labimotion
|
|
245
246
|
uuid = SecureRandom.uuid
|
246
247
|
props = klass.properties_release
|
247
248
|
props['uuid'] = uuid
|
248
|
-
props['
|
249
|
-
props['labimotion'] = Labimotion::VERSION
|
249
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
250
250
|
props['klass'] = 'Dataset'
|
251
251
|
dataset = Labimotion::Dataset.create!(
|
252
252
|
uuid: uuid,
|
@@ -20,7 +20,7 @@ module Labimotion
|
|
20
20
|
|
21
21
|
|
22
22
|
def self.header(opt = {})
|
23
|
-
opt || { :
|
23
|
+
opt || { timeout: 10, headers: { 'Content-Type' => 'text/json' } }
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.handle_response(oat, response) # rubocop: disable Metrics/PerceivedComplexity
|
@@ -35,16 +35,22 @@ module Labimotion
|
|
35
35
|
|
36
36
|
def self.list(klass)
|
37
37
|
body = { klass: klass }
|
38
|
-
response = HTTParty.get("#{uri('list')}?klass=#{klass}",
|
38
|
+
response = HTTParty.get("#{uri('list')}?klass=#{klass}", timeout: 10)
|
39
39
|
# response.parsed_response if response.code == 200
|
40
40
|
JSON.parse(response.body) if response.code == 200
|
41
|
+
rescue StandardError => e
|
42
|
+
Labimotion.log_exception(e)
|
43
|
+
error!('Cannot connect to Chemotion Repository', 401)
|
41
44
|
end
|
42
45
|
|
43
46
|
def self.fetch_identifier(klass, identifier)
|
44
47
|
# body = { klass: klass, identifier: identifier }
|
45
|
-
response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}",
|
48
|
+
response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}", timeout: 10)
|
46
49
|
# response.parsed_response if response.code == 200
|
47
50
|
JSON.parse(response.body) if response.code == 200
|
51
|
+
rescue StandardError => e
|
52
|
+
Labimotion.log_exception(e)
|
53
|
+
error!('Cannot connect to Chemotion Repository', 401)
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Datasetable concern
|
4
|
+
require 'labimotion/utils/utils'
|
4
5
|
|
5
6
|
module Labimotion
|
6
7
|
## Datasetable concern
|
@@ -21,23 +22,18 @@ module Labimotion
|
|
21
22
|
klass = Labimotion::DatasetKlass.find_by(id: args[:dataset_klass_id])
|
22
23
|
uuid = SecureRandom.uuid
|
23
24
|
props = args[:properties]
|
24
|
-
props['
|
25
|
-
props['
|
25
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
26
|
+
props['identifier'] = klass.identifier
|
27
|
+
props['uuid'] = uuid
|
28
|
+
props['klass'] = 'Dataset'
|
29
|
+
|
26
30
|
ds = Labimotion::Dataset.find_by(element_type: self.class.name, element_id: id)
|
27
31
|
if ds.present? && (ds.klass_uuid != props['klass_uuid'] || ds.properties != props)
|
28
|
-
props['uuid'] = uuid
|
29
|
-
props['eln'] = Chemotion::Application.config.version
|
30
|
-
props['labimotion'] = Labimotion::VERSION
|
31
|
-
props['klass'] = 'Dataset'
|
32
32
|
ds.update!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], properties: props, klass_uuid: props['klass_uuid'])
|
33
33
|
end
|
34
34
|
return if ds.present?
|
35
35
|
|
36
|
-
props['uuid'] = uuid
|
37
36
|
props['klass_uuid'] = klass.uuid
|
38
|
-
props['eln'] = Chemotion::Application.config.version
|
39
|
-
props['labimotion'] = Labimotion::VERSION
|
40
|
-
props['klass'] = 'Dataset'
|
41
37
|
Labimotion::Dataset.create!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], element_type: self.class.name, element_id: id, properties: props, klass_uuid: klass.uuid)
|
42
38
|
end
|
43
39
|
|
@@ -1,33 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Labimotion
|
4
|
-
|
4
|
+
## Generic Klass Revisions Helpers
|
5
|
+
module GenericKlassRevisions
|
5
6
|
extend ActiveSupport::Concern
|
6
7
|
included do
|
7
8
|
# has_many :element_klasses_revisions, dependent: :destroy
|
8
9
|
end
|
9
10
|
|
10
|
-
def create_klasses_revision(
|
11
|
+
def create_klasses_revision(current_user)
|
11
12
|
properties_release = properties_template
|
12
|
-
|
13
|
-
# properties_release['layers'][key]['layer'] = properties_release['layers'][key]['key']
|
14
|
-
# end
|
13
|
+
migrate_workflow if properties_release['flow'].present?
|
15
14
|
|
16
|
-
if properties_release['
|
17
|
-
elements = (properties_release['
|
15
|
+
if properties_release['flowObject'].present?
|
16
|
+
elements = (properties_release['flowObject']['nodes'] || []).map do |el|
|
18
17
|
if el['data'].present? && el['data']['lKey'].present?
|
19
18
|
layer = properties_release['layers'][el['data']['lKey']]
|
20
19
|
el['data']['layer'] = layer if layer.present?
|
21
20
|
end
|
22
21
|
el
|
23
22
|
end
|
24
|
-
properties_release['
|
23
|
+
properties_release['flowObject']['nodes'] = elements
|
25
24
|
end
|
25
|
+
klass_attributes = {
|
26
|
+
uuid: properties_template['uuid'],
|
27
|
+
properties_template: properties_release,
|
28
|
+
properties_release: properties_release,
|
29
|
+
released_at: DateTime.now,
|
30
|
+
updated_by: current_user&.id,
|
31
|
+
released_by: current_user&.id,
|
32
|
+
}
|
26
33
|
|
27
|
-
self.update!(
|
34
|
+
self.update!(klass_attributes)
|
28
35
|
reload
|
29
36
|
attributes = {
|
30
|
-
released_by:
|
37
|
+
released_by: released_by,
|
31
38
|
uuid: uuid,
|
32
39
|
version: version,
|
33
40
|
properties_release: properties_release,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'labimotion/utils/utils'
|
4
|
+
|
3
5
|
module Labimotion
|
4
6
|
# Segmentable concern
|
5
7
|
module Segmentable
|
@@ -45,25 +47,18 @@ module Labimotion
|
|
45
47
|
klass = Labimotion::SegmentKlass.find_by(id: seg['segment_klass_id'])
|
46
48
|
uuid = SecureRandom.uuid
|
47
49
|
props = seg['properties']
|
48
|
-
props['
|
49
|
-
props['
|
50
|
+
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
51
|
+
props['identifier'] = identifier
|
52
|
+
props['uuid'] = uuid
|
53
|
+
props['klass'] = 'Segment'
|
50
54
|
segment = Labimotion::Segment.find_by(element_type: Labimotion::Utils.element_name(self.class.name), element_id: self.id, segment_klass_id: seg['segment_klass_id'])
|
51
55
|
if segment.present? && (segment.klass_uuid != props['klass_uuid'] || segment.properties != props)
|
52
|
-
props['uuid'] = uuid
|
53
|
-
props['eln'] = Chemotion::Application.config.version
|
54
|
-
props['labimotion'] = Labimotion::VERSION
|
55
|
-
props['klass'] = 'Segment'
|
56
|
-
|
57
56
|
segment.update!(properties_release: klass.properties_release, properties: props, uuid: uuid, klass_uuid: props['klass_uuid'])
|
58
57
|
segments.push(segment)
|
59
58
|
end
|
60
59
|
next if segment.present?
|
61
60
|
|
62
|
-
props['uuid'] = uuid
|
63
61
|
props['klass_uuid'] = klass.uuid
|
64
|
-
props['eln'] = Chemotion::Application.config.version
|
65
|
-
props['labimotion'] = Labimotion::VERSION
|
66
|
-
props['klass'] = 'Segment'
|
67
62
|
segment = Labimotion::Segment.create!(properties_release: klass.properties_release, segment_klass_id: seg['segment_klass_id'], element_type: Labimotion::Utils.element_name(self.class.name), element_id: self.id, properties: props, created_by: args[:current_user_id], uuid: uuid, klass_uuid: klass.uuid)
|
68
63
|
segments.push(segment)
|
69
64
|
end
|
@@ -23,7 +23,6 @@ module Labimotion
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
26
|
def migrate_workflow
|
28
27
|
return if properties_template.nil? || properties_release.nil?
|
29
28
|
|
@@ -32,8 +31,5 @@ module Labimotion
|
|
32
31
|
update_column(:properties_template, split_workflow(properties_template)) if properties_template['flow']
|
33
32
|
update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
|
34
33
|
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
34
|
end
|
39
35
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'labimotion/version'
|
3
4
|
module Labimotion
|
4
5
|
## Generic Utils
|
5
6
|
class Utils
|
@@ -54,5 +55,36 @@ module Labimotion
|
|
54
55
|
def self.element_name_dc(name)
|
55
56
|
Labimotion::Utils.element_name(name)&.downcase
|
56
57
|
end
|
58
|
+
|
59
|
+
def self.next_version(release, current_version)
|
60
|
+
case release
|
61
|
+
when 'draft'
|
62
|
+
current_version
|
63
|
+
when 'major'
|
64
|
+
if current_version.nil? || current_version.split('.').length < 2
|
65
|
+
'1.0'
|
66
|
+
else
|
67
|
+
"#{current_version&.split('.').first.to_i + 1}.0"
|
68
|
+
end
|
69
|
+
when 'minor'
|
70
|
+
if current_version.nil? || current_version&.split('.').length < 2
|
71
|
+
'0.1'
|
72
|
+
else
|
73
|
+
"#{current_version&.split('.').first.to_i.to_s}.#{current_version&.split('.').last.to_i + 1}"
|
74
|
+
end
|
75
|
+
else
|
76
|
+
current_version
|
77
|
+
end
|
78
|
+
rescue StandardError => e
|
79
|
+
Labimotion.log_exception(e)
|
80
|
+
current_version
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.pkg(pkg)
|
84
|
+
pkg = {} if pkg.nil?
|
85
|
+
pkg['eln'] = Chemotion::Application.config.version
|
86
|
+
pkg['labimotion'] = Labimotion::VERSION
|
87
|
+
pkg
|
88
|
+
end
|
57
89
|
end
|
58
90
|
end
|
data/lib/labimotion/version.rb
CHANGED
data/lib/labimotion.rb
CHANGED
@@ -7,7 +7,7 @@ module Labimotion
|
|
7
7
|
@@labimotion_logger ||= Logger.new(Rails.root.join('log/labimotion.log')) # rubocop:disable Style/ClassVars
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.log_exception(exception, current_user =
|
10
|
+
def self.log_exception(exception, current_user = nil)
|
11
11
|
Labimotion.logger.error("version: #{Labimotion::VERSION}; #{Labimotion::IS_RAILS5}, (#{current_user&.id}) \n Exception: #{exception.message}")
|
12
12
|
Labimotion.logger.error(exception.backtrace.join("\n"))
|
13
13
|
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: 0.2.
|
4
|
+
version: 0.2.2
|
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: 2023-08-
|
12
|
+
date: 2023-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.18
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Chemotion LabIMotion
|