[subtask, mastertask] download fileov

This commit is contained in:
romankko2 committed 2023-06-30 17:47:33 +02:00
1 parent 25321a56b0
commit 412530fb93
7 files changed
+80 -15

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

@@ -58,7 +58,6 @@ export default {
mounted() { mounted() {
const monthIndex = new Date().getMonth() const monthIndex = new Date().getMonth()
this.filter.month = monthIndex < 9 ? `0${monthIndex + 1}` : `${monthIndex + 1}` this.filter.month = monthIndex < 9 ? `0${monthIndex + 1}` : `${monthIndex + 1}`
console.log(this.enrichedEmployees)
}, },
computed: { computed: {
@@ -1,14 +1,17 @@
<template> <template>
<p class="mt-5">Prílohy</p> <p class="mt-5">Prílohy</p>
<div class="w-100 d-flex align-center"> <div class="w-100 d-flex align-center">
<W-loadable :content="files" emptyMessage="Žiadne prílohy neboli nahraté">
<div v-for="(file, index) in files" :key="file.id" class="d-flex align-center flex-wrap" :class="[index === 0 ? 'ml-0' : 'ml-2']"> <div v-for="(file, index) in files" :key="file.id" class="d-flex align-center flex-wrap" :class="[index === 0 ? 'ml-0' : 'ml-2']">
<v-chip class="mt-2"> <v-chip class="mt-2">
<p @click="downloadFile(index)" class="cursor-pointer"> <p @click="handleDownload(index)" class="cursor-pointer">
{{ file.name }} {{ file.name }}
</p> </p>
<v-icon class="mx-1" icon="mdi-paperclip"></v-icon> <v-icon class="mx-1" icon="mdi-paperclip"></v-icon>
</v-chip> </v-chip>
<img v-if="showDownload" class="gif-loader" :src="require('@/plugins/app/_img/spinner.gif')" alt="Loading...">
</div> </div>
</W-loadable>
</div> </div>
</template> </template>
@@ -18,7 +21,36 @@ export default {
files: { files: {
type: Array, type: Array,
default: () => [] default: () => []
},
downloadFile: {
type: Function,
required: true
},
showDownload: {
type: Boolean,
required: true
}
},
data() {
return {
// downloadingIndex: null
}
},
methods: {
handleDownload(index) {
// this.downloadingIndex = index
this.downloadFile(index)
} }
} }
} }
</script> </script>
<style lang="sass" scoped>
.gif-loader
height: 30px
margin-left: 30px
</style>
@@ -7,10 +7,12 @@
<Z-remaining-time :hours="mastertask.duration - mastertask.time_worked" /> <Z-remaining-time :hours="mastertask.duration - mastertask.time_worked" />
<Z-spent-time :hours="mastertask.time_worked" :is-exceeded="mastertask.time_worked > mastertask.duration" /> <Z-spent-time :hours="mastertask.time_worked" :is-exceeded="mastertask.time_worked > mastertask.duration" />
<Z-description :description="mastertask.description" /> <Z-description :description="mastertask.description" />
<Z-files :files="mastertask.files" /> <Z-files :files="mastertask.files" :download-file="downloadFile" :showDownload="showDownload" />
</template> </template>
<script> <script>
import * as FileSaver from "file-saver"
import ZCreatedBy from '../../_components/read-only/z-created-by.vue' import ZCreatedBy from '../../_components/read-only/z-created-by.vue'
import ZDeadline from '../../_components/read-only/z-deadline.vue' import ZDeadline from '../../_components/read-only/z-deadline.vue'
import ZDescription from '../../_components/read-only/z-description.vue' import ZDescription from '../../_components/read-only/z-description.vue'
@@ -39,6 +41,25 @@ export default {
type: Object, type: Object,
required: true required: true
} }
},
data() {
return {
showDownload: false
}
},
methods: {
async downloadFile(id) {
this.showDownload = true
try {
const file = await this.$axios.get_auth_data(`v1/mastertasks/${this.mastertask.id}`, { responseType: "arraybuffer" })
FileSaver.saveAs(file.files[id].path, file.files[id].name)
} catch (error) {
this.$toast.error(error)
}
this.showDownload = false
},
} }
} }
</script> </script>
@@ -8,10 +8,12 @@
<A-task-remaining-time :hours="subtask.duration - subtask.spent_time" /> <A-task-remaining-time :hours="subtask.duration - subtask.spent_time" />
<A-task-spent-time :hours="subtask.spent_time" :subtask="subtask" /> <A-task-spent-time :hours="subtask.spent_time" :subtask="subtask" />
<A-task-description :description="subtask.description" :mastertask-description="subtask.master_task_description" /> <A-task-description :description="subtask.description" :mastertask-description="subtask.master_task_description" />
<Z-files :files="subtask.files" /> <Z-files :files="subtask.files" :download-file="downloadFile" :showDownload="showDownload" />
</template> </template>
<script> <script>
import * as FileSaver from "file-saver"
import AMastertaskName from './_components/a-mastertask-name.vue' import AMastertaskName from './_components/a-mastertask-name.vue'
import AMastertaskStatus from './_components/a-mastertask-status.vue' import AMastertaskStatus from './_components/a-mastertask-status.vue'
import ATaskTimeblocks from './_components/a-task-timeblocks.vue' import ATaskTimeblocks from './_components/a-task-timeblocks.vue'
@@ -44,6 +46,26 @@ export default {
type: Object, type: Object,
required: true required: true
} }
},
data() {
return {
showDownload: false
}
},
methods: {
async downloadFile(id) {
this.showDownload = true
try {
const file = await this.$axios.get_auth_data(`v1/subtasks/${this.subtask.id}`, { responseType: "arraybuffer" })
console.log(file)
FileSaver.saveAs(file.files[id].path, file.files[id].name)
} catch (error) {
this.$toast.error(error)
}
this.showDownload = false
},
} }
} }
</script> </script>
@@ -262,15 +262,6 @@ export default {
} }
}, },
async downloadFile(id) {
try {
const file = await this.$axios.get_auth_data(`v1/subtasks/${this.subtask.id}`, { responseType: "arraybuffer" })
FileSaver.saveAs(file.files[id].path, file.files[id].name)
} catch (error) {
this.$toast.error(error)
}
},
openDeleteTaskModal(subtask) { openDeleteTaskModal(subtask) {
this.$events.emit("show-delete-task-modal", { subtask }) this.$events.emit("show-delete-task-modal", { subtask })
}, },
@@ -54,6 +54,6 @@ export default {
</script> </script>
<style lang="sass" scoped> <style lang="sass" scoped>
div // div
height: calc( 100vh - 329px ) // height: calc( 100vh - 329px )
</style> </style>