Restructured Create Process Into Store
This commit is contained in:
@@ -40,29 +40,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
let fullName = itemInfo.value.firstName + ' ' + itemInfo.value.lastName
|
||||
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("contacts")
|
||||
.insert([{...itemInfo.value, fullName}])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
}
|
||||
toast.add({title: "Kontakt erfolgreich erstellt"})
|
||||
await dataStore.fetchContacts()
|
||||
router.push(`/contacts/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editCustomer = async () => {
|
||||
router.push(`/contacts/edit/${currentContact.id}`)
|
||||
setupPage()
|
||||
@@ -273,7 +250,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('contacts',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -37,27 +37,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("contracts")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
name: ""
|
||||
}
|
||||
toast.add({title: "Vertrag erfolgreich erstellt"})
|
||||
await dataStore.fetchContracts()
|
||||
router.push(`/contracts/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editCustomer = async () => {
|
||||
router.push(`/contracts/edit/${currentContract.id}`)
|
||||
setupPage()
|
||||
@@ -197,7 +176,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('contracts',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -19,7 +19,7 @@ let currentCustomer = ref(null)
|
||||
|
||||
//Working
|
||||
const mode = ref(route.params.mode || "show")
|
||||
const customerInfo = ref({
|
||||
const itemInfo = ref({
|
||||
name: "",
|
||||
infoData: {},
|
||||
active: true
|
||||
@@ -31,37 +31,11 @@ const setupPage = async () => {
|
||||
currentCustomer.value = await dataStore.getCustomerById(Number(useRoute().params.id))
|
||||
}
|
||||
|
||||
if(mode.value === "edit") customerInfo.value = currentCustomer.value
|
||||
if(mode.value === "edit") itemInfo.value = currentCustomer.value
|
||||
|
||||
|
||||
}
|
||||
|
||||
const createCustomer = async () => {
|
||||
|
||||
if(!customerInfo.value.customerNumber) customerInfo.value.customerNumber = await numberRange.useNextNumber()
|
||||
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("customers")
|
||||
.insert([customerInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
customerInfo.value = {
|
||||
id: 0,
|
||||
name: "",
|
||||
infoData: {}
|
||||
}
|
||||
toast.add({title: "Kunde erfolgreich erstellt"})
|
||||
await dataStore.fetchCustomers()
|
||||
router.push(`/customers/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editCustomer = async () => {
|
||||
router.push(`/customers/edit/${currentCustomer.value.id}`)
|
||||
setupPage()
|
||||
@@ -69,7 +43,7 @@ const editCustomer = async () => {
|
||||
|
||||
const cancelEditorCreate = () => {
|
||||
mode.value = "show"
|
||||
customerInfo.value = {
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
name: "",
|
||||
infoData: {}
|
||||
@@ -79,8 +53,8 @@ const cancelEditorCreate = () => {
|
||||
const updateCustomer = async () => {
|
||||
const {error} = await supabase
|
||||
.from("customers")
|
||||
.update(customerInfo.value)
|
||||
.eq('id',customerInfo.value.id)
|
||||
.update(itemInfo.value)
|
||||
.eq('id',itemInfo.value.id)
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
@@ -188,14 +162,14 @@ setupPage()
|
||||
</UCard>
|
||||
<UCard v-else-if="mode == 'edit' || mode == 'create'" >
|
||||
<template #header v-if="mode === 'edit'">
|
||||
<UBadge>{{customerInfo.customerNumber}}</UBadge>{{customerInfo.name}}
|
||||
<UBadge>{{itemInfo.customerNumber}}</UBadge>{{itemInfo.name}}
|
||||
</template>
|
||||
|
||||
<UFormGroup
|
||||
label="Name:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.name"
|
||||
v-model="itemInfo.name"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
@@ -203,7 +177,7 @@ setupPage()
|
||||
label="Kundennummer:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.customerNumber"
|
||||
v-model="itemInfo.customerNumber"
|
||||
placeholder="Leer lassen für automatisch generierte Nummer"
|
||||
/>
|
||||
</UFormGroup>
|
||||
@@ -213,7 +187,7 @@ setupPage()
|
||||
label="Kunde aktiv:"
|
||||
>
|
||||
<UCheckbox
|
||||
v-model="customerInfo.active"
|
||||
v-model="itemInfo.active"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</UTooltip>
|
||||
@@ -221,7 +195,7 @@ setupPage()
|
||||
label="Notizen:"
|
||||
>
|
||||
<UTextarea
|
||||
v-model="customerInfo.notes"
|
||||
v-model="itemInfo.notes"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
@@ -229,21 +203,21 @@ setupPage()
|
||||
label="Straße + Hausnummer"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.street"
|
||||
v-model="itemInfo.infoData.street"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="Postleitzahl"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.zip"
|
||||
v-model="itemInfo.infoData.zip"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="Ort"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.city"
|
||||
v-model="itemInfo.infoData.city"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
@@ -251,28 +225,28 @@ setupPage()
|
||||
label="Telefon:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.tel"
|
||||
v-model="itemInfo.infoData.tel"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="E-Mail:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.email"
|
||||
v-model="itemInfo.infoData.email"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="Webseite:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.web"
|
||||
v-model="itemInfo.infoData.web"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="USt-Id:"
|
||||
>
|
||||
<UInput
|
||||
v-model="customerInfo.infoData.ustid"
|
||||
v-model="itemInfo.infoData.ustid"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
@@ -285,7 +259,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createCustomer"
|
||||
@click="dataStore.createNewItem('customers',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -46,26 +46,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("absenceRequests")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
}
|
||||
toast.add({title: "Abwesenheit erfolgreich erstellt"})
|
||||
await dataStore.fetchAbsenceRequests()
|
||||
router.push(`/employees/absenceRequests/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
router.push(`/employees/absenceRequests/edit/${currentItem.id}`)
|
||||
setupPage()
|
||||
@@ -234,7 +214,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('absenceRequests', itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -40,26 +40,7 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("plants")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
title: "",
|
||||
}
|
||||
toast.add({title: "Anlage erfolgreich erstellt"})
|
||||
await dataStore.fetchPlants()
|
||||
router.push(`/plants/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
router.push(`/plants/edit/${currentItem.id}`)
|
||||
@@ -199,7 +180,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('plants', itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -33,26 +33,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("products")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
name: ""
|
||||
}
|
||||
toast.add({title: "Artikel erfolgreich erstellt"})
|
||||
await dataStore.fetchProducts()
|
||||
router.push(`/products/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
router.push(`/products/edit/${currentProduct.id}`)
|
||||
@@ -226,7 +206,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('products',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -124,27 +124,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("projects")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
title: "",
|
||||
}
|
||||
toast.add({title: "Projekt erfolgreich erstellt"})
|
||||
await dataStore.fetchProjects()
|
||||
router.push(`/projects/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
router.push(`/projects/edit/${currentItem.value.id}`)
|
||||
setupPage()
|
||||
@@ -533,7 +512,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('projects',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -10,7 +10,13 @@ const router = useRouter()
|
||||
const toast = useToast()
|
||||
const id = ref(route.params.id ? route.params.id : null )
|
||||
|
||||
let currentItem = null
|
||||
let currentItem = ref(null)
|
||||
|
||||
/*watch(dataStore.tasks, (oldVal,newVal) => {
|
||||
console.log("OK")
|
||||
console.log(dataStore.tasks)
|
||||
currentItem.value = dataStore.getTaskById(Number(useRoute().params.id))
|
||||
})*/
|
||||
|
||||
//Working
|
||||
const mode = ref(route.params.mode || "show")
|
||||
@@ -37,7 +43,10 @@ const setupPage = () => {
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
|
||||
|
||||
|
||||
/*const {data,error} = await supabase
|
||||
.from("tasks")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
@@ -50,11 +59,11 @@ const createItem = async () => {
|
||||
id: 0,
|
||||
title: "",
|
||||
}
|
||||
toast.add({title: "Aufgabe erfolgreich erstellt"})
|
||||
//toast.add({title: "Aufgabe erfolgreich erstellt"})
|
||||
await dataStore.fetchTasks()
|
||||
router.push(`/tasks/show/${data[0].id}`)
|
||||
//router.push(`/tasks/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
@@ -219,7 +228,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('tasks',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
@@ -329,8 +329,8 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="timeSelection = 'Letztes Jahr'"
|
||||
:variant="timeSelection === 'Letzes Jahr' ? 'solid' : 'outline'"
|
||||
color="slate"
|
||||
:variant="timeSelection === 'Letztes Jahr' ? 'solid' : 'outline'"
|
||||
color="rose"
|
||||
>
|
||||
Letztes Jahr
|
||||
</UButton>
|
||||
|
||||
@@ -68,26 +68,6 @@ const setupPage = () => {
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
const {data,error} = await supabase
|
||||
.from("vehicles")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {
|
||||
id: 0,
|
||||
name: ""
|
||||
}
|
||||
toast.add({title: "Fahrzeug erfolgreich erstellt"})
|
||||
await dataStore.fetchVehicles()
|
||||
router.push(`/vehicles/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
}
|
||||
|
||||
const editCustomer = async () => {
|
||||
router.push(`/vehicles/edit/${currentItem.value.id}`)
|
||||
@@ -257,7 +237,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('vehicles',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
36
spaces/pages/vendors/[mode]/[[id]].vue
vendored
36
spaces/pages/vendors/[mode]/[[id]].vue
vendored
@@ -13,7 +13,7 @@ const toast = useToast()
|
||||
const id = ref(route.params.id ? route.params.id : null )
|
||||
const numberRange = useNumberRange("vendors")
|
||||
|
||||
let currentItem = null
|
||||
let currentItem = ref(null)
|
||||
|
||||
|
||||
|
||||
@@ -25,35 +25,11 @@ const itemInfo = ref({
|
||||
|
||||
//Functions
|
||||
const setupPage = () => {
|
||||
if(mode.value === "show" || mode.value === "edit"){
|
||||
currentItem = dataStore.getVendorById(Number(useRoute().params.id))
|
||||
if (mode.value === "show" || mode.value === "edit") {
|
||||
currentItem.value = dataStore.getVendorById(Number(useRoute().params.id))
|
||||
}
|
||||
|
||||
if(mode.value === "edit") itemInfo.value = currentItem
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const createItem = async () => {
|
||||
|
||||
if(!itemInfo.value.vendorNumber) itemInfo.value.vendorNumber = await numberRange.useNextNumber()
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("vendors")
|
||||
.insert([itemInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
mode.value = "show"
|
||||
itemInfo.value = {}
|
||||
toast.add({title: "Lieferant erfolgreich erstellt"})
|
||||
await dataStore.fetchVendors()
|
||||
router.push(`/vendors/show/${data[0].id}`)
|
||||
setupPage()
|
||||
}
|
||||
if (mode.value === "edit") itemInfo.value = currentItem.value
|
||||
}
|
||||
|
||||
const editItem = async () => {
|
||||
@@ -75,7 +51,7 @@ const updateItem = async () => {
|
||||
console.log(error)
|
||||
} else {
|
||||
toast.add({title: "Lieferant erfolgreich gespeichert"})
|
||||
router.push(`/vendors/show/${currentItem.id}`)
|
||||
router.push(`/vendors/show/${currentItem.value.id}`)
|
||||
dataStore.fetchVendors()
|
||||
}
|
||||
|
||||
@@ -226,7 +202,7 @@ setupPage()
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode == 'create'"
|
||||
@click="createItem"
|
||||
@click="dataStore.createNewItem('vendors',itemInfo)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
|
||||
Reference in New Issue
Block a user