@@ -12,6 +12,7 @@ interface ActivityChartConfig {
12
12
canvas : HTMLCanvasElement ;
13
13
startDate : Date ;
14
14
counterId : number ;
15
+ locale : string ;
15
16
}
16
17
17
18
interface OpeningTime {
@@ -23,11 +24,9 @@ interface EventInput {
23
24
start : Date ;
24
25
end : Date ;
25
26
backgroundColor : string ;
27
+ title ?: string ;
26
28
}
27
29
28
- // TODO: Semaines passées
29
- // TODO: Manage locales
30
-
31
30
exportToHtml ( "loadChart" , loadChart ) ;
32
31
33
32
async function loadChart ( options : ActivityChartConfig ) {
@@ -44,25 +43,44 @@ async function loadChart(options: ActivityChartConfig) {
44
43
const calendar = new Calendar ( options . canvas , {
45
44
plugins : [ timeGridPlugin ] ,
46
45
initialView : "timeGridWeek" ,
47
- locale : "fr" ,
46
+ locale : options . locale ,
48
47
slotLabelFormat : { hour : "2-digit" , minute : "2-digit" , hour12 : false } ,
49
48
dayHeaderFormat : { weekday : "long" } ,
50
49
firstDay : 1 ,
51
50
views : { timeGrid : { allDaySlot : false } } ,
52
51
scrollTime : "09:00:00" ,
53
- headerToolbar : { left : "" , center : "" , right : "" } ,
52
+ headerToolbar : { left : "prev today " , center : "title " , right : "" } ,
54
53
events : events ,
55
54
nowIndicator : true ,
56
55
height : 600 ,
57
56
} ) ;
58
57
calendar . render ( ) ;
58
+
59
+ calendar . on ( "datesSet" , async ( info ) => {
60
+ if ( options . startDate <= info . start ) {
61
+ return ;
62
+ }
63
+ const newPerms = await paginated ( permanencyFetchPermanancies , {
64
+ query : {
65
+ counter : [ options . counterId ] ,
66
+ // biome-ignore lint/style/useNamingConvention: backend API uses snake_case
67
+ end_after : info . startStr ,
68
+ // biome-ignore lint/style/useNamingConvention: backend API uses snake_case
69
+ start_before : info . endStr ,
70
+ } ,
71
+ } as PermanencyFetchPermananciesData ) ;
72
+ options . startDate = info . start ;
73
+ calendar . addEventSource ( getEvents ( newPerms , false ) ) ;
74
+ permanancies . push ( ...newPerms ) ;
75
+ calendar . render ( ) ;
76
+ } ) ;
59
77
}
60
78
61
79
function roundToQuarter ( date : Date , ceil : boolean ) {
62
80
const result = date ;
63
81
const minutes = date . getMinutes ( ) ;
64
82
// removes minutes exceeding the lower quarter and adds 15 minutes if rounded to ceiling
65
- result . setMinutes ( minutes + + ceil * 15 - ( minutes % 15 ) , 0 , 0 ) ;
83
+ result . setMinutes ( minutes - ( minutes % 15 ) + + ceil * 15 , 0 , 0 ) ;
66
84
return result ;
67
85
}
68
86
@@ -99,12 +117,15 @@ function getOpeningTimes(rawPermanancies: PermanencySchema[]) {
99
117
return openingTimes ;
100
118
}
101
119
102
- function getEvents ( permanancies : PermanencySchema [ ] ) {
120
+ function getEvents ( permanancies : PermanencySchema [ ] , currentWeek = true ) : EventInput [ ] {
103
121
const openingTimes = getOpeningTimes ( permanancies ) ;
104
122
const events : EventInput [ ] = [ ] ;
105
123
for ( const openingTime of openingTimes ) {
106
- const lastMonday = getLastMonday ( ) ;
107
- const shift = openingTime . end < lastMonday ;
124
+ let shift = false ;
125
+ if ( currentWeek ) {
126
+ const lastMonday = getLastMonday ( ) ;
127
+ shift = openingTime . end < lastMonday ;
128
+ }
108
129
// if permanancies took place last week (=before monday),
109
130
// -> display them in lightblue as part of the current week
110
131
events . push ( {
@@ -117,8 +138,7 @@ function getEvents(permanancies: PermanencySchema[]) {
117
138
}
118
139
119
140
// Function to get last Monday at 00:00
120
- function getLastMonday ( ) : Date {
121
- const now = new Date ( ) ;
141
+ function getLastMonday ( now = new Date ( ) ) : Date {
122
142
const dayOfWeek = now . getDay ( ) ;
123
143
const lastMonday = new Date ( now ) ;
124
144
lastMonday . setDate ( now . getDate ( ) - ( ( dayOfWeek + 6 ) % 7 ) ) ; // Adjust for Monday as day 1
0 commit comments