Skip to content
14 changes: 7 additions & 7 deletions tcf_core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ def searchbar_context(request):
number__gte=latest_semester.number - 50 # 50 = 5 years * 10 semesters
).order_by("-number")

# Get weekdays from request, defaulting to all days if not specified
weekdays = request.GET.get("weekdays", "MON-TUE-WED-THU-FRI").split("-")
# Get saved filters from the session (or use defaults)
saved_filters = request.session.get("search_filters", {})

context = {
"disciplines": Discipline.objects.all().order_by("name"),
"subdepartments": Subdepartment.objects.all().order_by("mnemonic"),
"semesters": recent_semesters,
"selected_disciplines": request.GET.getlist("discipline"),
"selected_subdepartments": request.GET.getlist("subdepartment"),
"selected_weekdays": weekdays,
"from_time": request.GET.get("from_time", ""),
"to_time": request.GET.get("to_time", ""),
"selected_disciplines": saved_filters.get("disciplines", []),
"selected_subdepartments": saved_filters.get("subdepartments", []),
"selected_weekdays": saved_filters.get("weekdays", ["MON", "TUE", "WED", "THU", "FRI"]),
"from_time": saved_filters.get("from_time", ""),
"to_time": saved_filters.get("to_time", ""),
}
return context
13 changes: 6 additions & 7 deletions tcf_website/templates/course/course.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% include "common/toolbar.html" with breadcrumbs=breadcrumbs sorting=True %}
</div>

<div class="instructors container-lg mt-3">
<div class="instructors container-lg mt-3 px-0">
<div class="d-md-flex align-items-baseline my-3">
<h1 class="mr-md-3 text-nowrap">{{ course.code }}</h1>
<h2>{{ course.title }}</h2>
Expand All @@ -41,15 +41,14 @@ <h4 class="card-title">
</div>
{% endif %}
{% if course.disciplines.exists %}
<div>
<div class="mb-4">
<small class="mb-0 text-uppercase" style="font-size: 15px;">
<i class="fa-fw" aria-hidden="true"></i>Discipline(s):
</small>
<ul>
{% for discipline in course.disciplines.all %}
<li>{{ discipline.name }}</li>
{% endfor %}
</ul>
{% for discipline in course.disciplines.all %}
{{ discipline.name }}
{% if not forloop.last %} / {% endif %}
{% endfor %}
</div>
{% endif %}
<p class="card-text">
Expand Down
2 changes: 1 addition & 1 deletion tcf_website/templates/department/department.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% include "common/toolbar.html" with active_course_recency=active_course_recency latest_semester=latest_semester last_five_years=last_five_years dept_id=dept_id breadcrumbs=breadcrumbs sorting=True %}
</div>
<div class="subdepartments mt-3">
<div class="subdepartment container-lg">
<div class="subdepartment container-lg px-0">
{% if courses|length == 0 %}
<div class="new card col p-5 text-center">
<div class="card-body">
Expand Down
49 changes: 46 additions & 3 deletions tcf_website/templates/search/searchbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,47 @@ <h6 class="filter-header">
});
});

// Add clear all functionality
// Reordering function to pin selected checkboxes to the top
function reorderList(containerSelector, checkboxSelector) {
const container = document.querySelector(containerSelector);
if (!container) return;
const items = Array.from(container.children);
items.sort((a, b) => {
const aCheckbox = a.querySelector(checkboxSelector);
const bCheckbox = b.querySelector(checkboxSelector);

// Check if one is selected and the other is not
if (aCheckbox.checked && !bCheckbox.checked) return -1;
if (!aCheckbox.checked && bCheckbox.checked) return 1;

// If both are either checked or unchecked, sort alphabetically by label text
const aLabelText = a.querySelector('label').textContent.trim().toLowerCase();
const bLabelText = b.querySelector('label').textContent.trim().toLowerCase();
return aLabelText.localeCompare(bLabelText);
});
// Clear and reappend in new order
container.innerHTML = '';
items.forEach(item => container.appendChild(item));
}

// Add event listeners to re-sort subjects whenever a subject checkbox changes
document.querySelectorAll('.form-check-subjects').forEach(checkbox => {
checkbox.addEventListener('change', () => {
reorderList('.subject-list', '.form-check-subjects');
});
});

// Add event listeners to re-sort disciplines whenever a discipline checkbox changes
document.querySelectorAll('.form-check-disciplines').forEach(checkbox => {
checkbox.addEventListener('change', () => {
reorderList('.discipline-list', '.form-check-disciplines');
});
});

// Call reorder on page load in case some items are selected by default
reorderList('.subject-list', '.form-check-subjects');
reorderList('.discipline-list', '.form-check-disciplines');

const resetButton = document.querySelector('button[type="reset"]');
resetButton.addEventListener('click', function(e) {
e.preventDefault(); // Prevent default reset behavior
Expand All @@ -261,7 +301,10 @@ <h6 class="filter-header">
document.getElementById('to_time').value = '';

updateButtonState();


// Reorder lists after clearing filters (so any selected items, if any, are sorted correctly)
reorderList('.subject-list', '.form-check-subjects');
reorderList('.discipline-list', '.form-check-disciplines');
});

// Add weekdays handling
Expand All @@ -276,7 +319,7 @@ <h6 class="filter-header">
document.querySelectorAll('.day-checkbox').forEach(checkbox => {
checkbox.addEventListener('change', () => {
updateWeekdays();
updateFilterSummary();
updateButtonState();
});
});

Expand Down
2 changes: 1 addition & 1 deletion tcf_website/views/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def department(request, dept_id: int, course_recency=None):
request,
"department/department.html",
{
"subdepartments": dept.subdepartment_set.all(),
# "subdepartments": dept.subdepartment_set.all(),
"dept_id": dept_id,
"latest_semester": str(latest_semester),
"breadcrumbs": breadcrumbs,
Expand Down
4 changes: 4 additions & 0 deletions tcf_website/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def search(request):
"to_time": request.GET.get("to_time"),
}

# Save filters to session
request.session["search_filters"] = filters

if query:
courses = fetch_courses(query, filters)
instructors = fetch_instructors(query)
Expand Down Expand Up @@ -113,6 +116,7 @@ def fetch_instructors(query) -> list[dict]:

return instructors


def fetch_courses(query, filters):
"""Get course data using Django Trigram similarity"""
# lower similarity threshold for partial searches of course titles
Expand Down
Loading