diff --git a/src/app/home/user-home/user-home.page.ts b/src/app/home/user-home/user-home.page.ts index a88cb6b862..51d6be3f3e 100644 --- a/src/app/home/user-home/user-home.page.ts +++ b/src/app/home/user-home/user-home.page.ts @@ -188,13 +188,22 @@ export class UserHomePage implements OnInit, OnDestroy, OnTabViewWillEnter { ).toPromise(); this.frameworkCategoriesValue = {}; this.userFrameworkCategories = this.profile.categories ? JSON.parse(this.profile.categories) : this.profile.serverProfile.framework; + if (!Object.keys(this.userFrameworkCategories).length) { + await this.commonUtilService.getGuestUserConfig().then((profile) => { + this.userFrameworkCategories = JSON.parse(profile.categories); + if (!this.profile.syllabus.length) { + this.profile.syllabus = profile.syllabus; + } + }); + } await this.getFrameworkCategoriesLabel() this.preferenceList = []; setTimeout(() => { this.preferenceList = []; this.categoriesLabel.forEach((e) => { - if (this.userFrameworkCategories[e.code].length){ - this.preferenceList.push(this.userFrameworkCategories[e.code]); + let category = this.userFrameworkCategories[e.code] || this.userFrameworkCategories[e.identifier]; + if (category){ + this.preferenceList.push(Array.isArray(category) ? category : [category]); } }) }, 0); diff --git a/src/app/resources/resources.component.ts b/src/app/resources/resources.component.ts index 3e69d5a37a..84b21e1941 100644 --- a/src/app/resources/resources.component.ts +++ b/src/app/resources/resources.component.ts @@ -675,10 +675,10 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra }); } - getCategoryData() { + async getCategoryData() { const syllabus: Array = this.appGlobalService.getCurrentUser().syllabus; const frameworkId = (syllabus && syllabus.length > 0) ? syllabus[0] : undefined; - const categories: Array = FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES; + const categories = await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(frameworkId).then(); this.getMediumData(frameworkId, categories); this.getGradeLevelData(frameworkId, categories); this.getSubjectData(frameworkId, categories); @@ -699,25 +699,31 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra getMediumData(frameworkId, categories): any { const req: GetFrameworkCategoryTermsRequest = { - currentCategoryCode: FrameworkCategoryCode.MEDIUM, + currentCategoryCode: categories[1].code, language: this.translate.currentLang, - requiredCategories: categories, + requiredCategories: this.appGlobalService.getRequiredCategories(), frameworkId }; this.frameworkUtilService.getFrameworkCategoryTerms(req).toPromise() .then(async (res: CategoryTerm[]) => { this.categoryMediums = res; this.categoryMediumNamesArray = res.map(a => (a.name)); - await this.arrangeMediumsByUserData([...this.categoryMediumNamesArray]); + await this.arrangeMediumsByUserData([...this.categoryMediumNamesArray], categories[1]); }).catch(e => console.error(e)); } - async arrangeMediumsByUserData(categoryMediumsParam) { - if (this.appGlobalService.getCurrentUser() && - this.appGlobalService.getCurrentUser().medium && - this.appGlobalService.getCurrentUser().medium.length) { + async arrangeMediumsByUserData(categoryMediumsParam, category) { + let selectedCategory = []; + if (this.guestUser) { + selectedCategory = JSON.parse(this.profile.categories)[category.identifier]; + } else { + selectedCategory = this.profile.serverProfile.framework[category.code] + } + // if (this.appGlobalService.getCurrentUser() && + // this.appGlobalService.getCurrentUser().medium && + // this.appGlobalService.getCurrentUser().medium.length) { const matchedIndex = this.categoryMediumNamesArray.map(x => x.toLocaleLowerCase()) - .indexOf(this.appGlobalService.getCurrentUser().medium[0].toLocaleLowerCase()); + .indexOf(selectedCategory[0].toLocaleLowerCase()); for (let i = matchedIndex; i > 0; i--) { categoryMediumsParam[i] = categoryMediumsParam[i - 1]; if (i === 1) { @@ -730,24 +736,30 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra await this.mediumClickHandler(indexOfSelectedmediums, this.categoryMediumNamesArray[indexOfSelectedmediums]); } else { for (let i = 0, len = this.categoryMediumNamesArray.length; i < len; i++) { - if ((this.getGroupByPageReq.medium[0].toLowerCase().trim()) === this.categoryMediumNamesArray[i].toLowerCase().trim()) { + if ((selectedCategory[0].toLowerCase().trim()) === this.categoryMediumNamesArray[i].toLowerCase().trim()) { await this.mediumClickHandler(i, this.categoryMediumNamesArray[i]); } } } - } + // } } getGradeLevelData(frameworkId, categories): any { const req: GetFrameworkCategoryTermsRequest = { - currentCategoryCode: FrameworkCategoryCode.GRADE_LEVEL, + currentCategoryCode: categories[2].code, language: this.translate.currentLang, - requiredCategories: categories, + requiredCategories: this.appGlobalService.getRequiredCategories(), frameworkId }; this.frameworkUtilService.getFrameworkCategoryTerms(req).toPromise() .then(async (res: CategoryTerm[]) => { this.categoryGradeLevels = res; + let selectedCategory = []; + if (this.guestUser) { + selectedCategory = JSON.parse(this.profile.categories)[categories[2].identifier]; + } else { + selectedCategory = this.profile.serverProfile.framework[categories[2].code] + } this.categoryGradeLevelsArray = res.map(a => (a.name)); if (this.searchGroupingContents && this.searchGroupingContents.combination.gradeLevel) { const indexOfselectedClass = @@ -755,7 +767,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra await this.classClickHandler(indexOfselectedClass); } else { for (let i = 0, len = this.categoryGradeLevelsArray.length; i < len; i++) { - if (this.getGroupByPageReq.grade[0] === this.categoryGradeLevelsArray[i]) { + if (selectedCategory[0] === this.categoryGradeLevelsArray[i]) { await this.classClickHandler(i); } } diff --git a/src/services/framework-details.service.ts b/src/services/framework-details.service.ts index 7da3c6d732..41ae43a206 100644 --- a/src/services/framework-details.service.ts +++ b/src/services/framework-details.service.ts @@ -19,8 +19,20 @@ export class FrameworkDetailsService { ) { } async getFrameworkDetails(guestProfile?: any) { - let framework = {}; - framework = this.getCategoriesAndUpdateAttributes(guestProfile); + let framework :any = {}; + await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(guestProfile.syllabus[0]).then((categories) => { + if (categories) { + setTimeout(() => { + let frameworkData = categories; + let categoryDetails = JSON.parse(guestProfile.categories); + frameworkData.forEach((e) => { + if(categoryDetails[e.identifier]) { + framework[e.code] = Array.isArray(categoryDetails[e.identifier]) ? categoryDetails[e.identifier] : [categoryDetails[e.identifier]] + } + }); + }, 0); + } + }).catch(e => console.error(e)); framework['id'] = guestProfile.syllabus; // const boardList = await this.getBoardList(guestProfile).then((board) => { // return board.map(t => ({ name: t.name, code: t.code })); @@ -69,15 +81,21 @@ export class FrameworkDetailsService { if (loc) { acc[loc.type] = loc; } return acc; }, {}); - const state = await this.fetchStateCode(presetLocation.state).then((data) => { - return data; - }); - const district = await this.fetchDistrictCode(presetLocation).then((dis) => { - return dis; - }); const locationCodes = []; - locationCodes.push({ type: state.type, code: state.code }); - locationCodes.push({ type: district.type, code: district.code }); + if (presetLocation && presetLocation.state) { + await this.fetchStateCode(presetLocation.state).then((data) => { + if (data && data.type && data.code) { + locationCodes.push({ type: data.type, code: data.code }); + } + }); + } + if (presetLocation && presetLocation.district) { + await this.fetchDistrictCode(presetLocation).then((data) => { + if (data && data.type && data.code) { + locationCodes.push({ type: data.type, code: data.code }); + } + }); + } const req = { profileUserTypes: [{ type: guestProfile.profileType, @@ -176,20 +194,4 @@ export class FrameworkDetailsService { return response.find(d => d.id === location.district.id); }); } - - private async getCategoriesAndUpdateAttributes(profile) { - let framework = {} - await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(profile.syllabus[0]).then((categories) => { - if (categories) { - let frameworkData = categories; - let categoryDetails = JSON.parse(profile.categories); - frameworkData.forEach((e) => { - if(categoryDetails[e.identifier]) { - framework[e.code] = categoryDetails[e.identifier] - } - }); - return framework; - } - }).catch(e => console.error(e)); - } } diff --git a/src/services/handlers/tnc-update-handler.service.ts b/src/services/handlers/tnc-update-handler.service.ts index 25516f6376..af73d5be77 100644 --- a/src/services/handlers/tnc-update-handler.service.ts +++ b/src/services/handlers/tnc-update-handler.service.ts @@ -237,10 +237,9 @@ export class TncUpdateHandlerService { if (isSSOUser) { await this.consentService.getConsent(userDetails, true); } - if ((userDetails && userDetails.grade && userDetails.medium && userDetails.syllabus && - !userDetails.grade.length && !userDetails.medium.length && !userDetails.syllabus.length) + if ((userDetails && userDetails.syllabus && !userDetails.syllabus.length) || ((userDetails.profileType === ProfileType.NONE && userDetails.serverProfile.profileUserType.type === ProfileType.NONE) || - (userDetails.profileType === ProfileType.OTHER.toUpperCase() && + (userDetails.profileType === ProfileType.OTHER.toUpperCase() && !userDetails.serverProfile.framework.id && userDetails.serverProfile.profileUserType.type === ProfileType.OTHER.toUpperCase()) || userDetails.serverProfile.profileUserType.type === ProfileType.OTHER.toUpperCase())) { const guestProfile = await this.commonUtilService.getGuestUserConfig().then((profile) => { @@ -360,7 +359,7 @@ export class TncUpdateHandlerService { .then(async (data) => { await loader.dismiss(); this.commonUtilService.showToast( - this.commonUtilService.translateMessage('FRMELEMNTS_MSG_CHANGE_PROFILE', {role: req.profileUserTypes[0].type})); + this.commonUtilService.translateMessage('FRMELEMNTS_MSG_CHANGE_PROFILE', {role: req['profileUserTypes'][0].type})); this.events.publish('refresh:loggedInProfile'); }).catch(async (e) => { await loader.dismiss();