labimotion 1.3.0.rc4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/labimotion/apis/generic_element_api.rb +39 -41
- 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 -15
- data/lib/labimotion/helpers/param_helpers.rb +97 -0
- data/lib/labimotion/helpers/segment_helpers.rb +26 -18
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +6 -0
- data/lib/labimotion/utils/units.rb +22 -13
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +2 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94c2f0242360d6b6fd17c82850b0650fe18f86ccd484b47ce98ae7dfdccd50d1
|
4
|
+
data.tar.gz: 925eb30692c128d1339f97f96fdfe3b283f251822293fab6f25b9e2cffaedc25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b611c37931e15ee233ff01708d2fafa421746b68aa5e63af907a0b811ccc2958b04491c80da4219516bc62db7cad682138af2c999d85a9708eca6a688489e63c
|
7
|
+
data.tar.gz: 55680523c5140f1bfaffc632147ca1bce2a01969cb3866f1f1caa97681cfac9b497520b9002c9b2302e998792d6c6fd5c9ee50a5746493924982d745e031f8bc
|
@@ -13,6 +13,7 @@ module Labimotion
|
|
13
13
|
helpers Labimotion::SampleAssociationHelpers
|
14
14
|
helpers Labimotion::GenericHelpers
|
15
15
|
helpers Labimotion::ElementHelpers
|
16
|
+
helpers Labimotion::ParamHelpers
|
16
17
|
|
17
18
|
resource :generic_elements do
|
18
19
|
namespace :klass do
|
@@ -59,7 +60,6 @@ module Labimotion
|
|
59
60
|
when 'Dataset'
|
60
61
|
element = Labimotion::Dataset.find(params[:id])
|
61
62
|
end
|
62
|
-
## byebug
|
63
63
|
export = Labimotion::ExportElement.new current_user, element, params[:export_format]
|
64
64
|
env['api.format'] = :binary
|
65
65
|
content_type 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
@@ -78,12 +78,7 @@ module Labimotion
|
|
78
78
|
namespace :create_element_klass do
|
79
79
|
desc 'create Generic Element Klass'
|
80
80
|
params do
|
81
|
-
|
82
|
-
requires :label, type: String, desc: 'Element Klass Label'
|
83
|
-
requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
84
|
-
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
85
|
-
optional :desc, type: String, desc: 'Element Klass Desc'
|
86
|
-
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
81
|
+
use :create_element_klass_params
|
87
82
|
end
|
88
83
|
post do
|
89
84
|
authenticate_admin!('elements')
|
@@ -97,12 +92,7 @@ module Labimotion
|
|
97
92
|
namespace :update_element_klass do
|
98
93
|
desc 'update Generic Element Klass'
|
99
94
|
params do
|
100
|
-
|
101
|
-
optional :label, type: String, desc: 'Element Klass Label'
|
102
|
-
optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
103
|
-
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
104
|
-
optional :desc, type: String, desc: 'Element Klass Desc'
|
105
|
-
optional :place, type: String, desc: 'Element Klass Place'
|
95
|
+
use :update_element_klass_params
|
106
96
|
end
|
107
97
|
post do
|
108
98
|
authenticate_admin!('elements')
|
@@ -306,6 +296,39 @@ module Labimotion
|
|
306
296
|
end
|
307
297
|
end
|
308
298
|
|
299
|
+
namespace :upload_klass do
|
300
|
+
desc 'upload Generic Klass'
|
301
|
+
params do
|
302
|
+
use :upload_element_klass_params
|
303
|
+
end
|
304
|
+
post do
|
305
|
+
declared_params = declared(params, include_missing: false)
|
306
|
+
attributes = declared_params.merge(
|
307
|
+
created_by: current_user.id,
|
308
|
+
released_by: current_user.id,
|
309
|
+
updated_by: current_user.id,
|
310
|
+
is_active: false
|
311
|
+
)
|
312
|
+
validate_klass(attributes)
|
313
|
+
rescue StandardError => e
|
314
|
+
Labimotion.log_exception(e, current_user)
|
315
|
+
raise e
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
namespace :split do
|
320
|
+
desc 'split elements'
|
321
|
+
params do
|
322
|
+
requires :ui_state, type: Hash, desc: 'Selected elements from the UI'
|
323
|
+
end
|
324
|
+
post do
|
325
|
+
split_elements(params[:ui_state], current_user)
|
326
|
+
rescue StandardError => e
|
327
|
+
Labimotion.log_exception(e, current_user)
|
328
|
+
{ error: e.message }
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
309
332
|
desc 'Return serialized elements of current user'
|
310
333
|
params do
|
311
334
|
optional :collection_id, type: Integer, desc: 'Collection id'
|
@@ -319,7 +342,6 @@ module Labimotion
|
|
319
342
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
320
343
|
get do
|
321
344
|
scope = list_serialized_elements(params, current_user)
|
322
|
-
|
323
345
|
reset_pagination_page(scope)
|
324
346
|
generic_elements = paginate(scope).map do |element|
|
325
347
|
Labimotion::ElementEntity.represent(
|
@@ -363,13 +385,7 @@ module Labimotion
|
|
363
385
|
|
364
386
|
desc 'Create a element'
|
365
387
|
params do
|
366
|
-
|
367
|
-
requires :name, type: String
|
368
|
-
optional :properties, type: Hash
|
369
|
-
optional :properties_release, type: Hash
|
370
|
-
optional :collection_id, type: Integer
|
371
|
-
requires :container, type: Hash
|
372
|
-
optional :segments, type: Array, desc: 'Segments'
|
388
|
+
use :create_element_params
|
373
389
|
end
|
374
390
|
post do
|
375
391
|
begin
|
@@ -388,12 +404,7 @@ module Labimotion
|
|
388
404
|
|
389
405
|
desc 'Update element by id'
|
390
406
|
params do
|
391
|
-
|
392
|
-
optional :name, type: String
|
393
|
-
requires :properties, type: Hash
|
394
|
-
optional :properties_release, type: Hash
|
395
|
-
requires :container, type: Hash
|
396
|
-
optional :segments, type: Array, desc: 'Segments'
|
407
|
+
use :update_element_params
|
397
408
|
end
|
398
409
|
route_param :id do
|
399
410
|
before do
|
@@ -415,20 +426,7 @@ module Labimotion
|
|
415
426
|
raise e
|
416
427
|
end
|
417
428
|
end
|
418
|
-
end
|
419
|
-
|
420
|
-
namespace :split do
|
421
|
-
desc 'split elements'
|
422
|
-
params do
|
423
|
-
requires :ui_state, type: Hash, desc: 'Selected elements from the UI'
|
424
|
-
end
|
425
|
-
post do
|
426
|
-
split_elements(params[:ui_state], current_user)
|
427
|
-
rescue StandardError => e
|
428
|
-
Labimotion.log_exception(e, current_user)
|
429
|
-
{ error: e.message }
|
430
|
-
end
|
431
|
-
end
|
429
|
+
end
|
432
430
|
end
|
433
431
|
end
|
434
432
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'labimotion/version'
|
4
|
+
require 'labimotion/libs/export_element'
|
5
|
+
|
6
|
+
module Labimotion
|
7
|
+
# Generic Element API
|
8
|
+
class GenericKlassAPI < Grape::API
|
9
|
+
|
10
|
+
resource :generic_klass do
|
11
|
+
namespace :download_klass do
|
12
|
+
desc 'export klass'
|
13
|
+
params do
|
14
|
+
requires :id, type: Integer, desc: 'element id'
|
15
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
16
|
+
end
|
17
|
+
get do
|
18
|
+
entity = "Labimotion::#{params[:klass]}".constantize.find_by(id: params[:id])
|
19
|
+
entity.update_columns(identifier: SecureRandom.uuid) if entity&.identifier.nil?
|
20
|
+
env['api.format'] = :binary
|
21
|
+
content_type('application/json')
|
22
|
+
filename = URI.escape("LabIMotion_#{params[:klass]}_#{entity.label}-#{Time.new.strftime("%Y%m%d%H%M%S")}.json")
|
23
|
+
# header['Content-Disposition'] = "attachment; filename=abc.docx"
|
24
|
+
header('Content-Disposition', "attachment; filename=\"#{filename}\"")
|
25
|
+
"Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
|
26
|
+
# klass.as_json
|
27
|
+
rescue StandardError => e
|
28
|
+
Labimotion.log_exception(e, current_user)
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,6 +3,7 @@ module Labimotion
|
|
3
3
|
include Grape::Kaminari
|
4
4
|
helpers Labimotion::GenericHelpers
|
5
5
|
helpers Labimotion::SegmentHelpers
|
6
|
+
helpers Labimotion::ParamHelpers
|
6
7
|
|
7
8
|
resource :segments do
|
8
9
|
namespace :klasses do
|
@@ -30,11 +31,7 @@ module Labimotion
|
|
30
31
|
namespace :create_segment_klass do
|
31
32
|
desc 'create Generic Segment Klass'
|
32
33
|
params do
|
33
|
-
|
34
|
-
requires :element_klass, type: Integer, desc: 'Element Klass Id'
|
35
|
-
optional :desc, type: String, desc: 'Segment Klass Desc'
|
36
|
-
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
37
|
-
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
34
|
+
use :create_segment_klass_params
|
38
35
|
end
|
39
36
|
after_validation do
|
40
37
|
authenticate_admin!('segments')
|
@@ -50,11 +47,7 @@ module Labimotion
|
|
50
47
|
namespace :update_segment_klass do
|
51
48
|
desc 'update Generic Segment Klass'
|
52
49
|
params do
|
53
|
-
|
54
|
-
optional :label, type: String, desc: 'Segment Klass Label'
|
55
|
-
optional :desc, type: String, desc: 'Segment Klass Desc'
|
56
|
-
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
57
|
-
optional :identifier, type: String, desc: 'Segment Identifier'
|
50
|
+
use :update_segment_klass_params
|
58
51
|
end
|
59
52
|
after_validation do
|
60
53
|
authenticate_admin!('segments')
|
@@ -140,6 +133,28 @@ module Labimotion
|
|
140
133
|
raise e
|
141
134
|
end
|
142
135
|
end
|
136
|
+
|
137
|
+
namespace :upload_klass do
|
138
|
+
desc 'upload Generic Klass'
|
139
|
+
params do
|
140
|
+
use :upload_segment_klass_params
|
141
|
+
end
|
142
|
+
post do
|
143
|
+
declared_params = declared(params, include_missing: false)
|
144
|
+
attributes = declared_params.merge(
|
145
|
+
created_by: current_user.id,
|
146
|
+
released_by: current_user.id,
|
147
|
+
updated_by: current_user.id,
|
148
|
+
is_active: false
|
149
|
+
)
|
150
|
+
attr_klass = params['element_klass'] || {}
|
151
|
+
attributes.delete(:element_klass)
|
152
|
+
validate_klass(attributes, attr_klass)
|
153
|
+
rescue StandardError => e
|
154
|
+
Labimotion.log_exception(e, current_user)
|
155
|
+
raise e
|
156
|
+
end
|
157
|
+
end
|
143
158
|
end
|
144
159
|
end
|
145
160
|
end
|
@@ -294,37 +294,44 @@ module Labimotion
|
|
294
294
|
raise e
|
295
295
|
end
|
296
296
|
|
297
|
-
def
|
298
|
-
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
|
299
|
-
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
300
|
-
attributes['properties_release']['identifier'] = attributes['identifier']
|
301
|
-
attributes['properties_template'] = attributes['properties_release']
|
302
|
-
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
303
|
-
attributes['is_active'] = false
|
304
|
-
attributes['updated_by'] = current_user.id
|
305
|
-
attributes['sync_by'] = current_user.id
|
306
|
-
attributes['sync_time'] = DateTime.now
|
307
|
-
|
297
|
+
def validate_klass(attributes)
|
308
298
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
309
299
|
if element_klass.present?
|
310
300
|
if element_klass['uuid'] == attributes['uuid'] && element_klass['version'] == attributes['version']
|
311
|
-
{ status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
|
301
|
+
return { status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
|
312
302
|
else
|
313
303
|
element_klass.update!(attributes)
|
314
304
|
element_klass.create_klasses_revision(current_user)
|
315
|
-
{ status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
|
305
|
+
return { status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
|
316
306
|
end
|
317
307
|
else
|
318
308
|
exist_klass = Labimotion::ElementKlass.find_by(name: attributes['name'])
|
319
309
|
if exist_klass.present?
|
320
|
-
{ status: 'error', message: "The name [#{attributes['name']}] is already in use." }
|
310
|
+
return { status: 'error', message: "The name [#{attributes['name']}] is already in use." }
|
321
311
|
else
|
322
312
|
attributes['created_by'] = current_user.id
|
323
313
|
element_klass = Labimotion::ElementKlass.create!(attributes)
|
324
314
|
element_klass.create_klasses_revision(current_user)
|
325
|
-
{ status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
|
315
|
+
return { status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
|
326
316
|
end
|
327
317
|
end
|
318
|
+
|
319
|
+
rescue StandardError => e
|
320
|
+
Labimotion.log_exception(e, current_user)
|
321
|
+
return { status: 'error', message: e.message }
|
322
|
+
end
|
323
|
+
|
324
|
+
def create_repo_klass(params, current_user, origin)
|
325
|
+
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
|
326
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
327
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
328
|
+
attributes['properties_template'] = attributes['properties_release']
|
329
|
+
attributes['place'] = ((Labimotion::ElementKlass.all.length * 10) || 0) + 10
|
330
|
+
attributes['is_active'] = false
|
331
|
+
attributes['updated_by'] = current_user.id
|
332
|
+
attributes['sync_by'] = current_user.id
|
333
|
+
attributes['sync_time'] = DateTime.now
|
334
|
+
validate_klass(attributes)
|
328
335
|
rescue StandardError => e
|
329
336
|
Labimotion.log_exception(e, current_user)
|
330
337
|
# { error: e.message }
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'grape'
|
3
|
+
require 'labimotion/utils/utils'
|
4
|
+
# Helper for associated sample
|
5
|
+
module Labimotion
|
6
|
+
## Generic Helpers
|
7
|
+
module ParamHelpers
|
8
|
+
extend Grape::API::Helpers
|
9
|
+
## Element Klass Params
|
10
|
+
params :upload_element_klass_params do
|
11
|
+
requires :name, type: String, desc: 'Klass Name'
|
12
|
+
optional :label, type: String, desc: 'Klass label'
|
13
|
+
optional :desc, type: String, desc: 'Klass desc'
|
14
|
+
optional :klass_prefix, type: String, desc: 'Klass klass_prefix'
|
15
|
+
optional :icon_name, type: String, desc: 'Klass icon_name'
|
16
|
+
requires :properties_template, type: Hash, desc: 'Klass template'
|
17
|
+
optional :properties_release, type: Hash, desc: 'Klass release'
|
18
|
+
optional :released_at, type: DateTime, desc: 'Klass released_at'
|
19
|
+
requires :uuid, type: String, desc: 'Klass uuid'
|
20
|
+
requires :place, type: Integer, desc: 'Klass place'
|
21
|
+
requires :identifier, type: String, desc: 'Klass identifier'
|
22
|
+
optional :sync_time, type: DateTime, desc: 'Klass sync_time'
|
23
|
+
optional :version, type: String, desc: 'Klass version'
|
24
|
+
end
|
25
|
+
|
26
|
+
params :create_element_klass_params do
|
27
|
+
requires :name, type: String, desc: 'Element Klass Name'
|
28
|
+
requires :label, type: String, desc: 'Element Klass Label'
|
29
|
+
requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
30
|
+
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
31
|
+
optional :desc, type: String, desc: 'Element Klass Desc'
|
32
|
+
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
33
|
+
end
|
34
|
+
|
35
|
+
params :update_element_klass_params do
|
36
|
+
requires :id, type: Integer, desc: 'Element Klass ID'
|
37
|
+
optional :label, type: String, desc: 'Element Klass Label'
|
38
|
+
optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
39
|
+
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
40
|
+
optional :desc, type: String, desc: 'Element Klass Desc'
|
41
|
+
optional :place, type: String, desc: 'Element Klass Place'
|
42
|
+
end
|
43
|
+
|
44
|
+
## Element Params
|
45
|
+
params :create_element_params do
|
46
|
+
requires :element_klass, type: Hash
|
47
|
+
requires :name, type: String
|
48
|
+
optional :properties, type: Hash
|
49
|
+
optional :properties_release, type: Hash
|
50
|
+
optional :collection_id, type: Integer
|
51
|
+
requires :container, type: Hash
|
52
|
+
optional :segments, type: Array, desc: 'Segments'
|
53
|
+
end
|
54
|
+
|
55
|
+
params :update_element_params do
|
56
|
+
requires :id, type: Integer, desc: 'element id'
|
57
|
+
optional :name, type: String
|
58
|
+
requires :properties, type: Hash
|
59
|
+
optional :properties_release, type: Hash
|
60
|
+
requires :container, type: Hash
|
61
|
+
optional :segments, type: Array, desc: 'Segments'
|
62
|
+
end
|
63
|
+
|
64
|
+
## Segment Klass Params
|
65
|
+
params :upload_segment_klass_params do
|
66
|
+
requires :label, type: String, desc: 'Klass label'
|
67
|
+
optional :desc, type: String, desc: 'Klass desc'
|
68
|
+
requires :properties_template, type: Hash, desc: 'Klass template'
|
69
|
+
optional :properties_release, type: Hash, desc: 'Klass release'
|
70
|
+
optional :released_at, type: DateTime, desc: 'Klass released_at'
|
71
|
+
requires :uuid, type: String, desc: 'Klass uuid'
|
72
|
+
requires :place, type: Integer, desc: 'Klass place'
|
73
|
+
requires :identifier, type: String, desc: 'Klass identifier'
|
74
|
+
optional :sync_time, type: DateTime, desc: 'Klass sync_time'
|
75
|
+
optional :version, type: String, desc: 'Klass version'
|
76
|
+
requires :element_klass, type: Hash do
|
77
|
+
use :upload_element_klass_params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
params :update_segment_klass_params do
|
82
|
+
requires :id, type: Integer, desc: 'Segment Klass ID'
|
83
|
+
optional :label, type: String, desc: 'Segment Klass Label'
|
84
|
+
optional :desc, type: String, desc: 'Segment Klass Desc'
|
85
|
+
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
86
|
+
optional :identifier, type: String, desc: 'Segment Identifier'
|
87
|
+
end
|
88
|
+
|
89
|
+
params :create_segment_klass_params do
|
90
|
+
requires :label, type: String, desc: 'Segment Klass Label'
|
91
|
+
requires :element_klass, type: Integer, desc: 'Element Klass Id'
|
92
|
+
optional :desc, type: String, desc: 'Segment Klass Desc'
|
93
|
+
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
94
|
+
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -63,45 +63,53 @@ module Labimotion
|
|
63
63
|
raise e
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
attributes['properties_template'] = attributes['properties_release']
|
71
|
-
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
72
|
-
attributes['is_active'] = false
|
73
|
-
attributes['updated_by'] = current_user.id
|
74
|
-
attributes['sync_by'] = current_user.id
|
75
|
-
attributes['sync_time'] = DateTime.now
|
76
|
-
element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier']) if response.dig('element_klass','identifier').present?
|
77
|
-
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name'], is_generic: false) if element_klass.nil?
|
78
|
-
return { status: 'error', message: "The element [#{response['element_klass']['name']}] does not exist in this instance" } if element_klass.nil?
|
66
|
+
def validate_klass(attributes, attr_klass)
|
67
|
+
element_klass = Labimotion::ElementKlass.find_by(identifier: attr_klass['identifier']) if attr_klass.dig('identifier').present?
|
68
|
+
element_klass = Labimotion::ElementKlass.find_by(name: attr_klass['name'], is_generic: false) if element_klass.nil?
|
69
|
+
return { status: 'error', message: "The element [#{attr_klass['name']}] does not exist in this instance" } if element_klass.nil?
|
79
70
|
|
80
71
|
# el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
81
72
|
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
82
73
|
# Labimotion::ElementKlass.create!(el_attributes)
|
83
|
-
|
84
74
|
attributes['element_klass_id'] = element_klass.id
|
85
75
|
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
86
76
|
if segment_klass.present?
|
87
77
|
if segment_klass['uuid'] == attributes['uuid'] && segment_klass['version'] == attributes['version']
|
88
|
-
{ status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
|
78
|
+
return { status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
|
89
79
|
else
|
90
80
|
segment_klass.update!(attributes)
|
91
81
|
segment_klass.create_klasses_revision(current_user)
|
92
|
-
{ status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
|
82
|
+
return { status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
|
93
83
|
end
|
94
84
|
else
|
95
85
|
exist_klass = Labimotion::SegmentKlass.find_by(label: attributes['label'], element_klass_id: element_klass.id)
|
96
86
|
if exist_klass.present?
|
97
|
-
{ status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
|
87
|
+
return { status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
|
98
88
|
else
|
99
89
|
attributes['created_by'] = current_user.id
|
100
90
|
segment_klass = Labimotion::SegmentKlass.create!(attributes)
|
101
91
|
segment_klass.create_klasses_revision(current_user)
|
102
|
-
{ status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
|
92
|
+
return { status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
|
103
93
|
end
|
104
94
|
end
|
95
|
+
rescue StandardError => e
|
96
|
+
Labimotion.log_exception(e, current_user)
|
97
|
+
return { status: 'error', message: e.message }
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_repo_klass(params, current_user, origin)
|
101
|
+
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
|
102
|
+
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
|
103
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
104
|
+
attributes['properties_template'] = attributes['properties_release']
|
105
|
+
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
106
|
+
attributes['is_active'] = false
|
107
|
+
attributes['updated_by'] = current_user.id
|
108
|
+
attributes['sync_by'] = current_user.id
|
109
|
+
attributes['sync_time'] = DateTime.now
|
110
|
+
attr_klass = response.dig('element_klass', {}) # response['element_klass']
|
111
|
+
validate_klass(attributes, attr_klass)
|
112
|
+
|
105
113
|
rescue StandardError => e
|
106
114
|
Labimotion.log_exception(e, current_user)
|
107
115
|
raise e
|
@@ -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)
|
@@ -44,11 +44,11 @@ module Labimotion
|
|
44
44
|
"position": 35,
|
45
45
|
"placeholder": "amount of substance",
|
46
46
|
"units": [
|
47
|
-
{ "key": "mol", "label": "mol
|
48
|
-
{ "key": "mmol", "label": "mmol
|
49
|
-
{ "key": "umol", "label": "µmol
|
50
|
-
{ "key": "nmol", "label": "nmol
|
51
|
-
{ "key": "pmol", "label": "pmol
|
47
|
+
{ "key": "mol", "label": "mol", "nm": 1 },
|
48
|
+
{ "key": "mmol", "label": "mmol", "nm": 1000 },
|
49
|
+
{ "key": "umol", "label": "µmol", "nm": 1000000 },
|
50
|
+
{ "key": "nmol", "label": "nmol", "nm": 1.0e9 },
|
51
|
+
{ "key": "pmol", "label": "pmol", "nm": 1.0e12 }
|
52
52
|
]
|
53
53
|
},
|
54
54
|
{
|
@@ -59,11 +59,11 @@ module Labimotion
|
|
59
59
|
"position": 40,
|
60
60
|
"placeholder": "molarity",
|
61
61
|
"units": [
|
62
|
-
{ "key": "mol_l", "label": "mol/L
|
63
|
-
{ "key": "mmol_l", "label": "mmol/L
|
64
|
-
{ "key": "umol_l", "label": "µmol/L
|
65
|
-
{ "key": "nmol_l", "label": "nmol/L
|
66
|
-
{ "key": "pmol_l", "label": "pmol/L
|
62
|
+
{ "key": "mol_l", "label": "mol/L", "nm": 1 },
|
63
|
+
{ "key": "mmol_l", "label": "mmol/L", "nm": 1000 },
|
64
|
+
{ "key": "umol_l", "label": "µmol/L", "nm": 1000000 },
|
65
|
+
{ "key": "nmol_l", "label": "nmol/L", "nm": 1000000000 },
|
66
|
+
{ "key": "pmol_l", "label": "pmol/L", "nm": 1000000000000 }
|
67
67
|
]
|
68
68
|
},
|
69
69
|
{
|
@@ -168,6 +168,15 @@ module Labimotion
|
|
168
168
|
"placeholder": "Electric Charge in C",
|
169
169
|
"units": [{ "key": "ec_c", "label": "C", "nm": 1 }]
|
170
170
|
},
|
171
|
+
{
|
172
|
+
"type": "numeric",
|
173
|
+
"field": "electric_charge_mol",
|
174
|
+
"label": "Electric Charge per mol",
|
175
|
+
"default": "",
|
176
|
+
"position": 85,
|
177
|
+
"placeholder": "Electric Charge per mol",
|
178
|
+
"units": [{ "key": "ec_mol", "label": "C/mol", "nm": 1 }]
|
179
|
+
},
|
171
180
|
{
|
172
181
|
"type": "numeric",
|
173
182
|
"field": "electric_field",
|
@@ -206,12 +215,12 @@ module Labimotion
|
|
206
215
|
{
|
207
216
|
"type": "numeric",
|
208
217
|
"field": "faraday",
|
209
|
-
"label": "Faraday",
|
218
|
+
"label": "Faraday (Fd)",
|
210
219
|
"default": "",
|
211
220
|
"position": 95,
|
212
|
-
"placeholder": "Faraday",
|
221
|
+
"placeholder": "Faraday (Fd)",
|
213
222
|
"units": [
|
214
|
-
{ "key": "faraday", "label": "
|
223
|
+
{ "key": "faraday", "label": "Fd", "nm": 1 }
|
215
224
|
]
|
216
225
|
},
|
217
226
|
{
|
data/lib/labimotion/version.rb
CHANGED
data/lib/labimotion.rb
CHANGED
@@ -15,6 +15,7 @@ module Labimotion
|
|
15
15
|
autoload :Utils, 'labimotion/utils/utils'
|
16
16
|
|
17
17
|
######## APIs
|
18
|
+
autoload :GenericKlassAPI, 'labimotion/apis/generic_klass_api'
|
18
19
|
autoload :GenericElementAPI, 'labimotion/apis/generic_element_api'
|
19
20
|
autoload :GenericDatasetAPI, 'labimotion/apis/generic_dataset_api'
|
20
21
|
autoload :SegmentAPI, 'labimotion/apis/segment_api'
|
@@ -48,6 +49,7 @@ module Labimotion
|
|
48
49
|
autoload :SegmentHelpers, 'labimotion/helpers/segment_helpers'
|
49
50
|
autoload :DatasetHelpers, 'labimotion/helpers/dataset_helpers'
|
50
51
|
autoload :SearchHelpers, 'labimotion/helpers/search_helpers'
|
52
|
+
autoload :ParamHelpers, 'labimotion/helpers/param_helpers'
|
51
53
|
autoload :ConverterHelpers, 'labimotion/helpers/converter_helpers'
|
52
54
|
autoload :SampleAssociationHelpers, 'labimotion/helpers/sample_association_helpers'
|
53
55
|
autoload :RepositoryHelpers, 'labimotion/helpers/repository_helpers'
|
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.3.0
|
4
|
+
version: 1.3.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-04-
|
12
|
+
date: 2024-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/labimotion/apis/converter_api.rb
|
38
38
|
- lib/labimotion/apis/generic_dataset_api.rb
|
39
39
|
- lib/labimotion/apis/generic_element_api.rb
|
40
|
+
- lib/labimotion/apis/generic_klass_api.rb
|
40
41
|
- lib/labimotion/apis/labimotion_hub_api.rb
|
41
42
|
- lib/labimotion/apis/segment_api.rb
|
42
43
|
- lib/labimotion/collection/export.rb
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/labimotion/helpers/dataset_helpers.rb
|
61
62
|
- lib/labimotion/helpers/element_helpers.rb
|
62
63
|
- lib/labimotion/helpers/generic_helpers.rb
|
64
|
+
- lib/labimotion/helpers/param_helpers.rb
|
63
65
|
- lib/labimotion/helpers/repository_helpers.rb
|
64
66
|
- lib/labimotion/helpers/sample_association_helpers.rb
|
65
67
|
- lib/labimotion/helpers/search_helpers.rb
|
@@ -119,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
121
|
version: '0'
|
120
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
123
|
requirements:
|
122
|
-
- - "
|
124
|
+
- - ">="
|
123
125
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
126
|
+
version: '0'
|
125
127
|
requirements: []
|
126
128
|
rubygems_version: 3.1.6
|
127
129
|
signing_key:
|