FIX: Image Upload Bug
FIX: Minor Bugs
This commit is contained in:
@@ -35,6 +35,8 @@ const documentUrlsWithData = ref([]);
|
||||
const uploadedDocumentUrls = ref([]);
|
||||
const editMode = ref(false);
|
||||
const belonging = ref({
|
||||
documentUrls: [],
|
||||
mainImageUrls: [],
|
||||
location: {
|
||||
type: 'Point',
|
||||
coordinates: [0, 0]
|
||||
@@ -83,14 +85,14 @@ const handleDocumentGalleryDelete = (deletedDocumentUrl, index) => {
|
||||
|
||||
const handleImageUpload = (newImageUrls) => {
|
||||
uploadedMainImageUrls.value = newImageUrls.value;
|
||||
const tempConcatImages = [...belonging.value?.mainImageUrls, ...newImageUrls.value];
|
||||
mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||
// const tempConcatImages = [...belonging.value?.mainImageUrls, ...newImageUrls.value];
|
||||
// mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||
};
|
||||
|
||||
const handleImageDelete = (newImageUrls) => {
|
||||
uploadedMainImageUrls.value = newImageUrls;
|
||||
const tempConcatImages = [...belonging.value?.mainImageUrls.value, ...newImageUrls.value];
|
||||
mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||
// const tempConcatImages = [...belonging.value?.mainImageUrls.value, ...newImageUrls.value];
|
||||
// mainImageUrlsWithData.value = fillImagesArray(tempConcatImages);
|
||||
};
|
||||
|
||||
const handleImageGalleryDelete = (deletedImageUrl, index) => {
|
||||
@@ -254,6 +256,9 @@ const saveBelonging = async () => {
|
||||
belonging.value.features = extractFeatures(featuresValues.value);
|
||||
status = await BelongingService.updateBelonging(belonging.value._id, belonging.value);
|
||||
} 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);
|
||||
}
|
||||
|
||||
@@ -263,7 +268,9 @@ const saveBelonging = async () => {
|
||||
toast.add({ severity: 'error', summary: 'ناموفق', detail: status, life: 3000 });
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
await router.push('/belonging/list-belongings');
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const filters = ref({
|
||||
|
||||
@@ -9,7 +9,10 @@ import Chip from 'primevue/chip';
|
||||
import InputIcon from 'primevue/inputicon';
|
||||
import IconField from 'primevue/iconfield';
|
||||
import LoadingCheck from '@/components/LoadingCheck.vue';
|
||||
|
||||
import { useConfirm } from 'primevue/useconfirm';
|
||||
import ConfirmPopup from 'primevue/confirmpopup';
|
||||
import axios from 'axios';
|
||||
const deleteConfirm = useConfirm();
|
||||
onMounted(() => {
|
||||
loadData();
|
||||
});
|
||||
@@ -106,8 +109,8 @@ const onPageChange = (event) => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadData = () => {
|
||||
BelongingService.searchBelongings(route.query)
|
||||
const loadData = async () => {
|
||||
await BelongingService.searchBelongings(route.query)
|
||||
.then((response) => {
|
||||
console.log('response', response);
|
||||
belongings.value = response.belongings || response;
|
||||
@@ -115,7 +118,7 @@ const loadData = () => {
|
||||
pagesCount.value = Math.ceil(totalCount.value / per_page.value);
|
||||
})
|
||||
.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);
|
||||
});
|
||||
};
|
||||
@@ -135,6 +138,7 @@ const indexBelongings = async () => {
|
||||
// await new Promise((resolve) => setTimeout(resolve, 2000)); // Simulate API call
|
||||
await BelongingService.indexBelongings();
|
||||
// When indexing completes
|
||||
loadData();
|
||||
indexingFinished.value = true;
|
||||
indexingMessage.value = 'ایندکس با موفقیت انجام شد';
|
||||
} catch (error) {
|
||||
@@ -147,9 +151,51 @@ const indexBelongings = async () => {
|
||||
}, 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>
|
||||
|
||||
<template>
|
||||
<ConfirmPopup></ConfirmPopup>
|
||||
<div>
|
||||
<div class="card">
|
||||
<Toolbar class="mb-6">
|
||||
@@ -215,7 +261,7 @@ const indexBelongings = async () => {
|
||||
<Column :exportable="false" style="min-width: 12rem">
|
||||
<template #body="slotProps">
|
||||
<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>
|
||||
</Column>
|
||||
</DataTable>
|
||||
|
||||
Reference in New Issue
Block a user