From 08eaf9bd33fff53909e3f240e26f246c5fb96892 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Sat, 30 Mar 2019 08:03:40 -0400
Subject: make reusable Exporter component
---
src/components/exporter/exporter.js | 47 +++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 src/components/exporter/exporter.js
(limited to 'src/components/exporter/exporter.js')
diff --git a/src/components/exporter/exporter.js b/src/components/exporter/exporter.js
new file mode 100644
index 00000000..2ae9492c
--- /dev/null
+++ b/src/components/exporter/exporter.js
@@ -0,0 +1,47 @@
+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)
+ setTimeout(() => { this.processing = false }, 2000)
+ })
+ }
+ }
+}
+
+export default Exporter
--
cgit v1.2.3-70-g09d2
From a793835566d478503f4cadf7970ad62476dd75ac Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 29 Apr 2019 13:53:21 -0400
Subject: add a comment
---
src/components/exporter/exporter.js | 1 +
1 file changed, 1 insertion(+)
(limited to 'src/components/exporter/exporter.js')
diff --git a/src/components/exporter/exporter.js b/src/components/exporter/exporter.js
index 2ae9492c..8f507416 100644
--- a/src/components/exporter/exporter.js
+++ b/src/components/exporter/exporter.js
@@ -38,6 +38,7 @@ const Exporter = {
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)
})
}
--
cgit v1.2.3-70-g09d2