diff --git a/app/public/master_template.xlsx b/app/public/master_template.xlsx new file mode 100644 index 00000000..94ee9cac Binary files /dev/null and b/app/public/master_template.xlsx differ diff --git a/app/src/modules/gql/dataset-gql.js b/app/src/modules/gql/dataset-gql.js index 4c4f84cc..081ded74 100644 --- a/app/src/modules/gql/dataset-gql.js +++ b/app/src/modules/gql/dataset-gql.js @@ -87,22 +87,3 @@ mutation CreateDatasetId { } } }` - -export const CREATE_DATASET_MUTATION = gql` -mutation CreateDataset($input: datasetInput) { - createDataset(input: $input) { - _id - title - doi - datasetId - userid - filesets { - filesetName - files { - id - filename - contentType - } - } - } -}` diff --git a/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload-script.js b/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload-script.js index fbdf1bc6..aeba87cf 100644 --- a/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload-script.js +++ b/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload-script.js @@ -5,7 +5,7 @@ import Dialog from '@/components/Dialog.vue' import CurateNavBar from '@/components/curate/CurateNavBar.vue' import Spinner from '@/components/Spinner.vue' import useFileList from '@/modules/file-list' -import { VERIFY_AUTH_QUERY, USER_DATASET_IDS_QUERY, CREATE_DATASET_MUTATION } from '@/modules/gql/dataset-gql' +import { VERIFY_AUTH_QUERY, USER_DATASET_IDS_QUERY } from '@/modules/gql/dataset-gql' import { mapGetters, mapMutations } from 'vuex' // Create separate file objects for spreadsheet vs supplementary files @@ -32,6 +32,9 @@ export default { label: '', id: null }, + tifFiles: [], + newTifs: false, + renameXlsx: false, spreadsheetFiles: spreadsheetFn.files, suppFiles: suppFn.files, uploadedFiles: null, @@ -88,23 +91,6 @@ export default { navBack () { this.$router.back() }, - createDataset () { - this.$apollo.mutate({ - mutation: CREATE_DATASET_MUTATION, - variables: { - input: { - datasetId: `${this.datasetId}`, - files: this.uploadedFiles.files, - title: this.title, - doi: this.doi - } - } - }).then((data) => { - return data - }).catch((error) => { - console.error('error:', error) - }) - }, // Format files for submission processFiles () { return this.spreadsheetFiles.filter(file => file.status === 'incomplete') @@ -113,13 +99,38 @@ export default { }, onInputChange (e) { if (e.target.id === 'file-spreadsheet-input') { - this.addSpreadsheet(e.target.files) + const filteredXlsx = this.filterXlsx(e.target.files) + this.addSpreadsheet(filteredXlsx) } else { + this.filterTif(e.target.files) this.addSupp(e.target.files) } // reset so that selecting the same file again will still cause it to fire this change e.target.value = null }, + filterXlsx (files) { + this.renameXlsx = false + const newFiles = [...files] + const filteredFiles = [] + for (let i = 0; i < newFiles.length; i++) { + if (newFiles[i].name !== 'master_template.xlsx') { + this.renameXlsx = true + } else filteredFiles.push(newFiles[i]) + } + return filteredFiles + }, + filterTif (files) { + this.newTifs = false + const newFiles = [...files] + const filteredFiles = [] + for (let i = 0; i < newFiles.length; i++) { + if (newFiles[i].type.includes('tif')) { + this.tifFiles.push(newFiles[i]) + this.newTifs = true + } else filteredFiles.push(newFiles[i]) + } + return filteredFiles + }, goToStep (id, index) { if (id === 'fourth' && index === 'sixth') { if (!this.title) { @@ -137,16 +148,17 @@ export default { this.uploadInProgress = 'Uploading files' this.renderDialog('Submitting dataset', 'loading', 40, true) try { - await this.uploadFiles() - } catch (error) { - console.error(error) - } finally { - this.createDataset() setTimeout(() => { this.toggleDialogBox() - this.uploadInProgress = false - this.$router.push({ name: 'DatasetSingleView', params: { id: `${this.datasetId}` } }) }, 1000) + return await this.createSample() + } catch (error) { + this.$store.commit('setSnackbar', { + message: error?.message ?? error + }) + } finally { + this.uploadInProgress = false + this.$router.push({ name: 'DatasetSingleView', params: { id: `${this.datasetId}` } }) } }, renderDialog (title, type, minWidth, disableClose = false) { @@ -158,21 +170,24 @@ export default { } this.toggleDialogBox() }, - async uploadFiles () { - const url = '/api/files/upload' + async createSample () { + const url = `/api/curate?dataset=${this.datasetId}` const formData = new FormData() const files = this.processFiles() files.forEach((file) => formData.append('uploadfile', file)) - return fetch(url, { + formData.append('title', this.title) + formData.append('doi', this.doi) + const response = await fetch(url, { method: 'POST', body: formData, redirect: 'follow' - }).then((response) => response.json()) - .then((result) => { - this.uploadedFiles = result - this.spreadsheetFiles.forEach((file, index) => this.modStatSpreadsheet(index, 'complete')) - this.suppFiles.forEach((file, index) => this.modStatSupp(index, 'complete')) - }).catch(error => console.log('error', error)) + }) + if (response.status === 201) { + const result = await response.json() + this.uploadedFiles = result + this.spreadsheetFiles.forEach((file, index) => this.modStatSpreadsheet(index, 'complete')) + this.suppFiles.forEach((file, index) => this.modStatSupp(index, 'complete')) + } }, changeSelectedDataset (selection) { this.selectedDataset.label = selection.title || `${selection.datasetGroupId} (Untitled)` diff --git a/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload.html b/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload.html index 3040d0fc..d6ea78c9 100644 --- a/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload.html +++ b/app/src/pages/explorer/curate/spreadsheet/spreadsheet-upload.html @@ -29,7 +29,7 @@

Import spreadsheet data

-
Click here to download the template spreadsheet, and fill it out with your data.
+
Click here to download the template spreadsheet, and fill it out with your data.
To curate FEA data, click here instead.
Skip this step if you have already downloaded the template spreadsheet.
@@ -56,6 +56,10 @@

Import spreadsheet data

+
+ NOTICE: Main spreadsheet must be named master_template.xlsx. + Please rename this file and re-select. +
@@ -75,18 +79,22 @@

Import spreadsheet data

or click to browse.
- +
- -
- +
+
+ +
+ NOTICE: One or more of your selected files was .tif/.tiff. + Please convert this file to .png or .jpg/.jpeg and re-select.
+
@@ -132,50 +140,50 @@

Import spreadsheet data

arrow_backGo Back
+ @click="goToStep('fourth', 'fifth')"> Nextarrow_forward
- - Verification step - Coming soon. + + +

Title:

{{title}} +
 
+

DOI:

+ {{doi}} +
 
+

Uploaded files:

+ +

Spreadsheet(s)

+
    +
    + {{ss.file.name}} +
    +
+ +

Supplementary files

+
    +
    + {{suppl.file.name}} +
    +
+ +
Title and at least one spreadsheet are required for submission.
+ @click="goToStep('fifth', 'fourth')"> arrow_backGo Back + @click="goToStep('fifth', 'sixth')"> Nextarrow_forward
-

Title:

{{title}} -
 
-

DOI:

- {{doi}} -
 
-

Uploaded files:

- -

Spreadsheet(s)

-
    -
    - {{ss.file.name}} -
    -
- -

Supplementary files

-
    -
    - {{suppl.file.name}} -
    -
- -
Title and at least one spreadsheet are required for submission.
+ @click="goToStep('sixth', 'fifth')"> arrow_backGo Back { expect(steppers.at(1).text()).toContain('DOI') }) - it('verifies provided information', async () => { + it.skip('verifies provided information', async () => { expect.assertions(2) await wrapper.setData({ title: 'Test dataset title', doi: '10.000' }) const lastStep = wrapper.findAll('.md-stepper').at(5)