labimotion 2.2.0.rc7 → 2.2.0.rc8

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: a7b53d1daca8b636571715c7ff62caa557dc59082c1f7733cdd6e6a875795712
4
- data.tar.gz: cab23343b2c90f335571ae7b5b7e714b63cee7e1f403b50b8b3c89e944b23e4a
3
+ metadata.gz: 2342f8963ebba3b102957a308070a94ecb87e49ba05641b22c32b5d49a0ff0a6
4
+ data.tar.gz: 4ed1239dc5c9ed49c97c453abe0cff9c9656b54fd1faaaf5607f9ad9fc75a148
5
5
  SHA512:
6
- metadata.gz: ffbd3fac0cba826e516a8dd57fed5c0ac0b29a50c15752ca27453cc9dfd28736e71ce44b76efef72690daf1aa23f42a48309228b038a883ac67852564e74c94d
7
- data.tar.gz: 7a3da058102e765cdfa54fa5ece7e3dc022cff2a0f39e9eae1cc31e4053b8e7735b5eda17bc2c05927b1e54d81883c3a885e1367eb85624d4e8437505ee96191
6
+ metadata.gz: 53c17583059e150dd89e8308062ab4b658def233285940c0e0dbcc0aee9d3e15ce7d2fd7a05619f5416a4d5fd0a6507967a0a50b6b5f1894792864ee628bd682
7
+ data.tar.gz: 267f0cf9ac7c535642d8bff93fafa66cc5661d6cd7d820cf473ab41540f8b4004c9c1403f2d208187e4c199c612bf65171b6b9159fba2a49140a0b052095d16a
@@ -429,7 +429,6 @@ module Labimotion
429
429
  desc 'Return serialized elements of current user'
430
430
  params do
431
431
  optional :collection_id, type: Integer, desc: 'Collection id'
432
- optional :sync_collection_id, type: Integer, desc: 'SyncCollectionsUser id'
433
432
  optional :el_type, type: String, desc: 'element klass name'
434
433
  optional :from_date, type: Integer, desc: 'created_date from in ms'
435
434
  optional :to_date, type: Integer, desc: 'created_date to in ms'
@@ -12,8 +12,5 @@ module Labimotion
12
12
  mount Labimotion::LabimotionHubAPI
13
13
  mount Labimotion::StandardLayerAPI
14
14
  mount Labimotion::VocabularyAPI
15
- mount Labimotion::MttAPI
16
- mount Labimotion::DoseRespRequestAPI
17
- mount Labimotion::ElementVariationAPI
18
15
  end
19
16
  end
@@ -23,7 +23,6 @@ module Labimotion
23
23
  expose! :uuid
24
24
  expose! :user_labels
25
25
  expose! :preview_attachment # align with eln change
26
- expose! :variations_count
27
26
  end
28
27
 
29
28
  with_options(anonymize_below: 10) do
@@ -215,7 +215,7 @@ module Labimotion
215
215
  layer, field = params[:sort_column].split('.')
216
216
 
217
217
  element_klass = Labimotion::ElementKlass.find_by(name: params[:el_type])
218
- allowed_fields = element_klass.properties_release.dig(Labimotion::Prop::LAYERS, layer, Labimotion::Prop::FIELDS)&.pluck('field') || []
218
+ allowed_fields = element_klass&.properties_release&.dig(Labimotion::Prop::LAYERS, layer, Labimotion::Prop::FIELDS)&.pluck('field') || []
219
219
 
220
220
  if field.in?(allowed_fields)
221
221
  query = ActiveRecord::Base.sanitize_sql(
@@ -247,27 +247,21 @@ module Labimotion
247
247
  end
248
248
 
249
249
  def list_serialized_elements(params, current_user)
250
- collection_id =
251
- if params[:collection_id]
252
- Collection
253
- .belongs_to_or_shared_by(current_user.id, current_user.group_ids)
254
- .find_by(id: params[:collection_id])&.id
255
- elsif params[:sync_collection_id]
256
- current_user
257
- .all_sync_in_collections_users
258
- .find_by(id: params[:sync_collection_id])&.collection&.id
259
- end
250
+ scope = Labimotion::Element.none
260
251
 
261
- scope =
262
- if collection_id
263
- Labimotion::Element
264
- .joins(:element_klass, :collections_elements)
265
- .where(
266
- element_klasses: { name: params[:el_type] },
267
- collections_elements: { collection_id: collection_id },
268
- ).includes(:tag, collections: :sync_collections_users)
252
+ if params[:collection_id]
253
+ begin
254
+ collection = Collection.accessible_for(current_user).find(params[:collection_id])
255
+ scope = collection.elements
256
+ .joins(:element_klass)
257
+ .where(element_klasses: { name: params[:el_type] })
258
+ .includes(:tag)
259
+ rescue ActiveRecord::RecordNotFound
260
+ Labimotion::Element.none
261
+ end
269
262
  else
270
- Labimotion::Element.none
263
+ # All collection of current_user
264
+ scope = Labimotion::Element.for_user(current_user.id)
271
265
  end
272
266
 
273
267
  ## TO DO: refactor labimotion
@@ -278,7 +272,7 @@ module Labimotion
278
272
  layer, field = params[:sort_column].split('.')
279
273
 
280
274
  element_klass = Labimotion::ElementKlass.find_by(name: params[:el_type])
281
- allowed_fields = element_klass.properties_release.dig(Labimotion::Prop::LAYERS, layer, Labimotion::Prop::FIELDS)&.pluck('field') || []
275
+ allowed_fields = element_klass&.properties_release&.dig(Labimotion::Prop::LAYERS, layer, Labimotion::Prop::FIELDS)&.pluck('field') || []
282
276
 
283
277
  if field.in?(allowed_fields)
284
278
  query = ActiveRecord::Base.sanitize_sql(
@@ -146,11 +146,5 @@ module Labimotion
146
146
  requires :layer_id, type: String, desc: 'layer identifier'
147
147
  requires :field_id, type: String, desc: 'field identifier'
148
148
  end
149
-
150
-
151
- params :create_mtt_request_params do
152
- requires :id, type: Integer, desc: 'Element ID'
153
- requires :wellplate_ids, type: Array, desc: 'Selected Wellplates'
154
- end
155
149
  end
156
150
  end
@@ -125,7 +125,8 @@ module Labimotion
125
125
  tmp_file.rewind
126
126
 
127
127
  filename = oat.filename
128
- name = "#{File.basename(filename, '.*')}.zip"
128
+ # name = "#{File.basename(filename, '.*')}.zip"
129
+ name = "#{File.basename(filename, '.*')}#{File.extname(filename) == '.zip' ? '.bagit.zip' : '.zip'}"
129
130
  att = Attachment.new(
130
131
  filename: name,
131
132
  file_path: tmp_file.path,
@@ -34,7 +34,7 @@ module Labimotion
34
34
  return Labimotion::ConState::NONE if att.nil?
35
35
 
36
36
  result = process(att)
37
- return Labimotion::ConState::NONE if result.nil?
37
+ return Labimotion::ConState::WAIT if result.nil?
38
38
 
39
39
  handle_process_result(result, att, id, current_user)
40
40
  end
@@ -136,7 +136,7 @@ module Labimotion
136
136
  if result[:is_bagit]
137
137
  handle_bagit_result(att, id, current_user)
138
138
  elsif invalid_metadata?(result)
139
- Labimotion::ConState::NONE
139
+ Labimotion::ConState::WAIT
140
140
  else
141
141
  handle_nmr_result(result, att, current_user)
142
142
  end
@@ -31,6 +31,7 @@ module Labimotion
31
31
  case con_state
32
32
  when Labimotion::ConState::NMR
33
33
  self.con_state = Labimotion::NmrMapper.process_ds(id, current_user)
34
+ return exec_converter if con_state == Labimotion::ConState::WAIT
34
35
  update_column(:con_state, con_state)
35
36
  when Labimotion::ConState::WAIT
36
37
  self.con_state = Labimotion::Converter.jcamp_converter(id, current_user)
@@ -26,9 +26,9 @@ module Labimotion
26
26
  joins(collections: :user).where(collections: { user_id: user_id })
27
27
  )
28
28
 
29
- # Shared (synced) records
29
+ # Shared records
30
30
  shared = apply_filters.call(
31
- joins(collections: :sync_collections_users).where(sync_collections_users: { user_id: user_id })
31
+ left_joins(:collection_shares).where(collection_shares: { shared_with_id: user_id })
32
32
  )
33
33
 
34
34
  # Combine (remove duplicates), order, and limit
@@ -41,12 +41,6 @@ module Labimotion
41
41
  has_many :samples, through: :elements_samples, source: :sample
42
42
  has_one :container, :as => :containable
43
43
  has_many :elements_revisions, dependent: :destroy, class_name: 'Labimotion::ElementsRevision'
44
- has_one :element_variation, dependent: :destroy, class_name: 'Labimotion::ElementVariation', foreign_key: :element_id
45
-
46
- def variations_count
47
- rows = element_variation&.variations
48
- rows.is_a?(Hash) ? rows.size : 0
49
- end
50
44
 
51
45
  accepts_nested_attributes_for :collections_elements
52
46
 
@@ -141,9 +135,9 @@ module Labimotion
141
135
  joins(collections: :user).where(collections: { user_id: user_id })
142
136
  )
143
137
 
144
- # Shared (synced) elements
138
+ # Shared elements
145
139
  shared = apply_filters.call(
146
- joins(collections: :sync_collections_users).where(sync_collections_users: { user_id: user_id })
140
+ left_joins(:collection_shares).where(collection_shares: { shared_with_id: user_id })
147
141
  )
148
142
 
149
143
  # Combine (remove duplicates), order, and limit
@@ -12,7 +12,7 @@ module Labimotion
12
12
  end
13
13
 
14
14
  def self.elements_search(params, current_user, c_id, dl)
15
- collection = Collection.belongs_to_or_shared_by(current_user.id, current_user.group_ids).find(c_id)
15
+ collection = Collection.accessible_for(current_user).find(c_id)
16
16
  element_scope = Labimotion::Element.joins(:collections_elements).where('collections_elements.collection_id = ?', collection.id).joins(:element_klass).where('element_klasses.id = elements.element_klass_id AND element_klasses.name = ?', params[:selection][:genericElName])
17
17
  element_scope = element_scope.where('elements.name like (?)', "%#{params[:selection][:searchName]}%") if params[:selection][:searchName].present?
18
18
  element_scope = element_scope.where('elements.short_label like (?)', "%#{params[:selection][:searchShowLabel]}%") if params[:selection][:searchShowLabel].present?
@@ -97,7 +97,7 @@ module Labimotion
97
97
  def self.samples_search(c_id = @c_id)
98
98
  sqls = []
99
99
  sps = params[:selection][:searchProperties]
100
- collection = Collection.belongs_to_or_shared_by(current_user.id, current_user.group_ids).find(c_id)
100
+ collection = Collection.accessible_for(current_user).find(c_id)
101
101
  element_scope = Sample.joins(:collections_samples).where('collections_samples.collection_id = ?', collection.id)
102
102
  return element_scope if sps.empty?
103
103
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
- VERSION = '2.2.0.rc7'
5
+ VERSION = '2.2.0.rc8'
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -27,9 +27,6 @@ module Labimotion
27
27
  autoload :ExporterAPI, 'labimotion/apis/exporter_api'
28
28
  autoload :StandardLayerAPI, 'labimotion/apis/standard_layer_api'
29
29
  autoload :VocabularyAPI, 'labimotion/apis/vocabulary_api'
30
- autoload :MttAPI, 'labimotion/apis/mtt_api'
31
- autoload :DoseRespRequestAPI, 'labimotion/apis/dose_resp_request_api'
32
- autoload :ElementVariationAPI, 'labimotion/apis/element_variation_api'
33
30
 
34
31
  ######## Entities
35
32
  autoload :PropertiesEntity, 'labimotion/entities/properties_entity'
@@ -52,7 +49,6 @@ module Labimotion
52
49
  autoload :SegmentRevisionEntity, 'labimotion/entities/segment_revision_entity'
53
50
  ## autoload :DatasetRevisionEntity, 'labimotion/entities/dataset_revision_entity'
54
51
  autoload :VocabularyEntity, 'labimotion/entities/vocabulary_entity'
55
- autoload :ElementVariationEntity, 'labimotion/entities/element_variation_entity'
56
52
 
57
53
  ######## Helpers
58
54
  autoload :GenericHelpers, 'labimotion/helpers/generic_helpers'
@@ -118,14 +114,11 @@ module Labimotion
118
114
  autoload :StdLayersRevision, 'labimotion/models/std_layers_revision'
119
115
 
120
116
  autoload :DeviceDescription, 'labimotion/models/device_description'
121
- autoload :DoseRespRequest, 'labimotion/models/dose_resp_request'
122
- autoload :DoseRespOutput, 'labimotion/models/dose_resp_output'
123
117
  autoload :Reaction, 'labimotion/models/reaction'
124
118
  autoload :ResearchPlan, 'labimotion/models/research_plan'
125
119
  autoload :Sample, 'labimotion/models/sample'
126
120
  autoload :Screen, 'labimotion/models/screen'
127
121
  autoload :Wellplate, 'labimotion/models/wellplate'
128
- autoload :ElementVariation, 'labimotion/models/element_variation'
129
122
 
130
123
  ######## Models/Concerns
131
124
  autoload :GenericKlassRevisions, 'labimotion/models/concerns/generic_klass_revisions'
@@ -133,6 +126,6 @@ module Labimotion
133
126
  autoload :ElementFetchable, 'labimotion/models/concerns/element_fetchable'
134
127
  autoload :Segmentable, 'labimotion/models/concerns/segmentable'
135
128
  autoload :Datasetable, 'labimotion/models/concerns/datasetable'
136
- autoload :AttachmentConverter, 'labimotion/models/concerns/attachment_converter'
129
+ autoload :AttachmentConverter, 'labimotion/models/concerns/attachment_converter.rb'
137
130
  autoload :LinkedProperties, 'labimotion/models/concerns/linked_properties'
138
131
  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: 2.2.0.rc7
4
+ version: 2.2.0.rc8
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: 2026-05-04 00:00:00.000000000 Z
12
+ date: 2026-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: caxlsx
@@ -55,15 +55,12 @@ extra_rdoc_files: []
55
55
  files:
56
56
  - lib/labimotion.rb
57
57
  - lib/labimotion/apis/converter_api.rb
58
- - lib/labimotion/apis/dose_resp_request_api.rb
59
- - lib/labimotion/apis/element_variation_api.rb
60
58
  - lib/labimotion/apis/exporter_api.rb
61
59
  - lib/labimotion/apis/generic_dataset_api.rb
62
60
  - lib/labimotion/apis/generic_element_api.rb
63
61
  - lib/labimotion/apis/generic_klass_api.rb
64
62
  - lib/labimotion/apis/labimotion_api.rb
65
63
  - lib/labimotion/apis/labimotion_hub_api.rb
66
- - lib/labimotion/apis/mtt_api.rb
67
64
  - lib/labimotion/apis/segment_api.rb
68
65
  - lib/labimotion/apis/standard_api.rb
69
66
  - lib/labimotion/apis/standard_layer_api.rb
@@ -78,7 +75,6 @@ files:
78
75
  - lib/labimotion/entities/element_entity.rb
79
76
  - lib/labimotion/entities/element_klass_entity.rb
80
77
  - lib/labimotion/entities/element_revision_entity.rb
81
- - lib/labimotion/entities/element_variation_entity.rb
82
78
  - lib/labimotion/entities/eln_element_entity.rb
83
79
  - lib/labimotion/entities/generic_entity.rb
84
80
  - lib/labimotion/entities/generic_klass_entity.rb
@@ -94,7 +90,6 @@ files:
94
90
  - lib/labimotion/helpers/element_helpers.rb
95
91
  - lib/labimotion/helpers/exporter_helpers.rb
96
92
  - lib/labimotion/helpers/generic_helpers.rb
97
- - lib/labimotion/helpers/mtt_helpers.rb
98
93
  - lib/labimotion/helpers/param_helpers.rb
99
94
  - lib/labimotion/helpers/repository_helpers.rb
100
95
  - lib/labimotion/helpers/sample_association_helpers.rb
@@ -134,12 +129,9 @@ files:
134
129
  - lib/labimotion/models/dataset_klasses_revision.rb
135
130
  - lib/labimotion/models/datasets_revision.rb
136
131
  - lib/labimotion/models/device_description.rb
137
- - lib/labimotion/models/dose_resp_output.rb
138
- - lib/labimotion/models/dose_resp_request.rb
139
132
  - lib/labimotion/models/element.rb
140
133
  - lib/labimotion/models/element_klass.rb
141
134
  - lib/labimotion/models/element_klasses_revision.rb
142
- - lib/labimotion/models/element_variation.rb
143
135
  - lib/labimotion/models/elements_element.rb
144
136
  - lib/labimotion/models/elements_revision.rb
145
137
  - lib/labimotion/models/elements_sample.rb
@@ -1,241 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'labimotion/version'
4
-
5
- module Labimotion
6
- # Dose Response Request API
7
- class DoseRespRequestAPI < Grape::API
8
- helpers Labimotion::ParamHelpers
9
-
10
- resource :dose_resp_requests do
11
- desc 'Get all dose response requests for current user'
12
- params do
13
- optional :element_id, type: Integer, desc: 'Filter by element ID'
14
- optional :state, type: Integer, desc: 'Filter by state (-1, 0, 1, 2)'
15
- optional :page, type: Integer, desc: 'Page number', default: 1
16
- optional :per_page, type: Integer, desc: 'Items per page', default: 20
17
- end
18
- get do
19
- requests = Labimotion::DoseRespRequest.where(created_by: current_user.id)
20
-
21
- # Apply filters
22
- requests = requests.where(element_id: params[:element_id]) if params[:element_id]
23
- requests = requests.where(state: params[:state]) if params[:state]
24
-
25
- # Pagination
26
- page = params[:page] || 1
27
- per_page = [params[:per_page] || 20, 100].min # Max 100 per page
28
-
29
- total = requests.count
30
- requests = requests.order(created_at: :desc)
31
- .offset((page - 1) * per_page)
32
- .limit(per_page)
33
-
34
- {
35
- requests: requests.map do |req|
36
- {
37
- id: req.id,
38
- request_id: req.request_id,
39
- element_id: req.element_id,
40
- state: req.state,
41
- state_label: state_label(req.state),
42
- expires_at: req.expires_at,
43
- created_at: req.created_at,
44
- updated_at: req.updated_at,
45
- first_accessed_at: req.first_accessed_at,
46
- last_accessed_at: req.last_accessed_at,
47
- access_count: req.access_count,
48
- resp_message: req.resp_message,
49
- active: req.active?
50
- }
51
- end,
52
- pagination: {
53
- page: page,
54
- per_page: per_page,
55
- total: total,
56
- total_pages: (total.to_f / per_page).ceil
57
- }
58
- }
59
- rescue StandardError => e
60
- error!("Error: #{e.message}", 500)
61
- end
62
-
63
- desc 'Get a dose response request by ID'
64
- params do
65
- requires :id, type: Integer, desc: 'Request ID'
66
- end
67
- get ':id' do
68
- request = Labimotion::DoseRespRequest.find_by(id: params[:id])
69
- error!('Request not found', 404) unless request
70
-
71
- # Check authorization
72
- error!('Unauthorized', 403) unless request.created_by == current_user.id
73
-
74
- {
75
- id: request.id,
76
- request_id: request.request_id,
77
- element_id: request.element_id,
78
- state: request.state,
79
- state_label: state_label(request.state),
80
- wellplates_metadata: request.wellplates_metadata,
81
- input_metadata: request.input_metadata,
82
- expires_at: request.expires_at,
83
- revoked_at: request.revoked_at,
84
- created_at: request.created_at,
85
- updated_at: request.updated_at,
86
- first_accessed_at: request.first_accessed_at,
87
- last_accessed_at: request.last_accessed_at,
88
- access_count: request.access_count,
89
- resp_message: request.resp_message,
90
- active: request.active?,
91
- expired: request.expired?,
92
- revoked: request.revoked?
93
- }
94
- rescue StandardError => e
95
- error!("Error: #{e.message}", 500)
96
- end
97
-
98
- desc 'Update a dose response request'
99
- params do
100
- requires :id, type: Integer, desc: 'Request ID'
101
- optional :state, type: Integer, desc: 'State', values: [-1, 0, 1, 2]
102
- optional :resp_message, type: String, desc: 'Response message'
103
- optional :wellplates_metadata, type: Hash, desc: 'Wellplates metadata'
104
- end
105
- put ':id' do
106
- request = Labimotion::DoseRespRequest.find_by(id: params[:id])
107
- error!('Request not found', 404) unless request
108
-
109
- # Check authorization
110
- error!('Unauthorized', 403) unless request.created_by == current_user.id
111
-
112
- update_params = {}
113
- update_params[:state] = params[:state] if params[:state]
114
- update_params[:resp_message] = params[:resp_message] if params[:resp_message]
115
- update_params[:wellplates_metadata] = params[:wellplates_metadata] if params[:wellplates_metadata]
116
-
117
- request.update!(update_params)
118
-
119
- {
120
- success: true,
121
- message: 'Request updated successfully',
122
- request: {
123
- id: request.id,
124
- request_id: request.request_id,
125
- state: request.state,
126
- state_label: state_label(request.state),
127
- resp_message: request.resp_message,
128
- updated_at: request.updated_at
129
- }
130
- }
131
- rescue ActiveRecord::RecordInvalid => e
132
- error!("Validation error: #{e.message}", 422)
133
- rescue StandardError => e
134
- error!("Error: #{e.message}", 500)
135
- end
136
-
137
- desc 'Revoke a dose response request'
138
- params do
139
- requires :id, type: Integer, desc: 'Request ID'
140
- end
141
- post ':id/revoke' do
142
- request = Labimotion::DoseRespRequest.find_by(id: params[:id])
143
- error!('Request not found', 404) unless request
144
-
145
- # Check authorization
146
- error!('Unauthorized', 403) unless request.created_by == current_user.id
147
-
148
- request.revoke!
149
-
150
- {
151
- success: true,
152
- message: 'Request revoked successfully',
153
- request: {
154
- id: request.id,
155
- request_id: request.request_id,
156
- state: request.state,
157
- revoked_at: request.revoked_at,
158
- active: request.active?
159
- }
160
- }
161
- rescue StandardError => e
162
- error!("Error: #{e.message}", 500)
163
- end
164
-
165
- desc 'Delete a dose response request'
166
- params do
167
- requires :id, type: Integer, desc: 'Request ID'
168
- end
169
- delete ':id' do
170
- request = Labimotion::DoseRespRequest.find_by(id: params[:id])
171
- error!('Request not found', 404) unless request
172
-
173
- # Check authorization
174
- error!('Unauthorized', 403) unless request.created_by == current_user.id
175
-
176
- # Soft delete if acts_as_paranoid is enabled
177
- request.destroy
178
-
179
- {
180
- success: true,
181
- message: 'Request deleted successfully'
182
- }
183
- rescue StandardError => e
184
- error!("Error: #{e.message}", 500)
185
- end
186
-
187
- desc 'Get dose response requests by element ID'
188
- params do
189
- requires :element_id, type: Integer, desc: 'Element ID'
190
- end
191
- get 'by_element/:element_id' do
192
- element = Labimotion::Element.find_by(id: params[:element_id])
193
- error!('Element not found', 404) unless element
194
-
195
- # Check if user has access to element
196
- policy = ElementPolicy.new(current_user, element)
197
- error!('Unauthorized', 403) unless policy.read?
198
-
199
- requests = Labimotion::DoseRespRequest.where(element_id: params[:element_id])
200
- .where(created_by: current_user.id)
201
- .order(created_at: :desc)
202
-
203
- {
204
- element_id: element.id,
205
- element_name: element.name,
206
- requests: requests.map do |req|
207
- {
208
- id: req.id,
209
- request_id: req.request_id,
210
- state: req.state,
211
- state_label: state_label(req.state),
212
- expires_at: req.expires_at,
213
- created_at: req.created_at,
214
- access_count: req.access_count,
215
- active: req.active?
216
- }
217
- end
218
- }
219
- rescue StandardError => e
220
- error!("Error: #{e.message}", 500)
221
- end
222
- end
223
-
224
- helpers do
225
- def state_label(state)
226
- case state
227
- when Labimotion::DoseRespRequest::STATE_ERROR
228
- 'error'
229
- when Labimotion::DoseRespRequest::STATE_INITIAL
230
- 'initial'
231
- when Labimotion::DoseRespRequest::STATE_PROCESSING
232
- 'processing'
233
- when Labimotion::DoseRespRequest::STATE_COMPLETED
234
- 'completed'
235
- else
236
- 'unknown'
237
- end
238
- end
239
- end
240
- end
241
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labimotion
4
- class ElementVariationAPI < Grape::API
5
- rescue_from ActiveRecord::RecordNotFound do
6
- error!('404 Element not found', 404)
7
- end
8
-
9
- resource :element_variations do
10
- params do
11
- requires :element_id, type: Integer, desc: 'Generic element id'
12
- end
13
- route_param :element_id do
14
- before do
15
- @element = Labimotion::Element.find(params[:element_id])
16
- error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, @element).read?
17
- end
18
-
19
- desc 'Return element variations for a generic element'
20
- get do
21
- record = Labimotion::ElementVariation.find_or_initialize_by(element_id: @element.id)
22
- present record, with: Labimotion::ElementVariationEntity, root: 'element_variation'
23
- end
24
-
25
- desc 'Upsert element variations for a generic element'
26
- params do
27
- requires :variations, type: Hash, desc: 'Variations keyed by row uuid'
28
- optional :layout, type: Hash, desc: 'Column layout (selected/order/units/rowOrder)'
29
- end
30
- put do
31
- error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, @element).update?
32
-
33
- record = Labimotion::ElementVariation.find_or_initialize_by(element_id: @element.id)
34
- record.variations = params[:variations] || {}
35
- if params.key?(:layout) && record.class.column_names.include?('layout')
36
- record.layout = params[:layout] || {}
37
- end
38
- record.save!
39
-
40
- present record, with: Labimotion::ElementVariationEntity, root: 'element_variation'
41
- end
42
- end
43
- end
44
- end
45
- end