Ne uplne otestovany prepis storu
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import {ref} from "vue";
|
||||
import {usePhotosStore} from "stores/Photo";
|
||||
import {fetchFlight} from "src/composables/objects/flight";
|
||||
import {usePointsOfInterestStore} from "stores/PointsOfInterest";
|
||||
|
||||
export const openBatchEdit = ref(false);
|
||||
export const editBatchPhotos = ref([]);
|
||||
export const openBatchPhotoForm = (photos) => {
|
||||
openBatchEdit.value = true;
|
||||
editBatchPhotos.value = photos;
|
||||
}
|
||||
|
||||
export const handleBatchPhotoEdit = async (flightId, data) => {
|
||||
const photoIds = data.photoIds;
|
||||
delete data.photoIds;
|
||||
delete data.id;
|
||||
|
||||
if (data.pointOfInterest && !data.pointOfInterest.id) {
|
||||
const poiData = {
|
||||
...data.pointOfInterest,
|
||||
isPublic: false,
|
||||
description: "",
|
||||
}
|
||||
await usePointsOfInterestStore().create(poiData).then(poi => data.pointOfInterest = {id: poi.id, name: poi.name});
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
for (const id of photoIds) {
|
||||
const updateData = {};
|
||||
if (data.name !== '') updateData.name = data.name;
|
||||
if (data.description !== '') updateData.description = data.description;
|
||||
if (data.pointOfInterest) updateData.pointOfInterest = data.pointOfInterest;
|
||||
|
||||
if (Object.keys(updateData).length === 0) continue;
|
||||
|
||||
promises.push(usePhotosStore().update(id, updateData));
|
||||
}
|
||||
|
||||
Promise.all(promises).finally(() => fetchFlight(flightId))
|
||||
}
|
||||
@@ -1,55 +1,58 @@
|
||||
import {computed, ref, watch} from "vue";
|
||||
import {cropper} from "vue-picture-cropper";
|
||||
import {roundWithPrecision} from "src/composables/utils";
|
||||
import {photoAspectRatio} from "src/composables/photos/editor/photo";
|
||||
|
||||
export const cropperImgSizes = computed(() => [cropper.getImageData().width, cropper.getImageData().height]);
|
||||
export const photoAspectRatio = ref(0);
|
||||
|
||||
export const cropperImgSizes = computed(() => {
|
||||
if (!cropper) return [];
|
||||
|
||||
return [cropper.getImageData().width, cropper.getImageData().height]
|
||||
});
|
||||
export const croppedArea = ref(null);
|
||||
export const selectedAspectRatio = ref(null);
|
||||
|
||||
watch(() => selectedAspectRatio.value, (newVal) => {
|
||||
cropper.setAspectRatio(newVal);
|
||||
console.log(newVal);
|
||||
cropper.setAspectRatio(newVal);
|
||||
})
|
||||
|
||||
|
||||
export const setCropData = () => {
|
||||
const [w, h] = cropperImgSizes.value;
|
||||
const [w, h] = cropperImgSizes.value;
|
||||
|
||||
console.log("crop end");
|
||||
|
||||
const cropData = cropper.getCropBoxData();
|
||||
croppedArea.value = {
|
||||
left: roundWithPrecision(cropData.left / w, 5),
|
||||
top: roundWithPrecision(cropData.top / h, 5),
|
||||
width: roundWithPrecision(cropData.width / w, 5),
|
||||
height: roundWithPrecision(cropData.height / h, 5)
|
||||
};
|
||||
const cropData = cropper.getCropBoxData();
|
||||
croppedArea.value = {
|
||||
left: roundWithPrecision(cropData.left / w, 5),
|
||||
top: roundWithPrecision(cropData.top / h, 5),
|
||||
width: roundWithPrecision(cropData.width / w, 5),
|
||||
height: roundWithPrecision(cropData.height / h, 5)
|
||||
};
|
||||
}
|
||||
|
||||
export const aspectRatioOptions = computed(() =>
|
||||
[
|
||||
{label: '16:9', value: roundWithPrecision(16 / 9, 5)},
|
||||
{label: '4:3', value: roundWithPrecision(4 / 3, 5)},
|
||||
{label: '9:16', value: roundWithPrecision(9 / 16, 5)},
|
||||
{label: '3:4', value: roundWithPrecision(3 / 4, 5)},
|
||||
{label: '1:1', value: 1},
|
||||
{label: 'Volný', value: null},
|
||||
{label: 'Původní', value: roundWithPrecision(photoAspectRatio.value, 5)},
|
||||
]
|
||||
export const aspectRatioOptions = computed(() => [
|
||||
{label: '16:9', value: roundWithPrecision(16 / 9, 5)},
|
||||
{label: '4:3', value: roundWithPrecision(4 / 3, 5)},
|
||||
{label: '9:16', value: roundWithPrecision(9 / 16, 5)},
|
||||
{label: '3:4', value: roundWithPrecision(3 / 4, 5)},
|
||||
{label: '1:1', value: 1},
|
||||
{label: 'Volný', value: null},
|
||||
{label: 'Původní', value: roundWithPrecision(photoAspectRatio.value, 5)},
|
||||
]
|
||||
);
|
||||
|
||||
export const cropperReady = (e) => {
|
||||
if (croppedArea.value) {
|
||||
const [w, h] = cropperImgSizes.value;
|
||||
selectedAspectRatio.value = roundWithPrecision((croppedArea.value.width * w) / (croppedArea.value.height * h), 5);
|
||||
if (croppedArea.value && croppedArea.value.height) {
|
||||
const [w, h] = cropperImgSizes.value;
|
||||
selectedAspectRatio.value = roundWithPrecision((croppedArea.value.width * w) / (croppedArea.value.height * h), 5);
|
||||
|
||||
cropper.setCropBoxData({
|
||||
left: croppedArea.value.left * w,
|
||||
top: croppedArea.value.top * h,
|
||||
width: croppedArea.value.width * w,
|
||||
height: croppedArea.value.height * h
|
||||
});
|
||||
} else {
|
||||
selectedAspectRatio.value = roundWithPrecision(photoAspectRatio.value, 5);
|
||||
}
|
||||
cropper.setCropBoxData({
|
||||
left: croppedArea.value.left * w,
|
||||
top: croppedArea.value.top * h,
|
||||
width: croppedArea.value.width * w,
|
||||
height: croppedArea.value.height * h
|
||||
});
|
||||
} else {
|
||||
selectedAspectRatio.value = roundWithPrecision(photoAspectRatio.value, 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import {computed, ref} from "vue";
|
||||
import {usePhotosStore} from "stores/Photo";
|
||||
|
||||
export const loading = ref(true);
|
||||
export const photo = ref(null);
|
||||
export const fetchPhoto = (id) => {
|
||||
loading.value = true;
|
||||
return usePhotosStore().fetchDetail(id)
|
||||
.then(resp => {
|
||||
photo.value = resp;
|
||||
return resp;
|
||||
})
|
||||
.finally(() => loading.value = false);
|
||||
};
|
||||
|
||||
export const photoAspectRatio = computed(() => photo.value.width / photo.value.height);
|
||||
@@ -1,22 +0,0 @@
|
||||
import {usePhotosStore} from "stores/Photo";
|
||||
import {fetchFlight} from "src/composables/objects/flight";
|
||||
import {usePointsOfInterestStore} from "stores/PointsOfInterest";
|
||||
import {ref} from "vue";
|
||||
|
||||
export const handlePhotoUpdate = (flightId, formData) => {
|
||||
const photoId = formData.id;
|
||||
delete formData.id;
|
||||
|
||||
usePhotosStore().update(photoId, formData).then((data) => {
|
||||
fetchFlight(flightId); // nenacita se mi nove vytvoreny POI z comboboxu
|
||||
usePointsOfInterestStore().fetch();
|
||||
});
|
||||
};
|
||||
|
||||
export const openEdit = ref(false);
|
||||
export const editPhoto = ref(null);
|
||||
|
||||
export const openPhotoEdit = (photo) => {
|
||||
openEdit.value = true;
|
||||
editPhoto.value = photo;
|
||||
};
|
||||
Reference in New Issue
Block a user