diff --git a/.vscode/launch.json b/.vscode/launch.json index 1c021104d..ec5c149eb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,14 +10,16 @@ "request": "attach", "type": "pwa-chrome", "urlFilter": "http://127.0.0.1:8080/*", - "webRoot": "${workspaceFolder}" + "webRoot": "${workspaceFolder}", + "smartStep": true }, { "type": "chrome", "request": "launch", "name": "Launch Chrome against localhost", "url": "http://127.0.0.1:8080", - "webRoot": "${workspaceFolder}" + "webRoot": "${workspaceFolder}", + "smartStep": true } ] } diff --git a/jobconfigs/fragalysis-job-spec-1.1.json b/jobconfigs/fragalysis-job-spec-1.1.json deleted file mode 100644 index 0725e4157..000000000 --- a/jobconfigs/fragalysis-job-spec-1.1.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "global": { - "job_dir": "fragalysis-jobs/{username}/{job_name}-{timestamp}", - "inputs_dir": "fragalysis-files/{target}", - "protein_id": "{selected_protein}" - }, - "precompilation_ignore": ["job_dir", "protein_id"], - "fragalysis-jobs": [ - { - "job_collection": "fragmenstein", - "job_name": "fragmenstein-combine", - "job_version": "1.0.0", - "inputs": { - "fragments": { - "type": "array", - "uniqueItems": true, - "format": "chemical/x-mdl-molfile", - "items": { - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}.mol", - "enumNames": "{item}" - } - }, - "protein": { - "type": "string", - "format": "chemical/x-pdb", - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}_apo-desolv.pdb", - "enumNames": "{item}" - } - }, - "options": { - "outfile": { - "value": "{job_dir}/results_merged.sdf", - "ui:widget": "hidden" - }, - "count": { - "type": "integer", - "default": 5 - }, - "smilesFieldName": { - "type": "string", - "default": "original SMILES", - "ui:widget": "hidden" - }, - "fragIdField": { - "type": "string", - "default": "_Name", - "ui:widget": "hidden" - }, - "proteinFieldName": { - "type": "string", - "default": "ref_pdb", - "ui:widget": "hidden" - }, - "proteinFieldValue": { - "type": "string", - "default": "{protein_id}", - "ui:widget": "hidden" - } - }, - "outputs": { - "outputs": { "type": "string" } - }, - "results": ["Merged molecules"] - } - ] -} diff --git a/jobconfigs/fragalysis-job-spec-1.2.json b/jobconfigs/fragalysis-job-spec-1.2.json deleted file mode 100644 index 813b4d638..000000000 --- a/jobconfigs/fragalysis-job-spec-1.2.json +++ /dev/null @@ -1,190 +0,0 @@ -{ - "global": { - "job_dir": "fragalysis-jobs/{username}/{job_name}-{timestamp}", - "protein_id": "{selected_protein}" - }, - "precompilation_ignore": ["job_dir", "protein_id"], - "fragalysis-jobs": [ - { - "job_collection": "fragmenstein", - "job_name": "fragmenstein-combine", - "job_version": "1.0.0", - "inputs": { - "fragments": { - "type": "array", - "uniqueItems": true, - "format": "chemical/x-mdl-molfile", - "items": { - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}.mol", - "enumNames": "{item}" - } - }, - "protein": { - "type": "string", - "format": "chemical/x-pdb", - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}_apo-desolv.pdb", - "enumNames": "{item}" - } - }, - "options": { - "outfile": { - "default": "{job_dir}/merged.sdf", - "ui:widget": "hidden" - }, - "count": { - "type": "integer", - "default": 5 - }, - "smilesFieldName": { - "type": "string", - "default": "original SMILES", - "ui:widget": "hidden" - }, - "fragIdField": { - "type": "string", - "default": "_Name", - "ui:widget": "hidden" - }, - "proteinFieldName": { - "type": "string", - "default": "ref_pdb", - "ui:widget": "hidden" - }, - "proteinFieldValue": { - "type": "string", - "default": "{protein_id}", - "ui:widget": "hidden" - } - }, - "outputs": { - "outputs": { "type": "string" } - }, - "results": ["Merged molecules"] - }, - - { - "job_collection": "fragmenstein", - "job_name": "fragmenstein-combine-multi-scoring", - "job_version": "1.0.0", - "inputs": { - "fragments": { - "type": "array", - "uniqueItems": true, - "format": "chemical/x-mdl-molfile", - "items": { - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}.mol", - "enumNames": "{item}" - } - }, - "protein": { - "type": "string", - "format": "chemical/x-pdb", - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}_apo-desolv.pdb", - "enumNames": "{item}" - } - }, - "options": { - "outfile": { - "default": "{job_dir}/merged.sdf", - "ui:widget": "hidden" - }, - "count": { - "type": "integer", - "default": 5 - }, - "smilesFieldName": { - "type": "string", - "default": "original SMILES", - "ui:widget": "hidden" - }, - "fragIdField": { - "type": "string", - "default": "_Name", - "ui:widget": "hidden" - }, - "proteinFieldName": { - "type": "string", - "default": "ref_pdb", - "ui:widget": "hidden" - }, - "proteinFieldValue": { - "type": "string", - "value": "{protein_id}", - "ui:widget": "hidden" - } - }, - "outputs": { - "outputs": { "type": "string" } - }, - "results": ["Merged molecules"] - }, - - { - "job_collection": "fragmenstein", - "job_name": " fragmenstein-place-string", - "job_version": "1.0.0", - "inputs": { - "fragments": { - "type": "array", - "uniqueItems": true, - "format": "chemical/x-mdl-molfile", - "items": { - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}.mol", - "enumNames": "{item}" - } - }, - "protein": { - "type": "string", - "format": "chemical/x-pdb", - "from": "lhs", - "enum": "{inputs_dir}/{target}-{item}_apo-desolv.pdb", - "enumNames": "{item}" - } - }, - "options": { - "outfile": { - "default": "{job_dir}/merged.sdf", - "ui:widget": "hidden" - }, - "count": { - "type": "integer", - "default": 5 - }, - "smilesFieldName": { - "type": "string", - "default": "original SMILES", - "ui:widget": "hidden" - }, - "smiles": { - "items": { - "ui:widget": "textarea" - } - }, - "fragIdField": { - "type": "string", - "default": "_Name", - "ui:widget": "hidden" - }, - "proteinFieldName": { - "type": "string", - "default": "ref_pdb", - "ui:widget": "hidden" - }, - "proteinFieldValue": { - "type": "string", - "value": "{protein_id}", - "ui:widget": "hidden" - } - }, - "outputs": { - "outputs": { "type": "string" } - }, - "results": ["Merged molecules"] - } - ] -} diff --git a/jobconfigs/fragmenstein-combine-multi-scoring.json b/jobconfigs/fragmenstein-combine-multi-scoring.json deleted file mode 100644 index 821d9a192..000000000 --- a/jobconfigs/fragmenstein-combine-multi-scoring.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "application": { - "application_id": "datamanagerjobs.squonk.it", - "kind": "DataManagerJob", - "latest_version": "v3" - }, - "category": "comp chem", - "collection": "fragmenstein", - "command": "nextflow -log {{ DM_INSTANCE_DIRECTORY }}/nextflow.log run {{ CODE_DIRECTORY|default('/code') }}/frag_merge.nf --fragments '{{ fragments|join(\",\") }}' --protein '{{ protein }}' --outfile '{{ outfile }}' {% if count is defined %}--count {{ count }}{% endif %} --ref_mols_prop ref_mols {% if fragIdField %}--frag_id_field '{{ fragIdField }}'{% endif %} {% if smilesFieldName %}--smiles_prop '{{ smilesFieldName }}'{% endif %} {% if proteinFieldName %}--protein_prop_name '{{ proteinFieldName }}'{% endif %} {% if proteinFieldValue %}--protein_prop_value '{{ proteinFieldValue }}'{% endif %} {% if minNum is defined %}--min_num {{ minNum }}{% endif %} {% if maxNum is defined %}--max_num {{ maxNum }}{% endif %} {% if maxDist is defined %}--max_dist {{ maxDist }}{% endif %} {% if resultsDir is defined %}--publish_dir '{{ resultsDir }}'{% endif %} -with-trace {{ DM_INSTANCE_DIRECTORY }}/trace.txt -with-report {{ DM_INSTANCE_DIRECTORY }}/report.html", - "command_encoding": "JINJA2_3_0", - "description": "Given multiple fragment molecules generate pairs or tripples of these and for each set generate a merged molecule that combines aspects of those fragments. The merged molecules are minimised within the context of the protein and written to a SD-file.", - "doc_url": "https://gitlab.com/api/v4/projects/33094905/repository/files/data-manager%2fdocs%2ffragmenstein%2ffragmenstein.md/raw", - "exchange_rate": "10.0", - "id": 38, - "image_name": "registry.gitlab.com/informaticsmatters/squonk-fragmenstein/nextflow", - "image_project_directory": "/data", - "image_tag": "stable", - "image_type": "NEXTFLOW", - "image_working_directory": "/data", - "job": "fragmenstein-combine-multi-scoring", - "keywords": ["fragmenstein", "fbdd"], - "name": "Combine combinations of fragments using Fragmenstein", - "variables": { - "inputs": "{\"type\": \"object\", \"required\": [\"fragments\", \"protein\"], \"properties\": {\"fragments\": {\"title\": \"Fragment molecules\", \"multiple\": true, \"mime-types\": [\"chemical/x-mdl-molfile\", \"chemical/x-mdl-sdfile\"], \"type\": \"file\"}, \"protein\": {\"title\": \"PDB file for protein\", \"mime-types\": [\"chemical/x-pdb\"], \"type\": \"file\"}}}", - "options": "{\"type\": \"object\", \"required\": [\"outfile\"], \"properties\": {\"outfile\": {\"title\": \"Output file name\", \"type\": \"string\", \"default\": \"merged.sdf\"}, \"count\": {\"title\": \"Number of molecules to generate\", \"type\": \"integer\", \"default\": 1, \"minimum\": 1}, \"keepHydrogens\": {\"title\": \"Keep hydrogens in the outputs\", \"type\": \"boolean\", \"default\": false}, \"minNum\": {\"title\": \"Minimum number to combine\", \"type\": \"integer\", \"default\": 2, \"minimum\": 2, \"maximum\": 3}, \"maxNum\": {\"title\": \"Maximum number to combine\", \"type\": \"integer\", \"default\": 2, \"minimum\": 2, \"maximum\": 3}, \"maxDist\": {\"title\": \"Maximum distance\", \"type\": \"number\", \"default\": 1.5, \"minimum\": 0}, \"fragIdField\": {\"title\": \"Input field name containing the fragment ID\", \"type\": \"string\", \"default\": \"_Name\"}, \"smilesFieldName\": {\"title\": \"Includes SMILES in output using this field name\", \"type\": \"string\"}, \"proteinFieldName\": {\"title\": \"Include PDB details in output using this field name\", \"type\": \"string\"}, \"proteinFieldValue\": {\"title\": \"Use this value for the proteinFieldName (if not specified the file name is used)\", \"type\": \"string\"}}}", - "order": { - "options": [ - "outfile", - "count", - "minNum", - "maxNum", - "maxDist", - "keepHydrogens", - "fragIdField", - "smilesFieldName", - "proteinFieldName", - "proteinFieldValue" - ] - }, - "outputs": "{\"type\": \"object\", \"properties\": {\"outputs\": {\"title\": \"Merged molecules\", \"mime-types\": [\"chemical/x-mdl-sdfile\"], \"creates\": \"{{ outfile }}\", \"type\": \"file\", \"annotation-properties\": {\"fields-descriptor\": {\"origin\": \"squonk2-job\", \"description\": \"Combine combinations of fragments using Fragmenstein\", \"fields\": {\"IDX\": {\"type\": \"string\", \"description\": \"Molecule index\", \"required\": true}, \"DDG\": {\"type\": \"number\", \"description\": \"Delta deta G\", \"required\": true}, \"RMSD\": {\"type\": \"number\", \"description\": \"RMSD from input fragments\", \"required\": true}, \"ref_mols\": {\"type\": \"string\", \"description\": \"Input fragments\", \"required\": true}, \"smiles\": {\"type\": \"string\", \"expression\": \"{{ smilesFieldName }}\", \"description\": \"Molecule SMILES\", \"required\": true}, \"protein\": {\"type\": \"string\", \"expression\": \"{{ proteinFieldName }}\", \"description\": \"PDB file used\"}}}, \"service-execution\": {\"service_ref\": \"https://discourse.squonk.it/t/job-fragmenstein/110\"}, \"derived-from\": \"fragments\"}}}}" - }, - "version": "1.0.0" -} diff --git a/jobconfigs/fragmenstein-combine.json b/jobconfigs/fragmenstein-combine.json deleted file mode 100644 index 5e9c235f9..000000000 --- a/jobconfigs/fragmenstein-combine.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "application": { - "application_id": "datamanagerjobs.squonk.it", - "kind": "DataManagerJob", - "latest_version": "v2" - }, - "category": "comp chem", - "collection": "fragmenstein", - "command": "/code/merger.py --fragments{% for fragment in fragments %} '{{ fragment }}'{% endfor %} --protein '{{ protein }}' --outfile '{{ outfile }}' --count {{ count }} {% if keepHydrogens %}--keep-hydrogens{% endif %} --ref-mols-prop-name ref_mols {% if fragIdField %}--frag-id-field '{{ fragIdField }}'{% endif %} {% if smilesFieldName %}--smiles-prop-name '{{ smilesFieldName }}'{% endif %} --work-dir {{ DM_INSTANCE_DIRECTORY }}/output", - "command_encoding": "JINJA2_3_0", - "description": "Given 2 or more fragment molecules generate a merged molecule that combines aspects of those fragments. The merged molecules are minimised within the context of the protein and results written to the Job instance directory.", - "doc_url": "https://gitlab.com/api/v4/projects/33094905/repository/files/data-manager%2fdocs%2ffragmenstein%2ffragmenstein.md/raw", - "id": 32, - "image_name": "registry.gitlab.com/informaticsmatters/squonk-fragmenstein", - "image_project_directory": "/data", - "image_tag": "stable", - "image_type": "SIMPLE", - "image_working_directory": "/data", - "job": "fragmenstein-combine", - "keywords": ["fragmenstein", "fbdd"], - "name": "Combine fragments into a single molecule", - "variables": { - "inputs": "{\"type\": \"object\", \"required\": [\"fragments\", \"protein\"], \"properties\": {\"fragments\": {\"title\": \"Fragment molecules\", \"multiple\": true, \"mime-types\": [\"chemical/x-mdl-molfile\"], \"type\": \"file\"}, \"protein\": {\"title\": \"PDB file for protein\", \"mime-types\": [\"chemical/x-pdb\"], \"type\": \"file\"}}}", - "options": "{\"type\": \"object\", \"required\": [\"outfile\", \"count\", \"keepHydrogens\"], \"properties\": {\"outfile\": {\"title\": \"Output file name\", \"type\": \"string\", \"default\": \"merged.sdf\"}, \"count\": {\"title\": \"Number of molecules to generate\", \"type\": \"integer\", \"default\": 1, \"minimum\": 1}, \"keepHydrogens\": {\"title\": \"Keep hydrogens in the outputs\", \"type\": \"boolean\", \"default\": false}, \"fragIdField\": {\"title\": \"Input field name containing the fragment ID\", \"type\": \"string\", \"default\": \"_Name\"}, \"smilesFieldName\": {\"title\": \"Includes SMILES in output using this field name\", \"type\": \"string\"}}}", - "order": { - "options": ["outfile", "count", "keepHydrogens", "fragIdField", "smilesFieldName"] - }, - "outputs": "{\"type\": \"object\", \"properties\": {\"outputs\": {\"title\": \"Merged molecules\", \"mime-types\": [\"chemical/x-mdl-sdfile\"], \"creates\": \"{{ outfile }}\", \"type\": \"file\", \"annotation-properties\": {\"fields-descriptor\": {\"origin\": \"squonk2-job\", \"description\": \"Fragmenstein combine\", \"fields\": {\"IDX\": {\"type\": \"string\", \"description\": \"Molecule index\", \"required\": true}, \"DDG\": {\"type\": \"number\", \"description\": \"Delta deta G\", \"required\": true}, \"RMSD\": {\"type\": \"number\", \"description\": \"RMSD from input fragments\", \"required\": true}, \"ref_mols\": {\"type\": \"string\", \"description\": \"Input IDs\", \"required\": true}, \"smiles\": {\"type\": \"string\", \"expression\": \"{{ smilesFieldName }}\", \"description\": \"Molecule SMILES\"}}}, \"service-execution\": {\"service_ref\": \"https://discourse.squonk.it/t/job-fragmenstein/110\"}, \"derived-from\": \"fragments\"}}}}" - }, - "version": "1.0.0" -} diff --git a/jobconfigs/fragmenstein-place-string.json b/jobconfigs/fragmenstein-place-string.json deleted file mode 100644 index 05cd947fd..000000000 --- a/jobconfigs/fragmenstein-place-string.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "application": { - "application_id": "datamanagerjobs.squonk.it", - "kind": "DataManagerJob", - "latest_version": "v3" - }, - "category": "comp chem", - "collection": "fragmenstein", - "command": "/code/merger.py --fragments{% for fragment in fragments %} '{{ fragment }}'{% endfor %} --smiles-strings {% for smi in smiles %} '{{ smi }}'{% endfor %} --protein '{{ protein }}' --outfile '{{ outfile }}' --count {{ count }} {% if keepHydrogens %}--keep-hydrogens{% endif %} --ref-mols-prop-name ref_mols {% if fragIdField %}--frag-id-field '{{ fragIdField }}'{% endif %} {% if proteinFieldName %}--protein-prop-name '{{ proteinFieldName }}'{% endif %} {% if proteinFieldValue %}--protein-prop-value '{{ proteinFieldValue }}'{% endif %} --work-dir {{ DM_INSTANCE_DIRECTORY }}/output", - "command_encoding": "JINJA2_3_0", - "description": "Place a set of user entered SMILES onto fragment molecules to generate a conformer that mimics those fragments. The placed molecules are minimised within the context of the protein and results written to a SD-file.", - "doc_url": "https://gitlab.com/api/v4/projects/33094905/repository/files/data-manager%2fdocs%2ffragmenstein%2ffragmenstein.md/raw", - "exchange_rate": "10.0", - "id": 37, - "image_name": "registry.gitlab.com/informaticsmatters/squonk-fragmenstein", - "image_project_directory": "/data", - "image_tag": "stable", - "image_type": "SIMPLE", - "image_working_directory": "/data", - "job": "fragmenstein-place-string", - "keywords": ["fragmenstein", "fbdd"], - "name": "Place molecules onto fragments", - "variables": { - "inputs": "{\"type\": \"object\", \"required\": [\"fragments\", \"protein\"], \"properties\": {\"fragments\": {\"title\": \"Fragment molecules\", \"multiple\": true, \"mime-types\": [\"chemical/x-mdl-molfile\", \"chemical/x-mdl-sdfile\"], \"type\": \"file\"}, \"protein\": {\"title\": \"PDB file for protein\", \"mime-types\": [\"chemical/x-pdb\"], \"type\": \"file\"}}}", - "options": "{\"type\": \"object\", \"required\": [\"smiles\", \"outfile\", \"count\", \"keepHydrogens\"], \"properties\": {\"smiles\": {\"title\": \"SMILES to place\", \"type\": \"array\", \"items\": {\"type\": \"string\"}}, \"outfile\": {\"title\": \"Output file name\", \"type\": \"string\", \"default\": \"merged.sdf\"}, \"count\": {\"title\": \"Number of molecules to generate\", \"type\": \"integer\", \"default\": 1, \"minimum\": 1}, \"keepHydrogens\": {\"title\": \"Keep hydrogens in the outputs\", \"type\": \"boolean\", \"default\": false}, \"fragIdField\": {\"title\": \"Input field name containing the fragment ID\", \"type\": \"string\", \"default\": \"_Name\"}, \"proteinFieldName\": {\"title\": \"Include PDB details in output using this field name\", \"type\": \"string\"}, \"proteinFieldValue\": {\"title\": \"Use this value for the proteinFieldName (if not specified the file name is used)\", \"type\": \"string\"}}}", - "order": { - "options": ["smiles", "outfile", "count", "keepHydrogens", "fragIdField", "proteinFieldName", "proteinFieldValue"] - }, - "outputs": "{\"type\": \"object\", \"properties\": {\"outputs\": {\"title\": \"Merged molecules\", \"mime-types\": [\"chemical/x-mdl-sdfile\"], \"creates\": \"{{ outfile }}\", \"type\": \"file\", \"annotation-properties\": {\"fields-descriptor\": {\"origin\": \"squonk2-job\", \"description\": \"Fragmenstein combine\", \"fields\": {\"IDX\": {\"type\": \"string\", \"description\": \"Molecule index\", \"required\": true}, \"DDG\": {\"type\": \"number\", \"description\": \"Delta deta G\", \"required\": true}, \"RMSD\": {\"type\": \"number\", \"description\": \"RMSD from input fragments\", \"required\": true}, \"ref_mols\": {\"type\": \"string\", \"description\": \"Input IDs\", \"required\": true}, \"smiles\": {\"type\": \"string\", \"expression\": \"{{ smilesFieldName }}\", \"description\": \"Molecule SMILES\"}, \"protein\": {\"type\": \"string\", \"expression\": \"{{ proteinFieldName }}\", \"description\": \"PDB file used\"}}}, \"service-execution\": {\"service_ref\": \"https://discourse.squonk.it/t/job-fragmenstein/110\"}, \"derived-from\": \"fragments\"}}}}" - }, - "version": "1.0.0" -} diff --git a/js/components/preview/projectHistoryPanel/JobConfigurationDialog.js b/js/components/preview/projectHistoryPanel/JobConfigurationDialog.js index adeaef04c..251b013bb 100644 --- a/js/components/preview/projectHistoryPanel/JobConfigurationDialog.js +++ b/js/components/preview/projectHistoryPanel/JobConfigurationDialog.js @@ -1,4 +1,4 @@ -import React, { useContext, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Box, ClickAwayListener, @@ -21,9 +21,14 @@ import { setJobConfigurationDialogOpen, setJobLauncherDialogOpen, setJobLauncherData, - refreshJobsData + refreshJobsData, + setJobList } from '../../projects/redux/actions'; -import { getSnapshotAttributesByID, jobFileTransfer } from '../../projects/redux/dispatchActions'; +import { + getJobConfigurationsFromServer, + getSnapshotAttributesByID, + jobFileTransfer +} from '../../projects/redux/dispatchActions'; import { areArraysSame } from '../../../utils/array'; import { setDisableRedirect, setDontShowShareSnapshot } from '../../snapshot/redux/actions'; import { createNewSnapshot } from '../../snapshot/redux/dispatchActions'; @@ -205,6 +210,13 @@ const JobConfigurationDialog = ({ snapshots }) => { const jobList = useSelector(state => state.projectReducers.jobList); + useEffect(() => { + if (!jobList || jobList.length === 0) + dispatch(getJobConfigurationsFromServer()).then(jobs => { + dispatch(setJobList(jobs)); + }); + }, [dispatch, jobList]); + // if (currentProject && !currentProject.user_can_use_squonk) { // setErrorMsg( // `You do not have permission to use the Squonk job launcher for ${currentProject?.target_access_string}` @@ -393,7 +405,7 @@ const JobConfigurationDialog = ({ snapshots }) => { // dispatch(setJobConfigurationDialogOpen(false)); const getFilteredJob = job => { - return jobList.find(jobFiltered => job === jobFiltered.id); + return jobList && jobList.find(jobFiltered => job === jobFiltered.id); }; const repsonse = await jobFileTransfer({ @@ -479,11 +491,12 @@ const JobConfigurationDialog = ({ snapshots }) => { className={classes.width70} disabled={false} > - {Object.values(jobList).map(item => ( - - {item.slug} - - ))} + {jobList && + Object.values(jobList).map(item => ( + + {item.slug} + + ))} { Description - {jobList.filter(jobType => jobType['id'] === values.job).map(jobType => jobType['description'])} + {jobList && + jobList.filter(jobType => jobType['id'] === values.job).map(jobType => jobType['description'])}
diff --git a/js/components/preview/withLoadingJobSpecs.js b/js/components/preview/withLoadingJobSpecs.js index 1f15941d3..d7b4fc8bf 100644 --- a/js/components/preview/withLoadingJobSpecs.js +++ b/js/components/preview/withLoadingJobSpecs.js @@ -1,14 +1,22 @@ import React, { memo, useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { getJobConfigurations } from '../projects/redux/dispatchActions'; +import { getJobConfigurationsFromServer } from '../projects/redux/dispatchActions'; +import { DJANGO_CONTEXT } from '../../utils/djangoContext'; +import { setJobList } from '../projects/redux/actions'; export const withLoadingJobSpecs = WrappedComponent => { return memo(({ ...rest }) => { const dispatch = useDispatch(); - useEffect(() => { - dispatch(getJobConfigurations()); - }, [dispatch]); + const authenticated = DJANGO_CONTEXT['authenticated']; + + //now only authenticated users can see the job specs + // useEffect(() => { + // if (authenticated) { + // const jobsList = dispatch(getJobConfigurationsFromServer()); + // dispatch(setJobList(jobsList)); + // } + // }, [dispatch, authenticated]); return ; }); diff --git a/js/components/projects/redux/dispatchActions.js b/js/components/projects/redux/dispatchActions.js index 2d87354a1..72e43538a 100644 --- a/js/components/projects/redux/dispatchActions.js +++ b/js/components/projects/redux/dispatchActions.js @@ -29,14 +29,7 @@ import { setOpenDiscourseErrorModal } from '../../../reducers/api/actions'; import moment from 'moment'; import { resetNglTrackingState } from '../../../reducers/nglTracking/dispatchActions'; -// eslint-disable-next-line import/extensions -import fragmentsteinSpec from '../../../../jobconfigs/fragmenstein-combine.json'; -// eslint-disable-next-line import/extensions -import fragmentsteinMultiSpec from '../../../../jobconfigs/fragmenstein-combine-multi-scoring.json'; -// eslint-disable-next-line import/extensions -import fragmentsteinStringSpec from '../../../../jobconfigs/fragmenstein-place-string.json'; -// eslint-disable-next-line import/extensions -import fragmentsteinOverrides from '../../../../jobconfigs/fragalysis-job-spec-1.2.json'; +import _ from 'lodash'; export const assignSnapshotToProject = ({ projectID, snapshotID, ...rest }) => (dispatch, getState) => { dispatch(resetCurrentSnapshot()); @@ -494,35 +487,70 @@ export const jobRequest = data => { }); }; -export const getJobConfigurations = () => (dispatch, getState) => { - const jobs = [ - { - id: fragmentsteinSpec.id, - name: fragmentsteinSpec.collection, - description: fragmentsteinSpec.description, - slug: fragmentsteinSpec.job, - spec: fragmentsteinSpec, - overrides: fragmentsteinOverrides, - overrideIndex: 0 - }, - { - id: fragmentsteinMultiSpec.id, - name: fragmentsteinMultiSpec.collection, - description: fragmentsteinMultiSpec.description, - slug: fragmentsteinMultiSpec.job, - spec: fragmentsteinMultiSpec, - overrides: fragmentsteinOverrides, - overrideIndex: 1 - }, - { - id: fragmentsteinStringSpec.id, - name: fragmentsteinStringSpec.collection, - description: fragmentsteinStringSpec.description, - slug: fragmentsteinStringSpec.job, - spec: fragmentsteinStringSpec, - overrides: fragmentsteinOverrides, - overrideIndex: 2 +export const getJobConfigurationsFromServer = () => async (dispatch, getState) => { + const result = []; + + const overrides = await getJobOverrides(); + if (!overrides) { + return result; + } + + const availableJobs = overrides['fragalysis-jobs'].map((job, index) => { + return { job_collection: job.job_collection, job_name: job.job_name, job_version: job.job_version, index: index }; + }); + if (!availableJobs) { + return result; + } + + for (let i = 0; i < availableJobs.length; i++) { + const job = availableJobs[i]; + let jobConfig = await getJobConfigFromServer(job.job_collection, job.job_name, job.job_version); + jobConfig = preprocessJobConfig(jobConfig); + // console.log(JSON.stringify(filteredJobConfig)); + const jobOject = { + id: jobConfig.id, + name: jobConfig.collection, + description: jobConfig.description, + slug: jobConfig.job, + spec: jobConfig, + overrides: overrides, + overrideIndex: job.index + }; + result.push(jobOject); + } + + return result; +}; + +const preprocessJobConfig = jobConfig => { + const result = { ...jobConfig }; + removePropDeep(result, 'pattern'); + return result; +}; + +const removePropDeep = (obj, propName) => { + const keys = Object.keys(obj); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + if (key === propName) { + delete obj[key]; + } else if (_.isPlainObject(obj[key])) { + removePropDeep(obj[key], propName); } - ]; - dispatch(setJobList(jobs)); + } +}; + +const getJobConfigFromServer = async (job_collection, job_name, job_version) => { + const resultCall = await api({ + url: `${base_url}/api/job_config/?job_name=${job_name.trim()}&job_version=${job_version.trim()}&job_collection=${job_collection.trim()}` + }); + + return resultCall.data; +}; + +const getJobOverrides = async () => { + const resultCall = await api({ + url: `${base_url}/api/job_override/` + }); + return resultCall.data.results[0].override; }; diff --git a/js/hooks/useGetJobDefinition.js b/js/hooks/useGetJobDefinition.js index f0550a84d..9b5b4e90a 100644 --- a/js/hooks/useGetJobDefinition.js +++ b/js/hooks/useGetJobDefinition.js @@ -25,9 +25,12 @@ export const useGetJobDefinition = jobInfo => { return useMemo(() => { if (jobInfo) { - const inputs = JSON.parse(inputsJson); - const options = JSON.parse(optionsJson); - const outputs = JSON.parse(outputsJson); + // const inputs = JSON.parse(inputsJson); + // const options = JSON.parse(optionsJson); + // const outputs = JSON.parse(outputsJson); + const inputs = inputsJson; + const options = optionsJson; + const outputs = outputsJson; const jobOverrides = overrides['fragalysis-jobs'][overrideIndex];