FIX: Image Upload Bug
FIX: Minor Bugs
This commit is contained in:
@@ -35,6 +35,8 @@ const documentUrlsWithData = ref([]);
|
|||||||
const uploadedDocumentUrls = ref([]);
|
const uploadedDocumentUrls = ref([]);
|
||||||
const editMode = ref(false);
|
const editMode = ref(false);
|
||||||
const belonging = ref({
|
const belonging = ref({
|
||||||
|
documentUrls: [],
|
||||||
|
mainImageUrls: [],
|
||||||
location: {
|
location: {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
coordinates: [0, 0]
|
coordinates: [0, 0]
|
||||||
@@ -83,14 +85,14 @@ const handleDocumentGalleryDelete = (deletedDocumentUrl, index) => {
|
|||||||
|
|
||||||
const handleImageUpload = (newImageUrls) => {
|
const handleImageUpload = (newImageUrls) => {
|
||||||
uploadedMainImageUrls.value = newImageUrls.value;
|
uploadedMainImageUrls.value = newImageUrls.value;
|
||||||
const tempConcatImages = [...belonging.value?.mainImageUrls, ...newImageUrls.value];
|
// const tempConcatImages = [...belonging.value?.mainImageUrls, ...newImageUrls.value];
|
||||||
mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
// mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImageDelete = (newImageUrls) => {
|
const handleImageDelete = (newImageUrls) => {
|
||||||
uploadedMainImageUrls.value = newImageUrls;
|
uploadedMainImageUrls.value = newImageUrls;
|
||||||
const tempConcatImages = [...belonging.value?.mainImageUrls.value, ...newImageUrls.value];
|
// const tempConcatImages = [...belonging.value?.mainImageUrls.value, ...newImageUrls.value];
|
||||||
mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
// mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImageGalleryDelete = (deletedImageUrl, index) => {
|
const handleImageGalleryDelete = (deletedImageUrl, index) => {
|
||||||
@@ -254,6 +256,9 @@ const saveBelonging = async () => {
|
|||||||
belonging.value.features = extractFeatures(featuresValues.value);
|
belonging.value.features = extractFeatures(featuresValues.value);
|
||||||
status = await BelongingService.updateBelonging(belonging.value._id, belonging.value);
|
status = await BelongingService.updateBelonging(belonging.value._id, belonging.value);
|
||||||
} else {
|
} else {
|
||||||
|
belonging.value.mainImageUrls = mainImageUrlsWithData.value.map((x) => x.url);
|
||||||
|
belonging.value.documentUrls = documentUrlsWithData.value.map((x) => x.url);
|
||||||
|
belonging.value.features = extractFeatures(featuresValues.value);
|
||||||
status = await BelongingService.createBelonging(belonging.value);
|
status = await BelongingService.createBelonging(belonging.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +268,9 @@ const saveBelonging = async () => {
|
|||||||
toast.add({ severity: 'error', summary: 'ناموفق', detail: status, life: 3000 });
|
toast.add({ severity: 'error', summary: 'ناموفق', detail: status, life: 3000 });
|
||||||
}
|
}
|
||||||
|
|
||||||
await router.push('/belonging/list-belongings');
|
setTimeout(async () => {
|
||||||
|
await router.push('/belonging/list-belongings');
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const filters = ref({
|
const filters = ref({
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import Chip from 'primevue/chip';
|
|||||||
import InputIcon from 'primevue/inputicon';
|
import InputIcon from 'primevue/inputicon';
|
||||||
import IconField from 'primevue/iconfield';
|
import IconField from 'primevue/iconfield';
|
||||||
import LoadingCheck from '@/components/LoadingCheck.vue';
|
import LoadingCheck from '@/components/LoadingCheck.vue';
|
||||||
|
import { useConfirm } from 'primevue/useconfirm';
|
||||||
|
import ConfirmPopup from 'primevue/confirmpopup';
|
||||||
|
import axios from 'axios';
|
||||||
|
const deleteConfirm = useConfirm();
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadData();
|
loadData();
|
||||||
});
|
});
|
||||||
@@ -106,8 +109,8 @@ const onPageChange = (event) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadData = () => {
|
const loadData = async () => {
|
||||||
BelongingService.searchBelongings(route.query)
|
await BelongingService.searchBelongings(route.query)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log('response', response);
|
console.log('response', response);
|
||||||
belongings.value = response.belongings || response;
|
belongings.value = response.belongings || response;
|
||||||
@@ -115,7 +118,7 @@ const loadData = () => {
|
|||||||
pagesCount.value = Math.ceil(totalCount.value / per_page.value);
|
pagesCount.value = Math.ceil(totalCount.value / per_page.value);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.add({ severity: 'error', summary: 'Error', detail: 'Failed to load data', life: 3000 });
|
toast.add({ severity: 'error', summary: 'خطا', detail: 'خطا در بازیابی اطلاعات', life: 3000 });
|
||||||
console.error('Error loading data:', error);
|
console.error('Error loading data:', error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -135,6 +138,7 @@ const indexBelongings = async () => {
|
|||||||
// await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate API call
|
// await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate API call
|
||||||
await BelongingService.indexBelongings();
|
await BelongingService.indexBelongings();
|
||||||
// When indexing completes
|
// When indexing completes
|
||||||
|
loadData();
|
||||||
indexingFinished.value = true;
|
indexingFinished.value = true;
|
||||||
indexingMessage.value = 'ایندکس با موفقیت انجام شد';
|
indexingMessage.value = 'ایندکس با موفقیت انجام شد';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -147,9 +151,51 @@ const indexBelongings = async () => {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmDeleteBelonging = (id, event) => {
|
||||||
|
deleteConfirm.require({
|
||||||
|
target: event.currentTarget,
|
||||||
|
message: `آیا از حذف این دارایی اطمینان دارید؟`,
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
rejectProps: {
|
||||||
|
label: 'خیر',
|
||||||
|
severity: 'secondary',
|
||||||
|
outlined: true
|
||||||
|
},
|
||||||
|
acceptProps: {
|
||||||
|
label: 'بله'
|
||||||
|
},
|
||||||
|
accept: async () => {
|
||||||
|
try {
|
||||||
|
let url = '/api/belongings/admin/delete/' + id;
|
||||||
|
const method = 'delete';
|
||||||
|
const config = {
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
withCredentials: true
|
||||||
|
};
|
||||||
|
const response = await axios(config);
|
||||||
|
console.log(url, response);
|
||||||
|
toast.add({ severity: 'success', summary: 'موفقیت آمیز', detail: 'حذف دارایی با موفقیت انجام شد', life: 3000 });
|
||||||
|
|
||||||
|
await indexBelongings();
|
||||||
|
await loadData();
|
||||||
|
} catch (error) {
|
||||||
|
// handle error
|
||||||
|
toast.add({ severity: 'error', summary: ' خطا در انجام عملیات ', detail: error.response?.data?.message || 'خطایی در حذف دارایی', life: 3000 });
|
||||||
|
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
reject: () => {
|
||||||
|
// User rejected the confirmation, do nothing
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<ConfirmPopup></ConfirmPopup>
|
||||||
<div>
|
<div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<Toolbar class="mb-6">
|
<Toolbar class="mb-6">
|
||||||
@@ -215,7 +261,7 @@ const indexBelongings = async () => {
|
|||||||
<Column :exportable="false" style="min-width: 12rem">
|
<Column :exportable="false" style="min-width: 12rem">
|
||||||
<template #body="slotProps">
|
<template #body="slotProps">
|
||||||
<Button icon="pi pi-pencil" outlined rounded class="mr-2 mx-3" @click="editBelonging(slotProps.data._id)" />
|
<Button icon="pi pi-pencil" outlined rounded class="mr-2 mx-3" @click="editBelonging(slotProps.data._id)" />
|
||||||
<Button icon="pi pi-trash" outlined rounded severity="danger" class="mx-3" @click="confirmDeleteProduct(slotProps.data)" />
|
<Button icon="pi pi-trash" outlined rounded severity="danger" class="mx-3" @click="confirmDeleteBelonging(slotProps.data._id, $event)" />
|
||||||
</template>
|
</template>
|
||||||
</Column>
|
</Column>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
|||||||
Reference in New Issue
Block a user