diff --git a/src/app/category-list/category-list-page.ts b/src/app/category-list/category-list-page.ts index 485abc9aa6..e86d373c95 100755 --- a/src/app/category-list/category-list-page.ts +++ b/src/app/category-list/category-list-page.ts @@ -120,10 +120,11 @@ export class CategoryListPage implements OnInit, OnDestroy { profile: Profile; private existingSearchFilters = {}; filterIdentifier: any; - userPreferences: any; + userPreferences = {}; frameworkId: string; categoriesList = []; layoutConfigurations = {layout: 'v3'}; + frameworkCategories: any; constructor( @Inject('CONTENT_SERVICE') private contentService: ContentService, @@ -144,7 +145,7 @@ export class CategoryListPage implements OnInit, OnDestroy { const extrasState = this.router.getCurrentNavigation().extras.state; if (extrasState) { this.formField = extrasState.formField; - this.userPreferences = extrasState.userPreferences; + this.userPreferences = extrasState.userPreferences || this.userPreferences; this.frameworkId = extrasState.frameworkId; this.sectionCode = extrasState.code; this.searchCriteria = JSON.parse(JSON.stringify(extrasState.formField.searchCriteria)); @@ -182,6 +183,10 @@ export class CategoryListPage implements OnInit, OnDestroy { async ngOnInit() { this.appName = await this.commonUtilService.getAppName(); + this.profile = await this.profileService.getActiveSessionProfile({ requiredFields: ProfileConstants.REQUIRED_FIELDS }).toPromise(); + if (!Object.keys(this.userPreferences).length) { + await this.getUserFrameworkDetails(); + } this.getContentDetailsFrameworkCategory() if (!this.supportedFacets) { this.formAPIFacets = await this.searchFilterService.fetchFacetFilterFormConfig(this.filterIdentifier, this.frameworkId); @@ -218,7 +223,6 @@ export class CategoryListPage implements OnInit, OnDestroy { private async fetchAndSortData(searchCriteria, isInitialCall: boolean, refreshPillFilter = true, onSelectedFilter?: any, filterKey?) { this.showSheenAnimation = true; - this.profile = await this.profileService.getActiveSessionProfile({ requiredFields: ProfileConstants.REQUIRED_FIELDS }).toPromise(); if (onSelectedFilter) { const selectedData = []; onSelectedFilter.forEach((selectedFilter) => { @@ -257,7 +261,10 @@ export class CategoryListPage implements OnInit, OnDestroy { const temp = ((await this.contentService.buildContentAggregator (this.formService, this.courseService, this.profileService) .aggregate({ - interceptSearchCriteria: () => (searchCriteria), + interceptSearchCriteria: (searchCriteria) => { + searchCriteria = {...searchCriteria, ...this.userPreferences}; + return searchCriteria; + }, userPreferences: this.userPreferences }, [], null, [{ @@ -437,6 +444,7 @@ export class CategoryListPage implements OnInit, OnDestroy { subjectName: subject, corRelation: corRelationList, supportedFacets: this.supportedFacets, + categoryKeys: this.categoriesList, totalCount } }); @@ -595,4 +603,21 @@ export class CategoryListPage implements OnInit, OnDestroy { this.categoriesList.push({ code: 'lastPublishedBy', name: 'Published by' }) }); } + + async getUserFrameworkDetails() { + if (this.profile?.serverProfile?.framework){ + this.userPreferences = this.profile.serverProfile.framework; + } else if(this.profile.categories) { + let rootOrgId = this.profile.serverProfile ? this.profile.serverProfile['rootOrgId'] : undefined; + await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(this.profile.syllabus[0], rootOrgId).then((categories) => { + if (categories) { + this.frameworkCategories = categories.sort((a, b) => a.index - b.index); + let frameworkValue =typeof this.profile.categories === 'string' ? JSON.parse(this.profile.categories) : this.profile.categories; + categories.forEach((e) => { + this.userPreferences[e.code] = Array.isArray(frameworkValue[e.identifier]) ? frameworkValue[e.identifier] : [frameworkValue[e.identifier]] + }) + } + }); + } + } } diff --git a/src/app/courses/courses.page.ts b/src/app/courses/courses.page.ts index fefe580bca..e0b3d88761 100644 --- a/src/app/courses/courses.page.ts +++ b/src/app/courses/courses.page.ts @@ -123,6 +123,8 @@ export class CoursesPage implements OnInit, OnDestroy { resetCourseFilter: boolean; filter: ContentSearchCriteria; isCourseListEmpty: boolean; + userFrameworkDetails = {}; + frameworkCategories: any; constructor( @Inject('EVENTS_BUS_SERVICE') private eventBusService: EventsBusService, @@ -945,7 +947,8 @@ export class CoursesPage implements OnInit, OnDestroy { await this.router.navigate([RouterLinks.TEXTBOOK_VIEW_MORE], { state: { contentList: items, - subjectName: subject + subjectName: subject, + categoryKeys: this.appGlobalService.getCachedFrameworkCategory().value, } }); } else { @@ -953,42 +956,38 @@ export class CoursesPage implements OnInit, OnDestroy { } } + async getUserFrameworkDetails() { + if (this.profile?.serverProfile?.framework){ + this.userFrameworkDetails = this.profile.serverProfile.framework; + } else if(this.profile.categories) { + let rootOrgId = this.profile.serverProfile ? this.profile.serverProfile['rootOrgId'] : undefined; + await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(this.profile.syllabus[0], rootOrgId).then((categories) => { + if (categories) { + this.frameworkCategories = categories.sort((a, b) => a.index - b.index); + let frameworkValue =typeof this.profile.categories === 'string' ? JSON.parse(this.profile.categories) : this.profile.categories; + categories.forEach((e) => { + this.userFrameworkDetails[e.code] = Array.isArray(frameworkValue[e.identifier]) ? frameworkValue[e.identifier] : [frameworkValue[e.identifier]] + }) + } + }); + } + } + async getAggregatorResult(resetFilter?: boolean) { this.spinner(true); this.profile = await this.profileService.getActiveSessionProfile({ requiredFields: ProfileConstants.REQUIRED_FIELDS }).toPromise(); - const request: ContentAggregatorRequest = { + await this.getUserFrameworkDetails(); + const request = { + userPreferences: this.userFrameworkDetails, applyFirstAvailableCombination: {}, - userPreferences: { - board: this.profile.board, - medium: this.profile.medium, - gradeLevel: this.profile.grade, - subject: this.profile.subject - }, - interceptSearchCriteria: (contentSearchCriteria: ContentSearchCriteria) => { - if (this.filter) { - contentSearchCriteria = this.concatFilter(this.filter, contentSearchCriteria); - } - if (this.profile) { - if (this.profile.board && this.profile.board.length) { - contentSearchCriteria.board = applyProfileFilter(this.appGlobalService, this.profile.board, - contentSearchCriteria.board, 'board'); - } - - if (this.profile.medium && this.profile.medium.length) { - contentSearchCriteria.medium = applyProfileFilter(this.appGlobalService, this.profile.medium, - contentSearchCriteria.medium, 'medium'); - } - - if (this.profile.grade && this.profile.grade.length) { - contentSearchCriteria.grade = applyProfileFilter(this.appGlobalService, this.profile.grade, - contentSearchCriteria.grade, 'gradeLevel'); - } - } + interceptSearchCriteria: (contentSearchCriteria) => { + contentSearchCriteria = {...contentSearchCriteria, ...this.userFrameworkDetails}; return contentSearchCriteria; } - }; + } try { - this.dynamicCourses = await this.contentAggregatorHandler.newAggregate(request, AggregatorPageType.COURSE); + let rootOrgId = this.profile.serverProfile ? this.profile.serverProfile['rootOrgId'] : undefined; + this.dynamicCourses = await this.contentAggregatorHandler.newAggregate(request, AggregatorPageType.COURSE, rootOrgId, this.profile.syllabus[0]); if (this.dynamicCourses) { this.dynamicCourses = this.contentAggregatorHandler.populateIcons(this.dynamicCourses); this.isGroupedCoursesAvailable(this.dynamicCourses); diff --git a/src/app/home/user-home/user-home.page.ts b/src/app/home/user-home/user-home.page.ts index e0db34e3ec..6bf81b8e1d 100644 --- a/src/app/home/user-home/user-home.page.ts +++ b/src/app/home/user-home/user-home.page.ts @@ -412,6 +412,7 @@ export class UserHomePage implements OnInit, OnDestroy, OnTabViewWillEnter { Environment.HOME, PageId.HOME, undefined, values); + state['categoryKeys'] = this.categoriesLabel; const params: NavigationExtras = { state }; diff --git a/src/app/resources/resources.component.ts b/src/app/resources/resources.component.ts index 8f5d529cb6..62f6c47cd0 100644 --- a/src/app/resources/resources.component.ts +++ b/src/app/resources/resources.component.ts @@ -477,7 +477,8 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra }; // Get the book data try { - this.dynamicResponse = await this.contentAggregatorHandler.aggregate(request, AggregatorPageType.LIBRARY); + let rootOrgId = this.profile.serverProfile ? this.profile.serverProfile['rootOrgId'] : undefined; + this.dynamicResponse = await this.contentAggregatorHandler.aggregate(request, AggregatorPageType.LIBRARY, rootOrgId, this.profile.syllabus[0]); if (this.dynamicResponse) { this.dynamicResponse.forEach((val) => { if (val.theme && val.theme.orientation === Orientation.VERTICAL) { diff --git a/src/services/content/content-aggregator-handler.service.ts b/src/services/content/content-aggregator-handler.service.ts index bb441cdecc..fcd8a5d335 100644 --- a/src/services/content/content-aggregator-handler.service.ts +++ b/src/services/content/content-aggregator-handler.service.ts @@ -31,15 +31,14 @@ export class ContentAggregatorHandler { private appGlobalService: AppGlobalService, ) { } - async aggregate(request, pageName): Promise { + async aggregate(request, pageName, rootOrgId?: string, frameworkId?: string): Promise { let dataSrc: DataSourceType[] = ['TRACKABLE_COLLECTIONS']; if (this.appGlobalService.isUserLoggedIn()) { dataSrc = []; } try { - this.aggregatorResponse = await this.aggregateContent(request, dataSrc, - {...FormConstants.CONTENT_AGGREGATOR, subType: pageName}); + this.aggregatorResponse = await this.aggregateContent(request, dataSrc, pageName, rootOrgId, frameworkId); if (this.aggregatorResponse && this.aggregatorResponse.result) { this.aggregatorResponse.result.forEach((val) => { val['name'] = this.commonUtilService.getTranslatedValue(val.title, JSON.parse(val.title)['en']); @@ -75,15 +74,9 @@ export class ContentAggregatorHandler { if (this.appGlobalService.isUserLoggedIn()) { dataSrc = []; } - if (!rootOrgId) { - rootOrgId = await this.preferences.getString('defaultRootOrgId').toPromise(); - } - frameworkId = frameworkId ? frameworkId : (this.appGlobalService.getCachedFrameworkCategory().id - || this.appGlobalService.getCurrentUser().syllabus[0]); try { - this.aggregatorResponse = await this.aggregateContent(request, dataSrc, - {...FormConstants.CONTENT_AGGREGATOR, subType: pageName, framework: frameworkId || '*', rootOrgId: rootOrgId || '*'}); + this.aggregatorResponse = await this.aggregateContent(request, dataSrc, pageName, rootOrgId, frameworkId); return this.aggregatorResponse.result; } catch (e) { console.error(e); @@ -91,7 +84,13 @@ export class ContentAggregatorHandler { } } - private async aggregateContent(request, dataSrc, formRequest): Promise { + private async aggregateContent(request, dataSrc, pageName, rootOrgId?: string, frameworkId?: string): Promise { + if (!rootOrgId) { + rootOrgId = await this.preferences.getString('defaultRootOrgId').toPromise(); + } + frameworkId = frameworkId ? frameworkId : (this.appGlobalService.getCachedFrameworkCategory().id + || this.appGlobalService.getCurrentUser().syllabus[0]); + let formRequest = {...FormConstants.CONTENT_AGGREGATOR, subType: pageName, framework: frameworkId || '*', rootOrgId: rootOrgId || '*'} return this.contentService.buildContentAggregator(this.formService, this.courseService, this.profileService) .aggregate(request, dataSrc, formRequest, undefined, true).toPromise(); }