Skip to content

Commit

Permalink
feat: element device description #2281
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 8ee755d
Author: Beate Quednau <bq@megorei.com>
Date:   Mon Jan 20 18:58:25 2025 +0100

    Fix some fields and translations for device descriptions

commit 088f2a6
Author: Beate Quednau <bq@megorei.com>
Date:   Mon Jan 13 16:46:58 2025 +0100

    Fix deleted cell line for copy cell line

commit 88c7022
Author: Beate Quednau <bq@megorei.com>
Date:   Fri Jan 10 19:09:14 2025 +0100

    Fix attachment spec

commit 17fea2a
Author: Beate Quednau <bq@megorei.com>
Date:   Fri Jan 10 17:23:40 2025 +0100

    Fix rubocop

commit c109522
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Jan 10 13:52:03 2025 +0100

    Fix double getReactionId

commit 10565d2
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Jan 7 19:25:16 2025 +0100

    Fix some errors

commit ed4b182
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Jan 7 18:36:34 2025 +0100

    Fix sortable analyses list

commit 476bbe4
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Jan 6 17:42:15 2025 +0100

    Fix chem-generic-ui buttons and interface at device description details

commit 7a6df03
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Jan 6 17:23:03 2025 +0100

    Fix sortable ontologies list

commit 94994b0
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Jan 3 14:16:17 2025 +0100

    Move device description details and list

commit fe112db
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Nov 6 14:48:59 2024 +0100

    Fix user label warning

commit 7009e47
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Nov 5 19:42:01 2024 +0100

    Fix rubocop

commit ffcace3
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Nov 5 19:17:34 2024 +0100

    Fixes for attachments, image modal and textareas

commit 3ae0d40
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Nov 5 15:39:16 2024 +0100

    Remove unused scss files, Fix calendar

commit 52ccccb
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Nov 4 15:42:42 2024 +0100

    Fix for text template toolbar

commit 5374d5a
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Oct 30 18:19:16 2024 +0100

    Fix device description detail

commit e4fa139
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Oct 21 17:12:03 2024 +0200

    Fix device description list

commit fc20c08
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Oct 21 17:09:31 2024 +0200

    Fix device description icon

commit b7f8fa4
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Sep 26 11:46:20 2024 +0200

    Fix rubocop for profile.api

commit 486cc5d
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Sep 26 11:36:16 2024 +0200

    Fixes after rebase

commit 2f333d0
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Jun 6 12:41:07 2024 +0200

    Fix styles for staging

commit 7128808
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Jun 5 19:00:39 2024 +0200

    Fix styles for select in addon

commit fa1ee89
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Jun 3 14:41:09 2024 +0200

    Add maintenance tab fields

commit ebb1f29
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri May 31 14:07:56 2024 +0200

    Fix barcode function for device description, rubocop for code logs

commit a5fb0c1
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu May 30 16:45:37 2024 +0200

    Optimize some fields

commit fa88cbe
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu May 30 11:44:24 2024 +0200

    Fix for adding new device description

commit 24d73bb
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri May 24 18:47:10 2024 +0200

    Add missing key

commit 7b1ba66
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri May 24 18:13:25 2024 +0200

    Add set description with draggable components

commit 1cf9eaa
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu May 16 20:39:07 2024 +0200

    Add new field at properties tab

commit 5ced50a
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue May 14 17:40:23 2024 +0200

    Add styles for grouped device description list

commit 1aa6a7a
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Apr 30 19:51:56 2024 +0200

    Add list view for device description

commit 18aef07
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Apr 29 17:25:25 2024 +0200

    Fix rubocop for each

commit 47488c8
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 26 15:38:01 2024 +0200

    Add split for device description

commit f9c6787
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Apr 24 16:40:02 2024 +0200

    Add copy device description functionality

commit 4b20418
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Apr 23 19:23:32 2024 +0200

    Fix rubocop error for inverse_of at device description

commit b635781
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Apr 23 12:25:24 2024 +0200

    Add copy button

commit 7750ce8
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 19 13:34:45 2024 +0200

    Fix for taggable data of element tag

commit 38aa58c
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Apr 18 19:31:21 2024 +0200

    Add calendar button to device description detail header

commit 15f3f33
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Apr 17 20:09:29 2024 +0200

    Add buttons to device description header, Rename conflict fields

commit 390a4e9
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Apr 16 18:04:40 2024 +0200

    Fix some javascript warnings

commit d365bd6
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 12 19:45:51 2024 +0200

    Fix save for unchanged segements

commit 9f53c85
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 12 19:44:45 2024 +0200

    Add disabled tabs for new device description

commit 575c243
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 12 14:28:34 2024 +0200

    Add test for finding segment klasses by ontology

commit 6e5dfdd
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Apr 11 19:47:55 2024 +0200

    Fix rubocop errors

commit bb7a5f1
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Apr 11 17:29:12 2024 +0200

    Add more functions for adding ontologies to device descriptions

commit 6202b8b
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Apr 5 14:43:29 2024 +0200

    Add ontology details tab

commit 7b0969f
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Mar 15 14:22:18 2024 +0100

    Add button functionality for attachments and analyses

commit 3613173
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Mar 13 19:55:11 2024 +0100

    Add basic ontology requests

commit 493baed
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Mar 13 19:54:01 2024 +0100

    Fix update, delete attachments

commit a621ef7
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Mar 8 16:03:40 2024 +0100

    Add attachment form and handling

commit 79158e0
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Fri Mar 1 21:06:23 2024 +0100

    Add analyses container to device description, Fix detail level

commit 8e8532d
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Feb 22 19:29:49 2024 +0100

    Add operators at device description properties tab

commit 9c698f2
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Wed Feb 21 13:52:27 2024 +0100

    Fix for deleting device descriptions

commit f6c46d6
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Feb 20 19:46:04 2024 +0100

    Add more fields to properties form of device description

commit f1b73cf
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Feb 20 19:45:09 2024 +0100

    Add device description store

commit 1357f30
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Feb 20 19:42:43 2024 +0100

    Add device description to alt store and apis

commit c1d904d
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Feb 20 19:39:38 2024 +0100

    Add and change some fields at device description

commit 4c598ae
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Dec 18 15:56:08 2023 +0100

    Add basic form with tabs for device description

commit 3288efa
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Dec 14 15:08:17 2023 +0100

    Add device description fetcher, js model, text template, to collection

commit d94fc54
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Thu Dec 14 14:50:28 2023 +0100

    Add new element device description to eln

commit b1382f4
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Tue Dec 12 12:39:49 2023 +0100

    Add model collections_device_description

commit fd56b5b
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Dec 11 17:25:09 2023 +0100

    Add device description api endpoint

commit 319ef62
Author: Beate Quednau <beate@firma-pflaum.de>
Date:   Mon Dec 11 13:00:38 2023 +0100

    Add model device description
  • Loading branch information
PiTrem committed Jan 21, 2025
1 parent 8dbac90 commit e10774b
Show file tree
Hide file tree
Showing 116 changed files with 6,217 additions and 183 deletions.
4 changes: 3 additions & 1 deletion app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def to_json_camel_case(val)

TARGET = Rails.env.production? ? 'https://www.chemotion-repository.net/' : 'http://localhost:3000/'

ELEMENTS = %w[research_plan screen wellplate reaction sample cell_line].freeze
ELEMENTS = %w[research_plan screen wellplate reaction sample cell_line device_description].freeze

ELEMENT_CLASS = {
'research_plan' => ResearchPlan,
Expand All @@ -147,6 +147,7 @@ def to_json_camel_case(val)
'reaction' => Reaction,
'sample' => Sample,
'cell_line' => CelllineSample,
'device_description' => DeviceDescription,
}.freeze

mount Chemotion::LiteratureAPI
Expand Down Expand Up @@ -203,6 +204,7 @@ def to_json_camel_case(val)
mount Chemotion::AdminDeviceAPI
mount Chemotion::AdminDeviceMetadataAPI
mount Chemotion::ChemicalAPI
mount Chemotion::DeviceDescriptionAPI

add_swagger_documentation(info: {
title: 'Chemotion ELN',
Expand Down
4 changes: 3 additions & 1 deletion app/api/chemotion/attachable_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class AttachableAPI < Grape::API
begin
a.save!
attach_ary.push(a.id)
rp_attach_ary.push(a.id) if a.attachable_type.in?(%w[ResearchPlan Wellplate Labimotion::Element])
if a.attachable_type.in?(%w[ResearchPlan Wellplate DeviceDescription Labimotion::Element])
rp_attach_ary.push(a.id)
end
ensure
tempfile.close
tempfile.unlink
Expand Down
36 changes: 34 additions & 2 deletions app/api/chemotion/attachment_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def remove_duplicated(att)

@attachment = Attachment.find_by(identifier: params[:identifier]) if @attachment.nil? && params[:identifier]

# rubocop:disable Performance/StringInclude
case request.env['REQUEST_METHOD']
when /delete/i
error!('401 Unauthorized', 401) unless writable?(@attachment)
Expand All @@ -101,6 +102,13 @@ def remove_duplicated(att)
can_dwnld = can_read &&
ElementPermissionProxy.new(current_user, element, user_ids).read_dataset?
end
elsif /device_description_analyses/.match?(request.url)
@device_description = DeviceDescription.find(params[:device_description_id])
if (element = @device_description)
can_read = ElementPolicy.new(current_user, element).read?
can_dwnld = can_read &&
ElementPermissionProxy.new(current_user, element, user_ids).read_dataset?
end
elsif @attachment

can_dwnld = @attachment.container_id.nil? && @attachment.created_for == current_user.id
Expand All @@ -119,6 +127,7 @@ def remove_duplicated(att)
end
error!('401 Unauthorized', 401) unless can_dwnld
end
# rubocop:enable Performance/StringInclude
end

desc 'Bulk Delete Attachments'
Expand Down Expand Up @@ -347,20 +356,43 @@ def remove_duplicated(att)
end
end&.flatten&.reduce(:+) || 0
if tts > 300_000_000
DownloadAnalysesJob.perform_later(@sample.id, current_user.id, false)
DownloadAnalysesJob.perform_later(@sample.id, current_user.id, false, 'sample')
nil
else
env['api.format'] = :binary
content_type('application/zip, application/octet-stream')
filename = CGI.escape("#{@sample.short_label}-analytical-files.zip")
header('Content-Disposition', "attachment; filename=\"#{filename}\"")
zip = DownloadAnalysesJob.perform_now(@sample.id, current_user.id, true)
zip = DownloadAnalysesJob.perform_now(@sample.id, current_user.id, true, 'sample')
zip.rewind
zip.read

end
end

desc 'Download the zip attachment file by device_description_id'
get 'device_description_analyses/:device_description_id' do
# rubocop:disable Performance/Sum
tts = @device_description.analyses&.map do |a|
a.children&.map do |d|
d.attachments&.map(&:filesize)
end
end&.flatten&.reduce(:+) || 0
# rubocop:enable Performance/Sum
if tts > 300_000_000
DownloadAnalysesJob.perform_later(@device_description.id, current_user.id, false, 'device_description')
nil
else
env['api.format'] = :binary
content_type('application/zip, application/octet-stream')
filename = CGI.escape("#{@device_description.short_label}-analytical-files.zip")
header('Content-Disposition', "attachment; filename=\"#{filename}\"")
zip = DownloadAnalysesJob.perform_now(@device_description.id, current_user.id, true, 'device_description')
zip.rewind
zip.read
end
end

desc 'Return image attachment'

params do
Expand Down
25 changes: 13 additions & 12 deletions app/api/chemotion/code_log_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ class CodeLogAPI < Grape::API
get do
code = params[:code]
s = code&.size || 0
code_log = if s >= 39
CodeLog.find(CodeCreator.digit_to_uuid(code))
elsif s >= 8
# TODO: use where instead of find_by ?
CodeLog.where('value ~ ?', "\\A0#{code}").first
elsif s == 6
# TODO: use where instead of find_by ?
CodeLog.find_by(value_xs: code.to_i)
end
code_log =
if s >= 39
CodeLog.find(CodeCreator.digit_to_uuid(code))
elsif s >= 8
# TODO: use where instead of find_by ?
CodeLog.where('value ~ ?', "\\A0#{code}").first
elsif s == 6
# TODO: use where instead of find_by ?
CodeLog.find_by(value_xs: code.to_i)
end

if code_log.nil?
error!("Element with #{code.size}-digit code #{params[:code]} not found", 404)
Expand All @@ -48,7 +49,7 @@ class CodeLogAPI < Grape::API
namespace :print_codes do
desc 'Build PDF with element bar & qr code'
params do
requires :element_type, type: String, values: %w[sample reaction wellplate screen]
requires :element_type, type: String, values: %w[sample reaction wellplate screen device_description]
# TODO: check coerce with type Array[Integer] not working with before do
requires :ids, type: Array # , coerce_with: ->(val) { val.split(/,/).map(&:to_i) }
requires :width, type: Integer
Expand Down Expand Up @@ -97,7 +98,7 @@ class CodeLogAPI < Grape::API
namespace :print_analyses_codes do
desc 'Build PDF with analyses codes of one analysis type'
params do
requires :element_type, type: String, values: %w[sample reaction wellplate screen]
requires :element_type, type: String, values: %w[sample reaction wellplate screen device_description]
requires :id, type: Integer, desc: 'Element id'
requires :analyses_ids, type: Array[String]
requires :size, type: String, values: %w[small big]
Expand All @@ -118,7 +119,7 @@ class CodeLogAPI < Grape::API
content_type('application/pdf')
header 'Content-Disposition', "attachment; filename*=UTF-8''analysis_codes_#{params[:size]}.pdf"
env['api.format'] = :binary
# TODO: check container type/info instead
# TODO: check container type/info instead
# case params[:type]
# when "nmr_analysis"
# body AnalysisNmrPdf.new(elements).render
Expand Down
10 changes: 10 additions & 0 deletions app/api/chemotion/collection_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class CollectionAPI < Grape::API
optional :cell_line, type: Hash do
use :ui_state_params
end
optional :device_description, type: Hash do
use :ui_state_params
end
end
requires :collection_attributes, type: Hash do
requires :permission_level, type: Integer
Expand Down Expand Up @@ -221,6 +224,9 @@ class CollectionAPI < Grape::API
cell_lines = CelllineSample.by_collection_id(@cid)
.by_ui_state(params[:elements_filter][:cell_line])
.for_user_n_groups(user_ids)
device_descriptions = DeviceDescription.by_collection_id(@cid)
.by_ui_state(params[:elements_filter][:device_description])
.for_user_n_groups(user_ids)
elements = {}
Labimotion::ElementKlass.find_each do |klass|
elements[klass.name] = Labimotion::Element.by_collection_id(@cid).by_ui_state(params[:elements_filter][klass.name]).for_user_n_groups(user_ids)
Expand All @@ -237,6 +243,7 @@ class CollectionAPI < Grape::API
share_screens = ElementsPolicy.new(current_user, screens).share?
share_research_plans = ElementsPolicy.new(current_user, research_plans).share?
share_cell_lines = ElementsPolicy.new(current_user, cell_lines).share?
share_device_descriptions = ElementsPolicy.new(current_user, device_descriptions).share?
share_elements = !(elements&.length > 0)
elements.each do |k, v|
share_elements = ElementsPolicy.new(current_user, v).share?
Expand All @@ -249,6 +256,7 @@ class CollectionAPI < Grape::API
share_screens &&
share_research_plans &&
share_cell_lines &&
share_device_descriptions &&
share_elements
error!('401 Unauthorized', 401) if (!sharing_allowed || is_top_secret)

Expand All @@ -258,6 +266,7 @@ class CollectionAPI < Grape::API
@screen_ids = screens.pluck(:id)
@research_plan_ids = research_plans.pluck(:id)
@cell_line_ids = cell_lines.pluck(:id)
@device_description_ids = device_descriptions.pluck(:id)
@element_ids = elements&.transform_values { |v| v && v.pluck(:id) }
end

Expand All @@ -280,6 +289,7 @@ class CollectionAPI < Grape::API
screen_ids: @screen_ids,
research_plan_ids: @research_plan_ids,
cell_line_ids: @cell_line_ids,
device_description_ids: @device_description_ids,
element_ids: @element_ids,
collection_attributes: params[:collection_attributes].merge(shared_by_id: current_user.id)
).execute!
Expand Down
1 change: 1 addition & 0 deletions app/api/chemotion/comment_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def find_commentable(commentable_type, commentable_id)
Comment.wellplate_sections.values +
Comment.screen_sections.values +
Comment.research_plan_sections.values +
Comment.device_description_sections.values +
Comment.header_sections.values
end

Expand Down
Loading

0 comments on commit e10774b

Please sign in to comment.