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
33 changes: 29 additions & 4 deletions src/app/category-list/category-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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, [{
Expand Down Expand Up @@ -437,6 +444,7 @@ export class CategoryListPage implements OnInit, OnDestroy {
subjectName: subject,
corRelation: corRelationList,
supportedFacets: this.supportedFacets,
categoryKeys: this.categoriesList,
totalCount
}
});
Expand Down Expand Up @@ -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]]
})
}
});
}
}
}
59 changes: 29 additions & 30 deletions src/app/courses/courses.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -945,50 +947,47 @@ 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 {
await this.commonUtilService.presentToastForOffline('OFFLINE_WARNING_ETBUI');
}
}

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);
Expand Down
1 change: 1 addition & 0 deletions src/app/home/user-home/user-home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
3 changes: 2 additions & 1 deletion src/app/resources/resources.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 10 additions & 11 deletions src/services/content/content-aggregator-handler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ export class ContentAggregatorHandler {
private appGlobalService: AppGlobalService,
) { }

async aggregate(request, pageName): Promise<any> {
async aggregate(request, pageName, rootOrgId?: string, frameworkId?: string): Promise<any> {
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']);
Expand Down Expand Up @@ -75,23 +74,23 @@ 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);
throw e;
}
}

private async aggregateContent(request, dataSrc, formRequest): Promise<ContentAggregatorResponse> {
private async aggregateContent(request, dataSrc, pageName, rootOrgId?: string, frameworkId?: string): Promise<ContentAggregatorResponse> {
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();
}
Expand Down