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
13 changes: 11 additions & 2 deletions src/app/home/user-home/user-home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 27 additions & 15 deletions src/app/resources/resources.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,10 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra
});
}

getCategoryData() {
async getCategoryData() {
const syllabus: Array<string> = this.appGlobalService.getCurrentUser().syllabus;
const frameworkId = (syllabus && syllabus.length > 0) ? syllabus[0] : undefined;
const categories: Array<FrameworkCategoryCode> = FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES;
const categories = await this.formAndFrameworkUtilService.invokedGetFrameworkCategoryList(frameworkId).then();
this.getMediumData(frameworkId, categories);
this.getGradeLevelData(frameworkId, categories);
this.getSubjectData(frameworkId, categories);
Expand All @@ -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) {
Expand All @@ -730,32 +736,38 @@ 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 =
this.categoryGradeLevelsArray.indexOf(this.searchGroupingContents.combination.gradeLevel);
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);
}
}
Expand Down
54 changes: 28 additions & 26 deletions src/services/framework-details.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
}
7 changes: 3 additions & 4 deletions src/services/handlers/tnc-update-handler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
Expand Down