labimotion 2.2.0.rc6 → 2.2.0.rc7

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: 33131772f2889ec9b2975e3abc9b498439e7c9aba468a61c83d9572cbb100cbf
4
- data.tar.gz: 55bfe79124ed9311ceef46620e4bd32e7fb8f175fd8a116630b859328eb55f20
3
+ metadata.gz: a7b53d1daca8b636571715c7ff62caa557dc59082c1f7733cdd6e6a875795712
4
+ data.tar.gz: cab23343b2c90f335571ae7b5b7e714b63cee7e1f403b50b8b3c89e944b23e4a
5
5
  SHA512:
6
- metadata.gz: 87317b89ef68c85576470d1d29162118343f1f987188f30b7ff48658a19719ac8536c1009fd330582c38d6ff4f045a8cd69a07fe0cd0fc7466fc70c25f9850c7
7
- data.tar.gz: 30d9dd24177f85ecd3dfc6ccdfd83dbf86e7db9e33a1d63df8ad60b8ebfa0db5dac03419bcaf1405b5051f4c4ef69bc5c5202b41beac12299370f816ce2ffb57
6
+ metadata.gz: ffbd3fac0cba826e516a8dd57fed5c0ac0b29a50c15752ca27453cc9dfd28736e71ce44b76efef72690daf1aa23f42a48309228b038a883ac67852564e74c94d
7
+ data.tar.gz: 7a3da058102e765cdfa54fa5ece7e3dc022cff2a0f39e9eae1cc31e4053b8e7735b5eda17bc2c05927b1e54d81883c3a885e1367eb85624d4e8437505ee96191
@@ -0,0 +1,45 @@
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
@@ -14,5 +14,6 @@ module Labimotion
14
14
  mount Labimotion::VocabularyAPI
15
15
  mount Labimotion::MttAPI
16
16
  mount Labimotion::DoseRespRequestAPI
17
+ mount Labimotion::ElementVariationAPI
17
18
  end
18
19
  end
@@ -23,6 +23,7 @@ module Labimotion
23
23
  expose! :uuid
24
24
  expose! :user_labels
25
25
  expose! :preview_attachment # align with eln change
26
+ expose! :variations_count
26
27
  end
27
28
 
28
29
  with_options(anonymize_below: 10) do
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/entities/application_entity'
4
+
5
+ module Labimotion
6
+ class ElementVariationEntity < Labimotion::ApplicationEntity
7
+ expose :id
8
+ expose :element_id, as: :elementId
9
+ expose :variations
10
+ expose :layout
11
+
12
+ def variations
13
+ rows = object.variations_hash
14
+ rows.transform_values do |row|
15
+ next row unless row.is_a?(Hash)
16
+
17
+ row.symbolize_keys.slice(:uuid, :name, :properties, :metadata, :segments).tap do |slim|
18
+ slim[:properties] = (slim[:properties] || {})
19
+ slim[:metadata] = (slim[:metadata] || {}).slice('notes', 'analyses', 'group', :notes, :analyses, :group)
20
+ slim[:segments] = (slim[:segments] || {})
21
+ end
22
+ end
23
+ end
24
+
25
+ def layout
26
+ object.layout_hash
27
+ end
28
+ end
29
+ end
@@ -74,6 +74,7 @@ module Labimotion
74
74
  response_data = {
75
75
  id: dose_resp_request.id.to_s,
76
76
  request_id: dose_resp_request.request_id,
77
+ element_info: extract_element_properties(dose_resp_request.element),
77
78
  wellplates: wellplates_data
78
79
  }
79
80
 
@@ -382,6 +383,30 @@ module Labimotion
382
383
  end
383
384
  end
384
385
 
386
+ def extract_element_properties(element)
387
+ props = {
388
+ id: element.id.to_s,
389
+ name: element.name
390
+ }
391
+
392
+ layers = element.properties.dig('layers', 'general_information', 'fields') ||
393
+ element.properties.dig(:layers, :general_information, :fields) || []
394
+
395
+ endpoint_field = layers.find { |f| f['field'] == 'Endpoint' || f[:field] == 'Endpoint' }
396
+ props[:endpoint] = endpoint_field['value'] || endpoint_field[:value] if endpoint_field
397
+
398
+ props
399
+ end
400
+
401
+
402
+ def generate_element_metadata(element)
403
+ {
404
+ id: wellplate.id.to_s,
405
+ readoutTitles: extract_readout_titles(wellplate),
406
+ wells: extract_wells(wellplate)
407
+ }
408
+ end
409
+
385
410
 
386
411
  def generate_json_data(wellplates)
387
412
  # # Generate wellplates metadata
@@ -41,6 +41,12 @@ 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
44
50
 
45
51
  accepts_nested_attributes_for :collections_elements
46
52
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ class ElementVariation < ApplicationRecord
5
+ self.table_name = :element_variations
6
+
7
+ belongs_to :element, class_name: 'Labimotion::Element'
8
+
9
+ validates :element_id, uniqueness: true
10
+
11
+ def variations_hash
12
+ variations.is_a?(Hash) ? variations : {}
13
+ end
14
+
15
+ def layout_hash
16
+ return {} unless self.class.column_names.include?('layout')
17
+
18
+ layout.is_a?(Hash) ? layout : {}
19
+ end
20
+ end
21
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
- VERSION = '2.2.0.rc6'
5
+ VERSION = '2.2.0.rc7'
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -29,6 +29,7 @@ module Labimotion
29
29
  autoload :VocabularyAPI, 'labimotion/apis/vocabulary_api'
30
30
  autoload :MttAPI, 'labimotion/apis/mtt_api'
31
31
  autoload :DoseRespRequestAPI, 'labimotion/apis/dose_resp_request_api'
32
+ autoload :ElementVariationAPI, 'labimotion/apis/element_variation_api'
32
33
 
33
34
  ######## Entities
34
35
  autoload :PropertiesEntity, 'labimotion/entities/properties_entity'
@@ -51,6 +52,7 @@ module Labimotion
51
52
  autoload :SegmentRevisionEntity, 'labimotion/entities/segment_revision_entity'
52
53
  ## autoload :DatasetRevisionEntity, 'labimotion/entities/dataset_revision_entity'
53
54
  autoload :VocabularyEntity, 'labimotion/entities/vocabulary_entity'
55
+ autoload :ElementVariationEntity, 'labimotion/entities/element_variation_entity'
54
56
 
55
57
  ######## Helpers
56
58
  autoload :GenericHelpers, 'labimotion/helpers/generic_helpers'
@@ -123,6 +125,7 @@ module Labimotion
123
125
  autoload :Sample, 'labimotion/models/sample'
124
126
  autoload :Screen, 'labimotion/models/screen'
125
127
  autoload :Wellplate, 'labimotion/models/wellplate'
128
+ autoload :ElementVariation, 'labimotion/models/element_variation'
126
129
 
127
130
  ######## Models/Concerns
128
131
  autoload :GenericKlassRevisions, 'labimotion/models/concerns/generic_klass_revisions'
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.rc6
4
+ version: 2.2.0.rc7
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-03-29 00:00:00.000000000 Z
12
+ date: 2026-05-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: caxlsx
@@ -56,6 +56,7 @@ files:
56
56
  - lib/labimotion.rb
57
57
  - lib/labimotion/apis/converter_api.rb
58
58
  - lib/labimotion/apis/dose_resp_request_api.rb
59
+ - lib/labimotion/apis/element_variation_api.rb
59
60
  - lib/labimotion/apis/exporter_api.rb
60
61
  - lib/labimotion/apis/generic_dataset_api.rb
61
62
  - lib/labimotion/apis/generic_element_api.rb
@@ -77,6 +78,7 @@ files:
77
78
  - lib/labimotion/entities/element_entity.rb
78
79
  - lib/labimotion/entities/element_klass_entity.rb
79
80
  - lib/labimotion/entities/element_revision_entity.rb
81
+ - lib/labimotion/entities/element_variation_entity.rb
80
82
  - lib/labimotion/entities/eln_element_entity.rb
81
83
  - lib/labimotion/entities/generic_entity.rb
82
84
  - lib/labimotion/entities/generic_klass_entity.rb
@@ -137,6 +139,7 @@ files:
137
139
  - lib/labimotion/models/element.rb
138
140
  - lib/labimotion/models/element_klass.rb
139
141
  - lib/labimotion/models/element_klasses_revision.rb
142
+ - lib/labimotion/models/element_variation.rb
140
143
  - lib/labimotion/models/elements_element.rb
141
144
  - lib/labimotion/models/elements_revision.rb
142
145
  - lib/labimotion/models/elements_sample.rb