From 31b616b239596c5d39be0668ba7f66aa5ef99ef7 Mon Sep 17 00:00:00 2001 From: "chia-lin.lin" Date: Tue, 3 Nov 2020 16:28:05 +0100 Subject: [PATCH 001/258] Provide a X-Vial list in Chemotion Repository for the authorized users. - Fetch data from a collection(Repo: Open Data Collection) of Compound platform. - Use compound_open_data.yml as configuration file, put aurthized user id in allowed_uids. --- app/api/chemotion/public_api.rb | 33 ++++++++++++-- app/api/helpers/compound_helpers.rb | 20 +++++++++ .../components/common/RepoXvialButton.js | 43 +++++++++++++++++-- app/assets/javascripts/libHome/RepoCommon.js | 2 +- app/assets/javascripts/libHome/RepoPubl.js | 15 ++++++- .../libHome/RepoReactionDetails.js | 2 +- app/assets/javascripts/libHome/RepoSample.js | 5 ++- .../javascripts/libHome/RepoSampleDetails.js | 4 +- app/assets/stylesheets/repo_home.scss | 22 ++++++++-- app/models/compound_open_data.rb | 2 + .../molecule_guest_list_serializer.rb | 6 ++- .../reaction_guest_list_serializer.rb | 19 +++++++- config/compound_open_data.yml.example | 5 +++ config/deploy/server_chemotion_net.rb | 2 +- config/initializers/compound_open_data.rb | 18 ++++++++ db/functions/com_xvial_v01.sql | 15 +++++++ ...170400_create_compound_open_data_locals.rb | 5 +++ ...0201103124001_create_function_com_xvial.rb | 5 +++ db/views/compound_open_data_locals_v01.sql | 5 +++ 19 files changed, 205 insertions(+), 23 deletions(-) create mode 100644 app/api/helpers/compound_helpers.rb create mode 100644 app/models/compound_open_data.rb create mode 100644 config/compound_open_data.yml.example create mode 100644 config/initializers/compound_open_data.rb create mode 100644 db/functions/com_xvial_v01.sql create mode 100644 db/migrate/20201027170400_create_compound_open_data_locals.rb create mode 100644 db/migrate/20201103124001_create_function_com_xvial.rb create mode 100644 db/views/compound_open_data_locals_v01.sql diff --git a/app/api/chemotion/public_api.rb b/app/api/chemotion/public_api.rb index f6dfe35b0..a83d70095 100644 --- a/app/api/chemotion/public_api.rb +++ b/app/api/chemotion/public_api.rb @@ -3,7 +3,9 @@ # rubocop: disable Metrics/ClassLength require 'open-uri' +# Belong to Chemotion module module Chemotion + # API for Public data class PublicAPI < Grape::API include Grape::Kaminari helpers do @@ -26,6 +28,7 @@ def send_notification(attachment, user, status, has_error = false) ) end end + helpers CompoundHelpers namespace :public do get 'ping' do @@ -404,9 +407,27 @@ def query_ontologies(name) group by m.id ) c on c.molecule_id = molecules.id SQL - paginate(Molecule.joins(sample_join).joins(xvial_count).order("s.max_published_at desc").select( + com_config = Rails.configuration.compound_opendata + xvial_com = <<~SQL + inner join (select -1 as xvial_com, m.id molcule_id from molecules m) cod on cod.molcule_id = molecules.id + SQL + if com_config.present? + xvial_com = if com_config.allowed_uids.include?(current_user&.id) + <<~SQL + inner join ( + select count(a.x_id) as xvial_com, m.id molcule_id from molecules m left outer join com_xvial(true) a on a.x_inchikey = m.inchikey + group by m.id + ) cod on cod.molcule_id = molecules.id + SQL + else + <<~SQL + inner join (select -2 as xvial_com, m.id molcule_id from molecules m) cod on cod.molcule_id = molecules.id + SQL + end + end + paginate(Molecule.joins(sample_join).joins(xvial_count).joins(xvial_com).order("s.max_published_at desc").select( <<~SQL - molecules.*, sample_svg_file, xvial_count + molecules.*, sample_svg_file, xvial_count, xvial_com SQL )) end @@ -590,6 +611,7 @@ def query_ontologies(name) entities = Entities::ReactionEntity.represent(reaction, serializable: true) entities[:products].each do |p| pub_product = p + p[:xvialCom] = build_xvial_com(p[:molecule]['inchikey'], current_user&.id) pub_product_tag = pub_product[:tag]['taggable_data'] next if pub_product_tag.nil? @@ -599,6 +621,7 @@ def query_ontologies(name) unless current_user.present? && User.reviewer_ids.include?(current_user.id) pub_product_tag['xvial']['num'] = 'x' end + p[:xvialCom][:hasSample] = true end entities[:publication]['review']['history'] = [] entities[:literatures] = literatures unless entities.nil? || literatures.nil? || literatures.length == 0 @@ -620,6 +643,7 @@ def query_ontologies(name) end get do molecule = Molecule.find(params[:id]) + xvial_com = build_xvial_com(molecule.inchikey, current_user&.id) pub_id = Collection.public_collection_id if params[:adv_flag].present? && params[:adv_flag] == true && params[:adv_type].present? && params[:adv_type] == 'Authors' && params[:adv_val].present? adv = <<~SQL @@ -685,12 +709,15 @@ def query_ontologies(name) sample_id: s.id, reaction_ids: reaction_ids, sid: sid, xvial: xvial, showed_name: s.showed_name, pub_id: pub.id, ana_infos: ana_infos, pub_info: pub_info) end + x = published_samples.select { |s| s[:xvial].present? } + xvial_com[:hasSample] = x.length.positive? published_samples = published_samples.flatten.compact { molecule: MoleculeGuestSerializer.new(molecule).serializable_hash.deep_symbolize_keys, published_samples: published_samples, isLogin: current_user.nil? ? false : true, - isReviewer: (current_user.present? && User.reviewer_ids.include?(current_user.id)) ? true : false + isReviewer: (current_user.present? && User.reviewer_ids.include?(current_user.id)) ? true : false, + xvialCom: xvial_com } end end diff --git a/app/api/helpers/compound_helpers.rb b/app/api/helpers/compound_helpers.rb new file mode 100644 index 000000000..4a1d4bd86 --- /dev/null +++ b/app/api/helpers/compound_helpers.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# Compound data helper +module CompoundHelpers + extend Grape::API::Helpers + + def build_xvial_com(inchikey, uid) + xvial_com = { allowed: false, hasData: 0, data: [], hasSample: false } + com_config = Rails.configuration.compound_opendata + return xvial_com unless com_config.present? && inchikey.present? && uid.present? + + xvial_com = CompoundOpenData.where('x_inchikey = ?', inchikey).order(x_created_at: :desc) + { + allowed: com_config.allowed_uids.include?(uid), + hasData: xvial_com.length.positive?, + data: com_config.allowed_uids.include?(uid) ? xvial_com : [], + hasSample: false + } + end +end diff --git a/app/assets/javascripts/components/common/RepoXvialButton.js b/app/assets/javascripts/components/common/RepoXvialButton.js index d084b035c..0463219cb 100644 --- a/app/assets/javascripts/components/common/RepoXvialButton.js +++ b/app/assets/javascripts/components/common/RepoXvialButton.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Modal, Button, OverlayTrigger, Tooltip, FormControl } from 'react-bootstrap'; +import { Modal, Button, OverlayTrigger, Tooltip, FormControl, Table } from 'react-bootstrap'; +import uuid from 'uuid'; import RepositoryFetcher from '../fetchers/RepositoryFetcher'; import NotificationActions from '../actions/NotificationActions'; @@ -13,6 +14,40 @@ const registedCompoundTooltip = ( ); +const listCom = (xvialCom) => { + if (!xvialCom.allowed) return
; + const listComData = xvialCom.hasData ? ( + xvialCom.data.map(x => ( + + {x.x_data.xid} + {x.x_data.provided_by} + {x.x_created_at} + {x.x_short_label} + {x.x_data.origin_id} + + )) + ) : (No Data found in Compound platform.); + return ( +
+

Reference (data from Compound platform)

+ + + + + + + + + + + + {listComData} + +
X-VialProvided byCreated atShort label of SampleName of origin Sample
+
+ ); +}; + export default class RepoXvialButton extends React.Component { constructor(props) { super(props); @@ -69,7 +104,7 @@ export default class RepoXvialButton extends React.Component { render() { const { dataModalShow, requestModalShow } = this.state; const { - isEditable, isLogin, data, allowRequest + isEditable, isLogin, data, allowRequest, xvialCom } = this.props; const hasData = !!(data && data !== ''); const compoundLink = hasData ? ( @@ -78,11 +113,11 @@ export default class RepoXvialButton extends React.Component { ) : null; const dataModal = ( - this.closeModal()} backdrop="static"> + this.closeModal()} backdrop="static"> Compound X-vial number { this.xInput = m; }} /> -
+ {listCom(xvialCom)}  
diff --git a/app/assets/javascripts/libHome/RepoCommon.js b/app/assets/javascripts/libHome/RepoCommon.js index 50e81f8cc..64e552248 100644 --- a/app/assets/javascripts/libHome/RepoCommon.js +++ b/app/assets/javascripts/libHome/RepoCommon.js @@ -970,7 +970,7 @@ class RenderAnalysisHeader extends Component {   Product  - +  

diff --git a/app/assets/javascripts/libHome/RepoPubl.js b/app/assets/javascripts/libHome/RepoPubl.js index 9bc89e80f..85ba92d52 100644 --- a/app/assets/javascripts/libHome/RepoPubl.js +++ b/app/assets/javascripts/libHome/RepoPubl.js @@ -19,6 +19,17 @@ import AutoCompleteInput from '../components/search/AutoCompleteInput'; import StructureEditorModal from '../components/structure_editor/StructureEditorModal'; import Formula from '../components/common/Formula'; +const xvialTag = (element, hasXvial = null) => { + const hasX = hasXvial || (element.xvial_count && element.xvial_count > 0); + let hasXCom = hasX && (element.xvial_com && element.xvial_com !== 0); + if (element.xvial_com === -1 || element.xvial_com === -2) { + hasXCom = hasX; + } else { + hasXCom = (element.xvial_com > 0); + } + return (); +}; + const svgTag = (path, klassName, isPubElement) => { const popHover = ( @@ -56,7 +67,7 @@ const renderReaction = (element, currentElement, isPubElement) => { - {element.xvial_count && element.xvial_count > 0 ? : null} + {xvialTag(element)} ); @@ -306,7 +317,7 @@ export default class RepoPubl extends Component { {molecule.iupac_name} {pubchemInfo ? : null } - {molecule.xvial_count && molecule.xvial_count > 0 ? : null } + {xvialTag(molecule)} diff --git a/app/assets/javascripts/libHome/RepoReactionDetails.js b/app/assets/javascripts/libHome/RepoReactionDetails.js index c6a53c14a..6e5aec189 100644 --- a/app/assets/javascripts/libHome/RepoReactionDetails.js +++ b/app/assets/javascripts/libHome/RepoReactionDetails.js @@ -314,7 +314,7 @@ export default class RepoReactionDetails extends Component { return
; } const pdInfos = (this.props.reaction.infos && this.props.reaction.infos.pd_infos && this.props.reaction.infos.pd_infos[product && product.id]) || ''; - const productHeader = (typeof (product) !== 'undefined' && product) ? this.updateRepoXvial()} /> : ; + const productHeader = (typeof (product) !== 'undefined' && product) ? this.updateRepoXvial()} xvialCom={product.xvialCom} /> : ; const specSample = (type === 'Sample' && typeof (product) !== 'undefined' && product) ? new Sample(product) : null; const analysesView = analyses.map((analysis) => { const kind = analysis.extended_metadata && analysis.extended_metadata.kind && analysis.extended_metadata['kind'].split('|').pop().trim(); diff --git a/app/assets/javascripts/libHome/RepoSample.js b/app/assets/javascripts/libHome/RepoSample.js index 3ee525614..bcf06e1d3 100644 --- a/app/assets/javascripts/libHome/RepoSample.js +++ b/app/assets/javascripts/libHome/RepoSample.js @@ -76,8 +76,9 @@ export default class RepoSample extends Component { render() { const { sample, pubData, tagData, isPublished, - canComment, handleCommentBtn, isLogin, isReviewer + canComment, handleCommentBtn, isLogin, isReviewer, element } = this.props; + const { xvialCom } = element; const { expandSA } = this.state; const affiliationMap = AffiliationMap(sample.affiliation_ids); @@ -110,7 +111,7 @@ export default class RepoSample extends Component {       - this.updateRepoXvial(sample.molecule_id)} /> + this.updateRepoXvial(sample.molecule_id)} xvialCom={xvialCom} /> {IconLicense(sample.license, (sample.author_ids.length > 1))}   diff --git a/app/assets/javascripts/libHome/RepoSampleDetails.js b/app/assets/javascripts/libHome/RepoSampleDetails.js index 5557d6c9a..51a8b1a04 100644 --- a/app/assets/javascripts/libHome/RepoSampleDetails.js +++ b/app/assets/javascripts/libHome/RepoSampleDetails.js @@ -75,7 +75,7 @@ export default class RepoSampleDetails extends Component { } const { - molecule, isLogin, isReviewer + molecule, isLogin, isReviewer, xvialCom } = element; const idyLogin = typeof isLogin === 'undefined' ? true : isLogin; @@ -158,7 +158,7 @@ export default class RepoSampleDetails extends Component { /> : '' } {canClose ? : ''} - +
{details}
diff --git a/app/assets/stylesheets/repo_home.scss b/app/assets/stylesheets/repo_home.scss index cf7edc2b3..8cbc491e7 100644 --- a/app/assets/stylesheets/repo_home.scss +++ b/app/assets/stylesheets/repo_home.scss @@ -77,17 +77,31 @@ $bs-successcolor: #5cb85c; } } -.xvial-span { - display: flex; +@mixin xvial-span-base { justify-content: center; font-size: 80%; width: 22px; height: 22px; - color: $bs-primarycolor; padding: 2px; - border: 2px solid $bs-primarycolor; border-radius: 3px; background-color: white; + color: orange; // $bs-defaultcolor; + border: 2px solid orange; // $bs-defaultcolor; +} + +.xvial-span { + @include xvial-span-base; + display: none; +} + +.xvial { + display: flex; + color: $bs-primarycolor; +} + +.xvial-com { + display: flex; + border: 2px solid $bs-primarycolor; } .repo-registed-compound-desc { diff --git a/app/models/compound_open_data.rb b/app/models/compound_open_data.rb new file mode 100644 index 000000000..7d0e9fb37 --- /dev/null +++ b/app/models/compound_open_data.rb @@ -0,0 +1,2 @@ +class CompoundOpenData < ActiveRecord::Base +end diff --git a/app/serializers/molecule_guest_list_serializer.rb b/app/serializers/molecule_guest_list_serializer.rb index 0a93309bf..21db5779b 100644 --- a/app/serializers/molecule_guest_list_serializer.rb +++ b/app/serializers/molecule_guest_list_serializer.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + +# molecule list class for guest class MoleculeGuestListSerializer < ActiveModel::Serializer - attributes :id, :iupac_name, :inchikey, :inchistring, :sum_formular, - :molecule_svg_file, :tag, :sample_svg_file, :xvial_count + attributes :id, :iupac_name, :inchikey, :inchistring, :sum_formular, :molecule_svg_file, :tag, :sample_svg_file, :xvial_count, :xvial_com end diff --git a/app/serializers/reaction_guest_list_serializer.rb b/app/serializers/reaction_guest_list_serializer.rb index 6ff67bc26..771e3e5f6 100644 --- a/app/serializers/reaction_guest_list_serializer.rb +++ b/app/serializers/reaction_guest_list_serializer.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + +# reaction list class for guest class ReactionGuestListSerializer < ActiveModel::Serializer - attributes :id, :name, :reaction_svg_file, :tag, :xvial_count + attributes :id, :name, :reaction_svg_file, :tag, :xvial_count, :xvial_com def xvial_count xvial_count = <<~SQL @@ -7,4 +10,18 @@ def xvial_count SQL ReactionsSample.joins(xvial_count).where(type: 'ReactionsProductSample', reaction_id: id).length end + + def xvial_com + com_config = Rails.configuration.compound_opendata + return -1 unless com_config.present? + + return -2 unless com_config.allowed_uids.include?(scope.current_user&.id) + + xvial_com = <<~SQL + inner join samples s on reactions_samples.sample_id = s.id and s.deleted_at is null + inner join molecules m on m.id = s.molecule_id + inner join com_xvial(true) a on a.x_inchikey = m.inchikey + SQL + ReactionsSample.joins(xvial_com).where(type: 'ReactionsProductSample', reaction_id: id).length + end end diff --git a/config/compound_open_data.yml.example b/config/compound_open_data.yml.example new file mode 100644 index 000000000..40fe4e345 --- /dev/null +++ b/config/compound_open_data.yml.example @@ -0,0 +1,5 @@ +development: + :allowed_uids: [123,456] + +production: + :allowed_uids: [123,456] diff --git a/config/deploy/server_chemotion_net.rb b/config/deploy/server_chemotion_net.rb index db056ed32..227de1307 100644 --- a/config/deploy/server_chemotion_net.rb +++ b/config/deploy/server_chemotion_net.rb @@ -4,7 +4,7 @@ set :repo_url, 'git@git.scc.kit.edu:ComPlat/chemotion_REPO.git' set :branch, 'server_chemotion_net' -before 'deploy:migrate', 'deploy:backup' +#before 'deploy:migrate', 'deploy:backup' server 'www.chemotion.net', user: user, roles: %w{app web db} diff --git a/config/initializers/compound_open_data.rb b/config/initializers/compound_open_data.rb new file mode 100644 index 000000000..dddac63d7 --- /dev/null +++ b/config/initializers/compound_open_data.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +if File.exist? Rails.root.join('config', 'compound_open_data.yml') + compound_opendata = Rails.application.config_for :compound_open_data + + Rails.application.configure do + config.compound_opendata = ActiveSupport::OrderedOptions.new + config.compound_opendata.allowed_uids = compound_opendata[:allowed_uids] + sql = ActiveRecord::Base.send(:sanitize_sql_array, ['select to_regclass(?)::text as table_name', 'compound_open_data']) + table_name = ActiveRecord::Base.connection.exec_query(sql).to_a[0]['table_name'] + CompoundOpenData.table_name = table_name.present? ? table_name : 'compound_open_data_locals' + end +else + CompoundOpenData.table_name = 'compound_open_data_locals' + Rails.application.configure do + config.compound_opendata = nil + end +end diff --git a/db/functions/com_xvial_v01.sql b/db/functions/com_xvial_v01.sql new file mode 100644 index 000000000..d8707d121 --- /dev/null +++ b/db/functions/com_xvial_v01.sql @@ -0,0 +1,15 @@ +CREATE OR REPLACE FUNCTION public.com_xvial(p_allow boolean DEFAULT false) + RETURNS SETOF compound_open_data_locals + LANGUAGE plpgsql +AS $function$ +begin + if p_allow IS false then + return QUERY SELECT compound_open_data_locals.* FROM compound_open_data_locals; + elsif EXISTS(select * from to_regclass('compound_open_data') where to_regclass is not null) then + RETURN QUERY SELECT compound_open_data.* FROM compound_open_data; + else + return QUERY SELECT compound_open_data_locals.* FROM compound_open_data_locals; + end if; +END +$function$ +; diff --git a/db/migrate/20201027170400_create_compound_open_data_locals.rb b/db/migrate/20201027170400_create_compound_open_data_locals.rb new file mode 100644 index 000000000..6763c60e3 --- /dev/null +++ b/db/migrate/20201027170400_create_compound_open_data_locals.rb @@ -0,0 +1,5 @@ +class CreateCompoundOpenDataLocals < ActiveRecord::Migration + def change + create_view :compound_open_data_locals + end +end diff --git a/db/migrate/20201103124001_create_function_com_xvial.rb b/db/migrate/20201103124001_create_function_com_xvial.rb new file mode 100644 index 000000000..64e9ef495 --- /dev/null +++ b/db/migrate/20201103124001_create_function_com_xvial.rb @@ -0,0 +1,5 @@ +class CreateFunctionComXvial < ActiveRecord::Migration + def change + create_function :com_xvial + end +end diff --git a/db/views/compound_open_data_locals_v01.sql b/db/views/compound_open_data_locals_v01.sql new file mode 100644 index 000000000..9204c07d2 --- /dev/null +++ b/db/views/compound_open_data_locals_v01.sql @@ -0,0 +1,5 @@ +SELECT c.* FROM ( +SELECT null::INTEGER as x_id, null::INTEGER as x_sample_id, null::jsonb as x_data, null::timestamp as x_created_at, null::timestamp as x_updated_at, + null::varchar as x_inchikey, null::varchar as x_sum_formular, null::varchar as x_cano_smiles, null::varchar as x_external_label, null::varchar as x_short_label, + null::varchar as x_name, null::jsonb as x_stereo +) c WHERE c.x_id is not null From ee52bf79573b284470df8ac4ca36063ba7b8bba1 Mon Sep 17 00:00:00 2001 From: "chia-lin.lin" Date: Fri, 20 Nov 2020 18:20:17 +0100 Subject: [PATCH 002/258] add xvial and type check --- app/api/chemotion/search_api.rb | 24 ++++++++++++++++--- .../components/common/RepoXvialButton.js | 1 + .../reaction_guest_list_serializer.rb | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/api/chemotion/search_api.rb b/app/api/chemotion/search_api.rb index d208de5e6..9ae96c416 100644 --- a/app/api/chemotion/search_api.rb +++ b/app/api/chemotion/search_api.rb @@ -199,11 +199,29 @@ def serialization_by_elements_and_page(elements, page = 1, molecule_sort = false group by m.id ) c on c.molecule_id = molecules.id SQL - molecules = paginate(Molecule.joins(:samples).joins(xvial_count).where("samples.id in (?)", samples).includes(:tag)).select( + com_config = Rails.configuration.compound_opendata + xvial_com = <<~SQL + inner join (select -1 as xvial_com, m.id molcule_id from molecules m) cod on cod.molcule_id = molecules.id + SQL + if com_config.present? + xvial_com = if com_config.allowed_uids.include?(current_user&.id) + <<~SQL + inner join ( + select count(a.x_id) as xvial_com, m.id molcule_id from molecules m left outer join com_xvial(true) a on a.x_inchikey = m.inchikey + group by m.id + ) cod on cod.molcule_id = molecules.id + SQL + else + <<~SQL + inner join (select -2 as xvial_com, m.id molcule_id from molecules m) cod on cod.molcule_id = molecules.id + SQL + end + end + molecules = paginate(Molecule.joins(:samples).joins(xvial_count).joins(xvial_com).where("samples.id in (?)", samples).includes(:tag)).select( <<~SQL - molecules.*, max(samples.sample_svg_file) sample_svg_file, xvial_count + molecules.*, max(samples.sample_svg_file) sample_svg_file, xvial_count, xvial_com SQL - ).group('molecules.id, xvial_count').uniq + ).group('molecules.id, xvial_count, xvial_com').uniq serialized_molecules = molecules.map { |m| MoleculeGuestListSerializer.new(m).serializable_hash } paginated_reaction_ids = Kaminari.paginate_array(reaction_ids).page(page).per(page_size) serialized_reactions = Reaction.find(paginated_reaction_ids).map do |reaction| diff --git a/app/assets/javascripts/components/common/RepoXvialButton.js b/app/assets/javascripts/components/common/RepoXvialButton.js index 0463219cb..4dad172a6 100644 --- a/app/assets/javascripts/components/common/RepoXvialButton.js +++ b/app/assets/javascripts/components/common/RepoXvialButton.js @@ -15,6 +15,7 @@ const registedCompoundTooltip = ( ); const listCom = (xvialCom) => { + if (typeof xvialCom === 'undefined') return
; if (!xvialCom.allowed) return
; const listComData = xvialCom.hasData ? ( xvialCom.data.map(x => ( diff --git a/app/serializers/reaction_guest_list_serializer.rb b/app/serializers/reaction_guest_list_serializer.rb index 771e3e5f6..14f4b7a6e 100644 --- a/app/serializers/reaction_guest_list_serializer.rb +++ b/app/serializers/reaction_guest_list_serializer.rb @@ -15,7 +15,7 @@ def xvial_com com_config = Rails.configuration.compound_opendata return -1 unless com_config.present? - return -2 unless com_config.allowed_uids.include?(scope.current_user&.id) + return -2 unless com_config.allowed_uids.include?(scope&.current_user&.id) xvial_com = <<~SQL inner join samples s on reactions_samples.sample_id = s.id and s.deleted_at is null From bf96a8d3fca65a42950275a03ae84c2b4ce5993c Mon Sep 17 00:00:00 2001 From: Paggy Date: Fri, 20 Nov 2020 17:34:33 +0100 Subject: [PATCH 003/258] readonly for nmr --- app/packs/src/apps/mydb/elements/details/ViewSpectra.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/packs/src/apps/mydb/elements/details/ViewSpectra.js b/app/packs/src/apps/mydb/elements/details/ViewSpectra.js index 8b160e9db..ea04d557c 100644 --- a/app/packs/src/apps/mydb/elements/details/ViewSpectra.js +++ b/app/packs/src/apps/mydb/elements/details/ViewSpectra.js @@ -422,7 +422,7 @@ class ViewSpectra extends React.Component { JSON.stringify(selectedIntegration), JSON.stringify(selectedMutiplicity), predict, - handleSubmit, + sample.can_update === true ? handleSubmit : this.updateROPredict, keepPred, waveLengthStr, cyclicvolta, @@ -565,7 +565,7 @@ class ViewSpectra extends React.Component { } if (baseOps.length === 0) { - baseOps = [{ name: '- -', value: this.predictOp }]; + baseOps = [{ name: 'predict', value: this.predictOp }]; } return baseOps; From 1b71e0d640e92470934938e13b9c9615bff6b38c Mon Sep 17 00:00:00 2001 From: "chia-lin.lin" Date: Thu, 3 Dec 2020 10:01:09 +0100 Subject: [PATCH 004/258] trim data from orcid --- app/models/user.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ea9ab3785..08ebad3f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -217,8 +217,9 @@ def orcid_checker return if orcid.nil? result = Chemotion::OrcidService.record_person(orcid) - oc_given_names = result&.person&.given_names - oc_family_name = result&.person&.family_name + oc_given_names = result&.person&.given_names&.strip + oc_family_name = result&.person&.family_name&.strip + if result.nil? errors.add(:orcid, ' does not exist! Please check.') elsif oc_given_names&.casecmp(first_name) != 0 || oc_family_name&.casecmp(last_name) != 0 From 1f753c99e3754fb5ed3dce728476e5c3a2814541 Mon Sep 17 00:00:00 2001 From: "chia-lin.lin" Date: Wed, 2 Dec 2020 11:37:37 +0100 Subject: [PATCH 005/258] refresh embargo list --- .../components/actions/PublicActions.js | 11 +++++++++++ .../javascripts/components/stores/PublicStore.js | 15 ++++++++++++++- app/assets/javascripts/libHome/RepoReview.js | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/components/actions/PublicActions.js b/app/assets/javascripts/components/actions/PublicActions.js index da7feb71e..cd4540821 100644 --- a/app/assets/javascripts/components/actions/PublicActions.js +++ b/app/assets/javascripts/components/actions/PublicActions.js @@ -383,6 +383,17 @@ class PublicActions { } } + getEmbargoBundle() { + return (dispatch) => { + RepositoryFetcher.fetchEmbargoCollections() + .then((result) => { + dispatch(result) + }).catch((errorMessage) => { + console.log(errorMessage) + }); + } + } + publishedStatics() { return (dispatch) => { PublicFetcher.publishedStatics() diff --git a/app/assets/javascripts/components/stores/PublicStore.js b/app/assets/javascripts/components/stores/PublicStore.js index 362820671..718450f9b 100644 --- a/app/assets/javascripts/components/stores/PublicStore.js +++ b/app/assets/javascripts/components/stores/PublicStore.js @@ -61,6 +61,7 @@ class PublicStore { handleEmbargoMove: PublicActions.moveEmbargo, handleEmbargoAssign: PublicActions.assignEmbargo, handleRefreshPubElements: PublicActions.refreshPubElements, + handleRefreshEmbargoBundles: PublicActions.getEmbargoBundle, }); } @@ -315,6 +316,18 @@ class PublicStore { } } + handleRefreshEmbargoBundles(result) { + const cols = result.repository; + const { current_user } = result; + const bundles = []; + if (cols && cols.length > 0) { + cols.forEach((col) => { + bundles.push({ value: col.id, name: col.label, label: col.label }); + }); + } + this.setState({ bundles, current_user }); + } + handleDisplayEmbargoElement(result) { const publication = (result.element && result.element.publication) || {}; @@ -353,7 +366,7 @@ class PublicStore { } else { alert(result.message); // refresh embargo list - PublicActions.fetchEmbargoBundle(); + PublicActions.getEmbargoBundle(); // refresh element list PublicActions.getElements( this.selectType, this.selectState, this.searchType, diff --git a/app/assets/javascripts/libHome/RepoReview.js b/app/assets/javascripts/libHome/RepoReview.js index 1a9784b1f..d860eb8fb 100644 --- a/app/assets/javascripts/libHome/RepoReview.js +++ b/app/assets/javascripts/libHome/RepoReview.js @@ -87,7 +87,7 @@ export default class RepoReview extends Component { componentDidMount() { PublicStore.listen(this.onChange); PublicActions.getElements.defer(); - PublicActions.fetchEmbargoBundle(); + PublicActions.getEmbargoBundle(); } componentWillUnmount() { From b6e4fd00e2ab7283a6c8875a6b3f945722ab1a96 Mon Sep 17 00:00:00 2001 From: "chia-lin.lin" Date: Wed, 2 Dec 2020 00:06:42 +0100 Subject: [PATCH 006/258] add a button to redirect from db view to publication view --- .../javascripts/components/PublishCommon.js | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/components/PublishCommon.js b/app/assets/javascripts/components/PublishCommon.js index 3dc367290..5a3fad528 100644 --- a/app/assets/javascripts/components/PublishCommon.js +++ b/app/assets/javascripts/components/PublishCommon.js @@ -240,39 +240,40 @@ const LabelPublication = ({ element }) => { const time = new Date(publication.published_at || publication.doi_reg_at); const formattedTime = `${time.getDate()}-${time.getMonth() + 1}-${time.getFullYear()} `; const contributor = publication.contributors && publication.contributors.name; - const publishedBy = publication.creators && publication.creators[0] && publication.creators[0].name; - const tooltipText = `Published by ${contributor == null ? publishedBy : contributor} on ${formattedTime}`; + const publishedBy = publication.creators && publication.creators[0] && + publication.creators[0].name; + let tooltipText = `Published by ${contributor == null ? publishedBy : contributor} on ${formattedTime}`; const schemeOnly = (element && element.publication && element.publication.taggable_data && element.publication.taggable_data.scheme_only === true) || false; - const pubDoi = (element.type === 'reaction' && schemeOnly === true) ? `/home/publications/reactions/${element.id}` : `https://dx.doi.org/${publication.doi}` - - - if (publication.published_at) { + let openUrl = (element.type === 'reaction' && schemeOnly === true) ? `/home/publications/reactions/${element.id}` : `https://dx.doi.org/${publication.doi}`; + let btnStyle = 'default'; + if (!publication.published_at && element.publication) { + const pub = element.publication; + let pubCreatedAt = new Date(pub.created_at); + pubCreatedAt = `${pubCreatedAt.getDate()}-${pubCreatedAt.getMonth() + 1}-${pubCreatedAt.getFullYear()} `; + tooltipText = `Submitted by ${contributor == null ? publishedBy : contributor} on ${pubCreatedAt}`; + openUrl = `/pid/${element.publication.id}`; + btnStyle = 'success'; + } + if (publication.published_at || element.publication) { return ( {tooltipText}} onClick={e => e.stopPropagation()} > -