client brief > my images : upload images working
|
|
@ -19,3 +19,7 @@ Testimage: - file://4xs4UNZhQf3jLvsG
|
|||
----
|
||||
|
||||
Uuid: 6yh1yt2Sk45Y2sOl
|
||||
|
||||
----
|
||||
|
||||
Clientbriefimages: - file://ihuGLrw5vll0R4j2
|
||||
|
|
@ -1 +1,5 @@
|
|||
Template: blocks/image
|
||||
|
||||
----
|
||||
|
||||
Uuid: vHs87W6sM0r43thr
|
||||
|
After Width: | Height: | Size: 267 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
Description: nouvelle description
|
||||
|
||||
----
|
||||
|
||||
Tags: matériaux & textures
|
||||
|
||||
----
|
||||
|
||||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Uuid: vs4tgLg5q6QFeb43
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
Before Width: | Height: | Size: 213 KiB After Width: | Height: | Size: 213 KiB |
|
|
@ -1,3 +1,7 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
|
@ -6,7 +10,7 @@ Tags:
|
|||
|
||||
----
|
||||
|
||||
Uuid: Ke2XIraa5jlvtOdb
|
||||
Uuid: Nlkd6hX666PBBYlk
|
||||
|
||||
----
|
||||
|
||||
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
|
|
@ -1,3 +1,7 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
|
@ -6,7 +10,7 @@ Tags:
|
|||
|
||||
----
|
||||
|
||||
Uuid: nqa5cCGHGoWQXulB
|
||||
Uuid: UkFMsBPXVGpQMmXV
|
||||
|
||||
----
|
||||
|
||||
|
After Width: | Height: | Size: 232 KiB |
|
|
@ -1,3 +1,7 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
|
@ -6,7 +10,7 @@ Tags:
|
|||
|
||||
----
|
||||
|
||||
Uuid: FWKdZwxSimGOaO2x
|
||||
Uuid: DknJcJ7YnG29JXUN
|
||||
|
||||
----
|
||||
|
||||
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
||||
Tags:
|
||||
|
||||
----
|
||||
|
||||
Uuid: zGisP0BopebPl2ex
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
||||
Tags:
|
||||
|
||||
----
|
||||
|
||||
Uuid: 2Nt5Vv2SrGcE1iro
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
Before Width: | Height: | Size: 217 KiB After Width: | Height: | Size: 217 KiB |
|
|
@ -0,0 +1,17 @@
|
|||
Date: 2024-10-09 05:10
|
||||
|
||||
----
|
||||
|
||||
Description:
|
||||
|
||||
----
|
||||
|
||||
Tags:
|
||||
|
||||
----
|
||||
|
||||
Uuid: ih7KMM6KjNoQ2umR
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
|
@ -16,12 +16,13 @@ Description: test
|
|||
|
||||
Clientbriefimages:
|
||||
|
||||
- file://b4Ywx4ProE0Smc0Q
|
||||
- file://aCuD18YBmLHg6YaS
|
||||
- file://Ke2XIraa5jlvtOdb
|
||||
- file://QBax5c69DcENi2rt
|
||||
- file://nqa5cCGHGoWQXulB
|
||||
- file://FWKdZwxSimGOaO2x
|
||||
- file://DknJcJ7YnG29JXUN
|
||||
- file://Nlkd6hX666PBBYlk
|
||||
- file://zGisP0BopebPl2ex
|
||||
- file://ih7KMM6KjNoQ2umR
|
||||
- file://UkFMsBPXVGpQMmXV
|
||||
- file://2Nt5Vv2SrGcE1iro
|
||||
- file://vs4tgLg5q6QFeb43
|
||||
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
Description:
|
||||
|
||||
----
|
||||
|
||||
Tags: forme & design, coloris & nuances
|
||||
|
||||
----
|
||||
|
||||
Uuid: QBax5c69DcENi2rt
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
Description: test de description mais
|
||||
|
||||
----
|
||||
|
||||
Tags: parachèvements
|
||||
|
||||
----
|
||||
|
||||
Uuid: b4Ywx4ProE0Smc0Q
|
||||
|
||||
----
|
||||
|
||||
Template: image
|
||||
|
|
@ -8,15 +8,15 @@ return [
|
|||
$pageUri = kirby()->request()->query()->get('pageUri');
|
||||
$page = page($pageUri);
|
||||
|
||||
$allFiles = $page->clientBriefImages()->toFiles()->pluck('uuid', ',');
|
||||
|
||||
$alerts = [];
|
||||
$success = '';
|
||||
$newFiles = [];
|
||||
$allFiles = [];
|
||||
|
||||
foreach ($uploads->get('images') as $upload) {
|
||||
// check for duplicate
|
||||
$files = $page->files();
|
||||
$duplicates = $files->filter(function ($file) use ($upload) {
|
||||
// get original safename without prefix
|
||||
$pos = strpos($file->filename(), '_');
|
||||
$originalSafename = substr($file->filename(), $pos + 1);
|
||||
|
||||
|
|
@ -26,7 +26,12 @@ return [
|
|||
});
|
||||
|
||||
if ($duplicates->count() > 0) {
|
||||
$alerts[$upload['name']] = "The file already exists";
|
||||
$duplicate = $duplicates->first();
|
||||
|
||||
if (in_array($duplicate->uuid(), $allFiles)) {
|
||||
$allFiles[] = $duplicate->uuid();
|
||||
$alerts[$upload['name']] = "The file already exists, added to the field.";
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -50,18 +55,23 @@ return [
|
|||
}
|
||||
}
|
||||
|
||||
$images = array_map(function ($file) {
|
||||
return [
|
||||
'url' => $file->url(),
|
||||
'uuid' => $file->uuid()
|
||||
];
|
||||
}, $newFiles);
|
||||
|
||||
$newPage = $page->update([
|
||||
'clientBriefImages' => $allFiles
|
||||
]);
|
||||
|
||||
return compact('images', 'alerts', 'success');
|
||||
$images = [];
|
||||
|
||||
foreach ($newPage->clientBriefImages()->toFiles() as $image) {
|
||||
$images[] = [
|
||||
'url' => $image->url(),
|
||||
'uuid' => (string) $image->uuid(),
|
||||
'tags' => $image->tags()->split(),
|
||||
'name' => $image->filename(),
|
||||
'description' => $image->description()->value(),
|
||||
];
|
||||
}
|
||||
|
||||
return compact('images', 'alerts');
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
>
|
||||
Ajouter une ou plusieurs images
|
||||
</button>
|
||||
<template v-for="image in images" :key="image.uri">
|
||||
<template v-for="image in page.images" :key="image.uri">
|
||||
<figure
|
||||
v-if="
|
||||
selectedTags.length === 0 ||
|
||||
|
|
@ -35,7 +35,6 @@
|
|||
<AddImagesModal
|
||||
v-if="isAddImagesModalOpen"
|
||||
:isAddImagesModalOpen="isAddImagesModalOpen"
|
||||
:images="images"
|
||||
@close="isAddImagesModalOpen = false"
|
||||
/>
|
||||
<ImageDetailsModal
|
||||
|
|
@ -53,51 +52,23 @@ import { usePageStore } from "../../../stores/page";
|
|||
import { ref } from "vue";
|
||||
import ImageDetailsModal from "./ImageDetailsModal.vue";
|
||||
import AddImagesModal from "./add-images-modal/AddImagesModal.vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
const { page } = usePageStore();
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
|
||||
const selectedTags = ref([]);
|
||||
const imageDetails = ref(null);
|
||||
const images = ref(page.images);
|
||||
const isAddImagesModalOpen = ref(false);
|
||||
|
||||
function onAdvancedUpload(event) {
|
||||
if (event.xhr.status === 200) {
|
||||
toast.add({
|
||||
severity: "success",
|
||||
summary: "Upload réussi",
|
||||
detail: event.xhr.response.success,
|
||||
life: 3000,
|
||||
});
|
||||
const response = JSON.parse(event.xhr.response);
|
||||
console.log(response);
|
||||
images.value = response.images;
|
||||
} else {
|
||||
toast.add({
|
||||
severity: "error",
|
||||
summary: "Échec de l'upload",
|
||||
detail: event.xhr.response.error,
|
||||
life: 3000,
|
||||
});
|
||||
console.error(JSON.parse(event.xhr.response));
|
||||
}
|
||||
}
|
||||
|
||||
function beforeSend(event) {
|
||||
const formData = event.formData;
|
||||
formData.append(
|
||||
"pageUri",
|
||||
"projects/miss-dior-blooming-bouquet/client-brief"
|
||||
);
|
||||
}
|
||||
|
||||
function changeSelectedTags(newTags) {
|
||||
selectedTags.value = newTags;
|
||||
}
|
||||
|
||||
function removeImage(target) {
|
||||
console.log("remove", target);
|
||||
images.value = images.value.filter((image) => image.uuid !== target.uuid);
|
||||
page.value.images = page.value.images.filter(
|
||||
(image) => image.uuid !== target.uuid
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<div class="bg-grey-50 | rounded-2xl | p-8 | overflow-y">
|
||||
<component :is="activeTab.component" :params="activeTab.params" />
|
||||
</div>
|
||||
<ImagesEditPanel :images="images" />
|
||||
<ImagesEditPanel />
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
|
@ -66,9 +66,8 @@ import MyImages from "./MyImages.vue";
|
|||
import { usePageStore } from "../../../../stores/page";
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
const { isAddImagesModalOpen, images } = defineProps({
|
||||
const { isAddImagesModalOpen } = defineProps({
|
||||
isAddImagesModalOpen: Boolean,
|
||||
images: Array,
|
||||
});
|
||||
const emit = defineEmits(["update:isAddImagesModalOpen"]);
|
||||
|
||||
|
|
@ -83,9 +82,6 @@ const tabs = [
|
|||
{
|
||||
name: "Mes images",
|
||||
component: MyImages,
|
||||
params: {
|
||||
images,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Matériauthèque",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
style="--row-gap: var(--space-8)"
|
||||
>
|
||||
<AccordionPanel
|
||||
v-for="(image, index) in images"
|
||||
v-for="(image, index) in page.images"
|
||||
:key="index + 1"
|
||||
:value="index"
|
||||
class="w-full | bg-white | rounded-xl | p-12 pt-8"
|
||||
|
|
@ -109,18 +109,15 @@ import AccordionContent from "primevue/accordioncontent";
|
|||
import { usePageStore } from "../../../../stores/page";
|
||||
import { toPascalCase } from "../../../../helpers";
|
||||
import debounce from "lodash/debounce";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
const { images } = defineProps({
|
||||
images: Array,
|
||||
});
|
||||
|
||||
const { page } = usePageStore();
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
|
||||
function saveTags(image) {
|
||||
const headers = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
pageUri: page.uri,
|
||||
pageUri: page.value.uri,
|
||||
fileName: image.name,
|
||||
properties: [
|
||||
{
|
||||
|
|
@ -144,7 +141,7 @@ const saveDescription = debounce((image) => {
|
|||
const headers = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
pageUri: page.uri,
|
||||
pageUri: page.value.uri,
|
||||
fileName: image.name,
|
||||
properties: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
<div v-if="files.length > 0">Fichiers importés</div>
|
||||
</template>
|
||||
</FileUpload>
|
||||
<figure v-for="image in params.images" class="image">
|
||||
<figure v-for="image in page.images" class="image">
|
||||
<img :src="image.url" alt="" />
|
||||
</figure>
|
||||
<Toast />
|
||||
|
|
@ -53,11 +53,30 @@ import { usePageStore } from "../../../../stores/page";
|
|||
import Toast from "primevue/toast";
|
||||
import { useToast } from "primevue/usetoast";
|
||||
import FileUpload from "primevue/fileupload";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
const { params } = defineProps({
|
||||
params: Object,
|
||||
});
|
||||
|
||||
const { page } = usePageStore();
|
||||
const { page } = storeToRefs(usePageStore());
|
||||
const toast = useToast();
|
||||
|
||||
function onAdvancedUpload(event) {
|
||||
if (event.xhr.status === 200) {
|
||||
toast.add({
|
||||
severity: "success",
|
||||
summary: "Upload réussi",
|
||||
detail: event.xhr.response.success,
|
||||
life: 3000,
|
||||
});
|
||||
const response = JSON.parse(event.xhr.response);
|
||||
console.log(response);
|
||||
page.value.images = response.images;
|
||||
} else {
|
||||
toast.add({
|
||||
severity: "error",
|
||||
summary: "Échec de l'upload",
|
||||
detail: event.xhr.response.error,
|
||||
life: 3000,
|
||||
});
|
||||
console.error(JSON.parse(event.xhr.response));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||