nouveau-theatre-de-besancon/site/snippets/calendar-strip.php

167 lines
5.6 KiB
PHP
Raw Normal View History

<section
2024-07-24 09:43:31 +02:00
class="calendar-strip"
2024-07-26 10:33:31 +02:00
@mouseleave="open = false"
2024-07-24 09:43:31 +02:00
x-data="{
monthNumb: dayjs().month(),
weekIndex: (() => {
dayjs.extend(window.dayjs_plugin_weekOfYear);
const date = dayjs();
const firstDayOfMonth = dayjs(date).startOf('month');
const currentWeek = date.week();
const firstWeekOfMonth = firstDayOfMonth.week();
const weekIndex = currentWeek - firstWeekOfMonth - 1;
console.log(`currentWeek: ${currentWeek}, firstWeekOfMonth: ${firstWeekOfMonth}, weekIndex: ${weekIndex}`);
// Retourner l'index de la semaine
return weekIndex;
})(),
token: '<?= $site->mapadoToken() ?>',
contractId: '<?= $site->mapadoContractId() ?>',
dates: [],
targetSessions: [],
open: false,
today: dayjs().format('DD-MM-YYYY'),
get monthName() {
return dayjs().month(this.monthNumb).format('MMMM');
},
get currentWeek() {
const dates = JSON.parse(JSON.stringify(this.dates));
const start = this.weekIndex * 7;
const end = start + 7;
const allKeys = Object.keys(dates);
const slicedKeys = allKeys.slice(start, end);
const slicedObject = slicedKeys.reduce((obj, key) => {
obj[key] = dates[key];
return obj;
}, {});
return slicedObject;
},
async updateDates(resetWeek = false) {
const daysNode = document.querySelector('.calendar-strip__days');
daysNode.classList.toggle('progress');
this.dates = getDatesInMonth(this.monthNumb);
this.dates = await getMergedDates(this.monthNumb, this.dates);
console.log('Merged dates', this.dates);
daysNode.classList.toggle('progress');
if (resetWeek) {
this.weekIndex = 0
}
},
handleDayHover() {
if (this.date.sessions.length > 0) {
this.targetSessions = this.date.sessions;
this.open = true;
} else {
setTimeout(() => {
2024-08-28 19:11:58 +02:00
this.targetSessions = this.date.sessions;
}, 100);
this.open = false;
}
},
nextWeek() {
if (this.weekIndex < Math.floor(this.dates.length / 7)) {
this.weekIndex++;
} else {
this.monthNumb++;
this.updateDates();
2024-07-24 09:43:31 +02:00
}
},
prevWeek() {
if (this.weekIndex > 0) {
this.weekIndex--;
} else {
this.monthNumb--;
this.updateDates();
}
}
}"
2024-07-24 15:56:28 +02:00
x-init="updateDates()"
2024-07-24 09:43:31 +02:00
>
<div class="calendar-strip__selector">
2024-07-29 08:57:35 +02:00
<button class="prev-month" @click="monthNumb--; updateDates()"></button>
2024-07-24 09:43:31 +02:00
<span x-text="monthName"></span>
<button class="next-month" @click="monthNumb++; updateDates()"></button>
2024-07-24 09:43:31 +02:00
</div>
<ul class="calendar-strip__days">
<template x-for="(date, index) in currentWeek">
2024-08-30 15:39:40 +02:00
<li class="calendar-strip__day" :class="targetSessions.length > 0 && open && index == targetSessions[0].day ? 'active' : ''" :style="'animation-delay: ' + index * 0.03 + 's'">
2024-07-26 10:33:31 +02:00
<button
2024-08-28 19:11:58 +02:00
:class="date.full === today ? 'today' : ''"
:disabled="date.sessions.length === 0 ? true : false"
:title="date.sessions.length === 0 ? 'Pas de représentation.' : 'Voir les représentations.'"
2024-07-26 10:33:31 +02:00
@mouseenter="handleDayHover()"
2024-08-28 19:11:58 +02:00
>
<span x-text="date.initial"></span>
<span x-text="index"></span>
</button>
2024-07-24 18:19:25 +02:00
</li>
2024-07-24 09:43:31 +02:00
</template>
</ul>
2024-09-03 16:16:06 +02:00
<a href="<?= page('programme')->url() ?>" class="calendar-strip__calendar-btn">calendrier</a>
2024-07-26 10:33:31 +02:00
<div class="calendar-strip__date" :class="open ? 'open' : ''">
2024-09-02 14:02:13 +02:00
<ul class="sessions sessions--detailed">
2024-07-26 10:33:31 +02:00
<template x-for="session in targetSessions">
2024-09-04 17:02:37 +02:00
<li
x-data="{
stockThreshold: (session.totalStock / 100) * 25
}"
:style="'--color: ' + session.color"
class="session"
>
2024-09-02 14:02:13 +02:00
<a class="session__event-link" :href="session.eventUrl" title="En savoir plus">
2024-09-06 18:15:43 +02:00
<div class="session__info session__info--slot">
2024-09-02 14:02:13 +02:00
<p x-html="`${session.day} ${monthName}`"></p>
<p x-html="session.time"></p>
</div>
2024-09-06 18:15:43 +02:00
<div class="session__info session__info--title">
2024-08-28 19:11:58 +02:00
<p><strong x-html="`<strong>${session.title}</strong>`"></strong></p>
<p x-html="session.authors"></p>
2024-07-29 17:42:30 +02:00
</div>
2024-09-06 18:15:43 +02:00
<div x-text="session.duration ? session.duration : ''" class="session__info session__info--duration"></div>
<div x-text="`${session.place}`" class="session__info session__info--place"></div>
2024-08-28 19:11:58 +02:00
<template x-if="!session.ticketingUrl">
2024-09-06 18:15:43 +02:00
<div class="session__info session__info--book">
2024-08-28 19:11:58 +02:00
<a class="ticket-link" target="_blank" title="Entrée libre" disabled><?php snippet('ticket') ?> Entrée libre</a>
</div>
</template>
<template x-if="session.bookableStock === 0">
2024-09-06 18:15:43 +02:00
<div class="session__info session__info--book">
2024-09-03 16:48:13 +02:00
<a class="ticket-link" title="Plus de places disponibles" disabled><?php snippet('ticket') ?> Complet</a>
</div>
</template>
<template x-if="session.bookableStock > stockThreshold">
2024-09-03 16:48:13 +02:00
<div class="session__info">
<a class="ticket-link" title="Plateforme de réservation" :href="session.ticketingUrl" target="_blank"><?php snippet('ticket') ?> Billetterie</a>
</div>
</template>
<template x-if="session.bookableStock !== 0 && session.bookableStock < stockThreshold">
2024-09-03 16:48:13 +02:00
<div class="session__info">
<a class="ticket-link" title="Plateforme de réservation" :href="session.ticketingUrl" target="_blank"><?php snippet('ticket') ?> Plus que quelques places !</a>
</div>
</template>
2024-08-28 19:11:58 +02:00
</a>
2024-07-26 10:33:31 +02:00
</li>
</template>
</ul>
</div>
</section>
2024-07-24 18:19:25 +02:00