[chore] better filepicker for images
This commit is contained in:
parent
33d91c4b9a
commit
774db1873a
|
@ -37,9 +37,13 @@
|
||||||
</template>
|
</template>
|
||||||
<template #item="props">
|
<template #item="props">
|
||||||
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4">
|
<div class="q-pa-xs col-xs-12 col-sm-6 col-md-4">
|
||||||
|
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-img v-if="showPic && props.row.has_image" style="max-height: 256px" :src="image(props.row.id)" fit="contain">
|
<q-img
|
||||||
|
v-if="showPic && props.row.has_image"
|
||||||
|
style="max-height: 256px"
|
||||||
|
:src="image(props.row.id)"
|
||||||
|
fit="contain"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
v-if="!public && !nodetails && editable"
|
v-if="!public && !nodetails && editable"
|
||||||
class="absolute-top-right justify-end"
|
class="absolute-top-right justify-end"
|
||||||
|
@ -84,7 +88,12 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</q-img>
|
</q-img>
|
||||||
<q-img v-if="showPic && !props.row.has_image" class="bg-white" style="max-height: 256px" src="no-image.svg">
|
<q-img
|
||||||
|
v-if="showPic && !props.row.has_image"
|
||||||
|
class="bg-white"
|
||||||
|
style="max-height: 256px"
|
||||||
|
src="no-image.svg"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
v-if="!public && !nodetails && editable"
|
v-if="!public && !nodetails && editable"
|
||||||
class="absolute-top-right justify-end"
|
class="absolute-top-right justify-end"
|
||||||
|
@ -214,7 +223,7 @@ import { filter, Search } from '../utils/filter';
|
||||||
import SearchInput from './SearchInput.vue';
|
import SearchInput from './SearchInput.vue';
|
||||||
import DrinkModify from './DrinkModify.vue';
|
import DrinkModify from './DrinkModify.vue';
|
||||||
import { DeleteObjects } from '../utils/utils';
|
import { DeleteObjects } from '../utils/utils';
|
||||||
import { setNewImage, getNewImage} from '../utils/image';
|
import { setNewImage, getNewImage } from '../utils/image';
|
||||||
import { PERMISSIONS } from '../permissions';
|
import { PERMISSIONS } from '../permissions';
|
||||||
import { Notify } from 'quasar';
|
import { Notify } from 'quasar';
|
||||||
|
|
||||||
|
@ -546,10 +555,10 @@ export default defineComponent({
|
||||||
editDrink.value.id = _drink.id;
|
editDrink.value.id = _drink.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (drinkPic instanceof File) {
|
if (drinkPic instanceof File && drinkPic.name) {
|
||||||
await savePicture(drinkPic);
|
await savePicture(drinkPic);
|
||||||
if (drink.id > 0) {
|
if (drink.id > 0) {
|
||||||
setNewImage(drink.id)
|
setNewImage(drink.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editDrink.value = undefined;
|
editDrink.value = undefined;
|
||||||
|
@ -565,15 +574,13 @@ export default defineComponent({
|
||||||
|
|
||||||
function image(id: number | undefined) {
|
function image(id: number | undefined) {
|
||||||
if (id) {
|
if (id) {
|
||||||
const _newImage = getNewImage(id)
|
const _newImage = getNewImage(id);
|
||||||
if (_newImage) {
|
if (_newImage) {
|
||||||
return `${
|
return `${
|
||||||
api.defaults.baseURL || ''
|
api.defaults.baseURL || ''
|
||||||
}/pricelist/drinks/${id}/picture?thumbnail?t=${_newImage.lastModified.toString()}`
|
}/pricelist/drinks/${id}/picture?thumbnail?t=${_newImage.lastModified.toString()}`;
|
||||||
}
|
}
|
||||||
return `${
|
return `${api.defaults.baseURL || ''}/pricelist/drinks/${id}/picture?thumbnail`;
|
||||||
api.defaults.baseURL || ''
|
|
||||||
}/pricelist/drinks/${id}/picture?thumbnail`;
|
|
||||||
}
|
}
|
||||||
return 'no-image.svg';
|
return 'no-image.svg';
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,26 +24,28 @@
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-img :src="image" style="max-height: 256px" fit="contain" />
|
|
||||||
<div class="full-width row">
|
<div class="full-width row">
|
||||||
<div class="col-10 q-pa-sm">
|
<div class="col-10 q-pa-sm">
|
||||||
<q-file
|
<q-file
|
||||||
v-model="drinkPic"
|
v-model="drinkPic"
|
||||||
filled
|
filled
|
||||||
clearable
|
:clearable="drinkPic.name != ''"
|
||||||
dense
|
dense
|
||||||
|
accept=".jpg, .jpeg, .png, image/*"
|
||||||
@update:model-value="imagePreview"
|
@update:model-value="imagePreview"
|
||||||
@clear="imgsrc = undefined"
|
@clear="clear"
|
||||||
>
|
>
|
||||||
<template #prepend>
|
<template #file>
|
||||||
<q-icon name="mdi-image" />
|
<q-img :src="image" style="max-height: 256px" fit="contain" />
|
||||||
</template>
|
</template>
|
||||||
</q-file>
|
</q-file>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2 q-pa-sm text-right">
|
<div class="column justify-center">
|
||||||
<q-btn round icon="mdi-delete" color="negative" size="sm" @click="delete_pic">
|
<div class="col-2 q-pa-sm">
|
||||||
<q-tooltip> Bild entfernen </q-tooltip>
|
<q-btn round icon="mdi-delete" color="negative" size="sm" @click="delete_pic">
|
||||||
</q-btn>
|
<q-tooltip> Bild entfernen </q-tooltip>
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
@ -241,7 +243,7 @@ export default defineComponent({
|
||||||
edit_drink.value?.receipt?.splice(event, 1);
|
edit_drink.value?.receipt?.splice(event, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const drinkPic = ref<File | undefined>();
|
const drinkPic = ref<File>(new File([], '', {}));
|
||||||
const imgsrc = ref();
|
const imgsrc = ref();
|
||||||
|
|
||||||
const deletePic = ref(false);
|
const deletePic = ref(false);
|
||||||
|
@ -249,7 +251,7 @@ export default defineComponent({
|
||||||
function delete_pic() {
|
function delete_pic() {
|
||||||
deletePic.value = true;
|
deletePic.value = true;
|
||||||
imgsrc.value = undefined;
|
imgsrc.value = undefined;
|
||||||
drinkPic.value = undefined;
|
drinkPic.value = new File([], '', {});
|
||||||
if (edit_drink.value) {
|
if (edit_drink.value) {
|
||||||
edit_drink.value.has_image = false;
|
edit_drink.value.has_image = false;
|
||||||
}
|
}
|
||||||
|
@ -276,9 +278,11 @@ export default defineComponent({
|
||||||
return 'no-image.svg';
|
return 'no-image.svg';
|
||||||
}
|
}
|
||||||
if (edit_drink.value?.has_image) {
|
if (edit_drink.value?.has_image) {
|
||||||
const _image = getNewImage(edit_drink.value?.id)
|
const _image = getNewImage(edit_drink.value?.id);
|
||||||
if (_image) {
|
if (_image) {
|
||||||
return `${api.defaults.baseURL || ''}/pricelist/drinks/${edit_drink.value.id}/picture?thumbnail?t=${_image.lastModified.toString()}`
|
return `${api.defaults.baseURL || ''}/pricelist/drinks/${
|
||||||
|
edit_drink.value.id
|
||||||
|
}/picture?thumbnail?t=${_image.lastModified.toString()}`;
|
||||||
}
|
}
|
||||||
return `${api.defaults.baseURL || ''}/pricelist/drinks/${
|
return `${api.defaults.baseURL || ''}/pricelist/drinks/${
|
||||||
edit_drink.value.id
|
edit_drink.value.id
|
||||||
|
@ -331,6 +335,11 @@ export default defineComponent({
|
||||||
edit_volumes.value?.some((a) => a.ingredients.length > 0)
|
edit_volumes.value?.some((a) => a.ingredients.length > 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function clear(val: File) {
|
||||||
|
drinkPic.value = new File([], '', {});
|
||||||
|
imgsrc.value = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
edit_drink,
|
edit_drink,
|
||||||
save,
|
save,
|
||||||
|
@ -357,6 +366,7 @@ export default defineComponent({
|
||||||
hasIngredients,
|
hasIngredients,
|
||||||
hasPermission,
|
hasPermission,
|
||||||
PERMISSIONS,
|
PERMISSIONS,
|
||||||
|
clear,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,8 +13,8 @@ export function getNewImage(id: number) {
|
||||||
export function setNewImage(id: number) {
|
export function setNewImage(id: number) {
|
||||||
const image = newImage.value.find((a) => a.id === id);
|
const image = newImage.value.find((a) => a.id === id);
|
||||||
if (image) {
|
if (image) {
|
||||||
image.lastModified = new Date()
|
image.lastModified = new Date();
|
||||||
} else {
|
} else {
|
||||||
newImage.value.push({id, lastModified: new Date()})
|
newImage.value.push({ id, lastModified: new Date() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue