@@ -29,6 +29,10 @@ $(document).ready(function () {
29
29
}
30
30
31
31
var api = '/api/v1' ;
32
+ var eventsData ;
33
+
34
+
35
+ $ ( '#filters' ) . show ( ) ;
32
36
33
37
function getCentres ( ) {
34
38
@@ -42,9 +46,11 @@ $(document).ready(function () {
42
46
` ) ;
43
47
} ) ;
44
48
showBatchesAndRooms ( centres [ 0 ] ) ;
49
+ getFilters ( centres [ 0 ] . id ) ;
45
50
46
51
$centres . change ( ( ) => {
47
52
getCentre ( + ( $centres . val ( ) ) ) ;
53
+ getFilters ( + ( $centres . val ( ) ) ) ;
48
54
} )
49
55
} else {
50
56
$ . toast ( {
@@ -107,6 +113,125 @@ $(document).ready(function () {
107
113
} ) ;
108
114
}
109
115
116
+ function getFilters ( centreId ) {
117
+
118
+ const filters = $ ( '#filters' ) ;
119
+ filters . empty ( ) ;
120
+
121
+ let teachersString = "" ;
122
+ let batchesString = "" ;
123
+ let roomsString = "" ;
124
+
125
+ $ . get ( `${ api } /teachers` , function ( teachersData ) {
126
+ if ( teachersData . success && teachersData . data . length > 1 ) {
127
+ teachersString = `<div class="filter-column-divs">
128
+ <div class="filter-column-divs-heading">Teachers</div>
129
+ <div class="filter-column-divs-content">` ;
130
+ for ( let i = 0 ; i < teachersData . data . length ; i ++ ) {
131
+ teachersString += `
132
+ <label class="label-style">
133
+ <input class="checkbox-style" name="teachers" value="` + teachersData . data [ i ] . id + `" type="checkbox"> ` + teachersData . data [ i ] . name + `<br/>
134
+ </label>
135
+ <br>
136
+ ` ;
137
+ }
138
+ teachersString += `</div></div>` ;
139
+ filters . append ( teachersString ) ;
140
+
141
+ }
142
+
143
+ $ . get ( `${ api } /centres/${ centreId } /batches/active` , function ( batchesData ) {
144
+ if ( batchesData . success && batchesData . data . length > 1 ) {
145
+ batchesString = `<div class="filter-column-divs">
146
+ <div class="filter-column-divs-heading">Batches</div>
147
+ <div class="filter-column-divs-content">` ;
148
+ for ( let i = 0 ; i < batchesData . data . length ; i ++ ) {
149
+ batchesString += `
150
+ <label class="label-style">
151
+ <input class="checkbox-style" name="batches" value="` + batchesData . data [ i ] . id + `" type="checkbox"> ` + batchesData . data [ i ] . name + `<br/>
152
+ </label>
153
+ <br>
154
+ ` ;
155
+ }
156
+ batchesString += `</div></div>` ;
157
+ filters . append ( batchesString ) ;
158
+
159
+ }
160
+
161
+ $ . get ( `${ api } /centres/${ centreId } /rooms` , function ( roomsData ) {
162
+ if ( roomsData . success && roomsData . data . length > 1 ) {
163
+ roomsString = `<div class="filter-column-divs">
164
+ <div class="filter-column-divs-heading">Rooms</div>
165
+ <div class="filter-column-divs-content">` ;
166
+ for ( let i = 0 ; i < roomsData . data . length ; i ++ ) {
167
+ roomsString += `
168
+ <label class="label-style">
169
+ <input class="checkbox-style" name="rooms" value="` + roomsData . data [ i ] . id + `" type="checkbox"> ` + roomsData . data [ i ] . name + `<br/>
170
+ </label>
171
+ <br>
172
+ ` ;
173
+ }
174
+ roomsString += `</div></div>` ;
175
+ filters . append ( roomsString ) ;
176
+
177
+ }
178
+ $ ( 'input[type="checkbox"]' ) . off ( 'change' ) ;
179
+ for ( let i = 0 ; i < batchesData . data . length ; i ++ ) {
180
+ if ( batchesData . data [ i ] . name === getBatch ) {
181
+ $ ( `input[type="checkbox"][value="${ batchesData . data [ i ] . id } "]` ) . prop ( 'checked' , true )
182
+ }
183
+ }
184
+
185
+ $ ( 'input[type="checkbox"]' ) . change ( function ( ) {
186
+
187
+ let teachersArray = [ ] ;
188
+ let batchesArray = [ ] ;
189
+ let roomsArray = [ ] ;
190
+ let count = 0 ;
191
+
192
+ const teachersFilters = $ ( 'input[name="teachers"]' ) ;
193
+ const batchesFilters = $ ( 'input[name="batches"]' ) ;
194
+ const roomsFilters = $ ( 'input[name="rooms"]' ) ;
195
+
196
+ for ( let i = 0 ; i < teachersFilters . length ; i ++ ) {
197
+ if ( teachersFilters [ i ] . checked ) {
198
+ teachersArray . push ( + teachersFilters [ i ] . value ) ;
199
+ count ++ ;
200
+ }
201
+ }
202
+
203
+ for ( let i = 0 ; i < batchesFilters . length ; i ++ ) {
204
+ if ( batchesFilters [ i ] . checked ) {
205
+ batchesArray . push ( + batchesFilters [ i ] . value ) ;
206
+ count ++ ;
207
+ }
208
+ }
209
+
210
+ for ( let i = 0 ; i < roomsFilters . length ; i ++ ) {
211
+ if ( roomsFilters [ i ] . checked ) {
212
+ roomsArray . push ( + roomsFilters [ i ] . value ) ;
213
+ count ++ ;
214
+ }
215
+ }
216
+
217
+ let filteredevents = eventsData . filter ( function ( event ) {
218
+ if ( ( teachersArray . length === 0 || teachersArray . includes ( + event . teacherId ) ) &&
219
+ ( roomsArray . length === 0 || roomsArray . includes ( + event . resourceId ) ) &&
220
+ ( batchesArray . length === 0 || batchesArray . includes ( event . batchId ) ) )
221
+ return true ;
222
+ else
223
+ return false ;
224
+ } )
225
+
226
+ $ ( '#calendar' ) . fullCalendar ( 'removeEventSources' ) ;
227
+ $ ( '#calendar' ) . fullCalendar ( 'addEventSource' , filteredevents ) ;
228
+
229
+ } )
230
+ } ) ;
231
+ } ) ;
232
+ } ) ;
233
+ }
234
+
110
235
function showBatchesAndRooms ( centre ) {
111
236
112
237
const events = [ ] ;
@@ -161,7 +286,6 @@ $(document).ready(function () {
161
286
let batches = data . data ;
162
287
163
288
batches . forEach ( function ( batch ) {
164
-
165
289
let lectures = batch . lectures ;
166
290
lectures . forEach ( ( lecture ) => {
167
291
if ( lecture . startTime && lecture . endTime ) {
@@ -173,7 +297,9 @@ $(document).ready(function () {
173
297
stick : true ,
174
298
resourceId : lecture . roomId ,
175
299
batchCapacity : batch . size ,
300
+ batchId : batch . id ,
176
301
batchName : batch . name ,
302
+ teacherId : batch . teacher . id ,
177
303
teacherName : batch . teacher . name ,
178
304
courseName : batch . course . name
179
305
} ) ;
@@ -182,6 +308,7 @@ $(document).ready(function () {
182
308
183
309
} ) ;
184
310
311
+ eventsData = events . slice ( ) ;
185
312
$ ( '#calendar' ) . fullCalendar ( {
186
313
// put your options and callbacks here
187
314
schedulerLicenseKey : 'CC-Attribution-NonCommercial-NoDerivatives' ,
@@ -193,7 +320,7 @@ $(document).ready(function () {
193
320
fixedWeekCount : false ,
194
321
minTime : "07:00:00" ,
195
322
maxTime : "22:00:00" ,
196
- height : 'auto' ,
323
+ height : $ ( '#calendarContainer' ) . height ( ) - 60 ,
197
324
events : events ,
198
325
dayClick : function ( date , jsEvent , view , resourceObj ) {
199
326
$ ( '#calendar' ) . fullCalendar ( 'changeView' , 'agendaOneDay' , date ) ;
@@ -245,7 +372,7 @@ $(document).ready(function () {
245
372
Course: ${ event . courseName } <br/>
246
373
Batch: ${ event . batchName } <br/>
247
374
Teacher: ${ event . teacherName } <br/>
248
- Batch Capacity: ${ event . batchCapacity } <br/>
375
+ Batch Capacity: ${ event . batchCapacity } <br/>
249
376
Room: ${ resources [ index ] . title } <br/>
250
377
`
251
378
} ) . tooltip ( 'show' ) ;
0 commit comments