labimotion 0.1.18 → 0.2.0
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_dataset_api.rb +3 -4
- data/lib/labimotion/apis/generic_element_api.rb +5 -53
- data/lib/labimotion/apis/labimotion_hub_api.rb +4 -13
- data/lib/labimotion/apis/segment_api.rb +3 -4
- data/lib/labimotion/entities/generic_public_entity.rb +0 -2
- data/lib/labimotion/helpers/dataset_helpers.rb +8 -18
- data/lib/labimotion/helpers/element_helpers.rb +26 -64
- data/lib/labimotion/helpers/generic_helpers.rb +52 -28
- data/lib/labimotion/helpers/segment_helpers.rb +12 -27
- data/lib/labimotion/libs/converter.rb +11 -19
- data/lib/labimotion/libs/export_dataset.rb +3 -13
- data/lib/labimotion/libs/nmr_mapper.rb +4 -17
- data/lib/labimotion/libs/nmr_mapper_repo.rb +7 -22
- data/lib/labimotion/libs/template_hub.rb +6 -16
- data/lib/labimotion/models/concerns/attachment_converter.rb +0 -1
- data/lib/labimotion/models/concerns/datasetable.rb +10 -6
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +10 -17
- data/lib/labimotion/models/concerns/segmentable.rb +14 -8
- data/lib/labimotion/models/element.rb +1 -2
- data/lib/labimotion/models/element_klass.rb +4 -0
- data/lib/labimotion/utils/utils.rb +0 -32
- data/lib/labimotion/version.rb +3 -7
- data/lib/labimotion.rb +1 -1
- metadata +5 -6
- data/lib/labimotion/models/hub_log.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5939fc9b6467ddec95df7cffac59fa06737aabcf4109fbbae1a4bd1a7200e48
|
4
|
+
data.tar.gz: dc5447449a8d3370da9d22363ab589ed1e4cef25f2c2826825982d8673ca0315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d70a575a715b95296cd8fdd658dbce44b6000f8fa32de507a008a8ffecaa4a4616dc4991115e3645ba2463b6800d9622ac3ab7b201fbe2b7ff30ccd16fedb6
|
7
|
+
data.tar.gz: 6151278c9d2afe3e970138d635cb16411733290f4f80c9353baec576c0717e1e73fe9fe53c25a135d201fe5f86b809918f0ae5f721233309f4ab9b02e7681e51
|
@@ -30,7 +30,7 @@ module Labimotion
|
|
30
30
|
namespace :fetch_repo do
|
31
31
|
desc 'fetch Generic Dataset Klass from Chemotion Repository'
|
32
32
|
get do
|
33
|
-
fetch_repo('DatasetKlass'
|
33
|
+
fetch_repo('DatasetKlass')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,9 +40,8 @@ module Labimotion
|
|
40
40
|
requires :identifier, type: String, desc: 'Identifier'
|
41
41
|
end
|
42
42
|
post do
|
43
|
-
|
44
|
-
|
45
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
43
|
+
create_repo_klass(params, current_user)
|
44
|
+
present DatasetKlass.all, with: Labimotion::DatasetKlassEntity, root: 'klass'
|
46
45
|
rescue StandardError => e
|
47
46
|
Labimotion.log_exception(e, current_user)
|
48
47
|
{ error: e.message }
|
@@ -21,9 +21,6 @@ module Labimotion
|
|
21
21
|
get do
|
22
22
|
ek = Labimotion::ElementKlass.find_by(name: params[:name])
|
23
23
|
present ek, with: Labimotion::ElementKlassEntity, root: 'klass'
|
24
|
-
rescue StandardError => e
|
25
|
-
Labimotion.log_exception(e, current_user)
|
26
|
-
{ klass: [] }
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
@@ -35,9 +32,6 @@ module Labimotion
|
|
35
32
|
get do
|
36
33
|
list = klass_list(params[:generic_only])
|
37
34
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
38
|
-
rescue StandardError => e
|
39
|
-
Labimotion.log_exception(e, current_user)
|
40
|
-
{ klass: [] }
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
@@ -73,9 +67,6 @@ module Labimotion
|
|
73
67
|
post do
|
74
68
|
authenticate_admin!('elements')
|
75
69
|
update_element_klass(current_user, params)
|
76
|
-
rescue StandardError => e
|
77
|
-
Labimotion.log_exception(e, current_user)
|
78
|
-
raise e
|
79
70
|
end
|
80
71
|
end
|
81
72
|
|
@@ -88,9 +79,6 @@ module Labimotion
|
|
88
79
|
get do
|
89
80
|
list = list_klass_revisions(params)
|
90
81
|
present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
|
91
|
-
rescue StandardError => e
|
92
|
-
Labimotion.log_exception(e, current_user)
|
93
|
-
[]
|
94
82
|
end
|
95
83
|
end
|
96
84
|
|
@@ -102,9 +90,6 @@ module Labimotion
|
|
102
90
|
get do
|
103
91
|
list = element_revisions(params)
|
104
92
|
present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
|
105
|
-
rescue StandardError => e
|
106
|
-
Labimotion.log_exception(e, current_user)
|
107
|
-
[]
|
108
93
|
end
|
109
94
|
end
|
110
95
|
|
@@ -119,9 +104,6 @@ module Labimotion
|
|
119
104
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
120
105
|
delete_klass_revision(params)
|
121
106
|
status 201
|
122
|
-
rescue StandardError => e
|
123
|
-
Labimotion.log_exception(e, current_user)
|
124
|
-
raise e
|
125
107
|
end
|
126
108
|
end
|
127
109
|
|
@@ -135,9 +117,6 @@ module Labimotion
|
|
135
117
|
post do
|
136
118
|
delete_revision(params)
|
137
119
|
status 201
|
138
|
-
rescue StandardError => e
|
139
|
-
Labimotion.log_exception(e, current_user)
|
140
|
-
raise e
|
141
120
|
end
|
142
121
|
end
|
143
122
|
|
@@ -150,9 +129,6 @@ module Labimotion
|
|
150
129
|
klass = Labimotion::Segment.find(params[:id])
|
151
130
|
list = klass.segments_revisions unless klass.nil?
|
152
131
|
present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
|
153
|
-
rescue StandardError => e
|
154
|
-
Labimotion.log_exception(e, current_user)
|
155
|
-
[]
|
156
132
|
end
|
157
133
|
end
|
158
134
|
|
@@ -176,9 +152,6 @@ module Labimotion
|
|
176
152
|
post do
|
177
153
|
upload_generics_files(current_user, params)
|
178
154
|
true
|
179
|
-
rescue StandardError => e
|
180
|
-
Labimotion.log_exception(e, current_user)
|
181
|
-
raise e
|
182
155
|
end
|
183
156
|
end
|
184
157
|
|
@@ -187,19 +160,13 @@ module Labimotion
|
|
187
160
|
get do
|
188
161
|
list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
|
189
162
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
190
|
-
rescue StandardError => e
|
191
|
-
Labimotion.log_exception(e, current_user)
|
192
|
-
[]
|
193
163
|
end
|
194
164
|
end
|
195
165
|
|
196
166
|
namespace :fetch_repo do
|
197
167
|
desc 'fetch Generic Element Klass from Chemotion Repository'
|
198
168
|
get do
|
199
|
-
fetch_repo('ElementKlass'
|
200
|
-
rescue StandardError => e
|
201
|
-
Labimotion.log_exception(e, current_user)
|
202
|
-
[]
|
169
|
+
fetch_repo('ElementKlass')
|
203
170
|
end
|
204
171
|
end
|
205
172
|
|
@@ -209,9 +176,8 @@ module Labimotion
|
|
209
176
|
requires :identifier, type: String, desc: 'Identifier'
|
210
177
|
end
|
211
178
|
post do
|
212
|
-
|
213
|
-
|
214
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
179
|
+
create_repo_klass(params, current_user)
|
180
|
+
present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
|
215
181
|
rescue StandardError => e
|
216
182
|
Labimotion.log_exception(e, current_user)
|
217
183
|
{ error: e.message }
|
@@ -231,9 +197,6 @@ module Labimotion
|
|
231
197
|
end
|
232
198
|
post do
|
233
199
|
deactivate_klass(params)
|
234
|
-
rescue StandardError => e
|
235
|
-
Labimotion.log_exception(e, current_user)
|
236
|
-
raise e
|
237
200
|
end
|
238
201
|
end
|
239
202
|
|
@@ -246,9 +209,6 @@ module Labimotion
|
|
246
209
|
delete ':id' do
|
247
210
|
delete_klass(params)
|
248
211
|
status 201
|
249
|
-
rescue StandardError => e
|
250
|
-
Labimotion.log_exception(e, current_user)
|
251
|
-
raise e
|
252
212
|
end
|
253
213
|
end
|
254
214
|
|
@@ -265,10 +225,7 @@ module Labimotion
|
|
265
225
|
@klz = fetch_klass(params[:klass], params[:id])
|
266
226
|
end
|
267
227
|
post do
|
268
|
-
update_template(params
|
269
|
-
rescue StandardError => e
|
270
|
-
Labimotion.log_exception(e, current_user)
|
271
|
-
raise e
|
228
|
+
update_template(params)
|
272
229
|
end
|
273
230
|
end
|
274
231
|
|
@@ -280,10 +237,10 @@ module Labimotion
|
|
280
237
|
optional :from_date, type: Integer, desc: 'created_date from in ms'
|
281
238
|
optional :to_date, type: Integer, desc: 'created_date to in ms'
|
282
239
|
optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
|
283
|
-
optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
|
284
240
|
end
|
285
241
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
286
242
|
get do
|
243
|
+
|
287
244
|
scope = list_serialized_elements(params, current_user)
|
288
245
|
|
289
246
|
reset_pagination_page(scope)
|
@@ -299,9 +256,6 @@ module Labimotion
|
|
299
256
|
end
|
300
257
|
end
|
301
258
|
{ generic_elements: generic_elements }
|
302
|
-
rescue StandardError => e
|
303
|
-
Labimotion.log_exception(e, current_user)
|
304
|
-
{ generic_elements: [] }
|
305
259
|
end
|
306
260
|
|
307
261
|
desc 'Return serialized element by id'
|
@@ -329,8 +283,6 @@ module Labimotion
|
|
329
283
|
attachments: Entities::AttachmentEntity.represent(element.attachments),
|
330
284
|
}
|
331
285
|
end
|
332
|
-
rescue StandardError => e
|
333
|
-
Labimotion.log_exception(e, current_user)
|
334
286
|
end
|
335
287
|
end
|
336
288
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'open-uri'
|
4
|
-
require 'labimotion/models/hub_log'
|
5
4
|
|
6
5
|
# Belong to Chemotion module
|
7
6
|
module Labimotion
|
@@ -20,25 +19,20 @@ module Labimotion
|
|
20
19
|
list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
|
21
20
|
list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
|
22
21
|
entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props])
|
23
|
-
|
24
|
-
Labimotion.log_exception(e, current_user)
|
25
|
-
[]
|
22
|
+
# entities.length > 1 ? de_encode_json(entities) : []
|
26
23
|
end
|
27
24
|
end
|
28
25
|
namespace :fetch do
|
29
26
|
desc "get active generic templates"
|
30
27
|
params do
|
31
28
|
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
32
|
-
requires :
|
29
|
+
# requires :fqdn, type: Integer, desc: 'FQDN'
|
33
30
|
requires :identifier, type: String, desc: 'Identifier'
|
34
31
|
end
|
35
|
-
|
32
|
+
get do
|
36
33
|
entity = "Labimotion::#{params[:klass]}".constantize.find_by(identifier: params[:identifier])
|
37
|
-
Labimotion::HubLog.create(klass: entity, origin: params[:origin], uuid: entity.uuid, version: entity.version)
|
38
34
|
"Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
|
39
|
-
|
40
|
-
Labimotion.log_exception(e, current_user)
|
41
|
-
raise e
|
35
|
+
# entities.length > 1 ? de_encode_json(entities) : []
|
42
36
|
end
|
43
37
|
end
|
44
38
|
|
@@ -51,9 +45,6 @@ module Labimotion
|
|
51
45
|
list = Labimotion::ElementKlass.where(is_active: true) if params[:generic_only].present? && params[:generic_only] == true
|
52
46
|
list = Labimotion::ElementKlass.where(is_active: true) unless params[:generic_only].present? && params[:generic_only] == true
|
53
47
|
list.pluck(:name)
|
54
|
-
rescue StandardError => e
|
55
|
-
Labimotion.log_exception(e, current_user)
|
56
|
-
[]
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
@@ -118,7 +118,7 @@ module Labimotion
|
|
118
118
|
namespace :fetch_repo do
|
119
119
|
desc 'fetch Generic Segment Klass from Chemotion Repository'
|
120
120
|
get do
|
121
|
-
fetch_repo('SegmentKlass'
|
121
|
+
fetch_repo('SegmentKlass')
|
122
122
|
rescue StandardError => e
|
123
123
|
Labimotion.log_exception(e, current_user)
|
124
124
|
{ error: e.message }
|
@@ -131,9 +131,8 @@ module Labimotion
|
|
131
131
|
requires :identifier, type: String, desc: 'Identifier'
|
132
132
|
end
|
133
133
|
post do
|
134
|
-
|
135
|
-
|
136
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
134
|
+
create_repo_klass(params, current_user)
|
135
|
+
present SegmentKlass.all, with: Labimotion::SegmentKlassEntity, root: 'klass'
|
137
136
|
rescue StandardError => e
|
138
137
|
Labimotion.log_exception(e, current_user)
|
139
138
|
## { error: e.message }
|
@@ -5,7 +5,6 @@ require 'labimotion/entities/application_entity'
|
|
5
5
|
# Entity module
|
6
6
|
module Labimotion
|
7
7
|
class GenericPublicEntity < Labimotion::ApplicationEntity
|
8
|
-
expose! :uuid
|
9
8
|
expose! :name
|
10
9
|
expose! :desc
|
11
10
|
expose! :icon_name
|
@@ -13,7 +12,6 @@ module Labimotion
|
|
13
12
|
expose! :klass_name
|
14
13
|
expose! :label
|
15
14
|
expose! :identifier
|
16
|
-
expose! :version
|
17
15
|
expose! :released_at
|
18
16
|
expose! :properties_release, if: :displayed
|
19
17
|
expose :element_klass do |obj|
|
@@ -13,31 +13,21 @@ module Labimotion
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def create_repo_klass(params, current_user
|
17
|
-
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier]
|
18
|
-
attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier'
|
19
|
-
attributes['
|
20
|
-
attributes['properties_template'] = attributes['properties_release']
|
16
|
+
def create_repo_klass(params, current_user)
|
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['properties_template'] = response['properties_release']
|
21
20
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
22
21
|
attributes['is_active'] = false
|
23
22
|
attributes['updated_by'] = current_user.id
|
24
23
|
attributes['sync_by'] = current_user.id
|
25
24
|
attributes['sync_time'] = DateTime.now
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
{ status: 'success', message: "This dataset: #{attributes['label']} has the latest version!" }
|
30
|
-
else
|
31
|
-
ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
|
32
|
-
ds.update!(attributes)
|
33
|
-
ds.create_klasses_revision(current_user)
|
34
|
-
{ status: 'success', message: "This dataset: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
|
35
|
-
end
|
25
|
+
if Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
|
26
|
+
ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
|
27
|
+
ds.update!(attributes)
|
36
28
|
else
|
37
29
|
attributes['created_by'] = current_user.id
|
38
|
-
|
39
|
-
ds.create_klasses_revision(current_user)
|
40
|
-
{ status: 'success', message: "The dataset: #{attributes['label']} has been created using version: #{attributes['version']}!" }
|
30
|
+
Labimotion::DatasetKlass.create!(attributes)
|
41
31
|
end
|
42
32
|
rescue StandardError => e
|
43
33
|
Labimotion.log_exception(e, current_user)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'grape'
|
4
|
-
require 'labimotion/
|
4
|
+
require 'labimotion/version'
|
5
5
|
# require 'labimotion/models/element_klass'
|
6
6
|
module Labimotion
|
7
7
|
## ElementHelpers
|
@@ -20,10 +20,11 @@ module Labimotion
|
|
20
20
|
uuid = SecureRandom.uuid
|
21
21
|
template = { uuid: uuid, layers: {}, select_options: {} }
|
22
22
|
attributes = declared(params, include_missing: false)
|
23
|
-
attributes[:properties_template] =
|
24
|
-
attributes[:properties_template]
|
25
|
-
attributes[:properties_template]['
|
26
|
-
attributes[:properties_template]['
|
23
|
+
attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present?
|
24
|
+
attributes[:properties_template] = template unless attributes[:properties_template].present?
|
25
|
+
attributes[:properties_template]['eln'] = Chemotion::Application.config.version if attributes[:properties_template].present?
|
26
|
+
attributes[:properties_template]['labimotion'] = Labimotion::VERSION if attributes[:properties_template].present?
|
27
|
+
attributes[:properties_template]['klass'] = 'ElementKlass' if attributes[:properties_template].present?
|
27
28
|
attributes[:is_active] = false
|
28
29
|
attributes[:uuid] = uuid
|
29
30
|
attributes[:released_at] = DateTime.now
|
@@ -32,8 +33,8 @@ module Labimotion
|
|
32
33
|
|
33
34
|
new_klass = Labimotion::ElementKlass.create!(attributes)
|
34
35
|
new_klass.reload
|
35
|
-
new_klass.create_klasses_revision(current_user)
|
36
|
-
klass_names_file = Rails.root.join('
|
36
|
+
new_klass.create_klasses_revision(current_user.id)
|
37
|
+
klass_names_file = Rails.root.join('config', 'klasses.json')
|
37
38
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
38
39
|
File.write(klass_names_file, klasses)
|
39
40
|
klasses
|
@@ -67,12 +68,11 @@ module Labimotion
|
|
67
68
|
uuid = SecureRandom.uuid
|
68
69
|
params[:properties]['uuid'] = uuid
|
69
70
|
params[:properties]['klass_uuid'] = klass[:uuid]
|
70
|
-
params[:properties]['
|
71
|
+
params[:properties]['eln'] = Chemotion::Application.config.version
|
72
|
+
params[:properties]['labimotion'] = Labimotion::VERSION
|
71
73
|
params[:properties]['klass'] = 'Element'
|
72
|
-
params[:properties]['identifier'] = klass[:identifier]
|
73
74
|
properties = params[:properties]
|
74
75
|
properties.delete('flow') unless properties['flow'].nil?
|
75
|
-
properties.delete('flowObject') unless properties['flowObject'].nil?
|
76
76
|
properties.delete('select_options') unless properties['select_options'].nil?
|
77
77
|
attributes = {
|
78
78
|
name: params[:name],
|
@@ -109,14 +109,14 @@ module Labimotion
|
|
109
109
|
params.delete(:container)
|
110
110
|
params.delete(:properties)
|
111
111
|
attributes = declared(params.except(:segments), include_missing: false)
|
112
|
-
properties['
|
112
|
+
properties['eln'] = Chemotion::Application.config.version
|
113
|
+
properties['labimotion'] = Labimotion::VERSION
|
113
114
|
if element.klass_uuid != properties['klass_uuid'] || element.properties != properties || element.name != params[:name]
|
114
115
|
properties['klass'] = 'Element'
|
115
116
|
uuid = SecureRandom.uuid
|
116
117
|
properties['uuid'] = uuid
|
117
118
|
|
118
119
|
properties.delete('flow') unless properties['flow'].nil?
|
119
|
-
properties.delete('flowObject') unless properties['flowObject'].nil?
|
120
120
|
properties.delete('select_options') unless properties['select_options'].nil?
|
121
121
|
|
122
122
|
attributes['properties'] = properties
|
@@ -174,7 +174,8 @@ module Labimotion
|
|
174
174
|
true
|
175
175
|
rescue StandardError => e
|
176
176
|
Labimotion.log_exception(e, current_user)
|
177
|
-
false
|
177
|
+
## false
|
178
|
+
raise e
|
178
179
|
end
|
179
180
|
|
180
181
|
def element_revisions(params)
|
@@ -245,7 +246,7 @@ module Labimotion
|
|
245
246
|
.where(
|
246
247
|
element_klasses: { name: params[:el_type] },
|
247
248
|
collections_elements: { collection_id: collection_id },
|
248
|
-
).includes(:tag, collections: :sync_collections_users)
|
249
|
+
).includes(:tag, collections: :sync_collections_users).order('created_at DESC')
|
249
250
|
else
|
250
251
|
Labimotion::Element.none
|
251
252
|
end
|
@@ -254,46 +255,20 @@ module Labimotion
|
|
254
255
|
from = params[:from_date]
|
255
256
|
to = params[:to_date]
|
256
257
|
by_created_at = params[:filter_created_at] || false
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
allowed_fields = element_klass.properties_release.dig('layers', layer, 'fields')&.pluck('field') || []
|
262
|
-
|
263
|
-
if field.in?(allowed_fields)
|
264
|
-
query = ActiveRecord::Base.sanitize_sql(
|
265
|
-
[
|
266
|
-
"LEFT JOIN LATERAL(
|
267
|
-
SELECT field->'value' AS value
|
268
|
-
FROM jsonb_array_elements(properties->'layers'->:layer->'fields') a(field)
|
269
|
-
WHERE field->>'field' = :field
|
270
|
-
) a ON true",
|
271
|
-
{ layer: layer, field: field },
|
272
|
-
],
|
273
|
-
)
|
274
|
-
scope = scope.joins(query).order('value ASC NULLS FIRST')
|
275
|
-
else
|
276
|
-
scope = scope.order(updated_at: :desc)
|
277
|
-
end
|
278
|
-
else
|
279
|
-
scope = scope.order(updated_at: :desc)
|
280
|
-
end
|
281
|
-
|
282
|
-
scope = scope.elements_created_time_from(Time.at(from)) if from && by_created_at
|
283
|
-
scope = scope.elements_created_time_to(Time.at(to) + 1.day) if to && by_created_at
|
284
|
-
scope = scope.elements_updated_time_from(Time.at(from)) if from && !by_created_at
|
285
|
-
scope = scope.elements_updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
|
258
|
+
scope = scope.created_time_from(Time.at(from)) if from && by_created_at
|
259
|
+
scope = scope.created_time_to(Time.at(to) + 1.day) if to && by_created_at
|
260
|
+
scope = scope.updated_time_from(Time.at(from)) if from && !by_created_at
|
261
|
+
scope = scope.updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
|
286
262
|
scope
|
287
263
|
rescue StandardError => e
|
288
264
|
Labimotion.log_exception(e, current_user)
|
289
265
|
raise e
|
290
266
|
end
|
291
267
|
|
292
|
-
def create_repo_klass(params, current_user
|
293
|
-
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier]
|
294
|
-
attributes = response.slice('name', 'label', 'desc', 'icon_name', '
|
295
|
-
attributes['
|
296
|
-
attributes['properties_template'] = attributes['properties_release']
|
268
|
+
def create_repo_klass(params, current_user)
|
269
|
+
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
|
270
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
|
271
|
+
attributes['properties_template'] = response['properties_release']
|
297
272
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
298
273
|
attributes['is_active'] = false
|
299
274
|
attributes['updated_by'] = current_user.id
|
@@ -302,23 +277,10 @@ module Labimotion
|
|
302
277
|
|
303
278
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
304
279
|
if element_klass.present?
|
305
|
-
|
306
|
-
{ status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
|
307
|
-
else
|
308
|
-
element_klass.update!(attributes)
|
309
|
-
element_klass.create_klasses_revision(current_user)
|
310
|
-
{ status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
|
311
|
-
end
|
280
|
+
element_klass.update!(attributes)
|
312
281
|
else
|
313
|
-
|
314
|
-
|
315
|
-
{ status: 'error', message: "The name [#{attributes['name']}] is already in use." }
|
316
|
-
else
|
317
|
-
attributes['created_by'] = current_user.id
|
318
|
-
element_klass = Labimotion::ElementKlass.create!(attributes)
|
319
|
-
element_klass.create_klasses_revision(current_user)
|
320
|
-
{ status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
|
321
|
-
end
|
282
|
+
attributes['created_by'] = current_user.id
|
283
|
+
Labimotion::ElementKlass.create!(attributes)
|
322
284
|
end
|
323
285
|
rescue StandardError => e
|
324
286
|
Labimotion.log_exception(e, current_user)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'grape'
|
3
|
-
require 'labimotion/
|
3
|
+
require 'labimotion/version'
|
4
4
|
# Helper for associated sample
|
5
5
|
module Labimotion
|
6
6
|
## Generic Helpers
|
@@ -41,22 +41,43 @@ module Labimotion
|
|
41
41
|
raise e
|
42
42
|
end
|
43
43
|
|
44
|
-
def update_template(params
|
44
|
+
def update_template(params)
|
45
45
|
klz = fetch_klass(params[:klass], params[:id])
|
46
46
|
uuid = SecureRandom.uuid
|
47
47
|
properties = params[:properties_template]
|
48
|
-
|
49
|
-
|
48
|
+
if Labimotion::IS_RAILS5 == false
|
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
|
71
|
+
|
50
72
|
properties['version'] = klz.version
|
51
|
-
properties['
|
52
|
-
properties['
|
53
|
-
properties['
|
54
|
-
properties.delete('eln') if properties['eln'].present?
|
73
|
+
properties['eln'] = Chemotion::Application.config.version
|
74
|
+
properties['labimotion'] = Labimotion::VERSION
|
75
|
+
properties['klass'] = @klz.class.name.split('::').last
|
55
76
|
klz.updated_by = current_user.id
|
56
77
|
klz.properties_template = properties
|
57
78
|
klz.save!
|
58
79
|
klz.reload
|
59
|
-
klz.create_klasses_revision(current_user) if params[:release] != 'draft'
|
80
|
+
klz.create_klasses_revision(current_user.id) if params[:release] != 'draft'
|
60
81
|
klz
|
61
82
|
rescue StandardError => e
|
62
83
|
Labimotion.log_exception(e, current_user)
|
@@ -96,8 +117,12 @@ module Labimotion
|
|
96
117
|
|
97
118
|
|
98
119
|
###############
|
120
|
+
|
121
|
+
|
99
122
|
def generate_klass_file
|
100
|
-
|
123
|
+
klass_dir = File.join(Rails.root, 'data')
|
124
|
+
!File.directory?(klass_dir) && FileUtils.mkdir_p(klass_dir)
|
125
|
+
klass_names_file = File.join(klass_dir, 'klasses.json')
|
101
126
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
102
127
|
File.write(klass_names_file, klasses)
|
103
128
|
rescue StandardError => e
|
@@ -188,37 +213,37 @@ module Labimotion
|
|
188
213
|
raise e
|
189
214
|
end
|
190
215
|
|
191
|
-
def create_attachments(files, del_files, type, id,
|
216
|
+
def create_attachments(files, del_files, type, id, user_id)
|
192
217
|
attach_ary = []
|
193
|
-
(files || []).
|
218
|
+
(files || []).each do |file|
|
194
219
|
next unless (tempfile = file[:tempfile])
|
195
220
|
|
196
|
-
|
221
|
+
a = Attachment.new(
|
197
222
|
bucket: file[:container_id],
|
198
223
|
filename: file[:filename],
|
199
224
|
con_state: Labimotion::ConState::NONE,
|
200
225
|
file_path: file[:tempfile],
|
201
226
|
created_by: user_id,
|
202
227
|
created_for: user_id,
|
203
|
-
identifier: identifier[index],
|
204
228
|
content_type: file[:type],
|
205
229
|
attachable_type: type,
|
206
230
|
attachable_id: id,
|
207
231
|
)
|
208
232
|
begin
|
209
|
-
|
210
|
-
attach_ary.push(
|
233
|
+
a.save!
|
234
|
+
attach_ary.push(a.id)
|
211
235
|
ensure
|
212
236
|
tempfile.close
|
213
237
|
tempfile.unlink
|
214
238
|
end
|
215
239
|
end
|
216
240
|
unless (del_files || []).empty?
|
217
|
-
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
241
|
+
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
242
|
+
type).update_all(attachable_id: nil)
|
218
243
|
end
|
219
244
|
attach_ary
|
220
245
|
rescue StandardError => e
|
221
|
-
Labimotion.log_exception(e)
|
246
|
+
Labimotion.log_exception(e, current_user)
|
222
247
|
raise e
|
223
248
|
end
|
224
249
|
|
@@ -230,19 +255,18 @@ module Labimotion
|
|
230
255
|
Chemotion::Generic::Fetch::Template.list(API::TARGET, name)
|
231
256
|
end
|
232
257
|
|
233
|
-
def fetch_repo(name
|
234
|
-
|
258
|
+
def fetch_repo(name)
|
259
|
+
current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
|
235
260
|
response = Labimotion::TemplateHub.list(name)
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
(response && response['list']) || []
|
261
|
+
if response && response['list'].present? && response['list'].length.positive?
|
262
|
+
filter_list = response['list']&.reject do |ds|
|
263
|
+
current_klasses.include?(ds['identifier'])
|
264
|
+
end || []
|
265
|
+
end
|
266
|
+
filter_list || []
|
243
267
|
rescue StandardError => e
|
244
268
|
Labimotion.log_exception(e, current_user)
|
245
|
-
|
269
|
+
raise e
|
246
270
|
end
|
247
271
|
end
|
248
272
|
end
|