diff --git a/package-lock.json b/package-lock.json index b52ea402e..7fc10cab6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20625,7 +20625,7 @@ "tsserver": "bin/tsserver" }, "engines": { - "node": ">=14.17" + "node": ">=4.2.0" } }, "node_modules/unbox-primitive": { diff --git a/src/components/annotationSearch/index.jsx b/src/components/annotationSearch/index.jsx index 2f6074748..e180009f6 100644 --- a/src/components/annotationSearch/index.jsx +++ b/src/components/annotationSearch/index.jsx @@ -19,7 +19,7 @@ import { RiCloseCircleFill } from 'react-icons/ri'; import { FcAbout, FcClearFilters } from 'react-icons/fc'; -import { BiSearch, BiX, BiTrash, BiDownload, BiPlay } from 'react-icons/bi'; +import { BiSearch, BiX, BiTrash, BiDownload, BiPlay, BiUpload } from 'react-icons/bi'; import { BsEyeFill } from 'react-icons/bs'; import { AiOutlineSortAscending, AiOutlineSortDescending } from 'react-icons/ai'; import ReactTooltip from 'react-tooltip'; @@ -35,6 +35,7 @@ import { clearSelection, selectAnnotation, updateSearchTableIndex, refreshPage } import AnnotationDownloadModal from '../searchView/annotationDownloadModal'; import UploadModal from '../searchView/uploadModal'; import DeleteAlert from '../management/common/alertDeletionModal'; +import CSV2AIM from '../csv2aim/csv2aim' import { getPluginsForProject, addPluginsToQueue, @@ -1292,6 +1293,7 @@ const AnnotationSearch = props => { {/* {showProjects && ( { setShowProjects(false) }} />)} */} + {(showPlugins && mode !== 'teaching') && (
{ + setUploadClicked(false); + }; + + return ( + <> + + {uploadClicked && ( + setUploadClicked(false)} + onResolve={handleSubmitUpload} + /> + )} + + ); +} \ No newline at end of file diff --git a/src/components/csv2aim/uploadcsv.jsx b/src/components/csv2aim/uploadcsv.jsx new file mode 100644 index 000000000..9ddfe11fe --- /dev/null +++ b/src/components/csv2aim/uploadcsv.jsx @@ -0,0 +1,121 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Modal, Button } from 'react-bootstrap'; +import { uploadCsv }from '../../services/annotationServices'; +import { getTemplates } from '../annotationsList/action'; + +class UploadCSV extends React.Component { + mode = sessionStorage.getItem('mode'); + state = { + tiff: false, + osirix: false, + projects: [], + files: [], + projectID: '' + }; + + onSelect = e => { + const { name, checked } = e.target; + this.setState({ [name]: checked }); + }; + + onSelectFile = e => { + this.setState({ files: Array.from(e.target.files) }); + }; + + onUpload = () => { + let { + clearTreeData, + onResolve, + onCancel, + onSubmit, + clearTreeExpand + } = this.props; + + const promises = []; + const formData = new FormData(); + this.state.files.forEach((file, index) => { + formData.append(`file${index + 1}`, file); + }); + const config = { + headers: { + 'content-type': 'multipart/form-data' + } + }; + + if (onSubmit) onSubmit(); + promises.push(uploadCsv(formData, config)) + + Promise.all(promises) + .then(() => { + if (clearTreeData) { + localStorage.setItem('treeData', JSON.stringify({})); + clearTreeExpand(); + } + this.props.dispatch(getTemplates()); + if (onResolve) onResolve(); + }) + .catch(err => { + console.error(err); + if (onResolve) onResolve(); + }); + onCancel(); + this.setState({ projectID: '' }); + }; + + selectProject = e => { + this.setState({ projectID: e.target.value }); + }; + + renderUploadFileButton = () => { + return ( +
+ Select file: + +
+ ); + }; + + render = () => { + let disabled = this.state.files.length === 0; + let className = 'alert-upload'; + className = this.props.className + ? `${className} ${this.props.className}` + : className; + const { projects } = this.state; + return ( + + + Upload CSV + + + {this.renderUploadFileButton()} + + + + + + + ); + }; +} + +UploadCSV.propTypes = { + onCancel: PropTypes.func.isRequired, + clearTreeData: PropTypes.func, + onResolve: PropTypes.func, + onSubmit: PropTypes.func, + pid: PropTypes.string, + clearTreeExpand: PropTypes.func + +}; + +export default UploadCSV; diff --git a/src/services/annotationServices.js b/src/services/annotationServices.js index 8c436efde..a73c451f7 100644 --- a/src/services/annotationServices.js +++ b/src/services/annotationServices.js @@ -205,3 +205,15 @@ export function uploadSegmentation(segmentation, segName, projectId = "lite") { // }; // return http.post(url, segData, config); // } + +export function uploadCsv(csvData, config) { + let url = http.apiUrl() + "/processCsv"; +// const aimData = new FormData(); +// aimData.append("file", csv); +// const config = { +// headers: { +// "content-type": "multipart/form-data", +// }, +// }; + return http.post(url, csvData, config); +} \ No newline at end of file