Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def to_json_camel_case(val)
mount Chemotion::DevicesAnalysisAPI
mount Chemotion::GateAPI
mount Chemotion::ElementAPI
mount Chemotion::ExplorerAPI
mount Chemotion::ChemSpectraAPI
mount Chemotion::InstrumentAPI
mount Chemotion::MessageAPI
Expand Down
56 changes: 56 additions & 0 deletions app/api/chemotion/explorer_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module Chemotion
class ExplorerAPI < Grape::API

resource :explorer do
desc 'Fetch samples, reactions, and molecules belonging to a collection'

params do
requires :collection_id, type: Integer, desc: 'ID of the collection to explore'
end

after_validation do
@collection = current_user
.collections
.where(is_shared: false)
.find_by(id: params[:collection_id])

error!({ error: 'Collection not found' }, 404) unless @collection
end

get do
samples = @collection
.samples
.select(:id, :ancestry, :molecule_id, :name, :short_label, :sample_svg_file)

# reactions = @collection
# .reactions
# .select(:id, :name, :short_label)
reactions = @collection.reactions.includes(:reactants, :products).map do |r|
{
id: r.id,
name: r.name,
short_label: r.short_label,
starting_material_ids: r.starting_materials.pluck(:id),
reactant_ids: r.reactants.pluck(:id),
product_ids: r.products.pluck(:id),
reaction_svg_file: r.reaction_svg_file
}
end


molecule_ids = samples.pluck(:molecule_id).compact.uniq
molecules = Molecule
.where(id: molecule_ids)
.select(:id, :cano_smiles, :inchikey, :iupac_name)

{
samples: samples.as_json,
reactions: reactions.as_json,
molecules: molecules.as_json
}
end
end
end
end
13 changes: 13 additions & 0 deletions app/javascript/src/apps/mydb/elements/details/ElementDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import CellLineDetails from 'src/apps/mydb/elements/details/cellLines/CellLineDe
import VesselDetails from 'src/apps/mydb/elements/details/vessels/VesselDetails';
import VesselTemplateDetails from 'src/apps/mydb/elements/details/vessels/VesselTemplateDetails';
import VesselTemplateCreate from 'src/apps/mydb/elements/details/vessels/VesselTemplateCreate';
import ExplorerContainer from 'src/apps/mydb/elements/details/explorer/ExplorerContainer';

const tabInfoHash = {
metadata: {
Expand All @@ -45,6 +46,16 @@ const tabInfoHash = {
</span>
)
},
explorer: {
title: 'Explorer',
iconEl: (
<span>
<i className="fa fa-project-diagram" />
{/* &nbsp;&nbsp;
<i className="fa fa-pencil" /> */}
</span>
)
},
prediction: {
title: 'Synthesis Prediction',
iconEl: (
Expand Down Expand Up @@ -153,6 +164,8 @@ export default class ElementDetails extends Component {
return <MetadataContainer metadata={el} />;
case 'report':
return <ReportContainer report={el} />;
case 'explorer':
return <ExplorerContainer explorer={el} />;
case 'prediction':
//return <PredictionContainer prediction={el} />;
console.warn('Attempting to show outdated PredictionContainer')
Expand Down
Loading