Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into Third-Party-Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Jul 19, 2023
2 parents 39d2824 + 73260b3 commit 4fe35ba
Show file tree
Hide file tree
Showing 88 changed files with 5,130 additions and 442 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@

/public/json/*
!/public/json/schema.json
!/public/json/precautionaryPhrases.json
!/public/json/hazardPhrases.json
!/public/json/pictograms.json


/public/zip/*
!/public/zip/.keep
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
# Chemotion_ELN Changelog


## [v1.6.1]
> 2023-06-19
* Fixes
* scan result calculation [PR1325](https://github.com/ComPlat/chemotion_ELN/pull/1325)
* Load the correct url of nmrium wrapper [#1339](https://github.com/ComPlat/chemotion_ELN/pull/1339)
* Zooming in chemspectra on firefox [#1346](https://github.com/ComPlat/chemotion_ELN/pull/1346)
* AdminUI: Datacollector setting [#1344](https://github.com/ComPlat/chemotion_ELN/pull/1344)
* nmrium: display preview image after saving [#1356](https://github.com/ComPlat/chemotion_ELN/pull/1356)


## [v1.6.0]
> 2023-05-09
Expand Down
30 changes: 9 additions & 21 deletions app/api/chemotion/admin_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,18 @@ class AdminAPI < Grape::API
end

namespace :name do
desc 'Find top 3 matched user names by type'
desc 'Find top 4 matched user names by type'
params do
requires :type, type: String
requires :name, type: String
requires :type, type: String, values: %w[Group Device User Person Admin]
requires :name, type: String, desc: 'user name'
end
get do
if params[:name].present?
users = User.where(type: params[:type])
.by_name(params[:name])
.limit(3)
.select(
'first_name',
'last_name',
'name',
'id',
'name_abbreviation',
'name_abbreviation as abb',
'type as user_type')
.map(&:attributes)

{ users: users }
else
{ users: [] }
end
return { users: [] } if params[:name].blank?

users = User.where(type: params[:type])
.by_name(params[:name])
.limit(4)
present users, with: Entities::UserSimpleEntity, root: 'users'
end
end

Expand Down
26 changes: 19 additions & 7 deletions app/api/chemotion/attachment_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def upload_chunk_error_message
error!(message, 404)
end

resource :attachments do # rubocop:disable Metrics/BlockLength
before do # rubocop:disable Metrics/BlockLength
resource :attachments do
before do
@attachment = Attachment.find_by(id: params[:attachment_id])

@attachment = Attachment.find_by(identifier: params[:identifier]) if @attachment.nil? && params[:identifier]
Expand Down Expand Up @@ -163,7 +163,9 @@ def upload_chunk_error_message

env['api.format'] = :binary
store = @attachment.attachment.storage.directory
file_location = store.join(@attachment.attachment_data['derivatives']['annotation']['annotated_file_location'] ||'not available')
file_location = store.join(
@attachment.attachment_data['derivatives']['annotation']['annotated_file_location'] || 'not available',
)

uploaded_file = if file_location.present? && File.file?(file_location)
extension_of_annotation = File.extname(@attachment.filename)
Expand Down Expand Up @@ -238,20 +240,30 @@ def upload_chunk_error_message
end

desc 'Download the zip attachment file'
get 'zip/:container_id' do # rubocop:disable Metrics/BlockLength
get 'zip/:container_id' do
env['api.format'] = :binary
content_type('application/zip, application/octet-stream')
filename = CGI.escape("#{@container.parent&.name&.gsub(/\s+/, '_')}-#{@container.name.gsub(/\s+/, '_')}.zip")
header('Content-Disposition', "attachment; filename=\"#{filename}\"")
zip = Zip::OutputStream.write_buffer do |zip| # rubocop:disable Lint/ShadowingOuterLocalVariable
file_text = ''
@container.attachments.each do |att|
zip.put_next_entry att.filename
zip.write att.read_file
end
file_text = ''
@container.attachments.each do |att|
file_text += "#{att.filename} #{att.checksum}\n"
next unless att.annotated?

begin
annotated_file_name = "#{File.basename(att.filename, '.*')}_annotated#{File.extname(att.filename)}"
zip.put_next_entry annotated_file_name
file = File.open(att.annotated_file_location)
zip.write file.read
file_text += "#{annotated_file_name} #{file.size}\n"
ensure
file.close
end
end

hyperlinks_text = ''
JSON.parse(@container.extended_metadata.fetch('hyperlinks', '[]')).each do |link|
hyperlinks_text += "#{link} \n"
Expand Down
159 changes: 159 additions & 0 deletions app/api/chemotion/chemical_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# frozen_string_literal: true

module Chemotion
class ChemicalAPI < Grape::API
include Grape::Kaminari
resource :chemicals do
desc 'update chemicals'
params do
requires :chemical_data, type: Array[Hash], desc: 'chemical data'
optional :cas, type: String, desc: 'cas number'
end
route_param :sample_id do
put do
Chemotion::ChemicalsService.handle_exceptions do
attributes = declared(params, include_missing: false)
if params[:chemical_data].present? || params[:cas].present?
Chemical.find_by(sample_id: params[:sample_id]).update!(attributes)
else
status 204
end
end
end
end

desc 'Return chemical by sample_id'
params do
requires :sample_id, type: Integer, desc: 'sample id'
end

get do
Chemotion::ChemicalsService.handle_exceptions do
Chemical.find_by(sample_id: params[:sample_id]) || Chemical.new
end
end

resource :create do
desc 'Create a Chemical Entry'
params do
requires :chemical_data, type: Array[Hash], desc: 'chemical data'
requires :cas, type: String
requires :sample_id, type: Integer
end

post do
Chemotion::ChemicalsService.handle_exceptions do
attributes = declared(params, include_missing: false)
Chemical.create!(attributes)
end
end
end

resource :fetch_safetysheet do
desc 'fetch safety data sheet'
route_param :id do
params do
requires :data, type: Hash, desc: 'params'
end
get do
Chemotion::ChemicalsService.handle_exceptions do
data = params[:data]
molecule = Molecule.find(params[:id])
vendor = data[:vendor]
language = data[:language]
case data[:option]
when 'Common Name'
name = data[:searchStr] || molecule.names[0]
when 'CAS'
name = data[:searchStr] || molecule.cas[0]
end
case vendor
when 'Merck'
{ merck_link: Chemotion::ChemicalsService.merck(name, language) }
when 'Thermofisher'
{ alfa_link: Chemotion::ChemicalsService.alfa(name, language) }
else
{
alfa_link: Chemotion::ChemicalsService.alfa(name, language),
merck_link: Chemotion::ChemicalsService.merck(name, language),
}
end
end
end
end
end

resource :save_safety_datasheet do
desc 'save safety data sheet'

params do
requires :sample_id, type: Integer, desc: 'sample id'
requires :cas, type: String
requires :chemical_data, type: Array[Hash]
optional :vendor_product, type: String
end
post do
Chemotion::ChemicalsService.handle_exceptions do
chemical = Chemical.find_by(sample_id: params[:sample_id])
product_info = params[:chemical_data][0][params[:vendor_product]]
if chemical.present?
chemical.update!(chemical_data: params[:chemical_data])
else
Chemical.create!(sample_id: params[:sample_id], cas: params[:cas], chemical_data: params[:chemical_data])
end
file_path = "#{product_info['productNumber']}_#{product_info['vendor']}.pdf"
Chemotion::ChemicalsService.create_sds_file(file_path, product_info['sdsLink'])
end
end
end

resources :safety_phrases do
desc 'H and P safety phrases'

params do
requires :vendor, type: String, desc: 'params'
end

route_param :sample_id do
get do
Chemotion::ChemicalsService.handle_exceptions do
chemical = Chemical.find_by(sample_id: params[:sample_id]) || Chemical.new
if chemical.chemical_data.present?
if params[:vendor] == 'thermofischer' && chemical.chemical_data[0]['alfaProductInfo']
product_number = chemical.chemical_data[0]['alfaProductInfo']['productNumber']
Chemotion::ChemicalsService.safety_phrases_thermofischer(product_number)
elsif params[:vendor] == 'merck' && chemical.chemical_data[0]['merckProductInfo']
product_link = chemical.chemical_data[0]['merckProductInfo']['productLink']
Chemotion::ChemicalsService.safety_phrases_merck(product_link)
else
err_body = 'Please fetch and save corresponding safety data sheet first'
err_body
end
else
status 204
end
end
end
end
end

resources :chemical_properties do
desc 'additional chemical properties'

params do
requires :link, type: String, desc: 'vendor product link'
end

get do
Chemotion::ChemicalsService.handle_exceptions do
if params[:link].include? 'alfa'
Chemotion::ChemicalsService.chemical_properties_alfa(params[:link])
elsif params[:link].include? 'sigmaaldrich'
Chemotion::ChemicalsService.chemical_properties_merck(params[:link])
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/api/chemotion/container_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ContainerAPI < Grape::API
# NB: attachments are destroy through container (DJ in production)
# NB: attachments are not paranoidized so cannot be restored)
@container.self_and_descendants.each(&:destroy)
status 200
status 204
end

desc 'Update Container Content'
Expand Down
38 changes: 36 additions & 2 deletions app/api/chemotion/inbox_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,51 @@

module Chemotion
class InboxAPI < Grape::API
helpers ParamsHelpers

resource :inbox do
params do
requires :cnt_only, type: Boolean, desc: 'return count number only'
end

paginate per_page: 20, offset: 0, max_per_page: 50

get do
current_user.container = Container.create(name: 'inbox', container_type: 'root') unless current_user.container

if params[:cnt_only]
present current_user.container, with: Entities::InboxEntity, root: :inbox, only: [:inbox_count]
present current_user.container, with: Entities::InboxEntity,
root_container: true,
root: :inbox,
only: [:inbox_count]
else
present current_user.container, with: Entities::InboxEntity, root: :inbox
scope = current_user.container.children.order(created_at: :desc)

reset_pagination_page(scope)

device_boxes = paginate(scope).map do |device_box|
Entities::InboxEntity.represent(device_box, root_container: true)
end

inbox_service = InboxService.new(current_user.container)
present inbox_service.to_hash(device_boxes)
end
end

desc 'Return files by subcontainer ID'
params do
requires :container_id, type: Integer, desc: 'subcontainer ID'
optional :dataset_page, type: Integer, desc: 'Pagination number'
end

get 'containers/:container_id' do
if current_user.container.present?
container = current_user.container.children.find params[:container_id]

Entities::InboxEntity.represent(container,
root_container: false,
dataset_page: params[:dataset_page],
root: :inbox)
end
end

Expand Down
9 changes: 8 additions & 1 deletion app/api/chemotion/sample_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#require './helpers'

module Chemotion
# rubocop:disable Metrics/ClassLength
class SampleAPI < Grape::API
include Grape::Kaminari
helpers ContainerHelpers
Expand Down Expand Up @@ -53,7 +54,9 @@ class SampleAPI < Grape::API
col_id = ui_state[:currentCollectionId]
sample_ids = Sample.for_user(current_user.id).for_ui_state_with_collection(ui_state[:sample], CollectionsSample, col_id)
Sample.where(id: sample_ids).each do |sample|
subsample = sample.create_subsample current_user, col_id, true
# rubocop:disable Lint/UselessAssignment
subsample = sample.create_subsample(current_user, col_id, true, 'sample')
# rubocop:enable Lint/UselessAssignment
end

{} # JS layer does not use the reply
Expand Down Expand Up @@ -319,6 +322,7 @@ class SampleAPI < Grape::API
requires :container, type: Hash
optional :user_labels, type: Array
optional :decoupled, type: Boolean, desc: 'Sample is decoupled from structure?', default: false
optional :inventory_sample, type: Boolean, default: false
optional :molecular_mass, type: Float
optional :sum_formula, type: String
#use :root_container_params
Expand Down Expand Up @@ -431,6 +435,7 @@ class SampleAPI < Grape::API
optional :molecule_id, type: Integer
requires :container, type: Hash
optional :decoupled, type: Boolean, desc: 'Sample is decoupled from structure?', default: false
optional :inventory_sample, type: Boolean, default: false
optional :molecular_mass, type: Float
optional :sum_formula, type: String
end
Expand Down Expand Up @@ -462,6 +467,7 @@ class SampleAPI < Grape::API
stereo: params[:stereo],
molecule_name_id: params[:molecule_name_id],
decoupled: params[:decoupled],
inventory_sample: params[:inventory_sample],
molecular_mass: params[:molecular_mass],
sum_formula: params[:sum_formula]
}
Expand Down Expand Up @@ -557,3 +563,4 @@ class SampleAPI < Grape::API
end
end
end
# rubocop:enable Metrics/ClassLength

0 comments on commit 4fe35ba

Please sign in to comment.