Skip to content

Commit

Permalink
fix: catalog CSV export
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-bonnel committed Jun 20, 2024
1 parent 82e2c37 commit cfe8a4c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"http-link-header": "^1.1.0",
"json-schema-defaults": "^0.4.0",
"json-schema-ref-parser": "^9.0.9",
"json2csv": "^6.0.0-alpha.2",
"marked": "^4.3.0",
"memoizee": "^0.4.15",
"mime-types": "^2.1.35",
Expand Down
24 changes: 21 additions & 3 deletions public/pages/datasets/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ import DatasetCard from '~/components/dataset/card.vue'
import { isMobileOnly } from 'mobile-device-detect'
const { mapState, mapGetters, mapActions } = require('vuex')
const { Parser } = require('json2csv')
const fields = [
{ label: 'Identifiant', value: 'slug' },
{ label: 'Titre', value: 'title' },
{ label: 'Description', value: 'description' },
{ label: 'Themes', value: 'themes' },
{ label: 'Couverture spatiale', value: 'spatial' },
{ label: 'Page', value: 'page' },
{ label: 'Api', value: 'href' },
{ label: 'Date de création', value: 'createdAt' },
{ label: 'Date de mise a jour', value: 'dataUpdatedAt' }
]
const parser = new Parser({ fields })
export default {
components: {
DatasetCard
Expand Down Expand Up @@ -390,9 +404,13 @@ export default {
if (!this.user) params.visibility = 'public'
try {
const datasets = (await this.$axios.$get(this.$store.getters.dataFairUrl + '/api/v1/datasets', { params })).results
const header = 'identifiant,titre,description,themes,couverture spatiale,page,api,date de création,date de mise a jour'
const content = datasets.map(d => `${d.slug},"${d.title}","${d.description}","${(d.topics || []).map(t => t.title).join(';')}",${d.bbox ? ('"' + JSON.stringify(d.bbox) + '"') : ''},${this.url + '/' + d.id},${d.href},${d.dataUpdatedAt},${d.createdAt}`).join('\n')
const blob = new Blob([header + '\n' + content], { type: 'text/csv' })
datasets.forEach(d => {
d.themes = (d.topics || []).map(t => t.title).join(';')
d.spatial = d.bbox ? JSON.stringify(d.bbox) : ''
d.page = this.url + '/' + d.id
})
const csv = parser.parse(datasets)
const blob = new Blob([csv], { type: 'text/csv' })
fileDownload(blob, name)
} catch (err) { }
this.downloading = null
Expand Down

0 comments on commit cfe8a4c

Please sign in to comment.