designtopack/src/components/project/virtual-sample/VirtualSample.vue

181 lines
4.9 KiB
Vue
Raw Normal View History

2024-10-28 18:18:32 +01:00
<template>
<Dialog
id="virtual-sample"
v-model:visible="isOpen"
modal
:draggable="false"
2024-11-28 15:15:21 +01:00
dismissableMask="true"
header="Titre du rendu"
class="dialog"
:class="[
{ 'with-comments': isCommentsOpen },
activeTab,
{ 'with-dtl': correspondingDTLProposal },
]"
:closeOnEscape="true"
>
<template #header>
<div class="dialog__tabs" role="tablist">
<button
2024-11-21 13:20:57 +01:00
v-if="step.files.dynamic"
type="button"
role="tab"
class="btn btn--transparent | font-serif"
data-icon="cursor"
:aria-pressed="activeTab === 'dynamic' ? true : false"
aria-controls="dynamic"
@click="activeTab = 'dynamic'"
>
2024-12-16 15:29:54 +01:00
<span>Présentation dynamique</span>
</button>
<button
2024-11-21 13:20:57 +01:00
v-if="step.files.static"
type="button"
role="tab"
@click="activeTab = 'static'"
class="btn btn--transparent | font-serif"
data-icon="image"
:aria-pressed="activeTab === 'static' ? true : false"
aria-controls="static"
>
<span>Vue statique</span>
</button>
</div>
2024-11-20 18:42:37 +01:00
<h2 class="font-serif text-lg">Échantillon virtuel</h2>
</template>
2024-11-13 07:46:32 +01:00
<DynamicView id="dynamic" v-if="activeTab === 'dynamic'" />
<StaticView id="static" v-if="activeTab === 'static'" />
<template #footer>
2025-01-07 16:54:08 +01:00
<button
v-if="openedFile"
id="download-image"
class="btn btn--white-10"
data-icon="download"
2025-01-07 16:54:08 +01:00
@click="downloadFiles()"
>
2025-01-07 16:54:08 +01:00
<span>{{ downloadText }}</span>
</button>
<button
id="loop-animation"
2024-12-16 18:28:19 +01:00
class="btn"
:class="{ 'btn--transparent btn--outline': !isLoopAnimationEnabled }"
:data-icon="!isLoopAnimationEnabled ? 'loop' : 'pause'"
2024-12-16 16:27:21 +01:00
@click="isLoopAnimationEnabled = !isLoopAnimationEnabled"
>
2024-12-17 12:09:57 +01:00
<span>{{
!isLoopAnimationEnabled
? 'Animation en boucle'
: 'Arrêter lanimation'
2024-12-17 12:09:57 +01:00
}}</span>
</button>
<button
v-if="isCommentPanelEnabled"
id="toggle-comments"
:aria-pressed="isCommentsOpen"
class="btn btn--transparent btn--outline"
data-icon="comment"
@click="isCommentsOpen = !isCommentsOpen"
>
<span class="sr-only"
>{{ isCommentsOpen ? 'Masquer' : 'Afficher' }} les commentaires</span
>
</button>
</template>
2024-12-18 18:22:39 +01:00
<Comments v-if="isCommentsOpen" @show-draft-marker="showDraftMarker" />
</Dialog>
<DTLPanel
v-if="correspondingDTLProposal"
:proposals="[correspondingDTLProposal]"
/>
2024-10-28 18:18:32 +01:00
</template>
<script setup>
import Comments from '../../comments/Comments.vue';
import Dialog from 'primevue/dialog';
import DynamicView from './DynamicView.vue';
import StaticView from './StaticView.vue';
import DTLPanel from '../../design-to-light/DTLPanel.vue';
import { storeToRefs } from 'pinia';
import { ref, watch, computed } from 'vue';
import { useVirtualSampleStore } from '../../../stores/virtualSample';
import { useDialogStore } from '../../../stores/dialog';
import { useRoute, useRouter } from 'vue-router';
import { usePageStore } from '../../../stores/page';
const { file } = defineProps({
file: Object,
});
2024-11-20 08:26:12 +01:00
2025-01-07 16:54:08 +01:00
const {
activeTab,
currentFile,
step,
isLoopAnimationEnabled,
isDownloadTriggered,
} = storeToRefs(useVirtualSampleStore());
const { isCommentsOpen, isCommentPanelEnabled, activeTracks, openedFile } =
storeToRefs(useDialogStore());
const { page } = storeToRefs(usePageStore());
isLoopAnimationEnabled.value = false;
// Variables
2024-11-28 15:15:21 +01:00
const router = useRouter();
const route = useRoute();
2024-11-19 17:20:47 +01:00
const isOpen = ref(true);
2024-11-28 15:15:21 +01:00
watch(isOpen, (newValue) => {
router.push({ name: route.name });
openedFile.value = null;
2025-02-19 17:11:12 +01:00
activeTracks.value = [];
2024-11-28 15:15:21 +01:00
});
2025-01-07 16:54:08 +01:00
const downloadText = computed(() => {
if (activeTab.value === 'dynamic') {
2025-01-07 16:54:08 +01:00
if (activeTracks.value.length === 1) {
return "Télécharger l'image";
} else {
return 'Télécharger les images';
2025-01-07 16:54:08 +01:00
}
} else {
return 'Télécharger le PDF';
2025-01-07 16:54:08 +01:00
}
});
const correspondingDTLProposal = computed(() => {
const hasDTLProposal = page.value?.designToLight;
if (!hasDTLProposal || !isOpen.value || !openedFile.value) return false;
const correspondingDTLProposal = page.value.designToLight.find((proposal) => {
if (activeTab.value === 'dynamic') {
return (
proposal.location.type === 'dynamic' &&
activeTracks?.value?.some(
(activeTrack) => activeTrack.slug === proposal.location.trackSlug
)
);
} else {
return (
proposal.location.type === 'static' &&
openedFile.value?.source === proposal.location.source
);
}
});
if (!correspondingDTLProposal) return false;
return correspondingDTLProposal;
});
2025-01-07 16:54:08 +01:00
// Functions
function downloadFiles() {
isDownloadTriggered.value = true;
setTimeout(() => {
isDownloadTriggered.value = false;
}, 400);
}
</script>