logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

exporter.js (1225B)


  1. import { library } from '@fortawesome/fontawesome-svg-core'
  2. import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
  3. library.add(
  4. faCircleNotch
  5. )
  6. const Exporter = {
  7. props: {
  8. getContent: {
  9. type: Function,
  10. required: true
  11. },
  12. filename: {
  13. type: String,
  14. default: 'export.csv'
  15. },
  16. exportButtonLabel: { type: String },
  17. processingMessage: { type: String }
  18. },
  19. data () {
  20. return {
  21. processing: false
  22. }
  23. },
  24. methods: {
  25. process () {
  26. this.processing = true
  27. this.getContent()
  28. .then((content) => {
  29. const fileToDownload = document.createElement('a')
  30. fileToDownload.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content))
  31. fileToDownload.setAttribute('download', this.filename)
  32. fileToDownload.style.display = 'none'
  33. document.body.appendChild(fileToDownload)
  34. fileToDownload.click()
  35. document.body.removeChild(fileToDownload)
  36. // Add delay before hiding processing state since browser takes some time to handle file download
  37. setTimeout(() => { this.processing = false }, 2000)
  38. })
  39. }
  40. }
  41. }
  42. export default Exporter