diff --git a/src/pages/Admin/PhotosView.vue b/src/pages/Admin/PhotosView.vue index b1e32f94..257adef7 100644 --- a/src/pages/Admin/PhotosView.vue +++ b/src/pages/Admin/PhotosView.vue @@ -3,11 +3,10 @@ import { useI18n } from 'vue-i18n'; import { ref, onMounted, inject, reactive, computed } from 'vue'; import VnSelect from 'src/components/common/VnSelect.vue'; -import VnForm from 'src/components/common/VnForm.vue'; import VnInput from 'src/components/common/VnInput.vue'; import useNotify from 'src/composables/useNotify.js'; +import FormModel from 'src/components/common/FormModel.vue'; -const jApi = inject('jApi'); const api = inject('api'); const { t } = useI18n(); const { notify } = useNotify(); @@ -33,7 +32,7 @@ const statusIcons = { } }; const formInitialData = reactive({ - schema: 'catalog', + collectionFk: 'catalog', updateMatching: true }); const imageCollections = ref([]); @@ -45,9 +44,8 @@ const isSubmitable = computed(() => const getImageCollections = async () => { try { - imageCollections.value = await jApi.query( - 'SELECT name, `desc` FROM imageCollection ORDER BY `desc`' - ); + const { data } = await api.get('imageCollections'); + imageCollections.value = data; } catch (error) { console.error('Error getting image collections:', error); } @@ -61,38 +59,36 @@ const onSubmit = async data => { const filteredFiles = addedFiles.value.filter( file => file.uploadStatus === 'pending' ); - const promises = filteredFiles.map((file, index) => { + const promises = filteredFiles.map(async (file, index) => { const fileIndex = filteredFiles[index].index; addedFiles.value[fileIndex].uploadStatus = 'uploading'; - const formData = new FormData(); - formData.append('updateMatching', data.updateMatching); - formData.append('image', file.file); - formData.append('name', file.name); - formData.append('schema', data.schema); - formData.append('srv', 'json:image/upload'); - return api({ - method: 'post', - url: location.origin, - data: formData, + const now = new Date(); + const timestamp = now.getTime(); + const fileName = `${file.name}_${timestamp}`; + formData.append('image', file.file, fileName); + + await api.post('images/uploadPhotoAdmin', formData, { + params: { + name: fileName, + collection: data.collectionFk, + updateMatching: data.updateMatching + }, headers: { 'Content-Type': 'multipart/form-data' } }); }); - const results = await Promise.allSettled(promises); results.forEach((result, index) => { const fileIndex = filteredFiles[index].index; addedFiles.value[fileIndex].uploadStatus = result.status; - if (result.status === 'rejected') { addedFiles.value[fileIndex].errorMessage = t( result.reason?.response?.data?.data?.message ); } }); - const allSuccessful = results.every( result => result.status === 'fulfilled' ); @@ -139,16 +135,17 @@ onMounted(async () => getImageCollections());