Added Logo
Added Document Download Added zipjs
This commit is contained in:
@@ -150,7 +150,6 @@ setupPage()
|
||||
Bearbeiten
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="cancelEditorCreate"
|
||||
color="red"
|
||||
class="ml-2"
|
||||
disabled
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
<div>
|
||||
<div class="controlHeader">
|
||||
<UButton @click="uploadModalOpen = true">Hochladen</UButton>
|
||||
<UButton
|
||||
@click="downloadSelected"
|
||||
class="ml-2"
|
||||
:disabled="documents.filter(doc => doc.selected).length === 0"
|
||||
>Herunterladen</UButton>
|
||||
<UModal
|
||||
v-model="uploadModalOpen"
|
||||
>
|
||||
@@ -69,11 +74,11 @@
|
||||
fullscreen
|
||||
>
|
||||
<UCard class="h-full">
|
||||
|
||||
<embed
|
||||
{{selectedDocument}}
|
||||
<!-- <embed
|
||||
class="bigPreview mb-3"
|
||||
:src="selectedDocument.url"
|
||||
/>
|
||||
/>-->
|
||||
|
||||
<UBadge
|
||||
v-for="tag in selectedDocument.tags"
|
||||
@@ -107,7 +112,7 @@
|
||||
>
|
||||
<template #item="{item}">
|
||||
<div class="documentList">
|
||||
<div
|
||||
<a
|
||||
v-if="documents.filter(doc => doc.folder === item.label).length > 0"
|
||||
v-for="document in documents.filter(doc => doc.folder === item.label)"
|
||||
class="documentListItem"
|
||||
@@ -122,6 +127,10 @@
|
||||
>
|
||||
<UIcon name="i-heroicons-eye-solid" />
|
||||
</UButton>
|
||||
<UToggle
|
||||
v-model="document.selected"
|
||||
class="ml-2"
|
||||
/>
|
||||
|
||||
<!-- {{document.name}}<br>-->
|
||||
<!-- <UBadge
|
||||
@@ -134,7 +143,7 @@
|
||||
variant="outline"
|
||||
>{{document.state}}</UBadge>-->
|
||||
|
||||
</div>
|
||||
</a>
|
||||
<div v-else>
|
||||
<p>Keine Dokumente in diesem Ordner</p>
|
||||
<UButton
|
||||
@@ -153,6 +162,8 @@
|
||||
|
||||
<script setup>
|
||||
|
||||
import {BlobReader, BlobWriter, ZipWriter} from "@zip.js/zip.js";
|
||||
|
||||
definePageMeta({
|
||||
middleware: "auth"
|
||||
})
|
||||
@@ -230,19 +241,24 @@ const uploadFile = async () => {
|
||||
|
||||
const changeFolder = async () => {
|
||||
console.log("Change Folder")
|
||||
console.log(selectedDocument.value.path)
|
||||
console.log(selectedDocument.value)
|
||||
|
||||
let filename = selectedDocument.value.path.split("/")[2]
|
||||
let oldPath = selectedDocument.value.path
|
||||
let newPath = `${user.value.app_metadata.tenant}/${newFolder.value}/${filename}`
|
||||
console.log(oldPath)
|
||||
console.log(newPath)
|
||||
|
||||
const { data, error } = await supabase
|
||||
.storage
|
||||
.from('documents')
|
||||
.move(selectedDocument.value.path, newPath )
|
||||
.move(oldPath,newPath )
|
||||
|
||||
console.log(data)
|
||||
console.log(error)
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -257,6 +273,67 @@ const openDocument = async (document) => {
|
||||
showDocumentModal.value = true
|
||||
|
||||
}
|
||||
|
||||
|
||||
const downloadSelected = async () => {
|
||||
const bucket = "documents";
|
||||
|
||||
let files = []
|
||||
documents.value.filter(doc => doc.selected).forEach(doc => files.push(doc.path))
|
||||
|
||||
console.log(files)
|
||||
|
||||
// If there are no files in the folder, throw an error
|
||||
if (!files || !files.length) {
|
||||
throw new Error("No files to download");
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
|
||||
// Download each file in the folder
|
||||
files.forEach((file) => {
|
||||
promises.push(
|
||||
supabase.storage.from(bucket).download(`${file}`)
|
||||
);
|
||||
});
|
||||
|
||||
// Wait for all the files to download
|
||||
const response = await Promise.allSettled(promises);
|
||||
|
||||
// Map the response to an array of objects containing the file name and blob
|
||||
const downloadedFiles = response.map((result, index) => {
|
||||
if (result.status === "fulfilled") {
|
||||
return {
|
||||
name: files[index],
|
||||
blob: result.value.data,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new zip file
|
||||
const zipFileWriter = new BlobWriter("application/zip");
|
||||
const zipWriter = new ZipWriter(zipFileWriter, { bufferedWrite: true });
|
||||
|
||||
// Add each file to the zip file
|
||||
downloadedFiles.forEach((downloadedFile) => {
|
||||
if (downloadedFile) {
|
||||
zipWriter.add(downloadedFile.name, new BlobReader(downloadedFile.blob));
|
||||
}
|
||||
});
|
||||
|
||||
// Download the zip file
|
||||
const url = URL.createObjectURL(await zipWriter.close());
|
||||
const link = document.createElement("a");
|
||||
|
||||
link.href = url;
|
||||
link.setAttribute("download", "documents.zip");
|
||||
|
||||
document.body.appendChild(link);
|
||||
|
||||
link.click();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
90
spaces/pages/downloadFolder.vue
Normal file
90
spaces/pages/downloadFolder.vue
Normal file
@@ -0,0 +1,90 @@
|
||||
<script setup>
|
||||
import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
|
||||
const downloadFolder = async (folder) => {
|
||||
const supabaseClient = useSupabaseClient();
|
||||
|
||||
const bucket = "documents";
|
||||
|
||||
// Get a list of all the files in the path /my-bucket/images
|
||||
/*const { data: files, error } = await supabaseClient.storage
|
||||
.from(bucket)
|
||||
.list(folder);
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}*/
|
||||
|
||||
let files = [
|
||||
"1/Eingang/Rechnung_VRB170A0249604_2023-12-06.pdf"
|
||||
]
|
||||
|
||||
console.log(files)
|
||||
|
||||
// If there are no files in the folder, throw an error
|
||||
if (!files || !files.length) {
|
||||
throw new Error("No files to download");
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
|
||||
// Download each file in the folder
|
||||
files.forEach((file) => {
|
||||
promises.push(
|
||||
supabaseClient.storage.from(bucket).download(`${file}`)
|
||||
);
|
||||
});
|
||||
|
||||
// Wait for all the files to download
|
||||
const response = await Promise.allSettled(promises);
|
||||
|
||||
// Map the response to an array of objects containing the file name and blob
|
||||
const downloadedFiles = response.map((result, index) => {
|
||||
if (result.status === "fulfilled") {
|
||||
return {
|
||||
name: files[index],
|
||||
blob: result.value.data,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new zip file
|
||||
const zipFileWriter = new BlobWriter("application/zip");
|
||||
const zipWriter = new ZipWriter(zipFileWriter, { bufferedWrite: true });
|
||||
|
||||
// Add each file to the zip file
|
||||
downloadedFiles.forEach((downloadedFile) => {
|
||||
if (downloadedFile) {
|
||||
zipWriter.add(downloadedFile.name, new BlobReader(downloadedFile.blob));
|
||||
}
|
||||
});
|
||||
|
||||
// Download the zip file
|
||||
const url = URL.createObjectURL(await zipWriter.close());
|
||||
const link = document.createElement("a");
|
||||
|
||||
link.href = url;
|
||||
link.setAttribute("download", "documents.zip");
|
||||
|
||||
document.body.appendChild(link);
|
||||
|
||||
link.click();
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<UButton
|
||||
@click="downloadFolder('1/Eingang')"
|
||||
>
|
||||
Download
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
218
spaces/pages/jobs/[mode]/[[id]].vue
Normal file
218
spaces/pages/jobs/[mode]/[[id]].vue
Normal file
@@ -0,0 +1,218 @@
|
||||
<script setup>
|
||||
definePageMeta({
|
||||
middleware: "auth"
|
||||
})
|
||||
|
||||
//
|
||||
const supabase = useSupabaseClient()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
const id = ref(route.params.id ? route.params.id : null )
|
||||
|
||||
//Store
|
||||
const {jobs, customers} = storeToRefs(useDataStore())
|
||||
const {fetchJobs, getJobById} = useDataStore()
|
||||
|
||||
let currentItem = null
|
||||
|
||||
|
||||
|
||||
//Working
|
||||
const mode = ref(route.params.mode || "show")
|
||||
const itemInfo = ref({
|
||||
title: "",
|
||||
customer: 0,
|
||||
|
||||
})
|
||||
const states = ["Offen", "In Bearbeitung", "Erledigt"]
|
||||
|
||||
//Functions
|
||||
const setupPage = () => {
|
||||
if(mode.value === "show" || mode.value === "edit"){
|
||||
currentItem = getJobById(Number(useRoute().params.id))
|
||||
}
|
||||
|
||||
if(mode.value === "edit") itemInfo.value = currentItem
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("jobs")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
title: "",
|
||||
}
|
||||
toast.add({title: "Job erfolgreich erstellt"})
|
||||
await fetchJobs()
|
||||
router.push(`/jobs/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
router.push(`/jobs/edit/${currentItem.id}`)
|
||||
setupPage()
|
||||
}
|
||||
|
||||
const cancelEditorCreate = () => {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
infoData: {}
|
||||
}
|
||||
}
|
||||
|
||||
const updateItem = async () => {
|
||||
const {error} = await supabase
|
||||
.from("jobs")
|
||||
.update(itemInfo.value)
|
||||
.eq('id',itemInfo.value.id)
|
||||
console.log(error)
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
title: ""
|
||||
}
|
||||
toast.add({title: "Job erfolgreich gespeichert"})
|
||||
fetchJobs()
|
||||
}
|
||||
|
||||
|
||||
|
||||
setupPage()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<UCard v-if="currentItem && mode == 'show'" >
|
||||
<template #header>
|
||||
<UBadge>
|
||||
{{currentItem.state}}
|
||||
</UBadge>
|
||||
|
||||
{{currentItem.title}}
|
||||
</template>
|
||||
|
||||
Beschreibung:<br>
|
||||
{{currentItem.description}}<br>
|
||||
|
||||
|
||||
|
||||
<!-- Kontakte:<br>
|
||||
<!– <ul>
|
||||
<li v-for="contact in currentCustomer.contacts.data">{{contact.lastName}}, {{contact.firstName}}</li>
|
||||
</ul>–>
|
||||
<!– {{currentCustomer.contacts.data}}–>
|
||||
<br>
|
||||
Projekte:<br>
|
||||
<!– <ul>
|
||||
<li v-for="project in currentCustomer.projects.data"><router-link :to="'/projects?id=' + project.id">{{project.name}}</router-link></li>
|
||||
</ul>–>-->
|
||||
|
||||
|
||||
|
||||
<template #footer>
|
||||
<UButton
|
||||
v-if="mode == 'show' && currentItem.id"
|
||||
@click="editItem"
|
||||
>
|
||||
Bearbeiten
|
||||
</UButton>
|
||||
<UButton
|
||||
color="red"
|
||||
class="ml-2"
|
||||
disabled
|
||||
>
|
||||
Archivieren
|
||||
</UButton>
|
||||
<!-- TODO: Kunde archivieren -->
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
</UCard>
|
||||
<UCard v-else-if="mode == 'edit' || mode == 'create'" >
|
||||
<template #header>
|
||||
{{itemInfo.title}}
|
||||
</template>
|
||||
|
||||
<UFormGroup
|
||||
label="Titel:"
|
||||
>
|
||||
<UInput
|
||||
v-model="itemInfo.title"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup
|
||||
label="Status:"
|
||||
>
|
||||
<USelectMenu
|
||||
v-model="itemInfo.state"
|
||||
:options="states"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup
|
||||
label="Kundennummer:"
|
||||
>
|
||||
<USelectMenu
|
||||
v-model="itemInfo.customer"
|
||||
:options="customers"
|
||||
option-attribute="name"
|
||||
value-attribute="id"
|
||||
searchable
|
||||
:search-attributes="['name']"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
|
||||
<UFormGroup
|
||||
label="Beschreibung:"
|
||||
>
|
||||
<UTextarea
|
||||
v-model="itemInfo.description"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
|
||||
<template #footer>
|
||||
<UButton
|
||||
v-if="mode == 'edit'"
|
||||
@click="updateItem"
|
||||
>
|
||||
Speichern
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="cancelEditorCreate"
|
||||
color="red"
|
||||
class="ml-2"
|
||||
>
|
||||
Abbrechen
|
||||
</UButton>
|
||||
</template>
|
||||
|
||||
</UCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
51
spaces/pages/jobs/index.vue
Normal file
51
spaces/pages/jobs/index.vue
Normal file
@@ -0,0 +1,51 @@
|
||||
<template>
|
||||
<div id="main">
|
||||
|
||||
<UButton @click="router.push(`/jobs/create/`)">+ Job</UButton>
|
||||
|
||||
<UTable
|
||||
:rows="jobs"
|
||||
:columns="columns"
|
||||
@select="selectJob"
|
||||
|
||||
/>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
||||
definePageMeta({
|
||||
middleware: "auth"
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
const {jobs } = storeToRefs(useDataStore())
|
||||
const mode = ref("show")
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key: "title",
|
||||
label: "Titel",
|
||||
sortable: true
|
||||
},{
|
||||
key: "state",
|
||||
label: "Status",
|
||||
sortable: true
|
||||
},{
|
||||
key: "customer",
|
||||
label: "Kunde",
|
||||
sortable: true
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
const selectJob = (job) => {
|
||||
console.log(job)
|
||||
router.push(`/jobs/show/${job.id} `)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -6,7 +6,6 @@ definePageMeta({
|
||||
const supabase = useSupabaseClient()
|
||||
const user = useSupabaseUser()
|
||||
const toast = useToast()
|
||||
console.log(user)
|
||||
|
||||
const {times, projects} = storeToRefs(useDataStore())
|
||||
const {fetchTimes, getTimeTypes} = useDataStore()
|
||||
@@ -20,6 +19,38 @@ const timeInfo = ref({
|
||||
type: null
|
||||
})
|
||||
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key: "user",
|
||||
label: "Benutzer"
|
||||
},
|
||||
{
|
||||
key:"start",
|
||||
label:"Start"
|
||||
},
|
||||
{
|
||||
key:"type",
|
||||
label:"Typ"
|
||||
},
|
||||
{
|
||||
key: "end",
|
||||
label: "Ende"
|
||||
},
|
||||
{
|
||||
key: "duration",
|
||||
label: "Dauer"
|
||||
},
|
||||
{
|
||||
key: "projectId",
|
||||
label: "Projekt"
|
||||
},
|
||||
{
|
||||
key: "notes",
|
||||
label: "Notizen"
|
||||
}
|
||||
]
|
||||
|
||||
const runningTimeInfo = ref({
|
||||
|
||||
})
|
||||
@@ -43,7 +74,8 @@ const startTime = async () => {
|
||||
console.log(error)
|
||||
} else if(data) {
|
||||
timeInfo.value = data[0]
|
||||
fetchTimes()
|
||||
await fetchTimes()
|
||||
runningTimeInfo.value = times.value.find(time => time.user == user.value.id && !time.end)
|
||||
}
|
||||
|
||||
console.log(data)
|
||||
@@ -77,10 +109,17 @@ const stopStartedTime = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if(times.value.find(time => time.user == user.value.id && !time.end)) {
|
||||
runningTimeInfo.value = times.value.find(time => time.user == user.value.id && !time.end)
|
||||
}
|
||||
|
||||
const selectStartedTime = () => {
|
||||
runningTimeInfo.value = times.value.find(time => time.user == user.value.id && !time.end)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//selectStartedTime()
|
||||
|
||||
</script>
|
||||
@@ -101,12 +140,12 @@ const selectStartedTime = () => {
|
||||
>
|
||||
Stop
|
||||
</UButton>
|
||||
<UButton
|
||||
<!--<UButton
|
||||
class="controlButton"
|
||||
@click="selectStartedTime"
|
||||
>
|
||||
Zeit Wählen
|
||||
</UButton>
|
||||
</UButton>-->
|
||||
<UButton
|
||||
class="controlButton"
|
||||
@click="showAddTimeModal = true"
|
||||
@@ -227,6 +266,7 @@ const selectStartedTime = () => {
|
||||
<UTable
|
||||
class="mt-3"
|
||||
v-if="times && user"
|
||||
:columns="columns"
|
||||
:rows="times.filter(time => time.user === user.id)"
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user