Skip to content

Commit

Permalink
fix(#254): address linting and snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
aswallace committed Jun 20, 2023
1 parent b8a9f05 commit 20ef09d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 58 deletions.
78 changes: 37 additions & 41 deletions app/src/modules/whyis-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const defaultDataset = {
title: '',
description: '',
contactpoint: {
'@type': 'person',
'@type': 'schemaPerson',
'@id': null,
name: '',
cpfirstname: '',
Expand Down Expand Up @@ -48,7 +48,7 @@ const datasetFieldUris = {
cpfirstname: `${schema}givenName`,
cplastname: `${schema}familyName`,
individual: `${vcard}individual`,
person: `${schema}Person`,
schemaPerson: `${schema}Person`,

author: `${dct}creator`,
name: `${foaf}name`,
Expand Down Expand Up @@ -182,30 +182,26 @@ function deleteDataset (datasetUri) {

// Handle all of the uploads as multipart form
async function saveDataset (dataset, fileList, image, guuid) {
const [distrRes, imgRes] = await Promise.all([
saveDatasetFiles(fileList),
saveDatasetFiles([image]) //TODO: verify we want to use the same function for depiction
])

let p = Promise.resolve()
if (dataset.uri) {
p = deleteDataset(dataset.uri)
} else if (arguments.length === 1) {
dataset.uri = generateDatasetId()
} else {
dataset.uri = generateDatasetId(guuid)
}
const [distrRes, imgRes] = await Promise.all([
saveDatasetFiles(fileList),
saveDatasetFiles([image]), // TODO: verify we want to use the same function for depiction
p
])
const datasetLd = buildDatasetLd(dataset)
if (distrRes?.files?.length) {
datasetLd[datasetFieldUris.distribution] = buildDistrLd(distrRes?.files)
} if (imgRes?.files?.length) {
datasetLd[datasetFieldUris.depiction] = buildDepictionLd(imgRes?.files?.[0], dataset.uri)
}
try {
return postNewNanopub(datasetLd)
} catch (err) {
//TODO: Error handling
throw(err)
}
} return postNewNanopub(datasetLd)
// TODO: Error handling
}

async function saveDatasetFiles (fileList) {
Expand All @@ -222,7 +218,7 @@ async function saveDatasetFiles (fileList) {
}
})
return await result.json()
//TODO: Error handling
// TODO: Error handling
}
}

Expand All @@ -231,11 +227,11 @@ function buildDistrLd (fileList) {
Array
.from(Array(fileList.length).keys())
.map(x => {
//TODO: check if we want to keep distribution uri as /explorer/dataset/id/filename and redirect for download
// TODO: check if we want to keep distribution uri as /explorer/dataset/id/filename and redirect for download
distrLDs[x] = {
'@id': `${window.location.origin}/api/files?filename=${fileList[x].filename}`,
'@type': 'http://purl.org/net/provenance/ns#File',
'http://www.w3.org/2000/01/rdf-schema#label': fileList[x].originalname,
'http://www.w3.org/2000/01/rdf-schema#label': fileList[x].originalname
}
})
return distrLDs
Expand All @@ -251,32 +247,32 @@ function buildDepictionLd (file, uri) {
return depictionLd
}

// TODO: Remove if current version works. This is the old method
// Currently unused
async function saveImg (file, id) {
// Where to save the image
const uri = `${lodPrefix}/dataset/${id}/depiction`
// TODO: This is the wrong URL
const baseUrl = `${window.location.origin}/about?uri=${uri}`
// // TODO: Remove if current version works. This is the old method
// // Currently unused
// async function saveImg (file, id) {
// // Where to save the image
// const uri = `${lodPrefix}/dataset/${id}/depiction`
// // TODO: This is the wrong URL
// const baseUrl = `${window.location.origin}/about?uri=${uri}`

const form = new FormData()
form.append('upload_type', 'http://purl.org/net/provenance/ns#File')
form.append('depiction', file)
// const form = new FormData()
// form.append('upload_type', 'http://purl.org/net/provenance/ns#File')
// form.append('depiction', file)

var data = {
'@id': uri,
file: form
}
// var data = {
// '@id': uri,
// file: form
// }

await fetch(baseUrl, {
method: 'POST',
body: data,
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data'
}
})
return [uri, baseUrl]
}
// await fetch(baseUrl, {
// method: 'POST',
// body: data,
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'multipart/form-data'
// }
// })
// return [uri, baseUrl]
// }

export { getDefaultDataset, saveDataset, deleteDataset }
39 changes: 22 additions & 17 deletions app/src/pages/explorer/curate/sdd/SddForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ import FilePreview from '@/components/curate/FilePreview.vue'
import CurateNavBar from '@/components/curate/CurateNavBar.vue'
import useFileList from '@/modules/file-list'
import { saveDataset } from '@/modules/whyis-dataset'
import { mapGetters } from 'vuex'
import { mapGetters, mapMutations } from 'vuex'
const { v4: uuidv4 } = require('uuid')
const datasetId = uuidv4()
const distrFn = useFileList()
Expand All @@ -280,8 +280,8 @@ export default {
// Stepper data
active: 'first',
invalid: {
'first': false,
'second': false
first: false,
second: false
},
generatedUUID: datasetId,
doi: '',
Expand All @@ -294,7 +294,7 @@ export default {
// Dataset info: Step 2
title: '',
contactPoint: {
'@type': 'individual',
'@type': 'schemaPerson',
'@id': null,
cpFirstName: '',
cpLastName: '',
Expand All @@ -305,7 +305,7 @@ export default {
datePub: {
'@type': 'date',
'@value': ''
},
}
}
}
},
Expand All @@ -315,8 +315,8 @@ export default {
orcidData: 'explorer/curation/getOrcidData'
}),
secondPageFilled () {
return !!this.dataset.title && !!this.dataset.contactPoint['@id'] &&
!!this.dataset.contactPoint.cpFirstName && !!this.dataset.contactPoint.cpLastName &&
return !!this.dataset.title && !!this.dataset.contactPoint['@id'] &&
!!this.dataset.contactPoint.cpFirstName && !!this.dataset.contactPoint.cpLastName &&
!!this.dataset.contactPoint.cpEmail && !!this.dataset.description
}
},
Expand All @@ -338,6 +338,10 @@ export default {
}
},
methods: {
...mapMutations({
setSnackbar: 'setSnackbar',
clearSnackbar: 'resetSnackbar'
}),
addDistr: distrFn.addFiles,
removeDistr: distrFn.removeFile,
modStatDistr: distrFn.modifyStatus,
Expand All @@ -347,13 +351,14 @@ export default {
onInputChange (e) {
this.addDistr(e.target.files)
e.target.value = null
this.invalid['first'] = false
this.invalid.first = false
},
goToStep (id, index) {
if (id === 'first' && !this.dataset.distrFiles.length){
this.invalid['first'] = true
} if (id === 'second' && !this.secondPageFilled){
this.invalid['second'] = true
goToStep (id, index) {
this.clearSnackbar()
if (id === 'first' && !this.dataset.distrFiles.length) {
this.invalid.first = true
} if (id === 'second' && !this.secondPageFilled) {
this.invalid.second = true
} else {
this[id] = true
if (index) {
Expand Down Expand Up @@ -392,10 +397,10 @@ export default {
},
// Submit and post as nanopublication
async submitForm () {
this.clearSnackbar()
if (!this.dataset.distrFiles.length || !this.secondPageFilled) {
this.$store.commit('setSnackbar', {
message: 'Unable to submit, check for required fields',
duration: 3000
this.setSnackbar({
message: 'Unable to submit, check for required fields'
})
} else {
try {
Expand All @@ -404,7 +409,7 @@ export default {
// TODO: Decide where routing should go to
// .then(() => goToView(this.dataset.uri, "view"));
} catch (err) {
this.uploadError = err.response
this.setSnackbar({ message: err.response ?? err })
}
}
}
Expand Down

0 comments on commit 20ef09d

Please sign in to comment.