Skip to content

Commit

Permalink
Merge pull request #176 from nih-sparc/fix-in-progress-datasets-section
Browse files Browse the repository at this point in the history
Updated published and in progress datasets sections in Profile page
  • Loading branch information
egauzens authored Aug 9, 2024
2 parents 0ff0d98 + c8c9e22 commit 68df230
Showing 1 changed file with 31 additions and 49 deletions.
80 changes: 31 additions & 49 deletions pages/user/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ export default {
handler: async function (newValue) {
if (newValue && newValue !== '') {
await this.fetchOrganizations()
this.fetchPublishedDatasets(newValue)
this.fetchInProgressDatasets()
this.fetchUserDatasets()
this.fetchDatasetSubmissions()
this.fetchQuestions()
}
Expand All @@ -336,43 +335,7 @@ export default {
},
},
methods: {
async fetchPublishedDatasets(orcid) {
const filter = `contributors.curie:\"ORCID:${orcid}\"`
try {
const { hits } = await this.$algoliaClient.initIndex(this.$config.public.ALGOLIA_INDEX).search('', {
filters: filter,
hitsPerPage: 999
})
let items = []
for (const hit of hits) {
const datasetName = pathOr('', ['item', 'name'], hit)
const datasetId = propOr('', 'objectID', hit)
const pennsieveIdentifier = pathOr('', ['item', 'identifier'], hit)
let numCitations = await this.getCitationsCount(pennsieveIdentifier)
const numDownloads = this.getDownloadsCount(datasetId);
items.push({
'name': datasetName,
'intId': datasetId,
'banner': pathOr('', ['pennsieve', 'banner', 'uri'], hit),
'numDownloads': numDownloads,
'numCitations': numCitations
})
}
this.datasets = items
} catch (error) {
this.datasets = []
} finally {
this.datasetsLoading = false
}
},
async fetchInProgressDatasets() {
async fetchUserDatasets() {
let orgIntIds = []
this.organizations.forEach(org => {
orgIntIds.push(org.intId)
Expand All @@ -382,20 +345,41 @@ export default {
try {
await this.$axios.put(`${this.$config.public.LOGIN_API_URL}/session/switch-organization?organization_id=${id}&api_key=${this.userToken}`)
let { data } = await this.$axios.get(`${this.$config.public.LOGIN_API_URL}/datasets/paginated?onlyMyDatasets=true&publicationStatus=draft&api_key=${this.userToken}`)
const datasets = data.datasets
let { data } = await this.$axios.get(`${this.$config.public.LOGIN_API_URL}/datasets/paginated?onlyMyDatasets=true&api_key=${this.userToken}`)
const publishedDatasets = data.datasets.filter(dataset => dataset.publication.status == 'completed')
const inProgressDatasets = data.datasets.filter(dataset => dataset.publication.status != 'completed')
datasets.forEach(async dataset => {
for (let dataset of inProgressDatasets) {
let datasetId = dataset.content.id
let { data } = await this.$axios.get(`${this.$config.public.LOGIN_API_URL}/datasets/${datasetId}/banner?api_key=${this.userToken}`)
this.inProgressDatasets.push({
...dataset,
banner: data.banner
})
})
} catch(e) {}
}
for (let dataset of publishedDatasets) {
const intId = pathOr('', ['content', 'intId'], dataset)
const datasetName = pathOr('', ['content', 'name'], dataset)
const pennsieveIdentifier = pathOr('', ['content', 'id'], dataset)
let { data } = await this.$axios.get(`${this.$config.public.LOGIN_API_URL}/datasets/${pennsieveIdentifier}/banner?api_key=${this.userToken}`)
let numCitations = await this.getCitationsCount(pennsieveIdentifier)
const numDownloads = this.getDownloadsCount(intId)
this.datasets.push({
'name': datasetName,
'intId': intId,
'banner': data.banner,
'numDownloads': numDownloads,
'numCitations': numCitations
})
}
} catch (e) {
}
}
this.inProgressDatasetsLoading = false
this.datasetsLoading = false
},
async fetchDatasetSubmissions() {
const headers = { 'Authorization': `Bearer ${this.userToken}` }
Expand Down Expand Up @@ -425,12 +409,10 @@ export default {
const url = `${this.$config.public.LOGIN_API_URL}/datasets/${id}/external-publications`
try {
const response = await this.$axios.get(url, { headers })
const count = response.data.length
return count;
const { data } = await this.$axios.get(url, { headers })
return data.length
} catch (error) {
return 0
return 0
}
},
async fetchOrganizations() {
Expand Down

0 comments on commit 68df230

Please sign in to comment.