Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device description #21

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b200745
Add model device description
beque Dec 11, 2023
6be74eb
Add device description api endpoint
beque Dec 11, 2023
e31d9e0
Add model collections_device_description
beque Dec 12, 2023
6dc40be
Add new element device description to eln
beque Dec 14, 2023
e246620
Add device description fetcher, js model, text template, to collection
beque Dec 14, 2023
304c95d
Add basic form with tabs for device description
beque Dec 18, 2023
5e2bb15
Add and change some fields at device description
beque Feb 20, 2024
aabe039
Add device description to alt store and apis
beque Feb 20, 2024
5d03cf2
Add device description store
beque Feb 20, 2024
98da744
Add more fields to properties form of device description
beque Feb 20, 2024
1bcda50
Fix for deleting device descriptions
beque Feb 21, 2024
78547ae
Add operators at device description properties tab
beque Feb 22, 2024
d982291
Add analyses container to device description, Fix detail level
beque Mar 1, 2024
1c5f03a
Add attachment form and handling
beque Mar 8, 2024
193085b
Fix update, delete attachments
beque Mar 13, 2024
0fbe343
Add basic ontology requests
beque Mar 13, 2024
2020a4d
Add button functionality for attachments and analyses
beque Mar 15, 2024
4f45804
Add ontology details tab
beque Apr 5, 2024
83598d5
Add more functions for adding ontologies to device descriptions
beque Apr 11, 2024
613aea5
Fix rubocop errors
beque Apr 11, 2024
fb27256
Add test for finding segment klasses by ontology
beque Apr 12, 2024
36c2070
Add disabled tabs for new device description
beque Apr 12, 2024
f8b9831
Fix save for unchanged segements
beque Apr 12, 2024
e061aee
Fix some javascript warnings
beque Apr 16, 2024
27a33d0
Add buttons to device description header, Rename conflict fields
beque Apr 17, 2024
23e4464
Add calendar button to device description detail header
beque Apr 18, 2024
fa57d74
Fix for taggable data of element tag
beque Apr 19, 2024
8c49ab2
Add copy button
beque Apr 23, 2024
fc6501b
Fix rubocop error for inverse_of at device description
beque Apr 23, 2024
00e06e7
Add copy device description functionality
beque Apr 24, 2024
0e45986
Add split for device description
beque Apr 26, 2024
71fe316
Fix rubocop for each
beque Apr 29, 2024
5989833
Add list view for device description
beque Apr 30, 2024
79cd8f8
Add styles for grouped device description list
beque May 14, 2024
d65b7ec
Add new field at properties tab
beque May 16, 2024
4c8a5d5
Add set description with draggable components
beque May 24, 2024
d587dde
Add missing key
beque May 24, 2024
912045a
Fix for adding new device description
beque May 30, 2024
5512428
Optimize some fields
beque May 30, 2024
4b6d93a
Fix barcode function for device description, rubocop for code logs
beque May 31, 2024
e35b2a3
Add maintenance tab fields
beque Jun 3, 2024
9ab9765
Fix styles for select in addon
beque Jun 5, 2024
b58cb85
Fix styles for staging
beque Jun 6, 2024
eda9827
Fixes after rebase
beque Sep 26, 2024
9ade5e5
Fix rubocop for profile.api
beque Sep 26, 2024
86a1bf2
Fix device description icon
beque Oct 21, 2024
e7a4c18
Fix device description list
beque Oct 21, 2024
0d4e71a
Fix device description detail
beque Oct 30, 2024
4f7dd99
Fix for text template toolbar
beque Nov 4, 2024
3f07f87
Remove unused scss files, Fix calendar
beque Nov 5, 2024
bd03920
Fixes for attachments, image modal and textareas
beque Nov 5, 2024
07fb1cc
Fix rubocop
beque Nov 5, 2024
6a25645
Fix user label warning
beque Nov 6, 2024
dfe8d5a
Move device description details and list
beque Jan 3, 2025
c1afb52
Fix sortable ontologies list
beque Jan 6, 2025
47e2cf0
Fix chem-generic-ui buttons and interface at device description details
beque Jan 6, 2025
2597b03
Fix sortable analyses list
beque Jan 7, 2025
7e9d3eb
Fix some errors
beque Jan 7, 2025
ceafe96
Fix double getReactionId
beque Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

if Rails.env.development?
add_swagger_documentation(info: {
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)
beque marked this conversation as resolved.
Show resolved Hide resolved
@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
beque marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading