Skip to content

Commit

Permalink
added new object submission page
Browse files Browse the repository at this point in the history
  • Loading branch information
mnakano committed Apr 19, 2023
1 parent 5c7187c commit 70789bf
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 65 deletions.
110 changes: 91 additions & 19 deletions client/src/components/Admin/AddNewObject.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,92 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import styled from 'styled-components';
import CustomMessages from '../Shared/CustomMessages';
import CustomSelect from '../Shared/CustomSelect';
import CustomInputText from '../Shared/CustomInputText';
import { InputTextarea } from 'primereact/inputtextarea';
import {dataTypes} from '../Shared/Enums';
import datasetNoteObj from './JSONStructures/datasetnote';
import { psetDataset, genericDataset, clinicalDataset } from './JSONStructures/dataset';
import { baseDataObject, genomeDataObject } from './JSONStructures/dataobject';
import ObjectTextArea from './SubComponents/ObjectTextArea';

const StyledAddNewObject = styled.div`
width: 800px;
.dropdown {
margin-bottom: 10px;
}
`;

const AddNewObject = () => {

const [selected, setSelected] = useState(null);
const [datasetName, setDatasetName] = useState('');
const [datasetNote, setDatasetNote] = useState('');
const [dataset, setDataset] = useState('');
const [dataObj, setDataObj] = useState('');
const [datasetNote, setDatasetNote] = useState({text: '', submitting: false, id: ''});
const [dataset, setDataset] = useState({text: '', submitting: false, id: ''});
const [dataObj, setDataObj] = useState({text: '', submitting: false, id: ''});

useEffect(() => {
if(selected){
setDatasetNote({...datasetNote, text: JSON.stringify(datasetNoteObj, null, 2)});
if(selected.value === 'pset'){
setDataset({...dataset, text: JSON.stringify(psetDataset, null, 2)});
}else if(selected.value === 'clinicalgenomics' || selected.value === 'clinical_icb'){
setDataset({...dataset, text: JSON.stringify(clinicalDataset, null, 2)});
}else{
setDataset({...dataset, text: JSON.stringify(genericDataset, null, 2)});
}
if(selected.value === 'pset' || selected.value === 'radioset'){
setDataObj({...dataObj, text: JSON.stringify(genomeDataObject, null, 2)});
}else{
setDataObj({...dataObj, text: JSON.stringify(baseDataObject, null, 2)});
}
}
}, [selected]);

useEffect(() => {
if(selected){
let noteObj = JSON.parse(datasetNote.text);
let datasetObj = JSON.parse(dataset.text);
let dataObject = JSON.parse(dataObj.text);
noteObj.name = datasetName;
datasetObj.name = datasetName;
dataObject.name = datasetName;
setDatasetNote({...datasetNote, text: JSON.stringify(noteObj, null, 2)});
setDataset({...dataset, text: JSON.stringify(datasetObj, null, 2)});
setDataObj({...dataObj, text: JSON.stringify(dataObject, null, 2)});
}
}, [selected])
}, [datasetName]);

const submitObject = (type, object) => async (e) => {
e.preventDefault();
try{
const res = await axios.post(
'/api/admin/data-processing/submit_obj',
{objectType: type, object: object}
);
console.log(res.data);
switch(type){
case 'datasetNote':
setDatasetNote({...datasetNote, id: String(res.data._id)});
break;
case 'dataset':
setDataset({...dataset, id: String(res.data._id)});
break;
case 'dataObj':
setDataObj({...dataObj, id: String(res.data._id)});
break;
default:
break;
}
}catch(error){
console.log(error)
}
}

return(
<StyledAddNewObject>
<h3>Add new data object to the compendium</h3>
<div>
<div className='dropdown'>
<CustomSelect
selectOne
selected={selected}
Expand All @@ -43,20 +101,34 @@ const AddNewObject = () => {
label='Dataset name:'
value={datasetName}
onChange={(e) => {setDatasetName( e.target.value)}}
rows={10}
cols={100}
/>
</div>
<h4>Add a DatasetNote document</h4>
<div>
<InputTextarea value={datasetNote} onChange={(e) => setDatasetNote(e.target.value)} rows={10} cols={100} />
</div>
<h4>Add a Dataset document</h4>
<div>
<InputTextarea value={dataset} onChange={(e) => setDataset(e.target.value)} rows={30} cols={100} />
</div>
<h4>Add a DataObject document</h4>
<div>
<InputTextarea value={dataObj} onChange={(e) => setDataObj(e.target.value)} rows={30} cols={100} />
</div>
<ObjectTextArea
title='Add a DatasetNote document'
submit={submitObject('datasetNote', datasetNote)}
object={datasetNote}
setObject={setDatasetNote}
rows={10}
cols={100}
/>
<ObjectTextArea
title='Add a Dataset document'
submit={submitObject('dataset', dataset)}
object={dataset}
setObject={setDataset}
rows={30}
cols={100}
/>
<ObjectTextArea
title='Add a DataObject document'
submit={submitObject('dataObj', dataObj)}
object={dataObj}
setObject={setDataObj}
rows={30}
cols={100}
/>
</StyledAddNewObject>
)
}
Expand Down
16 changes: 4 additions & 12 deletions client/src/components/Admin/JSONStructures/dataobject.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export const baseDataObject = {
info: {
date: {
created: {
$date: "2023-00-00T00:00:00.000Z"
}
created: ""
},
status: "complete",
private: false,
Expand Down Expand Up @@ -37,9 +35,7 @@ export const baseDataObject = {
dataObjType: "BaseDataObject",
datasetType: "",
name: "",
dataset: {
$oid: ""
},
dataset: "",
repositories: [
{
version: "1.0",
Expand All @@ -58,9 +54,7 @@ export const baseDataObject = {
export const genomeDataObject = {
info: {
date: {
created: {
$date: "2023-00-00T00:00:00.000Z"
}
created: ""
},
status: "complete",
private: false,
Expand Down Expand Up @@ -95,9 +89,7 @@ export const genomeDataObject = {
dataObjType: "GenomeDataObject",
datasetType: "",
name: "",
dataset: {
$oid: ""
},
dataset: "",
repositories: [
{
version: "3.13",
Expand Down
13 changes: 3 additions & 10 deletions client/src/components/Admin/JSONStructures/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ export const psetDataset = {
options: []
}
],
datasetNote: {
$oid: ""
},
datasetNote: "",
releaseNotes: {
counts: [
{
Expand Down Expand Up @@ -103,7 +101,6 @@ export const psetDataset = {
},
info: {
includedData: "sensitivity",
pachydermPipeline: "getGDSCv1"
}
}

Expand Down Expand Up @@ -133,9 +130,7 @@ export const genericDataset = {
options: []
}
],
datasetNote: {
$oid: ""
},
datasetNote: "",
releaseNotes: {
counts: [
{
Expand Down Expand Up @@ -188,9 +183,7 @@ export const clinicalDataset = {
options: []
}
],
datasetNote: {
$oid: ""
},
datasetNote: "",
status: {
unavailable: false,
disabled: false,
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Admin/JSONStructures/datasetnote.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const datasetNote = {
name: "",
disclaimer: "The DatasetName data were re-processed and shared by the Haibe-Kains Lab (University Health Network). The Haibe-Kains Lab has re-annotated the data to maximize overlap with other clinical datasets.",
disclaimer: "The data in this dataset were re-processed and shared by the Haibe-Kains Lab (University Health Network). The Haibe-Kains Lab has re-annotated the data to maximize overlap with other clinical datasets.",
usagePolicy: "The data is under <a href='https://creativecommons.org/licenses/by/4.0/'>Creative Commons Attribution 4.0 International License</a> provided.<br />Source: <a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=gse15471'>https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=gse15471</a>",
citations: [
""
Expand Down
47 changes: 47 additions & 0 deletions client/src/components/Admin/SubComponents/ObjectTextArea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import { InputTextarea } from 'primereact/inputtextarea';
import { Button } from 'primereact/button';
import styled from 'styled-components';

const StyledTextArea = styled.div`
.submit-button {
display: flex;
align-items: center;
button {
margin-right: 10px;
}
.object-id {
font-size: 14px;
}
}
`;

const ObjectTextArea = (props) => {
const { title, submit, object, setObject, rows, cols, } = props;
return(
<StyledTextArea>
<h4>{title}</h4>
<div>
<InputTextarea
value={object.text}
onChange={(e) => setObject({...object, text: e.target.value})}
rows={rows}
cols={cols}
style={{whiteSpace: 'pre', overflowWrap: 'normal', overflowX: 'scroll', fontFamily: 'monospace'}}
/>
<div className='submit-button'>
<Button
label='Submit'
onClick={submit}
/>
{
object.id.length > 0 &&
<div className='object-id'>ID: {object.id}</div>
}
</div>
</div>
</StyledTextArea>
)
}

export default ObjectTextArea;
54 changes: 31 additions & 23 deletions routes/api/view/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const axios = require('axios');
const DataObject = require('../../../db/models/data-object').DataObject;
const DatasetNote = require('../../../db/models/dataset-note');
const Dataset = require('../../../db/models/dataset');
const dataObjectHelper = require('../../../helper/data-object');
const timers = require('timers/promises');

Expand Down Expand Up @@ -146,29 +148,36 @@ const uploadDataObject = async (req, res) => {
}
}

const updateSubmission = async (req, res) => {
// console.log(req.params.id);
// try{
// await dataSubmission.updateOne({_id: mongo.ObjectID(req.params.id)}, {'info.status': 'complete'});
// }catch(error){
// console.log(error);
// res.status(500);
// }finally{
// res.send();
// }
const submitObject = async (req, res) => {
let result = null;
try{
let objectType = req.body.objectType;
let object = JSON.parse(req.body.object.text);
switch(objectType){
case 'datasetNote':
let note = new DatasetNote(object);
result = await note.save();
break;
case 'dataset':
let dataset = new Dataset(object);
result = await dataset.save();
break;
case 'dataObj':
let dataObj = new DataObject(object);
result = await dataObj.save();
break;
default:
break;
}
}catch(error){
console.log(error);
res.status(500);
}finally{
res.send(result)
}
}

const getSubmissionList = async (req, res) => {
// let data = []
// try{
// data = await dataSubmission.list({}, {'projection': {'info': true}});
// }catch(error){
// console.log(error);
// res.status(500);
// }finally{
// res.send(data);
// }
}


module.exports = {
canonicalPSets,
Expand All @@ -177,6 +186,5 @@ module.exports = {
runPipeline,
processedDataObjects,
uploadDataObject,
updateSubmission,
getSubmissionList
submitObject
}
1 change: 1 addition & 0 deletions routes/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ router.get('/view/admin/pipelines', auth.verifyToken, auth.isAdmin, admin.getPip
router.post('/admin/data-processing/create-pipeline', auth.verifyToken, auth.isAdmin, admin.createPipeline);
router.post('/admin/data-processing/run-pipeline', auth.verifyToken, auth.isAdmin, admin.runPipeline);
router.post('/admin/data-processing/upload_data_obj', auth.verifyToken, auth.isAdmin, admin.uploadDataObject);
router.post('/admin/data-processing/submit_obj', auth.verifyToken, auth.isAdmin, admin.submitObject);

// data object
router.get('/data-objects/search', dataObject.search);
Expand Down

0 comments on commit 70789bf

Please sign in to comment.