2024-07-31 08:50:49 +02:00
< section
2024-07-24 09:43:31 +02:00
class = " calendar-strip "
x - data = " {
2024-09-11 16:34:58 +02:00
calendar : createEmptyCalendar (),
2024-09-12 14:16:14 +02:00
currentMonthIndex : dayjs () . month () + 1 ,
currentWeekIndex : (() => {
dayjs . extend ( window . dayjs_plugin_weekOfYear );
const today = dayjs ();
const firstDayOfMonth = today . startOf ( 'month' );
const currentWeek = today . week ();
const firstWeekOfMonth = firstDayOfMonth . week ();
const currentWeekIndex = currentWeek - firstWeekOfMonth ;
return currentWeekIndex ;
})(),
2024-09-11 16:34:58 +02:00
token : '<?= $site->mapadoToken() ?>' ,
contractId : '<?= $site->mapadoContractId() ?>' ,
targetSessions : [],
open : false ,
today : dayjs () . format ( 'DD-MM-YYYY' ),
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
get monthName () {
2024-09-12 14:16:14 +02:00
return dayjs () . month ( this . currentMonthIndex - 1 ) . format ( 'MMMM' );
2024-09-11 16:34:58 +02:00
},
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
get currentMonth () {
2024-09-12 14:16:14 +02:00
return this . calendar [ this . currentMonthIndex ]
},
get currentWeeks () {
const weeks = [[]];
let index = 0 ;
for ( let key in this . currentMonth ) {
const date = this . currentMonth [ key ]
weeks [ index ] . push ( date )
if ( date . indexInWeek === 7 ) {
weeks . push ([])
index ++
}
}
return weeks
},
get currentWeek () {
this . currentWeeks [ this . currentWeekIndex ];
2024-09-11 16:34:58 +02:00
},
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
async updateDates () {
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
fetch ( '/<?= page(' programme ')->children()->first()->uri() ?>/data.json' )
. then ( res => res . json ())
. then ( json => {
console . log ( 'Saved calendar : ' , json )
this . calendar = json
})
. catch ( error => console . log ( 'No saved calendar.' ))
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
const daysNode = document . querySelector ( '.calendar-strip__days' );
2024-09-12 14:16:14 +02:00
daysNode . classList . toggle ( 'progress' );
2024-09-11 16:34:58 +02:00
this . calendar = await getCurrentSeasonCalendar ();
console . log ( 'Updated calendar for current season :' , this . calendar );
daysNode . classList . toggle ( 'progress' );
},
2024-09-11 14:36:08 +02:00
2024-09-11 16:34:58 +02:00
handleDayHover () {
if ( ! this . date ) return
if ( this . date . sessions . length > 0 ) {
2024-08-28 19:11:58 +02:00
this . targetSessions = this . date . sessions ;
2024-09-11 16:34:58 +02:00
this . open = true ;
} else {
setTimeout (() => {
this . targetSessions = this . date . sessions ;
}, 100 );
this . open = false ;
}
},
2024-09-11 14:36:08 +02:00
2024-09-13 16:00:15 +02:00
prevWeek () {
if ( this . currentWeekIndex === 0 ) {
this . prevMonth ()
this . currentWeekIndex = this . currentWeeks . length - 1
} else {
this . currentWeekIndex --
}
},
nextWeek () {
if ( this . currentWeekIndex === this . currentWeeks . length - 1 ) {
this . nextMonth ()
this . currentWeekIndex = 0
} else {
this . currentWeekIndex ++
}
},
2024-09-11 16:34:58 +02:00
nextMonth () {
2024-09-12 14:16:14 +02:00
if ( this . currentMonthIndex == 12 ) {
this . currentMonthIndex = 1
2024-09-11 16:34:58 +02:00
} else {
2024-09-12 14:16:14 +02:00
this . currentMonthIndex ++
2024-09-11 16:34:58 +02:00
}
},
prevMonth () {
2024-09-12 14:16:14 +02:00
if ( this . currentMonthIndex == 1 ) {
this . currentMonthIndex = 12
2024-09-11 16:34:58 +02:00
} else {
2024-09-12 14:16:14 +02:00
this . currentMonthIndex --
2024-09-11 16:34:58 +02:00
}
2024-09-11 14:36:08 +02:00
}
2024-09-11 16:34:58 +02:00
} "
2024-09-11 14:36:08 +02:00
2024-07-24 15:56:28 +02:00
2024-07-24 18:01:01 +02:00
x - init = " updateDates() "
2024-07-24 09:43:31 +02:00
>
< div class = " calendar-strip__selector " >
2024-09-12 14:16:14 +02:00
< button class = " prev-month " @ click = " prevMonth() " : disabled = " currentMonthIndex === 9 " > ← </ button >
2024-07-24 09:43:31 +02:00
< span x - text = " monthName " ></ span >
2024-09-12 14:16:14 +02:00
< button class = " next-month " @ click = " nextMonth() " : disabled = " currentMonthIndex === 8 " > → </ button >
2024-07-24 09:43:31 +02:00
</ div >
2024-09-13 16:00:15 +02:00
< button @ click = " prevWeek() " class = " calendar-strip__change-week calendar-strip__next-week " > ← </ button >
2024-09-12 14:16:14 +02:00
2024-07-24 09:43:31 +02:00
< ul class = " calendar-strip__days " >
2024-09-12 14:16:14 +02:00
< template x - for = " (week, weekIndex) in currentWeeks " >
< li class = " week " : class = " weekIndex == currentWeekIndex ? 'current' : '' " >
< ul >
< template x - for = " date in week " >
< li class = " calendar-strip__day " : class = " targetSessions.length > 0 && open && date.index == targetSessions[0].day ? 'active' : '' " : style = " 'animation-delay: ' + date.index * 0.03 + 's' " >
< button
: class = " !date || date.full !== today ? '' : 'today' "
: disabled = " !date || date.sessions.length === 0 ? true : false "
: title = " !date || date.sessions.length === 0 ? 'Pas de représentation.' : 'Voir les représentations.' "
2024-09-16 15:04:09 +02:00
@ mouseover = " handleDayHover() "
2024-09-12 14:16:14 +02:00
>
< template x - if = " date " >
< span x - text = " date.initial " ></ span >
</ template >
< span x - text = " date.index " ></ span >
</ button >
</ li >
</ template >
</ ul >
2024-07-24 18:19:25 +02:00
</ li >
2024-07-24 09:43:31 +02:00
</ template >
</ ul >
2024-09-13 16:00:15 +02:00
< button @ click = " nextWeek() " class = " calendar-strip__change-week calendar-strip__next-week " > → </ button >
2024-09-12 14:16:14 +02:00
2024-09-03 16:16:06 +02:00
< a href = " <?= page('programme')->url() ?> " class = " calendar-strip__calendar-btn " > calendrier </ a >
2024-09-12 14:16:14 +02:00
2024-07-26 10:33:31 +02:00
< div class = " calendar-strip__date " : class = " open ? 'open' : '' " >
2024-09-12 13:05:44 +02:00
< ul class = " sessions " >
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-16 18:30:20 +02:00
< div class = " left-column mobile-group " >
< a class = " session__event-link " : href = " session.eventUrl " title = " En savoir plus " ></ a >
< div class = " session__info session__info--slot " >
< p x - html = " ` ${ session.day } ${ monthName } ` " ></ p >
2024-09-18 18:37:07 +02:00
< p x - html = " session.time " ></ p >
2024-09-12 13:05:44 +02:00
</ div >
2024-09-16 18:30:20 +02:00
</ div >
< div class = " middle-column mobile-group " >
< div class = " session__info session__info--title " >
< p >< strong x - html = " `<strong> ${ session.title } </strong>` " ></ strong ></ p >
< p x - html = " session.authors " ></ p >
2024-09-12 13:05:44 +02:00
</ div >
2024-09-16 18:30:20 +02:00
</ div >
2024-09-18 18:37:07 +02:00
< div class = " session__info session__info--duration desktop " >
< p x - text = " session.duration ? 'Durée : ' + session.duration : '' " ></ p >
< p x - text = " session.public ? session.public : '' " ></ p >
</ div >
2024-09-16 18:30:20 +02:00
< div x - text = " ` ${ session.place } ` " class = " session__info session__info--place desktop " ></ div >
< div class = " right-column mobile-group " >
< template x - if = " !session.ticketingUrl " >
< div class = " session__info session__info--book session__info--book-free " >
< a class = " ticket-link " target = " _blank " title = " Entrée libre " disabled >< ? php snippet ( 'ticket' ) ?> <span class="desktop">Entrée libre</span></a>
</ div >
</ template >
< template x - if = " session.bookableStock === 0 " >
< div class = " session__info session__info--book session__info--book-sold-out " >
< a class = " ticket-link " title = " Plus de places disponibles " disabled >< ? php snippet ( 'ticket' ) ?> <span class="desktop">Complet</span></a>
</ div >
</ template >
< template x - if = " session.bookableStock > stockThreshold " >
< div class = " session__info session__info--book session__info--book-open " >
< a class = " ticket-link " title = " Plateforme de réservation " : href = " session.ticketingUrl " target = " _blank " >< ? php snippet ( 'ticket' ) ?> <span class="desktop">Billetterie</span></a>
</ div >
</ template >
< template x - if = " session.bookableStock !== 0 && session.bookableStock < stockThreshold " >
< div class = " session__info session__info--book session__info--book-few-places " >
< a class = " ticket-link " title = " Plateforme de réservation " : href = " session.ticketingUrl " target = " _blank " >< ? php snippet ( 'ticket' ) ?> <span class="desktop">Plus que quelques places !</span></a>
</ div >
</ template >
</ div >
2024-07-26 10:33:31 +02:00
</ li >
</ template >
</ ul >
</ div >
2024-07-31 08:50:49 +02:00
</ section >
2024-07-24 18:19:25 +02:00