@@ -132,7 +132,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
132132 public contentManagerService : ContentManagerService , private cacheService : CacheService ,
133133 private browserCacheTtlService : BrowserCacheTtlService , private profileService : ProfileService ,
134134 private segmentationTagService : SegmentationTagService , private observationUtil : ObservationUtilService ,
135- private genericResourceService : GenericResourceService , private cdr : ChangeDetectorRef , private cslFrameworkService :CslFrameworkService ) {
135+ private genericResourceService : GenericResourceService , private cdr : ChangeDetectorRef , private cslFrameworkService : CslFrameworkService ) {
136136 this . genericResourceService . initialize ( ) ;
137137 this . instance = ( < HTMLInputElement > document . getElementById ( 'instance' ) )
138138 ? ( < HTMLInputElement > document . getElementById ( 'instance' ) ) . value . toUpperCase ( ) : 'SUNBIRD' ;
@@ -241,14 +241,17 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
241241 if ( _ . get ( currentPage , 'filter' ) ) {
242242 this . isFilterEnabled = _ . get ( currentPage , 'filter.isEnabled' ) ;
243243 }
244+
244245 if ( ( _ . get ( currentPage , 'filter' ) && ! _ . get ( currentPage , 'filter.isEnabled' ) ) ) {
245246 this . fetchContents$ . next ( currentPage ) ;
246247 }
247248 this . setFilterConfig ( currentPage ) ;
249+
248250 } ) ,
249- switchMap ( this . fetchEnrolledCoursesSection . bind ( this ) )
251+ switchMap ( this . fetchEnrolledCoursesSection . bind ( this ) ) ,
250252 ) ;
251253
254+
252255 this . subscription$ = merge ( concat ( this . fetchChannelData ( ) , enrolledSection$ ) , this . initLayout ( ) , this . fetchContents ( ) )
253256 . pipe (
254257 takeUntil ( this . unsubscribe$ ) ,
@@ -267,9 +270,9 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
267270 public fetchEnrolledCoursesSection ( ) {
268271 return this . coursesService . enrolledCourseData$
269272 . pipe (
270- tap ( ( { enrolledCourses, err } ) => {
273+ map ( ( { enrolledCourses, err } ) => {
271274 this . enrolledCourses = this . enrolledSection = [ ] ;
272- this . completeCourses = this . completedCourseSection = [ ] ;
275+ this . completeCourses = this . completedCourseSection = [ ] ;
273276 const sortingField = ( get ( this . getCurrentPageData ( ) , 'sortingField' ) ) ?
274277 ( get ( this . getCurrentPageData ( ) , 'sortingField' ) ) : 'enrolledDate' ;
275278 const sortingOrder = ( get ( this . getCurrentPageData ( ) , 'sortingOrder' ) ) ?
@@ -281,80 +284,104 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
281284 count : 0 ,
282285 contents : [ ]
283286 } ;
284-
287+
285288 const completedCourseSection = {
286- name : this . getSectionName ( get ( this . activatedRoute , 'snapshot.queryParams.selectedTab' ) ) ,
289+ name : this . getSectionName ( get ( this . activatedRoute , 'snapshot.queryParams.selectedTab' ) ) ,
287290 length : 0 ,
288291 count : 0 ,
289292 contents : [ ]
290293 } ;
291-
294+
292295 const { contentType : pageContentType = null , search : { filters : { primaryCategory : pagePrimaryCategories = [ ] } } } = this . getCurrentPageData ( ) ;
293-
294- if ( err ) {
295- return enrolledSection ;
296+
297+ if ( err ) {
298+ return enrolledSection ;
296299 }
297-
300+
298301 const enrolledContentPredicate = course => {
299302 const { primaryCategory = null , contentType = null } = _ . get ( course , 'content' ) || { } ;
300303 return pagePrimaryCategories . some ( category =>
301- ( _ . toLower ( category ) === _ . toLower ( primaryCategory ) ) ||
304+ ( _ . toLower ( category ) === _ . toLower ( primaryCategory ) ) ||
302305 ( _ . toLower ( category ) === _ . toLower ( contentType ) ) ) ||
303306 ( _ . toLower ( contentType ) === _ . toLower ( pageContentType ) ) ;
304307 } ;
305-
308+
306309 let filteredCourses = _ . filter ( enrolledCourses || [ ] , enrolledContentPredicate ) ;
307310 filteredCourses = _ . orderBy ( filteredCourses , [ sortingField ] , [ sortingOrder ] ) ;
308- this . enrolledCourses = filteredCourses
309-
311+ this . enrolledCourses = filteredCourses ;
310312 const { constantData, metaData, dynamicFields } = _ . get ( this . configService , 'appConfig.CoursePageSection.enrolledCourses' ) ;
311-
312-
313+
314+
313315 enrolledSection . contents = _ . compact ( _ . map ( filteredCourses , content => {
314316 if ( content . status === 2 ) {
315- return null ;
317+ return null ;
316318 }
317-
319+
318320 const formatedContent = this . utilService . processContent ( content , constantData , dynamicFields , metaData ) ;
319321 formatedContent . organisation = content . content . organisation ;
320322 delete formatedContent . category ;
321323 formatedContent . metaData . mimeType = 'application/vnd.ekstep.content-collection' ;
322324 formatedContent . metaData . contentType = _ . get ( content , 'content.primaryCategory' ) || _ . get ( content , 'content.contentType' ) ;
323-
325+
324326 const trackableObj = _ . get ( content , 'content.trackable' ) ;
325327 if ( trackableObj ) {
326328 formatedContent . metaData . trackable = trackableObj ;
327329 }
328-
330+
329331 return formatedContent ;
330332 } ) ) ;
331-
333+
332334 this . allEnrolledCourses = filteredCourses ;
333-
335+
334336 completedCourseSection . contents = _ . compact ( _ . map ( filteredCourses , content => {
335337 if ( content . status !== 2 ) {
336- return null ;
338+ return null ;
337339 }
338-
340+
339341 const formatedContent = this . utilService . processContent ( content , constantData , dynamicFields , metaData ) ;
340342 formatedContent . metaData . mimeType = 'application/vnd.ekstep.content-collection' ;
341343 formatedContent . metaData . contentType = _ . get ( content , 'content.primaryCategory' ) || _ . get ( content , 'content.contentType' ) ;
342344 formatedContent . organisation = content . content . organisation ;
343345 delete formatedContent . category ;
344-
346+
345347 const trackableObj = _ . get ( content , 'content.trackable' ) ;
346348 if ( trackableObj ) {
347349 formatedContent . metaData . trackable = trackableObj ;
348350 }
349-
351+
350352 return formatedContent ;
351353 } ) ) ;
354+
352355 enrolledSection . count = enrolledSection . contents . length ;
353356 completedCourseSection . count = completedCourseSection . contents . length ;
354357 completedCourseSection . name = this . resourceService . frmelmnts . lbl . completedCourses || "Completed courses" ;
358+
359+ if ( ! _ . isEmpty ( this . enrolledCourses ) ) {
360+ this . searchService . contentSearch ( { filters : { identifier : _ . map ( this . enrolledCourses , 'content.identifier' ) } , fields : _ . get ( this . getCurrentPageData ( ) , 'search.fields' ) } )
361+ . subscribe ( ( response ) => {
362+ const contentMap = _ . keyBy ( get ( response , 'result.content' ) , 'identifier' ) ;
363+ const filterCategories = this . cslFrameworkService . getGlobalFilterCategoriesObject ( ) ;
364+ for ( const content of this . enrolledSection . contents ) {
365+ const metadata = contentMap [ _ . get ( content , 'metaData.courseId' ) ] ;
366+ if ( metadata && filterCategories ) {
367+ for ( const category of filterCategories ) {
368+ if ( category . type === 'framework' ) {
369+ content [ category . code ] =
370+ _ . get ( metadata , category . code ) ??
371+ _ . get ( metadata , category . alternativeCode ) ;
372+ }
373+ }
374+ }
375+ }
376+ } ) ;
377+
378+ }
379+
355380 this . enrolledSection = enrolledSection ;
356381 this . completedCourseSection = completedCourseSection ;
382+
357383 } )
384+
358385 ) ;
359386 }
360387
@@ -433,6 +460,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
433460 this . setDesktopFilters ( false ) ;
434461 }
435462 this . fetchContents$ . next ( currentPageData ) ;
463+
436464 }
437465
438466 setDesktopFilters ( isDefaultFilters ) {
@@ -501,8 +529,8 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
501529 }
502530 const option = this . searchService . getSearchRequest ( request , get ( filters , 'primaryCategory' ) ) ;
503531 const params = _ . get ( this . activatedRoute , 'snapshot.queryParams' ) ;
504- _ . filter ( Object . keys ( params ) , filterValue => {
505- if ( ( ( _ . get ( currentPageData , 'metaData.filters' ) . indexOf ( filterValue ) !== - 1 ) ) ) {
532+ _ . filter ( Object . keys ( params ) , filterValue => {
533+ if ( ( ( _ . get ( currentPageData , 'metaData.filters' , [ ] ) . indexOf ( filterValue ) !== - 1 ) ) ) {
506534 let param = { } ;
507535 param [ filterValue ] = ( typeof ( params [ filterValue ] ) === "string" ) ? params [ filterValue ] . split ( ',' ) : params [ filterValue ] ;
508536 if ( param [ filterValue ] . length === 1 && param [ filterValue ] [ 0 ] === 'CBSE/NCERT' ) {
@@ -514,13 +542,15 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
514542 if ( this . userService . loggedIn ) {
515543 option . filters [ 'visibility' ] = option . filters [ 'channel' ] = [ ] ;
516544 }
545+
517546 return this . searchService . contentSearch ( option )
518547 . pipe (
519548 map ( ( response ) => {
520549 const { subject : selectedSubjects = [ ] } = ( this . selectedFilters || { } ) as { subject : [ ] } ;
521550 this . _facets$ . next ( request . facets ?
522551 this . utilService . processCourseFacetData ( _ . get ( response , 'result' ) , _ . get ( request , 'facets' ) ) : { } ) ;
523552 this . searchResponse = get ( response , 'result.content' ) ;
553+
524554 if ( _ . has ( response , 'result.QuestionSet' ) ) {
525555 this . searchResponse = _ . merge ( this . searchResponse , _ . get ( response , 'result.QuestionSet' ) ) ;
526556 }
@@ -530,14 +560,14 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
530560 if ( globalFilterCategoriesObject ) {
531561 const categoryObj = globalFilterCategoriesObject . find ( ( filter ) => filter ?. code === lastCategory || filter ?. alternativeCode === lastCategory ) ;
532562 if ( categoryObj ) {
533- lastCategoryCode = categoryObj ?. alternativeCode ;
563+ lastCategoryCode = categoryObj ?. alternativeCode ;
534564 }
535- }
536-
565+ }
566+
537567 const filteredContents = omit ( groupBy ( this . searchResponse , content => {
538568 return content [ groupByKey ] || content [ lastCategoryCode ] || 'Others' ;
539569 } ) , [ 'undefined' ] ) ;
540-
570+
541571 for ( const [ key , value ] of Object . entries ( filteredContents ) ) {
542572 const isMultipleCategoryValues = key && key . split ( ',' ) . length > 1 ;
543573 if ( isMultipleCategoryValues ) {
@@ -561,6 +591,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
561591 sections . push ( {
562592 name : section ,
563593 contents : filteredContents [ section ]
594+
564595 } ) ;
565596 }
566597 }
@@ -607,12 +638,15 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
607638 }
608639 } ) ;
609640 this . facetSections = _ . sortBy ( this . facetSections , [ 'index' ] ) ;
641+
610642 this . facetSections = this . facetSections . filter ( section => section . data && section . data . length > 0 ) ;
611643 if ( facetKeys . indexOf ( 'search' ) > - 1 ) {
612644 this . contentSections = [ ] ;
613645 const searchSections = currentPageData . sections . filter ( sec => sec . facetKey === 'search' ) ;
614646 searchSections . forEach ( ( item ) => {
615647 this . contentSections . push ( this . getContentSection ( item , option ) ) ;
648+
649+
616650 } ) ;
617651
618652 }
@@ -625,8 +659,8 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
625659 } ) ;
626660 } ) , tap ( data => {
627661 // this.userPreference = this.setUserPreferences();
628- this . showLoader = false ;
629- const userProfileSubjects = _ . get ( this . userService , `userProfile.framework.${ this . frameworkCategoriesList [ 3 ] } ` ) || [ ] ;
662+ this . showLoader = false ;
663+ const userProfileSubjects = _ . get ( this . userService , `userProfile.framework.${ this . frameworkCategoriesList [ 3 ] } ` ) || [ ] ;
630664 const [ userSubjects , notUserSubjects ] = partition ( sortBy ( data , [ 'name' ] ) , value => {
631665 const { name = null } = value || { } ;
632666 if ( ! name ) { return false ; }
@@ -678,7 +712,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
678712 data [ currentBoard ] [ currentUserType ] ) {
679713 this . showTargetedCategory = true ;
680714 this . dataThemeAttribute = document . documentElement . getAttribute ( 'data-mode' ) ;
681- const pillBgColor = this . dataThemeAttribute === 'light' ? "rgba(255,255,255,1)" :"rgba(36,37,36,1)"
715+ const pillBgColor = this . dataThemeAttribute === 'light' ? "rgba(255,255,255,1)" : "rgba(36,37,36,1)"
682716 this . targetedCategory = data [ currentBoard ] [ currentUserType ] ;
683717 this . targetedCategorytheme = {
684718 "iconBgColor" : "rgba(255,255,255,1)" ,
@@ -1142,11 +1176,11 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
11421176 try {
11431177 if ( this . isUserLoggedIn ( ) ) {
11441178 this . userPreference = { framework : this . userService . defaultFrameworkFilters } ;
1145- this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
1179+ this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
11461180 } else {
11471181 this . userService . getGuestUser ( ) . subscribe ( ( response ) => {
11481182 this . userPreference = response ;
1149- this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
1183+ this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
11501184 } ) ;
11511185 }
11521186 } catch ( error ) {
@@ -1240,7 +1274,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
12401274 if ( this . isUserLoggedIn ( ) ) {
12411275 this . profileService . updateProfile ( { framework : event } ) . subscribe ( res => {
12421276 this . userPreference . framework = event ;
1243- this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
1277+ this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
12441278 this . getFormConfigs ( ) ;
12451279 this . toasterService . success ( _ . get ( this . resourceService , 'messages.smsg.m0058' ) ) ;
12461280 this . _addFiltersInTheQueryParams ( event ) ;
@@ -1255,7 +1289,7 @@ export class ExplorePageComponent implements OnInit, OnDestroy, AfterViewInit {
12551289 const req = { ...this . userPreference , framework : event } ;
12561290 this . userService . updateGuestUser ( req ) . subscribe ( res => {
12571291 this . userPreference . framework = event ;
1258- this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
1292+ this . transformUserPreference = this . cslFrameworkService . frameworkLabelTransform ( this . frameworkCategoriesObject , this . userPreference ) ;
12591293 this . getFormConfigs ( ) ;
12601294 this . toasterService . success ( _ . get ( this . resourceService , 'messages.smsg.m0058' ) ) ;
12611295 this . showorHideBanners ( ) ;
0 commit comments