Fix for Object Create from Customer
This commit is contained in:
@@ -29,7 +29,6 @@ const props = defineProps({
|
||||
|
||||
const emit = defineEmits(["returnData"])
|
||||
|
||||
|
||||
const {type} = props
|
||||
|
||||
defineShortcuts({
|
||||
@@ -53,11 +52,10 @@ const route = useRoute()
|
||||
const dataStore = useDataStore()
|
||||
const modal = useModal()
|
||||
|
||||
|
||||
const dataType = dataStore.dataTypes[type]
|
||||
const openTab = ref(0)
|
||||
const item = ref(JSON.parse(props.item))
|
||||
console.log(item.value)
|
||||
// console.log(item.value)
|
||||
|
||||
const oldItem = ref(null)
|
||||
const generateOldItemData = () => {
|
||||
@@ -66,6 +64,39 @@ const generateOldItemData = () => {
|
||||
generateOldItemData()
|
||||
|
||||
|
||||
// --- ÄNDERUNG START: Computed Property statt Watcher/Function ---
|
||||
// Dies berechnet den Status automatisch neu, egal woher die Daten kommen (Init oder User-Eingabe)
|
||||
const saveAllowed = computed(() => {
|
||||
if (!item.value) return false
|
||||
|
||||
let allowedCount = 0
|
||||
// Nur Input-Felder berücksichtigen
|
||||
const relevantColumns = dataType.templateColumns.filter(i => i.inputType)
|
||||
|
||||
relevantColumns.forEach(datapoint => {
|
||||
if(datapoint.required) {
|
||||
if(datapoint.key.includes(".")){
|
||||
const [parentKey, childKey] = datapoint.key.split('.')
|
||||
// Prüfung: Existiert Parent UND ist Child "truthy" (nicht null/undefined/empty)
|
||||
if(item.value[parentKey] && item.value[parentKey][childKey]) {
|
||||
allowedCount += 1
|
||||
}
|
||||
} else {
|
||||
if(item.value[datapoint.key]) {
|
||||
allowedCount += 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Wenn nicht required, zählt es immer als "erlaubt"
|
||||
allowedCount += 1
|
||||
}
|
||||
})
|
||||
|
||||
return allowedCount >= relevantColumns.length
|
||||
})
|
||||
// --- ÄNDERUNG ENDE ---
|
||||
|
||||
|
||||
const setupCreate = () => {
|
||||
dataType.templateColumns.forEach(datapoint => {
|
||||
if(datapoint.key.includes(".")){
|
||||
@@ -78,10 +109,7 @@ const setupCreate = () => {
|
||||
} else {
|
||||
item.value[datapoint.key] = {}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
setupCreate()
|
||||
@@ -91,49 +119,45 @@ const setupQuery = () => {
|
||||
console.log(props.mode)
|
||||
if(props.mode === "create" && (route.query || props.createQuery)) {
|
||||
|
||||
|
||||
let data = !props.inModal ? route.query : props.createQuery
|
||||
|
||||
Object.keys(data).forEach(key => {
|
||||
if(dataType.templateColumns.find(i => i.key === key)) {
|
||||
if (dataType.templateColumns.find(i => i.key === key)) {
|
||||
if (["customer", "contract", "plant", "contact", "project"].includes(key)) {
|
||||
item.value[key] = Number(data[key])
|
||||
} else {
|
||||
item.value[key] = data[key]
|
||||
}
|
||||
} else if(key === "resources") {
|
||||
} else if (key === "resources") {
|
||||
/*item.value[key] = data[key]*/
|
||||
JSON.parse(data[key]).forEach(async (i) => {
|
||||
console.log(i)
|
||||
let type = i.substring(0,1)
|
||||
let id = i.substring(2,i.length)
|
||||
let type = i.substring(0, 1)
|
||||
let id = i.substring(2, i.length)
|
||||
console.log(type)
|
||||
console.log(id)
|
||||
let holder = ""
|
||||
if(type === "P"){
|
||||
if (type === "P") {
|
||||
holder = "profiles"
|
||||
} else if(type === "F"){
|
||||
} else if (type === "F") {
|
||||
holder = "vehicles"
|
||||
id = Number(id)
|
||||
} else if(type === "I"){
|
||||
} else if (type === "I") {
|
||||
holder = "inventoryitems"
|
||||
id = Number(id)
|
||||
} else if(type === "G"){
|
||||
} else if (type === "G") {
|
||||
holder = "inventoryitemgroups"
|
||||
}
|
||||
|
||||
if(typeof item.value[holder] === "object") {
|
||||
if (typeof item.value[holder] === "object") {
|
||||
item.value[holder].push(id)
|
||||
} else {
|
||||
item.value[holder] = [id]
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
// calcSaveAllowed() -> Entfernt, da computed automatisch reagiert
|
||||
}
|
||||
}
|
||||
setupQuery()
|
||||
@@ -148,14 +172,14 @@ const loadOptions = async () => {
|
||||
})
|
||||
|
||||
for await(const option of optionsToLoad) {
|
||||
if(option.option === "countrys") {
|
||||
if (option.option === "countrys") {
|
||||
loadedOptions.value[option.option] = useEntities("countrys").selectSpecial()
|
||||
} else if(option.option === "units") {
|
||||
} else if (option.option === "units") {
|
||||
loadedOptions.value[option.option] = useEntities("units").selectSpecial()
|
||||
} else {
|
||||
loadedOptions.value[option.option] = (await useEntities(option.option).select())
|
||||
|
||||
if(dataType.templateColumns.find(x => x.key === option.key).selectDataTypeFilter){
|
||||
if (dataType.templateColumns.find(x => x.key === option.key).selectDataTypeFilter) {
|
||||
loadedOptions.value[option.option] = loadedOptions.value[option.option].filter(i => dataType.templateColumns.find(x => x.key === option.key).selectDataTypeFilter(i, item))
|
||||
}
|
||||
}
|
||||
@@ -165,47 +189,23 @@ const loadOptions = async () => {
|
||||
loadOptions()
|
||||
|
||||
const contentChanged = (content, datapoint) => {
|
||||
if(datapoint.key.includes(".")){
|
||||
item[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].html = content.html
|
||||
item[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].text = content.text
|
||||
item[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].json = content.json
|
||||
if (datapoint.key.includes(".")) {
|
||||
item.value[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].html = content.html
|
||||
item.value[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].text = content.text
|
||||
item.value[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]].json = content.json
|
||||
} else {
|
||||
item[datapoint.key].html = content.html
|
||||
item[datapoint.key].text = content.text
|
||||
item[datapoint.key].json = content.json
|
||||
item.value[datapoint.key].html = content.html
|
||||
item.value[datapoint.key].text = content.text
|
||||
item.value[datapoint.key].json = content.json
|
||||
}
|
||||
}
|
||||
|
||||
const saveAllowed = ref(false)
|
||||
const calcSaveAllowed = (item) => {
|
||||
let allowedCount = 0
|
||||
|
||||
dataType.templateColumns.filter(i => i.inputType).forEach(datapoint => {
|
||||
if(datapoint.required) {
|
||||
|
||||
if(datapoint.key.includes(".")){
|
||||
if(item[datapoint.key.split('.')[0]][datapoint.key.split('.')[1]]) allowedCount += 1
|
||||
} else {
|
||||
if(item[datapoint.key]) allowedCount += 1
|
||||
}
|
||||
} else {
|
||||
allowedCount += 1
|
||||
}
|
||||
})
|
||||
|
||||
saveAllowed.value = allowedCount >= dataType.templateColumns.filter(i => i.inputType).length
|
||||
}
|
||||
//calcSaveAllowed()
|
||||
|
||||
watch(item.value, async (newItem, oldItem) => {
|
||||
calcSaveAllowed(newItem)
|
||||
})
|
||||
|
||||
const createItem = async () => {
|
||||
let ret = null
|
||||
|
||||
if(props.inModal) {
|
||||
ret = await useEntities(type).create(item.value, true)
|
||||
if (props.inModal) {
|
||||
ret = await useEntities(type).create(item.value, true)
|
||||
|
||||
} else {
|
||||
ret = await useEntities(type).create(item.value)//dataStore.createNewItem(type,item.value)
|
||||
@@ -218,7 +218,7 @@ const createItem = async () => {
|
||||
const updateItem = async () => {
|
||||
let ret = null
|
||||
|
||||
if(props.inModal) {
|
||||
if (props.inModal) {
|
||||
ret = await useEntities(type).update(item.value.id, item.value, true)
|
||||
emit('returnData', ret)
|
||||
modal.close()
|
||||
@@ -226,11 +226,7 @@ const updateItem = async () => {
|
||||
ret = await useEntities(type).update(item.value.id, item.value)
|
||||
emit('returnData', ret)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -245,16 +241,15 @@ const updateItem = async () => {
|
||||
<UButton
|
||||
icon="i-heroicons-chevron-left"
|
||||
variant="outline"
|
||||
@click="router.back()/*router.push(`/standardEntity/${type}`)*/"
|
||||
@click="router.back()"
|
||||
>
|
||||
<!-- {{dataType.label}}-->
|
||||
</UButton>
|
||||
</template>
|
||||
<template #center>
|
||||
<h1
|
||||
v-if="item"
|
||||
:class="['text-xl','font-medium', 'text-center']"
|
||||
>{{item.id ? `${dataType.labelSingle} bearbeiten` : `${dataType.labelSingle} erstellen` }}</h1>
|
||||
>{{ item.id ? `${dataType.labelSingle} bearbeiten` : `${dataType.labelSingle} erstellen` }}</h1>
|
||||
</template>
|
||||
<template #right>
|
||||
<ArchiveButton
|
||||
@@ -295,7 +290,7 @@ const updateItem = async () => {
|
||||
<h1
|
||||
v-if="item"
|
||||
:class="['text-xl','font-medium']"
|
||||
>{{item.id ? `${dataType.labelSingle} bearbeiten` : `${dataType.labelSingle} erstellen` }}</h1>
|
||||
>{{ item.id ? `${dataType.labelSingle} bearbeiten` : `${dataType.labelSingle} erstellen` }}</h1>
|
||||
</template>
|
||||
<template #right>
|
||||
<UButton
|
||||
@@ -330,11 +325,7 @@ const updateItem = async () => {
|
||||
v-for="(columnName,index) in dataType.inputColumns"
|
||||
:class="platform === 'mobile' ? ['w-full'] : [`w-1/${dataType.inputColumns.length}`, ... index < dataType.inputColumns.length -1 ? ['mr-5'] : []]"
|
||||
>
|
||||
<UDivider>{{columnName}}</UDivider>
|
||||
|
||||
<!--
|
||||
Die Form Group darf nur in der ersten bearbeitet werden und muss dann runterkopiert werden
|
||||
-->
|
||||
<UDivider>{{ columnName }}</UDivider>
|
||||
|
||||
<div
|
||||
v-for="datapoint in dataType.templateColumns.filter(i => i.inputType && i.inputColumn === columnName)"
|
||||
@@ -362,7 +353,7 @@ const updateItem = async () => {
|
||||
:placeholder="datapoint.inputIsNumberRange ? 'Leer lassen für automatisch generierte Nummer' : ''"
|
||||
>
|
||||
<template #trailing v-if="datapoint.inputTrailing">
|
||||
<span class="text-gray-500 dark:text-gray-400 text-xs">{{datapoint.inputTrailing}}</span>
|
||||
<span class="text-gray-500 dark:text-gray-400 text-xs">{{ datapoint.inputTrailing }}</span>
|
||||
</template>
|
||||
</UInput>
|
||||
<UToggle
|
||||
@@ -436,7 +427,6 @@ const updateItem = async () => {
|
||||
/>
|
||||
</template>
|
||||
</UPopover>
|
||||
<!-- TODO: DISABLED FOR TIPTAP -->
|
||||
<Tiptap
|
||||
v-else-if="datapoint.inputType === 'editor'"
|
||||
@updateContent="(i) => contentChanged(i,datapoint)"
|
||||
@@ -463,7 +453,7 @@ const updateItem = async () => {
|
||||
:placeholder="datapoint.inputIsNumberRange ? 'Leer lassen für automatisch generierte Nummer' : ''"
|
||||
>
|
||||
<template #trailing v-if="datapoint.inputTrailing">
|
||||
{{datapoint.inputTrailing}}
|
||||
{{ datapoint.inputTrailing }}
|
||||
</template>
|
||||
</UInput>
|
||||
<UToggle
|
||||
@@ -537,7 +527,6 @@ const updateItem = async () => {
|
||||
/>
|
||||
</template>
|
||||
</UPopover>
|
||||
<!-- TODO: Color/Required for TipTap and MaterialComposing -->
|
||||
<Tiptap
|
||||
v-else-if="datapoint.inputType === 'editor'"
|
||||
@updateContent="(i) => contentChanged(i,datapoint)"
|
||||
@@ -562,35 +551,8 @@ const updateItem = async () => {
|
||||
icon="i-heroicons-x-mark"
|
||||
/>
|
||||
</InputGroup>
|
||||
<!-- <div
|
||||
v-if="profileStore.ownTenant.ownFields"
|
||||
>
|
||||
<UDivider
|
||||
class="mt-3"
|
||||
>Eigene Felder</UDivider>
|
||||
|
||||
<UFormGroup
|
||||
v-for="field in profileStore.ownTenant.ownFields.contracts"
|
||||
:key="field.key"
|
||||
:label="field.label"
|
||||
>
|
||||
<UInput
|
||||
v-if="field.type === 'text'"
|
||||
v-model="item.ownFields[field.key]"
|
||||
/>
|
||||
<USelectMenu
|
||||
v-else-if="field.type === 'select'"
|
||||
:options="field.options"
|
||||
v-model="item.ownFields[field.key]"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</div>-->
|
||||
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<UFormGroup
|
||||
@@ -616,7 +578,7 @@ const updateItem = async () => {
|
||||
:placeholder="datapoint.inputIsNumberRange ? 'Leer lassen für automatisch generierte Nummer' : ''"
|
||||
>
|
||||
<template #trailing v-if="datapoint.inputTrailing">
|
||||
<span class="text-gray-500 dark:text-gray-400 text-xs">{{datapoint.inputTrailing}}</span>
|
||||
<span class="text-gray-500 dark:text-gray-400 text-xs">{{ datapoint.inputTrailing }}</span>
|
||||
</template>
|
||||
</UInput>
|
||||
<UToggle
|
||||
@@ -690,7 +652,6 @@ const updateItem = async () => {
|
||||
/>
|
||||
</template>
|
||||
</UPopover>
|
||||
<!-- TODO: DISABLED FOR TIPTAP -->
|
||||
<Tiptap
|
||||
v-else-if="datapoint.inputType === 'editor'"
|
||||
@updateContent="(i) => contentChanged(i,datapoint)"
|
||||
@@ -717,7 +678,7 @@ const updateItem = async () => {
|
||||
:placeholder="datapoint.inputIsNumberRange ? 'Leer lassen für automatisch generierte Nummer' : ''"
|
||||
>
|
||||
<template #trailing v-if="datapoint.inputTrailing">
|
||||
{{datapoint.inputTrailing}}
|
||||
{{ datapoint.inputTrailing }}
|
||||
</template>
|
||||
</UInput>
|
||||
<UToggle
|
||||
@@ -791,7 +752,6 @@ const updateItem = async () => {
|
||||
/>
|
||||
</template>
|
||||
</UPopover>
|
||||
<!-- TODO: Color/Required for TipTap and MaterialComposing -->
|
||||
<Tiptap
|
||||
v-else-if="datapoint.inputType === 'editor'"
|
||||
@updateContent="(i) => contentChanged(i,datapoint)"
|
||||
@@ -800,8 +760,8 @@ const updateItem = async () => {
|
||||
|
||||
|
||||
<MaterialComposing
|
||||
v-else-if="datapoint.inputType === 'materialComposing'"
|
||||
:item="item"
|
||||
v-else-if="datapoint.inputType === 'materialComposing'"
|
||||
:item="item"
|
||||
/>
|
||||
<PersonalComposing
|
||||
v-else-if="datapoint.inputType === 'personalComposing'"
|
||||
@@ -816,30 +776,6 @@ const updateItem = async () => {
|
||||
icon="i-heroicons-x-mark"
|
||||
/>
|
||||
</InputGroup>
|
||||
<!-- <div
|
||||
v-if="profileStore.ownTenant.ownFields"
|
||||
>
|
||||
<UDivider
|
||||
class="mt-3"
|
||||
>Eigene Felder</UDivider>
|
||||
|
||||
<UFormGroup
|
||||
v-for="field in profileStore.ownTenant.ownFields.contracts"
|
||||
:key="field.key"
|
||||
:label="field.label"
|
||||
>
|
||||
<UInput
|
||||
v-if="field.type === 'text'"
|
||||
v-model="item.ownFields[field.key]"
|
||||
/>
|
||||
<USelectMenu
|
||||
v-else-if="field.type === 'select'"
|
||||
:options="field.options"
|
||||
v-model="item.ownFields[field.key]"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</div>-->
|
||||
|
||||
</UFormGroup>
|
||||
</UForm>
|
||||
</UDashboardPanelContent>
|
||||
|
||||
Reference in New Issue
Block a user