Skip to content

Commit 26dbdae

Browse files
committed
rename template titles with | instead of -; make paginator retain list url params; cleanup filters logic with local storage
1 parent 7c1d9dc commit 26dbdae

File tree

20 files changed

+92
-88
lines changed

20 files changed

+92
-88
lines changed

tcf_core/context_processors.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@ def searchbar_context(request):
2121
number__gte=latest_semester.number - 50 # 50 = 5 years * 10 semesters
2222
).order_by("-number")
2323

24-
# No longer use session to store filters
25-
# Empty defaults are provided instead
24+
# Provide only the data needed for the filter options
25+
# Filter values are managed by localStorage on the client side
2626
context = {
2727
"disciplines": Discipline.objects.all().order_by("name"),
2828
"subdepartments": Subdepartment.objects.all().order_by("mnemonic"),
2929
"semesters": recent_semesters,
30-
"selected_disciplines": [],
31-
"selected_subdepartments": [],
32-
"selected_weekdays": [],
33-
"from_time": "",
34-
"to_time": "",
35-
"open_sections": False,
36-
"min_gpa": 0.0,
3730
}
3831
return context

tcf_website/static/search/filters.js

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ document.addEventListener("DOMContentLoaded", function () {
1212
const minGpaText = document.getElementById("min-gpa-text");
1313
const minGpaInput = document.getElementById("min-gpa-input");
1414

15-
// Check if filters should be loaded from localStorage
15+
// Load filters from localStorage before setting up any event handlers
1616
loadFiltersFromLocalStorage();
1717

1818
// Check initial state (in case of page refresh with active filters)
@@ -117,17 +117,31 @@ document.addEventListener("DOMContentLoaded", function () {
117117
if (filters.subdepartments && filters.subdepartments.length) {
118118
filters.subdepartments.forEach((mnemonic) => {
119119
const input = document.getElementById(`subject-${mnemonic}`);
120-
if (input) input.checked = true;
120+
if (input) {
121+
input.checked = true;
122+
}
121123
});
122124
}
123125

124126
// Set disciplines
125127
if (filters.disciplines && filters.disciplines.length) {
126128
filters.disciplines.forEach((name) => {
127-
const input = document.getElementById(
128-
`discipline-${name.toLowerCase().replace(/\s+/g, "-")}`,
129+
// Find the discipline by checking all discipline checkboxes with matching value
130+
const disciplineCheckboxes = document.querySelectorAll(
131+
".form-check-disciplines",
129132
);
130-
if (input) input.checked = true;
133+
let found = false;
134+
135+
disciplineCheckboxes.forEach((checkbox) => {
136+
if (checkbox.value === name) {
137+
checkbox.checked = true;
138+
found = true;
139+
}
140+
});
141+
142+
if (!found) {
143+
console.warn(`Discipline not found: ${name}`);
144+
}
131145
});
132146
}
133147

@@ -221,46 +235,53 @@ document.addEventListener("DOMContentLoaded", function () {
221235
".discipline-list .form-check",
222236
);
223237

224-
// Reordering function to pin selected checkboxes to the top
225-
function reorderList(containerSelector, checkboxSelector) {
238+
// Create a safer version of the reordering function
239+
function reorderItems(containerSelector, checkboxSelector) {
226240
const container = document.querySelector(containerSelector);
227-
if (!container) return;
228-
const items = Array.from(container.children);
229-
items.sort((a, b) => {
230-
const aCheckbox = a.querySelector(checkboxSelector);
231-
const bCheckbox = b.querySelector(checkboxSelector);
232-
233-
// Check if one is selected and the other is not
234-
if (aCheckbox.checked && !bCheckbox.checked) return -1;
235-
if (!aCheckbox.checked && bCheckbox.checked) return 1;
236-
237-
// If both are either checked or unchecked, sort alphabetically by label text
238-
const aLabelText = a
239-
.querySelector("label")
240-
.textContent.trim()
241-
.toLowerCase();
242-
const bLabelText = b
243-
.querySelector("label")
244-
.textContent.trim()
245-
.toLowerCase();
246-
return aLabelText.localeCompare(bLabelText);
241+
if (!container) {
242+
console.error(`Container not found: ${containerSelector}`);
243+
return;
244+
}
245+
246+
// Get all items and convert to array for sorting
247+
const items = Array.from(container.querySelectorAll(".form-check"));
248+
249+
if (items.length === 0) {
250+
console.warn(`No items found in container: ${containerSelector}`);
251+
return;
252+
}
253+
254+
// Instead of moving DOM elements, use CSS to set their order
255+
items.forEach((item, index) => {
256+
const checkbox = item.querySelector(checkboxSelector);
257+
if (checkbox && checkbox.checked) {
258+
item.style.order = "1"; // Checked items first
259+
} else {
260+
item.style.order = "2"; // Unchecked items second
261+
}
247262
});
248-
// Clear and reappend in new order
249-
container.innerHTML = "";
250-
items.forEach((item) => container.appendChild(item));
263+
264+
// Make sure container uses flexbox for ordering
265+
container.style.display = "flex";
266+
container.style.flexDirection = "column";
251267
}
252268

253269
// Setup reordering for subjects and disciplines
254270
function setupReordering(checkboxSelector, containerSelector) {
271+
// Initial ordering
272+
reorderItems(containerSelector, checkboxSelector);
273+
274+
// Add change event to checkboxes
255275
document.querySelectorAll(checkboxSelector).forEach((checkbox) => {
256276
checkbox.addEventListener("change", () => {
257-
reorderList(containerSelector, checkboxSelector);
277+
// Reorder items when a checkbox changes
278+
reorderItems(containerSelector, checkboxSelector);
279+
saveFiltersToLocalStorage();
258280
});
259281
});
260-
// Call reorder on page load in case some items are selected by default
261-
reorderList(containerSelector, checkboxSelector);
262282
}
263283

284+
// Setup reordering after DOM is fully loaded
264285
setupReordering(".form-check-subjects", ".subject-list");
265286
setupReordering(".form-check-disciplines", ".discipline-list");
266287

@@ -281,6 +302,7 @@ document.addEventListener("DOMContentLoaded", function () {
281302
document.getElementById("subject-search").value = "";
282303
document.querySelectorAll(".subject-list .form-check").forEach((item) => {
283304
item.style.display = ""; // Show all subjects
305+
item.style.order = "2"; // Reset ordering
284306
});
285307

286308
// Clear discipline search
@@ -289,6 +311,7 @@ document.addEventListener("DOMContentLoaded", function () {
289311
.querySelectorAll(".discipline-list .form-check")
290312
.forEach((item) => {
291313
item.style.display = ""; // Show all disciplines
314+
item.style.order = "2"; // Reset ordering
292315
});
293316

294317
// Set time inputs to empty
@@ -305,10 +328,6 @@ document.addEventListener("DOMContentLoaded", function () {
305328

306329
// Clear localStorage filters
307330
localStorage.removeItem("search_filters");
308-
309-
// Reorder lists after clearing filters
310-
reorderList(".subject-list", ".form-check-subjects");
311-
reorderList(".discipline-list", ".form-check-disciplines");
312331
}
313332

314333
// Add weekdays handling

tcf_website/templates/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% load static %}
44

5-
{% block title %}404 - theCourseForum{% endblock %}
5+
{% block title %}404 | theCourseForum{% endblock %}
66

77
{% block body %}
88

tcf_website/templates/about/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}About - theCourseForum{% endblock %}
4+
{% block title %}About | theCourseForum{% endblock %}
55

66
{% block styles %}
77
<link rel="stylesheet" href="{% static 'about/about.css' %}" />

tcf_website/templates/about/privacy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}Privacy - theCourseForum{% endblock %}
4+
{% block title %}Privacy | theCourseForum{% endblock %}
55

66
{% block styles %}
77
{% endblock %}

tcf_website/templates/about/terms.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}Terms - theCourseForum{% endblock %}
4+
{% block title %}Terms | theCourseForum{% endblock %}
55

66
{% block styles %}
77
{% endblock %}

tcf_website/templates/browse/browse.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}Browse - theCourseForum{% endblock %}
4+
{% block title %}Browse | theCourseForum{% endblock %}
55

66
{% block styles %}
77
<link rel="stylesheet" href="{% static 'browse/browse.css' %}"/>

tcf_website/templates/club/category.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}{{ category.name }} Clubs - theCourseForum{% endblock %}
4+
{% block title %}{{ category.name }} Clubs | theCourseForum{% endblock %}
55

66
{% block styles %}
77
<link rel="stylesheet" href="{% static 'department/department.css' %}" />

tcf_website/templates/common/pagination.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
<div class="pagination">
88
{% if paginated_items.has_previous %}
9-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ 1 }}">&lt;&lt;</a>
10-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ paginated_items.previous_page_number }}">&lt;</a>
9+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ 1 }}">&lt;&lt;</a>
10+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ paginated_items.previous_page_number }}">&lt;</a>
1111
{% endif %}
1212

1313
{% if paginated_items.number == 1 %}
1414
<span class="current">1</span>
1515
{% else %}
16-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page=1">1</a>
16+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page=1">1</a>
1717
{% endif %}
1818

1919
{% if paginated_items.number > 4 %}
@@ -26,7 +26,7 @@
2626
{% if page_num == paginated_items.number %}
2727
<span class="current">{{ page_num }}</span>
2828
{% else %}
29-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ page_num }}">{{ page_num }}</a>
29+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ page_num }}">{{ page_num }}</a>
3030
{% endif %}
3131
{% endif %}
3232
{% endif %}
@@ -40,14 +40,14 @@
4040
{% if paginated_items.number == paginated_items.paginator.num_pages %}
4141
<span class="current">{{ paginated_items.paginator.num_pages }}</span>
4242
{% else %}
43-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ paginated_items.paginator.num_pages }}">
43+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ paginated_items.paginator.num_pages }}">
4444
{{ paginated_items.paginator.num_pages }}
4545
</a>
4646
{% endif %}
4747
{% endif %}
4848

4949
{% if paginated_items.has_next %}
50-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ paginated_items.next_page_number }}">&gt;</a>
51-
<a href="?{% for key, value in request.GET.items %}{% if key != 'page' %}{{ key }}={{ value }}&{% endif %}{% endfor %}page={{ paginated_items.paginator.num_pages }}">&gt;&gt;</a>
50+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ paginated_items.next_page_number }}">&gt;</a>
51+
<a href="?{% for key, values in request.GET.lists %}{% if key != 'page' %}{% for value in values %}{{ key }}={{ value }}&{% endfor %}{% endif %}{% endfor %}page={{ paginated_items.paginator.num_pages }}">&gt;&gt;</a>
5252
{% endif %}
5353
</div>

tcf_website/templates/course/course_professor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends "base/base.html" %}
22
{% load static %}
33

4-
{% block title %}{{course.code}} - {{instructor.full_name}} | theCourseForum{% endblock %}
4+
{% block title %}{{course.code}} | {{instructor.full_name}} | theCourseForum{% endblock %}
55

66
{% block page_metadata %}
77
<!-- Course and instructor meta data for localStorage -->

0 commit comments

Comments
 (0)