diff --git a/src/app/collection-detail-etb/collection-detail-etb.page.html b/src/app/collection-detail-etb/collection-detail-etb.page.html index 5cd6decd05..8f3a4db51a 100644 --- a/src/app/collection-detail-etb/collection-detail-etb.page.html +++ b/src/app/collection-detail-etb/collection-detail-etb.page.html @@ -80,6 +80,7 @@
diff --git a/src/app/collection-detail-etb/collection-detail-etb.page.ts b/src/app/collection-detail-etb/collection-detail-etb.page.ts index 98adbf9b25..eb12664196 100644 --- a/src/app/collection-detail-etb/collection-detail-etb.page.ts +++ b/src/app/collection-detail-etb/collection-detail-etb.page.ts @@ -64,6 +64,7 @@ import { ConfirmAlertComponent } from '../components/confirm-alert/confirm-alert import { SbSharePopupComponent } from '../components/popups/sb-share-popup/sb-share-popup.component'; import { TextbookTocService } from './textbook-toc-service'; import { TagPrefixConstants } from '../../services/segmentation-tag/segmentation-tag.service'; +import { FormAndFrameworkUtilService } from './../../services/formandframeworkutil.service'; @Component({ selector: 'app-collection-detail-etb', @@ -284,6 +285,8 @@ export class CollectionDetailEtbPage implements OnInit { expandBehavior: ExpandBehavior.EXPAND_FIRST }; showContentDetails = false; + categories: any; + profile: Profile; constructor( @Inject('CONTENT_SERVICE') private contentService: ContentService, @@ -307,7 +310,8 @@ export class CollectionDetailEtbPage implements OnInit { private textbookTocService: TextbookTocService, private contentPlayerHandler: ContentPlayerHandler, private contentDeleteHandler: ContentDeleteHandler, - private sbProgressLoader: SbProgressLoader + private sbProgressLoader: SbProgressLoader, + private formAndFrameworkUtilService: FormAndFrameworkUtilService ) { this.objRollup = new Rollup(); this.defaultAppIcon = 'assets/imgs/ic_launcher.png'; @@ -365,6 +369,7 @@ export class CollectionDetailEtbPage implements OnInit { async ionViewWillEnter() { await this.headerService.showStatusBar(); this.registerDeviceBackButton(); + this.profile = this.appGlobalService.getCurrentUser(); await this.zone.run(async () => { this.headerObservable = this.headerService.headerEventEmitted$.subscribe(async eventName => { await this.handleHeaderEvents(eventName); @@ -376,6 +381,7 @@ export class CollectionDetailEtbPage implements OnInit { this.headerService.updatePageConfig(this.headerConfig); this.hiddenGroups.clear(); this.shownGroups = undefined; + await this.getFrameworkCategory() await this.assignCardData(); this.resetVariables(); await this.setContentDetails(this.identifier, true); @@ -440,7 +446,6 @@ export class CollectionDetailEtbPage implements OnInit { contentId: this.identifier, contentType: this.content.contentType }; - const profile: Profile = this.appGlobalService.getCurrentUser(); this.profileService.addContentAccess(addContentAccessRequest).toPromise().then((data) => { if (data) { this.events.publish(EventTopics.LAST_ACCESS_ON, true); @@ -449,7 +454,7 @@ export class CollectionDetailEtbPage implements OnInit { console.error(error); }); const contentMarkerRequest: ContentMarkerRequest = { - uid: profile.uid, + uid: this.profile.uid, contentId: this.identifier, data: JSON.stringify(this.content.contentData), marker: MarkerType.PREVIEWED, @@ -1572,4 +1577,12 @@ export class CollectionDetailEtbPage implements OnInit { contentInfo() { this.showContentDetails = !this.showContentDetails; } + + async getFrameworkCategory() { + await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(this.profile.syllabus[0]).then((categories) => { + if (categories) { + this.categories = categories.sort((a, b) => b.index - a.index) + } + }); + } } \ No newline at end of file diff --git a/src/app/content-details/content-details.page.ts b/src/app/content-details/content-details.page.ts index e61bc53925..af66aaa112 100644 --- a/src/app/content-details/content-details.page.ts +++ b/src/app/content-details/content-details.page.ts @@ -371,7 +371,8 @@ export class ContentDetailsPage implements OnInit, OnDestroy { * Ionic life cycle hook */ async ionViewWillEnter() { - const frameworkId = this.appGlobalService.getCachedFrameworkCategory().id; + let framework = this.appGlobalService.getCachedFrameworkCategory(); + const frameworkId = framework ? framework.id : this.cardData.contentData.framework; this.getContentCategories(frameworkId); this.headerService.hideStatusBar(); await this.headerService.hideHeader(); @@ -766,7 +767,7 @@ export class ContentDetailsPage implements OnInit, OnDestroy { await this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); } if (this.isSingleContent) { - !this.onboarding ? await this.router.navigate([`/${RouterLinks.TABS}`]) : window.history.go(-3); + this.appGlobalService.isOnBoardingCompleted ? await this.router.navigate([`/${RouterLinks.TABS}`]) : window.history.go(-3); } else if (this.source === PageId.ONBOARDING_PROFILE_PREFERENCES) { if (this.appGlobalService.isOnBoardingCompleted) { await this.router.navigate([`/${RouterLinks.TABS}`]); diff --git a/src/app/resources/resources.component.ts b/src/app/resources/resources.component.ts index bf5f95a2e2..fda33cb0f8 100644 --- a/src/app/resources/resources.component.ts +++ b/src/app/resources/resources.component.ts @@ -714,7 +714,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra async arrangeMediumsByUserData(categoryMediumsParam, category) { let selectedCategory = []; if (this.guestUser) { - selectedCategory = JSON.parse(this.profile.categories)[category.identifier]; + selectedCategory =typeof this.profile.categories === 'string' ? JSON.parse(this.profile.categories)[category.identifier] : this.profile.categories[category.identifier]; } else { selectedCategory = this.profile.serverProfile.framework[category.code] } @@ -755,7 +755,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra this.categoryGradeLevels = res; let selectedCategory = []; if (this.guestUser) { - selectedCategory = JSON.parse(this.profile.categories)[categories[2].identifier]; + selectedCategory = typeof this.profile.categories === 'string' ? JSON.parse(this.profile.categories)[categories[2].identifier] : this.profile.categories[categories[2].identifier]; } else { selectedCategory = this.profile.serverProfile.framework[categories[2].code] } @@ -1245,7 +1245,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra this.listofCategory = categories.sort((a, b) => a.index - b.index) if (this.profile.categories) { this.userFrameworkCategories = {} - let frameworkValue = JSON.parse(this.profile.categories); + let frameworkValue =typeof this.profile.categories === 'string' ? JSON.parse(this.profile.categories) : this.profile.categories; this.listofCategory.forEach((e) => { this.userFrameworkCategories[e.code] = Array.isArray(frameworkValue[e.identifier]) ? frameworkValue[e.identifier] : [frameworkValue[e.identifier]] }) diff --git a/src/app/search/search.page.ts b/src/app/search/search.page.ts index 18a67d4bc1..3073efc9a7 100644 --- a/src/app/search/search.page.ts +++ b/src/app/search/search.page.ts @@ -173,6 +173,7 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi isFilterApplied: boolean = false; rootOrgId: string; categoryKeys: any; + requiredCategories = []; constructor( @Inject('CONTENT_SERVICE') private contentService: ContentService, @@ -261,9 +262,14 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi } this.handleDeviceBackButton(); - let framework = this.appGlobalService.getCachedFrameworkCategory(); - let frameworkId = this.profile.syllabus[0] || framework.id; + let frameworkId = ''; + if (this.appGlobalService.isOnBoardingCompleted) { + let framework = this.appGlobalService.getCachedFrameworkCategory(); + frameworkId = this.profile.syllabus[0] || framework.id; this.frameworkCategory = framework.value; + } else { + frameworkId = await this.preferences.getString('defaultFrameworkId').toPromise().then(); + } this.getCategoriesKeyForContent(frameworkId); const rootOrgId = this.onboardingConfigurationService.getAppConfig().overriddenDefaultChannelId; this.searchFilterConfig = await this.formAndFrameworkUtilService.getFrameworkCategoryFilter(frameworkId, {...FormConstants.SEARCH_FILTER, framework: frameworkId, rootOrgId: rootOrgId}); @@ -699,7 +705,7 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi const getSuggestedFrameworksRequest: GetSuggestedFrameworksRequest = { language: this.translate.currentLang, - requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES + requiredCategories: this.requiredCategories }; // Auto update the profile if that board/framework is listed in custodian framework list. this.frameworkUtilService.getActiveChannelSuggestedFrameworkList(getSuggestedFrameworksRequest).toPromise() @@ -712,11 +718,18 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi this.isProfileUpdated = true; const frameworkDetailsRequest: FrameworkDetailsRequest = { frameworkId: element.identifier, - requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES + requiredCategories: this.requiredCategories }; this.frameworkService.getFrameworkDetails(frameworkDetailsRequest).toPromise() - .then((framework: Framework) => { + .then(async (framework: Framework) => { this.categories = framework.categories; + if (!this.appGlobalService.isOnBoardingCompleted) { + this.loader = await this.commonUtilService.getLoader(); + await this.loader.present(); + this.updateUserProfile(data).then((request) => { + this.editProfile(data.framework, request) + }); + } this.boardList = find(this.categories, (category) => category.code === 'board').terms; this.mediumList = find(this.categories, (category) => category.code === 'medium').terms; this.gradeList = find(this.categories, (category) => category.code === 'gradeLevel').terms; @@ -795,42 +808,47 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi } } - editProfile() { - const req: Profile = { - board: this.profile.board, - grade: this.profile.grade, - medium: this.profile.medium, - subject: this.profile.subject, - uid: this.profile.uid, - handle: this.profile.handle, - profileType: this.profile.profileType, - source: this.profile.source, - createdAt: this.profile.createdAt, - syllabus: this.profile.syllabus + async editProfile(frameworkId?, request?) { + // const req: Profile = { + // board: this.profile.board, + // grade: this.profile.grade, + // medium: this.profile.medium, + // subject: this.profile.subject, + // uid: this.profile.uid, + // handle: this.profile.handle, + // profileType: this.profile.profileType, + // source: this.profile.source, + // createdAt: this.profile.createdAt, + // syllabus: this.profile.syllabus + // }; + // if (this.profile.grade && this.profile.grade.length > 0) { + // this.profile.grade.forEach(gradeCode => { + // for (let i = 0; i < this.gradeList.length; i++) { + // if (this.gradeList[i].code === gradeCode) { + // req.gradeValue = this.profile.gradeValue; + // req.gradeValue[this.gradeList[i].code] = this.gradeList[i].name; + // break; + // } + // } + // }); + // } + const updateProfileRequest: Profile = { + ...this.profile, + syllabus: [frameworkId], + categories: request }; - if (this.profile.grade && this.profile.grade.length > 0) { - this.profile.grade.forEach(gradeCode => { - for (let i = 0; i < this.gradeList.length; i++) { - if (this.gradeList[i].code === gradeCode) { - req.gradeValue = this.profile.gradeValue; - req.gradeValue[this.gradeList[i].code] = this.gradeList[i].name; - break; - } - } - }); - } - this.profileService.updateProfile(req).toPromise() + await this.profileService.updateProfile(updateProfileRequest).toPromise() .then(async (res: any) => { - if (res.syllabus && res.syllabus.length && res.board && res.board.length - && res.grade && res.grade.length && res.medium && res.medium.length) { - this.events.publish(AppGlobalService.USER_INFO_UPDATED); - this.events.publish('refresh:profile'); - await this.appGlobalService.setOnBoardingCompleted(); + await this.appGlobalService.setOnBoardingCompleted(); + if (this.loader) { + await this.loader.dismiss(); } + this.events.publish(AppGlobalService.USER_INFO_UPDATED); + this.events.publish('refresh:profile'); this.commonUtilService.handleToTopicBasedNotification(); this.appGlobalService.guestUserProfile = res; this.telemetryGeneratorService.generateProfilePopulatedTelemetry(PageId.DIAL_CODE_SCAN_RESULT, - req, 'auto'); + updateProfileRequest, 'auto'); }) .catch(() => { }); @@ -863,7 +881,7 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi } this.frameworkCategory.forEach((e) => { if (e.alternative && element.name === e.code) { - element['alternative'] = e.alternative; + element['alterNativeCode'] = e.alternative; } }) await this.router.navigate(['/filters'], { @@ -1913,9 +1931,31 @@ export class SearchPage implements OnInit, AfterViewInit, OnDestroy, OnTabViewWi async getCategoriesKeyForContent(frameworkId) { await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(frameworkId).then((data) => { - data.map((e) => e.label = this.translateJsonPipe.transform(e.label)); - this.categoryKeys = data; + this.frameworkCategory = data; + this.requiredCategories = data.map(e => e.code) + let frameworkData = JSON.parse(JSON.stringify(data)); + frameworkData.map((e) => e.label = this.translateJsonPipe.transform(e.label)); + this.categoryKeys = frameworkData; this.categoryKeys.push({code: 'lastPublishedBy', name: 'Published by'}) }); } + + updateUserProfile(content) { + return new Promise((resolve, reject) => { + let req = {} + setTimeout(() => { + this.frameworkCategory.forEach((e) => { + if (e.index === 1) { + req[e.identifier] = [content.framework]; + } else { + let terms = this.categories.find(ele => e.code === ele.code).terms; + let code = content[e.code] || content[e.alterNativeCode] + code = Array.isArray(code) ? code[0] : code; + req[e.identifier] = [terms.find((ter) => ter.name === code || ter.identifier === code).code]; + } + }); + resolve(req); + }, 100); + }) + } } diff --git a/src/app/user-type-selection/user-type-selection.ts b/src/app/user-type-selection/user-type-selection.ts index 943610cea1..9ee76d0de8 100644 --- a/src/app/user-type-selection/user-type-selection.ts +++ b/src/app/user-type-selection/user-type-selection.ts @@ -112,6 +112,7 @@ export class UserTypeSelectionPage implements OnDestroy { await this.frameworkService.getDefaultChannelDetails().toPromise() .then(async(data) => { this.defaultFramework = data; + await this.preferences.putString('defaultFrameworkId', this.defaultFramework.defaultFramework).toPromise(); await this.preferences.putString('defaultRootOrgId', data.identifier).toPromise(); }) }