diff options
| author | taehoon <th.dev91@gmail.com> | 2019-03-30 08:03:40 -0400 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-04-27 08:31:06 -0400 |
| commit | 08eaf9bd33fff53909e3f240e26f246c5fb96892 (patch) | |
| tree | 78217e6e663808fa48261a431225ebe693fbf1aa /src/components/exporter | |
| parent | 0ab2f9dfa58c1f4caf01f083175a171d19272cda (diff) | |
make reusable Exporter component
Diffstat (limited to 'src/components/exporter')
| -rw-r--r-- | src/components/exporter/exporter.js | 47 | ||||
| -rw-r--r-- | src/components/exporter/exporter.vue | 20 |
2 files changed, 67 insertions, 0 deletions
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 diff --git a/src/components/exporter/exporter.vue b/src/components/exporter/exporter.vue new file mode 100644 index 00000000..f22e579e --- /dev/null +++ b/src/components/exporter/exporter.vue @@ -0,0 +1,20 @@ +<template> + <div class="exporter"> + <div v-if="processing"> + <i class="icon-spin4 animate-spin exporter-processing"></i> + <span>{{processingMessage}}</span> + </div> + <button class="btn btn-default" @click="process" v-else>{{exportButtonLabel}}</button> + </div> +</template> + +<script src="./exporter.js"></script> + +<style lang="scss"> +.exporter { + &-processing { + font-size: 1.5em; + margin: 0.25em; + } +} +</style> |
