Commit 2e519890 authored by Anton's avatar Anton

Add CSV export

parent 1ced4b59
......@@ -27,6 +27,7 @@ app, including a local transcoder service
- Audio annotations (supported types: `.m4a` and `.mp3`) can be added
under `videos/create` (playback possible using forked
[vue-video-player](https://github.com/dasantonym/vue-video-player))
- Export timelines as CSV
### Changed
......
......@@ -23,12 +23,14 @@ export default {
copy_url: 'Copy URL',
delete: 'Delete',
download_archive: 'Download Archive',
download_csv: 'Download CSV',
download_package: 'Download Package',
download: 'Download',
done: 'Done',
edit: 'Edit',
export_grid: 'Export Grid',
export_timeline: 'Export Timeline',
export_timeline_csv: 'Export Timeline as CSV',
forgot_password: 'Forgot Password',
live_annotate: 'Live Annotate',
live_annotate_timeline: 'Live Annotate this timeline',
......@@ -156,6 +158,7 @@ export default {
textual_body: 'Annotations',
title: 'Title',
title_unknown: 'Unknown Title',
timeline: 'Timeline',
type: 'Type',
video_duration: 'Video duration',
video_title: 'Video title',
......@@ -344,6 +347,10 @@ export default {
title: 'Edit Timeline',
caption: 'Edit timeline details.'
},
export: {
title: 'Export Timeline',
caption: 'Export associated annotations.'
},
list: {
title: 'All timelines',
caption: 'All timelines you have access to.'
......
<template lang="pug">
full-screen
content-block(:position="'first'")
headline(:content="$t('routes.piecemaker.timelines.export.title')")
| {{ $t('routes.piecemaker.timelines.export.caption') }}
content-paragraph(v-if="timeline")
p
strong {{ timeline.title }}
q-btn(@click="exportCSV", :label="exportLabel")
</template>
<script>
import constants from 'mbjs-data-models/src/constants'
import PageSubNav from '../../../components/shared/navigation/PageSubNav'
import ContentBlock from '../../../components/shared/elements/ContentBlock'
import ContentParagraph from '../../../components/shared/elements/ContentParagraph'
import Headline from '../../../components/shared/elements/Headline'
export default {
components: {
PageSubNav,
ContentBlock,
ContentParagraph,
Headline
},
data () {
return {
timeline: undefined,
downloadURL: undefined,
exportLabel: this.$t('buttons.export_timeline_csv'),
type: constants.mapTypes.MAP_TYPE_TIMELINE
}
},
async mounted () {
this.$root.$emit('setBackButton', '/piecemaker/timelines')
this.$q.loading.show()
this.timeline = await this.$store.dispatch('maps/get', this.$route.params.uuid)
this.$q.loading.hide()
},
methods: {
async exportCSV () {
if (this.downloadURL) {
document.body.appendChild(this.downloadURL)
return this.downloadURL.click()
}
this.$q.loading.show()
const { items } = await this.$store.dispatch('annotations/find', {
'target.id': this.timeline.id
})
const entries = [[
'Value',
'Purpose',
'Start',
'Duration (s)',
'Author',
'Type',
'Created',
'Updated'
]].concat(items.sort(this.$sort.onRef).map(annotation => {
const
parsed = annotation.target.selector.parse(),
dateTime = parsed['date-time:t'],
start = Array.isArray(dateTime) ? dateTime[0].toISO() : dateTime.toISO(),
duration = annotation.target.selector.getDuration()
return [
annotation.body.source.id ? annotation.body.source.id : annotation.body.value,
annotation.body.purpose,
start,
duration ? duration.as('seconds') : '',
annotation.author.name || 'Unknown',
annotation.body.type,
annotation._created,
annotation._updated || ''
]
}))
let csvData = 'data:text/csv;charset=utf-8,'
entries.forEach(entry => {
csvData += entry.map(v => `"${v.toString().replace('"', '\\"')}"`).join(';') + '\r\n'
})
const download = document.createElement('a')
download.setAttribute('href', encodeURI(csvData))
download.setAttribute('download', `${this.timeline._uuid}.csv`)
this.exportLabel = this.$t('buttons.download_csv')
this.downloadURL = download
this.$q.loading.hide()
}
}
}
</script>
import create from './create'
import edit from './edit'
import exportTimeline from './export'
import list from './list'
import show from './sessions'
import annotate from './annotate'
......@@ -8,6 +9,7 @@ import user from './user'
export {
create,
edit,
exportTimeline,
list,
show,
annotate,
......
......@@ -45,6 +45,12 @@ export default {
name: 'piecemaker.timelines.annotate',
meta: {private: true}
},
{
path: '/piecemaker/timelines/:uuid/export',
component: () => import('pages/piecemaker/timelines/export'),
name: 'piecemaker.timelines.export',
meta: {private: true}
},
{
path: '/piecemaker/timelines/:uuid/search',
component: () => import('pages/piecemaker/timelines/search'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment