2020-10-19 19:35:46 +00:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
library.add(
|
|
|
|
faCircleNotch
|
|
|
|
)
|
|
|
|
|
2019-03-30 12:03:40 +00:00
|
|
|
const Exporter = {
|
|
|
|
props: {
|
|
|
|
getContent: {
|
|
|
|
type: Function,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
filename: {
|
|
|
|
type: String,
|
|
|
|
default: 'export.csv'
|
|
|
|
},
|
2021-04-25 11:12:34 +00:00
|
|
|
exportButtonLabel: { type: String },
|
|
|
|
processingMessage: { type: String }
|
2019-03-30 12:03:40 +00:00
|
|
|
},
|
|
|
|
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)
|
2019-04-29 17:53:21 +00:00
|
|
|
// Add delay before hiding processing state since browser takes some time to handle file download
|
2019-03-30 12:03:40 +00:00
|
|
|
setTimeout(() => { this.processing = false }, 2000)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Exporter
|