Skip to content

Commit ea04668

Browse files
Merge pull request #59 from kapillamba4/fix-56
Allow anonymous users to set filters
2 parents ac352a7 + b31e2cf commit ea04668

File tree

3 files changed

+155
-22
lines changed

3 files changed

+155
-22
lines changed

public_html/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
</div>
3737

3838
<div class="row no-gutters">
39+
<div id="side-menu" class="col-sm-2">
40+
<hr style="margin: 0; border-top: solid 1px #999">
41+
<div style="padding: 15px; color: #eee; font-size: 16px;" id="sidebar">
42+
<div id="filters" style="color: white; display: none"></div>
43+
</div>
44+
</div>
3945
<div id="calendarContainer" class="col-sm-10 ml-auto mr-auto wrapper"
4046
style="padding: 10px; background-color: #F4F6F9">
4147
<div id="colors" class="row text-center" style="height: 20px;width: 100%">

public_html/index.js

+130-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ $(document).ready(function () {
2929
}
3030

3131
var api = '/api/v1';
32+
var eventsData;
33+
34+
35+
$('#filters').show();
3236

3337
function getCentres() {
3438

@@ -42,9 +46,11 @@ $(document).ready(function () {
4246
`);
4347
});
4448
showBatchesAndRooms(centres[0]);
49+
getFilters(centres[0].id);
4550

4651
$centres.change(() => {
4752
getCentre(+($centres.val()));
53+
getFilters(+($centres.val()));
4854
})
4955
} else {
5056
$.toast({
@@ -107,6 +113,125 @@ $(document).ready(function () {
107113
});
108114
}
109115

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">&nbsp;&nbsp;` + 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">&nbsp;&nbsp;` + 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">&nbsp;&nbsp;` + 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+
110235
function showBatchesAndRooms(centre) {
111236

112237
const events = [];
@@ -161,7 +286,6 @@ $(document).ready(function () {
161286
let batches = data.data;
162287

163288
batches.forEach(function (batch) {
164-
165289
let lectures = batch.lectures;
166290
lectures.forEach((lecture) => {
167291
if (lecture.startTime && lecture.endTime) {
@@ -173,7 +297,9 @@ $(document).ready(function () {
173297
stick: true,
174298
resourceId: lecture.roomId,
175299
batchCapacity: batch.size,
300+
batchId: batch.id,
176301
batchName: batch.name,
302+
teacherId: batch.teacher.id,
177303
teacherName: batch.teacher.name,
178304
courseName: batch.course.name
179305
});
@@ -182,6 +308,7 @@ $(document).ready(function () {
182308

183309
});
184310

311+
eventsData = events.slice();
185312
$('#calendar').fullCalendar({
186313
// put your options and callbacks here
187314
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
@@ -193,7 +320,7 @@ $(document).ready(function () {
193320
fixedWeekCount: false,
194321
minTime: "07:00:00",
195322
maxTime: "22:00:00",
196-
height: 'auto',
323+
height: $('#calendarContainer').height() - 60,
197324
events: events,
198325
dayClick: function (date, jsEvent, view, resourceObj) {
199326
$('#calendar').fullCalendar('changeView', 'agendaOneDay', date);
@@ -245,7 +372,7 @@ $(document).ready(function () {
245372
Course: ${event.courseName}<br/>
246373
Batch: ${event.batchName}<br/>
247374
Teacher: ${event.teacherName}<br/>
248-
Batch Capacity: ${event.batchCapacity}<br/>
375+
Batch Capacity: ${event.batchCapacity}<br/>
249376
Room: ${resources[index].title}<br/>
250377
`
251378
}).tooltip('show');

public_html/style.css

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
body {
33
background-color: #F4F6F9;
4-
/*height: 100vh;*/
5-
/*overflow-y: hidden;*/
64
}
75

86
.container-fluid {
@@ -11,18 +9,16 @@ body {
119
}
1210

1311
#side-menu {
14-
/*height: 100vh;*/
15-
/*position: fixed;*/
12+
height: 100vh;
1613
background-color: #343a40;
14+
padding: 0;
15+
overflow-x: hidden;
1716
}
1817

1918
.header-bar {
2019
background-color: #343a40;
2120
z-index: 10;
2221
height: auto;
23-
/*position: fixed;*/
24-
/*top: 0px;*/
25-
/*width: 100%;*/
2622
padding-top: 10px;
2723
padding-bottom: 10px;
2824
}
@@ -48,9 +44,21 @@ ul {
4844
padding-left: 20px;
4945
}
5046

51-
/*#calendar{*/
52-
/*margin-top: 20px;*/
53-
/*}*/
47+
.filter-column-divs{
48+
color: #ddd;
49+
}
50+
51+
.filter-column-divs-heading{
52+
padding-bottom: 15px;
53+
}
54+
55+
.filter-column-divs-content{
56+
padding-left: 10px;
57+
}
58+
59+
.label-style {
60+
color: #aaa;
61+
}
5462

5563
#sidebar .list-group-item {
5664
border-radius: 0;
@@ -167,21 +175,15 @@ ul {
167175
}
168176

169177
.titlerow {
170-
/*background-color: white;*/
171178
height: auto;
172179
padding: 30px;
173180
padding-top: 0;
174181
padding-bottom: 0;
175-
/*box-shadow: #DDD 0 0 8px 1px ;*/
176-
/*border-radius: .125rem;*/
177182
}
178183

179184
.minicourses {
180-
/*background-color: white;*/
181185
height: auto;
182186
padding: 20px;
183-
/*box-shadow: #DDD 0 0 8px 1px ;*/
184-
/*border-radius: .125rem;*/
185187
}
186188

187189
.minicourses-list {
@@ -199,13 +201,11 @@ ul {
199201

200202
.minicourses-list-li-div {
201203
width: 100%;
202-
/*padding-top: 10px;*/
203204
height: auto;
204205
border-bottom: solid 2px #EEE;
205206
background-color: white;
206207
box-shadow: #DDD 0 0 8px 1px;
207208
border-radius: .125rem;
208-
/*cursor: pointer;*/
209209
}
210210

211211
#minicourses-list > li {
@@ -222,4 +222,4 @@ a {
222222

223223
.fc-content {
224224
color: white;
225-
}
225+
}

0 commit comments

Comments
 (0)