Some Changes

This commit is contained in:
2024-07-09 21:35:19 +02:00
parent 101b8d3361
commit eb4b8a8d9b
13 changed files with 436 additions and 170 deletions

View File

@@ -3,14 +3,28 @@ definePageMeta({
middleware: "auth"
})
defineShortcuts({
'backspace': () => {
router.push("/services")
},
'arrowleft': () => {
if(openTab.value > 0){
openTab.value -= 1
}
},
'arrowright': () => {
if(openTab.value < 3) {
openTab.value += 1
}
},
})
const dataStore = useDataStore()
const route = useRoute()
const router = useRouter()
const toast = useToast()
const id = ref(route.params.id ? route.params.id : null )
let currentItem = ref(null)
//Working
const mode = ref(route.params.mode || "show")
const itemInfo = ref({
@@ -18,30 +32,20 @@ const itemInfo = ref({
tags: []
})
const openTab = ref(0)
//Functions
const setupPage = () => {
if(mode.value === "show" || mode.value === "edit"){
currentItem.value = dataStore.getServiceById(Number(useRoute().params.id))
}
if(mode.value === "edit") itemInfo.value = currentItem.value
}
const cancelEditorCreate = () => {
if(currentItem.value) {
router.push(`/services/show/${currentItem.value.id}`)
} else {
router.push(`/services/`)
itemInfo.value = dataStore.getServiceById(Number(useRoute().params.id))
}
}
setupPage()
</script>
<template>
<UDashboardNavbar :title="currentItem ? currentItem.name : (mode === 'create' ? 'Leistung erstellen' : 'Leistung bearbeiten')">
<UDashboardNavbar :title="itemInfo ? itemInfo.name : (mode === 'create' ? 'Leistung erstellen' : 'Leistung bearbeiten')">
<template #right>
<UButton
v-if="mode === 'edit'"
@@ -56,7 +60,7 @@ setupPage()
Erstellen
</UButton>
<UButton
@click="cancelEditorCreate"
@click="itemInfo.value ? router.push(`/services/show/${itemInfo.value.id}`) : router.push(`/services/`)"
color="red"
class="ml-2"
v-if="mode === 'edit' || mode === 'create'"
@@ -65,7 +69,7 @@ setupPage()
</UButton>
<UButton
v-if="mode === 'show'"
@click="router.push(`/services/edit/${currentItem.id}`)"
@click="router.push(`/services/edit/${itemInfo.id}`)"
>
Bearbeiten
</UButton>
@@ -75,6 +79,7 @@ setupPage()
:items="[{label: 'Informationen'},{label: 'Logbuch'},{label: 'Dokumente'}]"
v-if="mode === 'show'"
class="p-5"
v-model="openTab"
>
<template #item="{item}">
<UCard class="mt-5">
@@ -82,9 +87,9 @@ setupPage()
v-if="item.label === 'Informationen'"
>
<div class="truncate">
<p v-if="currentItem.sellingPrice">Verkaufspreis: {{String(Number(currentItem.sellingPrice).toFixed(2)).replace(".",",")}} </p>
<p v-if="itemInfo.sellingPrice">Verkaufspreis: {{String(Number(itemInfo.sellingPrice).toFixed(2)).replace(".",",")}} </p>
<p>Beschreibung:</p>
<pre>{{currentItem.description}}</pre>
<pre>{{itemInfo.description}}</pre>
</div>
@@ -94,14 +99,14 @@ setupPage()
>
<HistoryDisplay
type="product"
v-if="currentItem"
:element-id="currentItem.id"
v-if="itemInfo"
:element-id="itemInfo.id"
/>
</div>
<div
v-if="item.label === 'Bestand'"
>
Bestand: {{dataStore.getStockByProductId(currentItem.id)}} {{dataStore.units.find(unit => unit.id === currentItem.unit) ? dataStore.units.find(unit => unit.id === currentItem.unit).name : ""}}
Bestand: {{dataStore.getStockByProductId(itemInfo.id)}} {{dataStore.units.find(unit => unit.id === itemInfo.unit) ? dataStore.units.find(unit => unit.id === itemInfo.unit).name : ""}}
</div>
<div
@@ -110,12 +115,12 @@ setupPage()
<Toolbar>
<DocumentUpload
type="product"
:element-id="currentItem.id"
:element-id="itemInfo.id"
/>
</Toolbar>
<DocumentList :documents="dataStore.getDocumentsByProductId(currentItem.id)"/>
<DocumentList :documents="dataStore.getDocumentsByProductId(itemInfo.id)"/>
</div>
</UCard>
</template>

View File

@@ -45,6 +45,15 @@
@select="(i) => router.push(`/services/show/${i.id}`) "
:empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: 'Keine Leistungen anzuzeigen' }"
>
<template #name-data="{row}">
<span
v-if="row === filteredRows[selectedItem]"
class="text-primary-500 font-bold">{{row.name}}</span>
<span v-else>
{{row.name}}
</span>
</template>
<template #sellingPrice-data="{row}">
{{row.sellingPrice ? Number(row.sellingPrice).toFixed(2) + " €" : ""}}
</template>
@@ -68,6 +77,26 @@ defineShortcuts({
},
'+': () => {
router.push("/services/create")
},
'Enter': {
usingInput: true,
handler: () => {
router.push(`/services/show/${filteredRows.value[selectedItem.value].id}`)
}
},
'arrowdown': () => {
if(selectedItem.value < filteredRows.value.length - 1) {
selectedItem.value += 1
} else {
selectedItem.value = 0
}
},
'arrowup': () => {
if (selectedItem.value === 0) {
selectedItem.value = filteredRows.value.length - 1
} else {
selectedItem.value -= 1
}
}
})
@@ -75,6 +104,16 @@ const dataStore = useDataStore()
const supabase = useSupabaseClient()
const router = useRouter()
const items = ref([])
const selectedItem = ref(0)
const setupPage = async () => {
items.value = await useSupabaseSelect("services","*")
}
setupPage()
const templateColumns = [
{
key: "name",
@@ -103,15 +142,9 @@ const columns = computed(() => templateColumns.filter((column) => selectedColumn
const searchString = ref('')
const filteredRows = computed(() => {
if(!searchString.value) {
return dataStore.services
}
return dataStore.services.filter(product => {
return Object.values(product).some((value) => {
return String(value).toLowerCase().includes(searchString.value.toLowerCase())
})
})
return useSearch(searchString.value, items.value)
})
</script>