edit panel remembering modifications in other tabs
This commit is contained in:
parent
d197447ad6
commit
9df71b4949
9 changed files with 133 additions and 79 deletions
|
|
@ -40,7 +40,7 @@
|
||||||
v-model="localSelectedTags"
|
v-model="localSelectedTags"
|
||||||
/>
|
/>
|
||||||
<label class="btn btn--sm btn--primary" :for="`${tag}`">{{
|
<label class="btn btn--sm btn--primary" :for="`${tag}`">{{
|
||||||
toPascalCase(tag)
|
StringUtils.toPascalCase(tag)
|
||||||
}}</label>
|
}}</label>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { usePageStore } from "../../../stores/page";
|
import { usePageStore } from "../../../stores/page";
|
||||||
import { toPascalCase } from "../../../helpers";
|
import StringUtils from "../../../utils/string";
|
||||||
import debounce from "lodash/debounce";
|
import debounce from "lodash/debounce";
|
||||||
|
|
||||||
const { selectedTags } = defineProps({
|
const { selectedTags } = defineProps({
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
v-model="image.tags"
|
v-model="image.tags"
|
||||||
/>
|
/>
|
||||||
<label class="btn btn--sm btn--primary" :for="pageTag + '-image'">{{
|
<label class="btn btn--sm btn--primary" :for="pageTag + '-image'">{{
|
||||||
toPascalCase(pageTag)
|
StringUtils.toPascalCase(pageTag)
|
||||||
}}</label>
|
}}</label>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { usePageStore } from "../../../stores/page";
|
import { usePageStore } from "../../../stores/page";
|
||||||
import { toPascalCase } from "../../../helpers";
|
import StringUtils from "../../../utils/string";
|
||||||
import Dialog from "primevue/dialog";
|
import Dialog from "primevue/dialog";
|
||||||
import debounce from "lodash/debounce";
|
import debounce from "lodash/debounce";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li
|
||||||
v-for="tab in tabs"
|
v-for="tab in tabs"
|
||||||
:class="{ active: activeTab.name === tab.name }"
|
:class="{ active: activeTabId === tab.id }"
|
||||||
@click="activeTab = tab"
|
@click="activeTabId = tab.id"
|
||||||
>
|
>
|
||||||
{{ tab.name }}
|
{{ tab.name }}
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
:is="tab.component"
|
:is="tab.component"
|
||||||
:params="tab.params ? tab.params : {}"
|
:params="tab.params ? tab.params : {}"
|
||||||
:class="{ hidden: activeTab.name !== tab.name }"
|
:class="{ hidden: activeTab.name !== tab.name }"
|
||||||
|
:activeTab="activeTab"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -60,59 +61,24 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import Dialog from "primevue/dialog";
|
import Dialog from "primevue/dialog";
|
||||||
import ImagesResources from "./ImagesResources.vue";
|
|
||||||
import ImagesEditPanel from "./ImagesEditPanel.vue";
|
import ImagesEditPanel from "./ImagesEditPanel.vue";
|
||||||
import MyImages from "./MyImages.vue";
|
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
import { useAddImagesModalStore } from "../../../../stores/addImagesModal";
|
||||||
|
|
||||||
const { isAddImagesModalOpen } = defineProps({
|
const { isAddImagesModalOpen } = defineProps({
|
||||||
isAddImagesModalOpen: Boolean,
|
isAddImagesModalOpen: Boolean,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(["update:isAddImagesModalOpen"]);
|
const emit = defineEmits(["update:isAddImagesModalOpen"]);
|
||||||
|
const { activeTab, activeTabId, tabs } = storeToRefs(useAddImagesModalStore());
|
||||||
|
|
||||||
const isOpen = ref(isAddImagesModalOpen);
|
const isOpen = ref(isAddImagesModalOpen);
|
||||||
watch(isOpen, (newValue) => {
|
watch(isOpen, () => {
|
||||||
emit("close");
|
emit("close");
|
||||||
});
|
});
|
||||||
|
|
||||||
const images = ref([]);
|
|
||||||
|
|
||||||
const deleteIsOpen = false;
|
const deleteIsOpen = false;
|
||||||
|
|
||||||
const tabs = [
|
|
||||||
{
|
|
||||||
name: "Mes images",
|
|
||||||
component: MyImages,
|
|
||||||
params: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Matériauthèque",
|
|
||||||
component: ImagesResources,
|
|
||||||
params: {
|
|
||||||
targetPage: "materials",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Réalisations",
|
|
||||||
component: ImagesResources,
|
|
||||||
params: {
|
|
||||||
targetPage: "creations",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Inspirations",
|
|
||||||
component: ImagesResources,
|
|
||||||
params: false,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const activeTab = ref(tabs[0]);
|
|
||||||
|
|
||||||
function addImages(newImages) {
|
|
||||||
console.log(newImages);
|
|
||||||
images.value = images.value.concat(newImages);
|
|
||||||
console.log(images.value);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
style="--row-gap: var(--space-8)"
|
style="--row-gap: var(--space-8)"
|
||||||
>
|
>
|
||||||
<AccordionPanel
|
<AccordionPanel
|
||||||
v-for="(image, index) in images"
|
v-for="(image, index) in activeTab.selectedImages"
|
||||||
:key="index + 1"
|
:key="index + 1"
|
||||||
:value="index"
|
:value="index"
|
||||||
class="w-full | bg-white | rounded-xl | p-12 pt-8"
|
class="w-full | bg-white | rounded-xl | p-12 pt-8"
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
<label
|
<label
|
||||||
class="btn btn--sm btn--primary"
|
class="btn btn--sm btn--primary"
|
||||||
:for="`${tag}-image-edit`"
|
:for="`${tag}-image-edit`"
|
||||||
>{{ toPascalCase(tag) }}</label
|
>{{ StringUtils.toPascalCase(tag) }}</label
|
||||||
>
|
>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -105,15 +105,14 @@ import AccordionPanel from "primevue/accordionpanel";
|
||||||
import AccordionHeader from "primevue/accordionheader";
|
import AccordionHeader from "primevue/accordionheader";
|
||||||
import AccordionContent from "primevue/accordioncontent";
|
import AccordionContent from "primevue/accordioncontent";
|
||||||
import { usePageStore } from "../../../../stores/page";
|
import { usePageStore } from "../../../../stores/page";
|
||||||
import { toPascalCase } from "../../../../helpers";
|
import StringUtils from "../../../../utils/string";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
|
import { useAddImagesModalStore } from "../../../../stores/addImagesModal";
|
||||||
const { images } = defineProps({
|
|
||||||
images: Object,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { page } = storeToRefs(usePageStore());
|
const { page } = storeToRefs(usePageStore());
|
||||||
|
|
||||||
|
const { activeTab } = storeToRefs(useAddImagesModalStore());
|
||||||
|
|
||||||
// function saveTags(image) {
|
// function saveTags(image) {
|
||||||
// const headers = {
|
// const headers = {
|
||||||
// method: "POST",
|
// method: "POST",
|
||||||
|
|
@ -184,7 +183,7 @@ function addImagesToBrief() {
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((json) => console.log(json))
|
.then((json) => (page.value.images = json.images))
|
||||||
.catch((error) => console.error("Error:", error));
|
.catch((error) => console.error("Error:", error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,26 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="auto-grid" style="--min: 15rem; --gap: 0.5rem">
|
<div class="auto-grid" style="--min: 15rem; --gap: 0.5rem">
|
||||||
<figure v-for="image in images" class="image" @click="addImage(image)">
|
<figure v-for="image in tab.images" class="image">
|
||||||
<img :src="image.url" alt="" />
|
<img
|
||||||
|
:src="image.url"
|
||||||
|
alt=""
|
||||||
|
@click="ArrayUtils.toggle(tab.selectedImages, image)"
|
||||||
|
/>
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { storeToRefs } from "pinia";
|
||||||
import { useApiStore } from "../../../../stores/api";
|
import { useAddImagesModalStore } from "../../../../stores/addImagesModal";
|
||||||
|
import { computed } from "vue";
|
||||||
|
import ArrayUtils from "../../../../utils/array";
|
||||||
|
|
||||||
const { params } = defineProps({
|
const { tabs } = storeToRefs(useAddImagesModalStore());
|
||||||
params: Object,
|
|
||||||
|
const tab = computed(() => {
|
||||||
|
return tabs.value.find((tab) => tab.id === "materials");
|
||||||
});
|
});
|
||||||
const emit = defineEmits(["add-images"]);
|
|
||||||
|
|
||||||
const api = useApiStore();
|
console.log(ArrayUtils);
|
||||||
const images = ref([]);
|
|
||||||
|
|
||||||
api
|
|
||||||
.fetchPageData(params.targetPage)
|
|
||||||
.then((json) => (images.value = json.images));
|
|
||||||
|
|
||||||
function addImage(image) {
|
|
||||||
emit("add-images", [image]);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,12 @@
|
||||||
<div v-if="files.length > 0">Fichiers importés</div>
|
<div v-if="files.length > 0">Fichiers importés</div>
|
||||||
</template>
|
</template>
|
||||||
</FileUpload>
|
</FileUpload>
|
||||||
<figure v-for="image in images" class="image">
|
<figure v-for="image in tab.images" class="image">
|
||||||
<img :src="image.url" alt="" />
|
<img
|
||||||
|
:src="image.url"
|
||||||
|
alt=""
|
||||||
|
@click="ArrayUtils.toggle(tab.selectedImages, image)"
|
||||||
|
/>
|
||||||
</figure>
|
</figure>
|
||||||
<Toast />
|
<Toast />
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -54,7 +58,9 @@ import Toast from "primevue/toast";
|
||||||
import { useToast } from "primevue/usetoast";
|
import { useToast } from "primevue/usetoast";
|
||||||
import FileUpload from "primevue/fileupload";
|
import FileUpload from "primevue/fileupload";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
import { useAddImagesModalStore } from "../../../../stores/addImagesModal";
|
||||||
|
import ArrayUtils from "../../../../utils/array";
|
||||||
|
|
||||||
const { page } = storeToRefs(usePageStore());
|
const { page } = storeToRefs(usePageStore());
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
@ -62,9 +68,13 @@ const toast = useToast();
|
||||||
const emit = defineEmits(["add-images"]);
|
const emit = defineEmits(["add-images"]);
|
||||||
const uploadBtn = ref(null);
|
const uploadBtn = ref(null);
|
||||||
|
|
||||||
const images = ref([]);
|
const { tabs } = storeToRefs(useAddImagesModalStore());
|
||||||
|
|
||||||
function addImages(event) {
|
const tab = computed(() => {
|
||||||
|
return tabs.value.find((tab) => tab.id === "my-images");
|
||||||
|
});
|
||||||
|
|
||||||
|
function addImages() {
|
||||||
const newImages = uploadBtn.value.files.map((file) => {
|
const newImages = uploadBtn.value.files.map((file) => {
|
||||||
return {
|
return {
|
||||||
url: URL.createObjectURL(file),
|
url: URL.createObjectURL(file),
|
||||||
|
|
@ -73,7 +83,7 @@ function addImages(event) {
|
||||||
name: file.name,
|
name: file.name,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
images.value = images.value.concat(newImages);
|
tab.value.images = [...tab.value.images, ...newImages];
|
||||||
emit("add-images", newImages);
|
tab.value.selectedImages = [...tab.value.selectedImages, ...newImages];
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
66
src/stores/addImagesModal.js
Normal file
66
src/stores/addImagesModal.js
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import { defineStore } from "pinia";
|
||||||
|
import { ref, computed } from "vue";
|
||||||
|
import { useApiStore } from "./api";
|
||||||
|
import MyImages from "../components/project/client-brief/add-images-modal/MyImages.vue";
|
||||||
|
import ImagesResources from "../components/project/client-brief/add-images-modal/ImagesResources.vue";
|
||||||
|
|
||||||
|
export const useAddImagesModalStore = defineStore("add-images-modal", () => {
|
||||||
|
const tabs = ref([
|
||||||
|
{
|
||||||
|
name: "Mes images",
|
||||||
|
id: "my-images",
|
||||||
|
component: MyImages,
|
||||||
|
params: false,
|
||||||
|
images: [],
|
||||||
|
selectedImages: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Matériauthèque",
|
||||||
|
id: "materials",
|
||||||
|
component: ImagesResources,
|
||||||
|
params: {
|
||||||
|
targetPage: "materials",
|
||||||
|
},
|
||||||
|
images: [],
|
||||||
|
selectedImages: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Réalisations",
|
||||||
|
id: "creations",
|
||||||
|
component: ImagesResources,
|
||||||
|
images: [],
|
||||||
|
selectedImages: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Inspirations",
|
||||||
|
id: "inspirations",
|
||||||
|
component: ImagesResources,
|
||||||
|
params: false,
|
||||||
|
images: [],
|
||||||
|
selectedImages: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const activeTabId = ref("my-images");
|
||||||
|
|
||||||
|
const activeTab = computed(() => {
|
||||||
|
return tabs.value.find((tab) => tab.id === activeTabId.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const images = ref({
|
||||||
|
myImages: [],
|
||||||
|
materials: [],
|
||||||
|
inspirations: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const api = useApiStore();
|
||||||
|
api
|
||||||
|
.fetchPageData("materials")
|
||||||
|
.then((json) => (images.value = tabs.value[1].images = json.images));
|
||||||
|
|
||||||
|
api
|
||||||
|
.fetchPageData("creations")
|
||||||
|
.then((json) => (images.value = tabs.value[2].images = json.images));
|
||||||
|
|
||||||
|
return { images, activeTabId, tabs, activeTab };
|
||||||
|
});
|
||||||
13
src/utils/array.js
Normal file
13
src/utils/array.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
function toggle(array, element) {
|
||||||
|
const index = array.indexOf(element);
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
array.push(element);
|
||||||
|
} else {
|
||||||
|
array.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ArrayUtils = { toggle };
|
||||||
|
|
||||||
|
export default ArrayUtils;
|
||||||
|
|
@ -6,4 +6,6 @@ function toPascalCase(string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { toPascalCase };
|
const StringUtils = { toPascalCase };
|
||||||
|
|
||||||
|
export default StringUtils;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue