@@ -244,9 +244,9 @@ export const model = {
244244 console . log ( level ) ;
245245 } ,
246246
247- updateDepartmentFilter ( department ) {
248- this . filterOptions . department = department ;
249- } ,
247+ updateLevelFilter ( level ) {
248+ this . filterOptions . level = level ;
249+ } ,
250250
251251 updateLanguageFilter ( languages ) {
252252 this . filterOptions . language = languages ;
@@ -316,45 +316,89 @@ export const model = {
316316 ) ;
317317 return fields ;
318318 } ,
319- async getAverageRating ( courseCode , option ) {
320- const reviews = await getReviewsForCourse ( courseCode ) ;
321- if ( ! reviews || reviews . length === 0 ) return null ;
322-
323- let validReviews = 0 ;
324- let total = 0 ;
325-
326- switch ( option ) {
327- case "avg" :
328- reviews . forEach ( ( review ) => {
329- if ( typeof review . overallRating === "number" ) {
330- total += review . overallRating ;
331- validReviews ++ ;
332- }
333- } ) ;
334- break ;
335- case "diff" :
336- reviews . forEach ( ( review ) => {
337- if ( typeof review . difficultyRating === "number" ) {
338- total += review . difficultyRating ;
339- validReviews ++ ;
340- }
341- } ) ;
342- break ;
343- case "prof" :
344- reviews . forEach ( ( review ) => {
345- if ( typeof review . professorRating === "number" ) {
346- total += review . professorRating ;
347- validReviews ++ ;
348- }
349- } ) ;
350- break ;
351- default :
352- return null ;
353- }
354-
355- if ( validReviews === 0 ) return null ;
356- return ( total / validReviews ) . toFixed ( 1 ) ;
357- } ,
319+ setApplyTranscriptFilter ( transcriptFilterState ) {
320+ this . filterOptions . applyTranscriptFilter = transcriptFilterState ;
321+ } ,
322+ setApplyLevelFilter ( levelFilterState ) {
323+ this . filterOptions . applyLevelFilter = levelFilterState ;
324+ } ,
325+ setApplyLanguageFilter ( languageFilterState ) {
326+ this . filterOptions . applyLanguageFilter = languageFilterState ;
327+ } ,
328+ setApplyLocationFilter ( locationFilterState ) {
329+ this . filterOptions . applyLocationFilter = locationFilterState ;
330+ } ,
331+ setApplyCreditsFilter ( creditsFilterState ) {
332+ this . filterOptions . applyCreditsFilter = creditsFilterState ;
333+ } ,
334+ setApplyDepartmentFilter ( departmentFilterState ) {
335+ this . filterOptions . applyDepartmentFilter = departmentFilterState ;
336+ } ,
337+ setApplyPeriodFilter ( periodfilterState ) {
338+ this . filterOptions . applyPeriodFilter = periodfilterState ;
339+ } ,
340+ //for better display we would like the departments in a structured format based on school
341+ formatDepartments ( ) {
342+ const grouped = this ?. departments . reduce ( ( acc , item ) => {
343+ const [ school , department ] = item . split ( "/" ) ;
344+ if ( ! acc [ school ] ) {
345+ acc [ school ] = [ ] ;
346+ }
347+ acc [ school ] . push ( department ?. trim ( ) ) ;
348+ return acc ;
349+ } , { } ) ;
350+ const sortedGrouped = Object . keys ( grouped )
351+ . sort ( )
352+ . reduce ( ( acc , key ) => {
353+ acc [ key ] = grouped [ key ] . sort ( ) ;
354+ return acc ;
355+ } , { } ) ;
356+ const fields = Object . entries ( sortedGrouped ) . map ( ( [ school , departments ] , index ) => ( {
357+ id : index + 1 ,
358+ label : school ,
359+ subItems : departments ,
360+ } ) ) ;
361+ return fields ;
362+ } ,
363+ async getAverageRating ( courseCode , option ) {
364+ const reviews = await getReviewsForCourse ( courseCode ) ;
365+ if ( ! reviews || reviews . length === 0 ) return null ;
366+
367+ let validReviews = 0 ;
368+ let total = 0 ;
369+
370+ switch ( option ) {
371+ case "avg" :
372+ reviews . forEach ( review => {
373+ if ( typeof review . overallRating === 'number' ) {
374+ total += review . overallRating ;
375+ validReviews ++ ;
376+ }
377+ } ) ;
378+ break ;
379+ case "diff" :
380+ reviews . forEach ( review => {
381+ if ( typeof review . difficultyRating === 'number' ) {
382+ total += review . difficultyRating ;
383+ validReviews ++ ;
384+ }
385+ } ) ;
386+ break ;
387+ case "prof" :
388+ reviews . forEach ( review => {
389+ if ( typeof review . professorRating === 'number' ) {
390+ total += review . professorRating ;
391+ validReviews ++ ;
392+ }
393+ } ) ;
394+ break ;
395+ default :
396+ return null ;
397+ }
398+
399+ if ( validReviews === 0 ) return null ;
400+ return ( total / validReviews ) . toFixed ( 1 ) ;
401+ } ,
358402
359403 setPopupOpen ( isOpen ) {
360404 if ( ! isOpen ) {
0 commit comments