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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<div *ngIf="content && showContentDetails">
<app-relevant-content-card
[contentData]="contentDetail?.contentData"
[frameworkCategories]="categories"
[isAlreadyEnrolled]="isAlreadyEnrolled">
</app-relevant-content-card>
</div>
Expand Down
19 changes: 16 additions & 3 deletions src/app/collection-detail-etb/collection-detail-etb.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
});
}
}
5 changes: 3 additions & 2 deletions src/app/content-details/content-details.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}`]);
Expand Down
6 changes: 3 additions & 3 deletions src/app/resources/resources.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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]]
})
Expand Down
116 changes: 78 additions & 38 deletions src/app/search/search.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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(() => {
});
Expand Down Expand Up @@ -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'], {
Expand Down Expand Up @@ -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);
})
}
}
1 change: 1 addition & 0 deletions src/app/user-type-selection/user-type-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
}
Expand Down