diff options
| author | Shpuld Shpludson <shp@cock.li> | 2019-04-30 15:11:30 +0000 |
|---|---|---|
| committer | Shpuld Shpludson <shp@cock.li> | 2019-04-30 15:11:30 +0000 |
| commit | b1bd5bd08eccbe93d37aa1708692cad50003fd58 (patch) | |
| tree | de2de7d792a17ccd1ac74773cd05f3d18c2de60e /src/components/exporter/exporter.js | |
| parent | da08388d6af314fb298bae011da31bcfc8ac0a45 (diff) | |
| parent | 0f7f685c5e720d870cc732f07f68fb6eac278a68 (diff) | |
Merge branch 'develop' into 'brendenbice1222/pleroma-fe-issues/pleroma-fe-202-show-boosted-users'
# Conflicts:
# src/services/api/api.service.js
Diffstat (limited to 'src/components/exporter/exporter.js')
| -rw-r--r-- | src/components/exporter/exporter.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/components/exporter/exporter.js b/src/components/exporter/exporter.js new file mode 100644 index 00000000..8f507416 --- /dev/null +++ b/src/components/exporter/exporter.js @@ -0,0 +1,48 @@ +const Exporter = { + props: { + getContent: { + type: Function, + required: true + }, + filename: { + type: String, + default: 'export.csv' + }, + exportButtonLabel: { + type: String, + default () { + return this.$t('exporter.export') + } + }, + processingMessage: { + type: String, + default () { + return this.$t('exporter.processing') + } + } + }, + data () { + return { + processing: false + } + }, + methods: { + process () { + this.processing = true + this.getContent() + .then((content) => { + const fileToDownload = document.createElement('a') + fileToDownload.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content)) + fileToDownload.setAttribute('download', this.filename) + fileToDownload.style.display = 'none' + document.body.appendChild(fileToDownload) + fileToDownload.click() + document.body.removeChild(fileToDownload) + // Add delay before hiding processing state since browser takes some time to handle file download + setTimeout(() => { this.processing = false }, 2000) + }) + } + } +} + +export default Exporter |
