Skip to content
Merged
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
2 changes: 2 additions & 0 deletions backend/src/main/java/edu/gcc/hallmonitor/Department.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private static Filter deserialize(JsonNode value) {
private static Set<String> possibleValues(List<Course> courses) {
return courses.stream()
.map(Course::department)
// Don't include ZLOAD "courses"
.filter(s -> !s.equals("ZLOAD"))
.collect(Collectors.toSet());
}

Expand Down
6 changes: 6 additions & 0 deletions backend/src/main/java/edu/gcc/hallmonitor/ProfName.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ private static Set<String> possibleValue(List<Course> courses) {
return courses.stream()
.map(Course::professor)
.flatMap(List::stream)
// Remove the staff entries
.filter(s -> !s.contains("Staff, -"))
// Remove empty entries
.filter(s -> !s.isEmpty())
// Strip PhD from names
.map(s -> s.replace("PhD", "").trim())
.collect(Collectors.toSet());

}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/edu/gcc/hallmonitor/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Search {
private List<Course> searchResults;
private List<Course> matchResults;

private static List<Course> allCourses;
public static List<Course> allCourses;
private static HashMap<String, Course> courseMap;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.stream.Collectors;

import io.javalin.Javalin;
import java.util.List;

public class SearchController {
private static Search search = new Search();
Expand Down Expand Up @@ -62,5 +63,13 @@ public static void registerRoutes(Javalin app) {
search.removeFilter(f);
}
});

app.get("/search/filter-values/{filter-type}", ctx -> {
List<Course> courses = search.getMatchResults();
if (courses.isEmpty()) {
courses = Search.allCourses;
}
ctx.json(Filter.possibleValues(ctx.pathParam("filter-type"), courses));
});
}
}
2 changes: 1 addition & 1 deletion backend/src/main/java/edu/gcc/hallmonitor/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static Set<String> possibleValues(List<Course> courses) {
.flatMap(List::stream)
.map(time -> List.of(time.startTime(), time.endTime()))
.flatMap(List::stream)
.map(time -> time.format(DateTimeFormatter.ofPattern("HH:MM")))
.map(time -> time.format(DateTimeFormatter.ofPattern("HH:mm")))
.forEach(times::add);
return times;
}
Expand Down
56 changes: 21 additions & 35 deletions frontend/src/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,42 +170,30 @@ export default function SearchPage() {
setTimeEnd(end);
};






// --- LOAD COURSES FOR FILTERS ---
// Set the filter options
useEffect(() => {
const fetchCourses = async () => {
const res = await fetch('/courses');
const items: Course[] = await res.json();

setDepartments(
Array.from(new Set(items.map(c => c.subject).filter(d => d && d !== 'ZLOAD'))).sort()
);

setProfessors(
Array.from(
new Set(
items
.flatMap(c => c.faculty || [])
.filter(p => p && !p.includes('Staff, -') && p !== '-')
.map(p => p.replace(/,?\s*PhD\.?/i, '').trim())
)
).sort()
);

setAvailableCredits(
Array.from(new Set(items.map(c => c.credits).filter(c => c != null))).map(String).sort()
);

const times = items
.flatMap(c => c.times?.map(t => t.start_time) || [])
.filter(t => t); // remove empty
setAvailableTimes(Array.from(new Set(times)).sort());
const getValues = async (t: string) => {
const res = await fetch(`/search/filter-values/${t}`);
const list = await res.json();
return list.sort();
};
const updateFilters = async () => {
// Update:
// Departments
setDepartments(await getValues('department'));
// Professors
setProfessors(await getValues('professor'));
// availableTimes
setAvailableTimes(await getValues('timeRange'));
// availableCredits
setAvailableCredits(await getValues('credits'));
};
updateFilters();
// Only whenever the course list changes
}, [courses]);

// --- LOAD COURSES FOR FILTERS ---
useEffect(() => {
const fetchResults = async() => {
const res = await fetch("/search/results");
const items = (await res.json()) as Course[];
Expand All @@ -223,8 +211,6 @@ export default function SearchPage() {

fetchQuery();

fetchCourses();

const setFilters = async () => {
const resp = await fetch('/search/filter');
for (const filter of await resp.json()) {
Expand Down
Loading