Added File Download

Added File Loading Screen
This commit is contained in:
2025-02-03 18:06:20 +01:00
parent ce52c983a8
commit 2a63ff827b

View File

@@ -88,6 +88,9 @@ const currentFolder = ref(null)
const loadingDocs = ref(false) const loadingDocs = ref(false)
const isDragTarget = ref(false) const isDragTarget = ref(false)
const loaded = ref(false)
const setupPage = async () => { const setupPage = async () => {
folders.value = await useSupabaseSelect("folders") folders.value = await useSupabaseSelect("folders")
@@ -124,6 +127,7 @@ const setupPage = async () => {
loadingDocs.value = false loadingDocs.value = false
loaded.value = true
} }
setupPage() setupPage()
@@ -244,12 +248,11 @@ const uploadFiles = async (files) => {
} }
const downloadSelected = async () => { const downloadSelected = async () => {
const bucket = "files"; const bucket = "filesdev";
let files = [] let files = []
dataStore.documents.filter(doc => doc.selected).forEach(doc => files.push(doc.path))
console.log(files) files = filteredDocuments.value.filter(i => selectedFiles.value[i.id] === true).map(i => i.path)
// If there are no files in the folder, throw an error // If there are no files in the folder, throw an error
if (!files || !files.length) { if (!files || !files.length) {
@@ -272,8 +275,6 @@ const downloadSelected = async () => {
const downloadedFiles = response.map((result, index) => { const downloadedFiles = response.map((result, index) => {
if (result.status === "fulfilled") { if (result.status === "fulfilled") {
console.log(files[index].split("/")[files[index].split("/").length -1])
return { return {
name: files[index].split("/")[files[index].split("/").length -1], name: files[index].split("/")[files[index].split("/").length -1],
blob: result.value.data, blob: result.value.data,
@@ -297,7 +298,7 @@ const downloadSelected = async () => {
const link = document.createElement("a"); const link = document.createElement("a");
link.href = url; link.href = url;
link.setAttribute("download", "documents.zip"); link.setAttribute("download", "dateien.zip");
document.body.appendChild(link); document.body.appendChild(link);
@@ -332,6 +333,16 @@ const showFile = (fileId) => {
documentData: documents.value.find(i => i.id === fileId), documentData: documents.value.find(i => i.id === fileId),
}) })
} }
const selectedFiles = ref({});
const selectAll = () => {
if(Object.keys(selectedFiles.value).find(i => selectedFiles.value[i] === true)) {
selectedFiles.value = {}
} else {
selectedFiles.value = Object.fromEntries(filteredDocuments.value.map(i => i.id).map(k => [k,true]))
}
}
@@ -363,11 +374,18 @@ const showFile = (fileId) => {
</template> </template>
</USelectMenu> </USelectMenu>
<UButton @click="modal.open(DocumentUploadModal,{fileData: {folder: currentFolder.id}})">+ Datei</UButton> <UButton @click="modal.open(DocumentUploadModal,{fileData: {folder: currentFolder.id}})">+ Datei</UButton>
<UButton <UButton
@click="createFolderModalOpen = true" @click="createFolderModalOpen = true"
variant="outline" variant="outline"
>+ Ordner</UButton> >+ Ordner</UButton>
<UButton
@click="downloadSelected"
icon="i-heroicons-cloud-arrow-down"
variant="outline"
v-if="Object.keys(selectedFiles).find(i => selectedFiles[i] === true)"
>Herunterladen</UButton>
<UModal <UModal
v-model="createFolderModalOpen" v-model="createFolderModalOpen"
> >
@@ -400,16 +418,27 @@ const showFile = (fileId) => {
</template> </template>
</UDashboardToolbar> </UDashboardToolbar>
<div id="drop_zone" class="h-full scrollList" > <div id="drop_zone" class="h-full scrollList" >
<div v-if="loaded">
<UDashboardPanelContent v-if="!isDragTarget" > <UDashboardPanelContent v-if="!isDragTarget" >
<div v-if="displayMode === 'list'"> <div v-if="displayMode === 'list'">
<table class="w-full"> <table class="w-full">
<thead> <thead>
<tr> <tr>
<td>
<UCheckbox
@change="selectAll"
/>
</td>
<td class="font-bold">Name</td> <td class="font-bold">Name</td>
<td class="font-bold">Erstellt am</td> <td class="font-bold">Erstellt am</td>
</tr> </tr>
</thead> </thead>
<tr v-for="(entry,index) in renderedFileList"> <tr v-for="(entry,index) in renderedFileList">
<td>
<UCheckbox
v-model="selectedFiles[entry.id]"
/>
</td>
<td> <td>
<UIcon class="mr-1" :name="entry.type === 'folder' ? 'i-heroicons-folder' : 'i-heroicons-document'"/> <UIcon class="mr-1" :name="entry.type === 'folder' ? 'i-heroicons-folder' : 'i-heroicons-document'"/>
<a <a
@@ -476,7 +505,9 @@ const showFile = (fileId) => {
</template> </template>
</UCard> </UCard>
</div> </div>
<UProgress animation="carousel" v-else class="w-5/6 mx-auto mt-5"/>
</div>