Skip to content

Commit 163f942

Browse files
committed
Reverted model changes
1 parent 2ad4b82 commit 163f942

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

my-app/src/model.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@ export const model = {
1111
courses: [],
1212
favourites: [],
1313
isReady: false,
14-
filtersChange: false, //
14+
filtersChange: false,
1515
filtersCalculated: false,
1616
filteredCourses: [],
1717
filterOptions: {
1818
applyTranscriptFilter: true,
1919
eligibility: "weak", //the possible values for the string are: "weak"/"moderate"/"strong"
2020
applyLevelFilter: true,
21-
level: [], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
21+
level: ["PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
2222
applyLanguageFilter: true,
2323
language: "none", //the possible values for the string are: "none"/"english"/"swedish"/"both"
2424
applyLocationFilter:true,
2525
location: [], //the possible values for the array are: 'KTH Campus', 'KTH Kista', 'AlbaNova', 'KTH Flemingsberg', 'KTH Solna', 'KTH Södertälje', 'Handelshögskolan', 'KI Solna', 'Stockholms universitet', 'KONSTFACK'
2626
applyCreditsFilter:true,
2727
creditMin: 0,
2828
creditMax: 45,
29-
applyDepartmentFilter:false,
30-
department: []
29+
applyDepartmentFilter: true,
30+
department: ["EECS/Computational Science and Technology", "EECS/Theoretical Computer Science", "EECS/Electric Power and Energy Systems", "EECS/Network and Systems Engineering",
31+
"ITM/Learning in Engineering Sciences", "ITM/Industrial Economics and Management", "ITM/Energy Systems", "ITM/Integrated Product Development and Design", "ITM/SKD GRU",
32+
"SCI/Mathematics", "SCI/Applied Physics", "SCI/Mechanics", "SCI/Aeronautical and Vehicle Engineering",
33+
"ABE/Sustainability and Environmental Engineering", "ABE/Concrete Structures", "ABE/Structural Design & Bridges", "ABE/History of Science, Technology and Environment", ],
34+
applyRemoveNullCourses: false
3135
},
3236

3337
setUser(user) {
@@ -84,15 +88,17 @@ export const model = {
8488
entries.forEach(entry => {
8589
const course = {
8690
code: entry[1].code,
87-
name: entry[1]?.name ?? "",
88-
location: entry[1]?.location ?? "",
89-
department: entry[1]?.department ?? "",
90-
language: entry[1]?.language ?? "",
91-
description: entry[1]?.description ?? "",
92-
academicLevel: entry[1]?.academic_level ?? "",
93-
period: entry[1]?.period ?? "",
91+
name: entry[1]?.name ?? "null",
92+
location: entry[1]?.location ?? "null",
93+
department: entry[1]?.department ?? "null",
94+
language: entry[1]?.language ?? "null",
95+
description: entry[1]?.description ?? "null",
96+
academicLevel: entry[1]?.academic_level ?? "null",
97+
period: entry[1]?.period ?? "null",
9498
credits: entry[1]?.credits ?? 0,
95-
prerequisites: entry[1]?.prerequisites ?? "",
99+
prerequisites: entry[1]?.prerequisites ?? "null",
100+
prerequisites_text: entry[1]?.prerequisites_text ?? "null",
101+
learning_outcomes: entry[1]?.learning_outcomes ?? "null"
96102
};
97103
this.addCourse(course);
98104
});
@@ -128,10 +134,20 @@ export const model = {
128134
setFilterOptions(options){
129135
this.filterOptions = options; // do we want to set the flags? What about useEffect?
130136
},
137+
138+
setApplyRemoveNullCourses() {
139+
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
140+
this.setFiltersChange();
141+
},
131142

132143
updateLevelFilter(level) {
133144
this.filterOptions.level = level;
134145
},
146+
147+
updateDepartmentFilter(department) {
148+
this.filterOptions.department = department;
149+
},
150+
135151
updateLanguageFilter(languages) {
136152
this.filterOptions.language = languages;
137153
},
@@ -162,10 +178,13 @@ export const model = {
162178
setApplyCreditsFilter(creditsFilterState) {
163179
this.filterOptions.applyCreditsFilter = creditsFilterState;
164180
},
165-
// setApplyDepartmentFilter(departmentFilterState) {
166-
// this.filterOptions.applyDepartmentFilter = departmentFilterState;
167-
// },
168-
169-
170-
181+
setApplyDepartmentFilter(departmentFilterState) {
182+
this.filterOptions.applyDepartmentFilter = departmentFilterState;
183+
},
184+
async getAverageRating(courseCode) {
185+
const reviews = await getReviewsForCourse(courseCode);
186+
if (!reviews || reviews.length === 0) return null;
187+
const total = reviews.reduce((sum, review) => sum + (review.overallRating || 0), 0);
188+
return (total / reviews.length).toFixed(1);
189+
},
171190
};

0 commit comments

Comments
 (0)