Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged course inputs and added a venue filter #173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,51 +291,52 @@ <h4>Add Courses To Timetable</h4>
<div class="panel-body">
<form class="col-xs-12">
<div class="row">
<div class="form-group col-xs-12 col-sm-4">
<div class="form-group col-xs-12 col-sm-7">
<label
for="inputCourseCode"
class="control-label"
>Course code:</label
>Course</label
>
<div>
<input
type="text"
class="form-control"
id="inputCourseCode"
placeholder="eg: CSE1001"
id="inputCourse"
placeholder="eg: CSE1001 or PROBLEM SOLVING AND PROGRAMMING"
/>
</div>
</div>

<div class="form-group col-xs-12 col-sm-5">
<!-- Filter course by slot -->
<div class="form-group col-xs-12 col-sm-3">
<label
for="inputCourseTitle"
for="filter-by-slot"
class="control-label"
>Course title:</label
>Filter By Slot</label
>
<div>
<input
type="text"
class="form-control"
id="inputCourseTitle"
placeholder="eg: PROBLEM SOLVING AND PROGRAMMING"
/>
<select
id="filter-by-slot"
multiple="multiple"
>
<!-- <option value="A1">A1</option> -->
</select>
</div>
</div>

<!-- Filter course by slot -->
<div class="form-group col-xs-12 col-sm-3">
<!-- Filter course by venue -->
<div class="form-group col-xs-12 col-sm-2">
<label
for="filter-by-slot"
class="control-label"
>Filter By Slot</label
>Filter By Venue</label
>
<div>
<select
id="filter-by-slot"
id="filter-by-venue"
multiple="multiple"
>
<!-- <option value="A1">A1</option> -->
<!-- <option value="AB1-101">AB1-101</option> -->
</select>
</div>
</div>
Expand Down Expand Up @@ -1002,8 +1003,7 @@ <h5 class="list-group-item-heading">F1+TF1</h5>
</tr>
<tr class="success">
<th>Slot</th>
<th>Code</th>
<th>Title</th>
<th>Course</th>
<th>Faculty</th>
<th>Venue</th>
<th>Credits</th>
Expand Down
183 changes: 125 additions & 58 deletions src/js/autocomplete_course.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import $ from 'jquery';

export let filterSlotArr = [];
export function resetFilterSlotArr(params) {
export function resetFilterSlotArr() {
filterSlotArr = [];
}

export let filterVenueArr = [];
export function resetFilterVenueArr() {
filterVenueArr = [];
}

const courses_data = {
unique_courses: [],
all_data: [],
};

var multiselectConfig = {
var multiselectSlotConfig = {
enableCaseInsensitiveFiltering: true,
delimiterText: '; ',
enableClickableOptGroups: true,
Expand Down Expand Up @@ -82,6 +87,78 @@ var multiselectConfig = {
},
};

var multiselectVenueConfig = {
enableCaseInsensitiveFiltering: true,
delimiterText: '; ',
enableClickableOptGroups: true,
disableIfEmpty: true,
disabledText: 'Apply Venue Filter',
buttonWidth: '100%',
maxHeight: 200,
onChange: function(option, checked) {
if (checked) {
for (var key = 0; key < option.length; key++) {
if (option[key.toString()].value) {
filterVenueArr.indexOf(option[key.toString()].value) ===
-1 && filterVenueArr.push(option[key.toString()].value);
} else {
var allSelectOption = option[key.toString()];
for (
var innerkey = 0;
innerkey < allSelectOption.length;
innerkey++
) {
if (allSelectOption[innerkey.toString()].value) {
filterVenueArr.indexOf(
allSelectOption[innerkey.toString()].value,
) === -1 &&
filterVenueArr.push(
allSelectOption[innerkey.toString()].value,
);
}
}
}
}
} else {
for (var key = 0; key < option.length; key++) {
if (option[key.toString()].value) {
var filterSlotIndex = filterVenueArr.indexOf(
option[key.toString()].value,
);
filterVenueArr.splice(filterSlotIndex, 1);
} else {
var allSelectOption = option[key.toString()];
for (
var innerkey = 0;
innerkey < allSelectOption.length;
innerkey++
) {
if (allSelectOption[innerkey.toString()].value) {
var filterSlotIndex = filterVenueArr.indexOf(
allSelectOption[innerkey.toString()].value,
);
filterVenueArr.splice(filterSlotIndex, 1);
}
}
}
}
}
$('#insertCourseSelectionOptions button').show();
if (filterVenueArr.length) {
$('#insertCourseSelectionOptions button')
.not(function(i, el) {
var elVenue = $(el).data('venue');
if (filterVenueArr.indexOf(elVenue) > -1) {
return true;
} else {
return false;
}
})
.hide();
}
},
};

export function initAutocomplete(isChennai) {
if (isChennai) {
courses_data.all_data = require('../data/all_data_chennai.json');
Expand All @@ -92,10 +169,12 @@ export function initAutocomplete(isChennai) {
}

// autocomplete options
var courseCodeOption = {
var courseOptions = {
data: courses_data.unique_courses,

getValue: 'CODE',
getValue: function(el) {
return el.CODE + ' - ' + el.TITLE;
},

list: {
match: {
Expand All @@ -105,56 +184,17 @@ export function initAutocomplete(isChennai) {
maxNumberOfElements: 10,

onSelectItemEvent: function() {
var title = $('#inputCourseCode').getSelectedItemData().TITLE;
$('#inputCourseTitle')
.val(title)
var title = $('#inputCourse').getSelectedItemData().TITLE;
var code = $('#inputCourse').getSelectedItemData().CODE;
$('#inputCourse')
.val(code + ' - ' + title)
.trigger('change');
var code = $('#inputCourseCode').getSelectedItemData().CODE;
addSlotButtons(code);
},
},

template: {
type: 'description',
fields: {
description: 'TITLE',
addFilterButtons(code);
},
},

placeholder: 'Search...',
};

var courseTitleOption = {
data: courses_data.unique_courses,

getValue: 'TITLE',

list: {
match: {
enabled: true,
},

onSelectItemEvent: function() {
var code = $('#inputCourseTitle').getSelectedItemData().CODE;
$('#inputCourseCode')
.val(code)
.trigger('change');
addSlotButtons(code);
},
},

template: {
type: 'description',
fields: {
description: 'CODE',
},
},

placeholder: 'Search...',
};

$('#inputCourseTitle').easyAutocomplete(courseTitleOption);
$('#inputCourseCode').easyAutocomplete(courseCodeOption);
$('#inputCourse').easyAutocomplete(courseOptions);
$('div.easy-autocomplete').removeAttr('style'); // for dynamic width
}

Expand All @@ -166,16 +206,12 @@ export function postInitAutocomplete() {
});

$('#insertCourseSelectionOptions').on('click', 'button', function() {
var code = $(this).data('code');
var title = $(this).data('title');
var slot = $(this).data('slot');
var faculty = $(this).data('faculty');
var type = $(this).data('type');
var venue = $(this).data('venue');
var credits = $(this).data('credits');

$('#inputCourseCode').val(code);
$('#inputCourseTitle').val(title);
$('#inputSlotString').val(slot);
$('#inputFaculty').val(faculty);
$('#inputVenue').val(venue);
Expand All @@ -189,7 +225,8 @@ export function postInitAutocomplete() {
});

// Init Multiselect
$('#filter-by-slot').multiselect(multiselectConfig);
$('#filter-by-slot').multiselect(multiselectSlotConfig);
$('#filter-by-venue').multiselect(multiselectVenueConfig);
}

// Add slot selection buttons from array of slots
Expand Down Expand Up @@ -224,7 +261,7 @@ function getSlotSelectionButton(
return $slotButton;
}

function addSlotButtons(code) {
function addFilterButtons(code) {
var BUTTONS_PER_DIV = 4;

var buttonsPerDiv = BUTTONS_PER_DIV;
Expand All @@ -233,9 +270,14 @@ function addSlotButtons(code) {
$('#insertCourseSelectionOptions').append($buttonDiv);

$('#filter-by-slot').html('');
$('#filter-by-venue').html('');

resetFilterSlotArr();
resetFilterVenueArr();

var theorySlotGroupSelect = [];
var labSlotGroupSelect = [];
var venueGroupSelect = [];

$.each(courses_data.all_data, function(key, value) {
if (value.CODE === code) {
Expand All @@ -252,15 +294,28 @@ function addSlotButtons(code) {

// Build Multiselect group list
if (value.SLOT[0] === 'L') {
if (labSlotGroupSelect.indexOf(value.SLOT) === -1) {
if (
typeof value.SLOT != 'undefined' &&
labSlotGroupSelect.indexOf(value.SLOT) === -1
) {
labSlotGroupSelect.push(value.SLOT);
}
} else {
if (theorySlotGroupSelect.indexOf(value.SLOT) === -1) {
if (
typeof value.SLOT != 'undefined' &&
theorySlotGroupSelect.indexOf(value.SLOT) === -1
) {
theorySlotGroupSelect.push(value.SLOT);
}
}

if (
typeof value.VENUE != 'undefined' &&
venueGroupSelect.indexOf(value.VENUE) === -1
) {
venueGroupSelect.push(value.VENUE);
}

buttonsPerDiv--;

if (buttonsPerDiv === 0) {
Expand All @@ -280,14 +335,26 @@ function addSlotButtons(code) {
});
$('#filter-by-slot').append($theorySlotGroupSelect);
}

// Multiselect Lab
if (labSlotGroupSelect.length) {
// Multiselect Lab
var $labSlotGroupSelect = $('<optgroup label="Lab"></optgroup>');
labSlotGroupSelect.forEach(function(el) {
var $option = $('<option value="' + el + '">' + el + '</option>');
$labSlotGroupSelect.append($option);
});
$('#filter-by-slot').append($labSlotGroupSelect);
}

// Multiselect Venue
if (venueGroupSelect.length) {
var $venueGroupSelect = $('#filter-by-venue');
venueGroupSelect.forEach(function(el) {
var $option = $('<option value="' + el + '">' + el + '</option>');
$venueGroupSelect.append($option);
});
}

$('#filter-by-slot').multiselect('rebuild');
$('#filter-by-venue').multiselect('rebuild');
}
Loading