diff --git a/src/app/home/user-home/user-home.page.ts b/src/app/home/user-home/user-home.page.ts index 51d6be3f3e..6a426af831 100644 --- a/src/app/home/user-home/user-home.page.ts +++ b/src/app/home/user-home/user-home.page.ts @@ -643,7 +643,7 @@ export class UserHomePage implements OnInit, OnDestroy, OnTabViewWillEnter { PageId.LIBRARY, ); - const formConfig = await this.formAndFrameworkUtilService.getContentRequestFormConfig(); + const formConfig = await this.formAndFrameworkUtilService.getContentRequestFormConfig(this.profile.syllabus[0]); this.appGlobalService.formConfig = formConfig; this.frameworkSelectionDelegateService.delegate = this; await this.router.navigate([`/${RouterLinks.PROFILE}/${RouterLinks.FRAMEWORK_SELECTION}`], diff --git a/src/app/profile/framework-selection/framework-selection.page.ts b/src/app/profile/framework-selection/framework-selection.page.ts index 2b32693c6f..4d23157ec3 100644 --- a/src/app/profile/framework-selection/framework-selection.page.ts +++ b/src/app/profile/framework-selection/framework-selection.page.ts @@ -115,7 +115,7 @@ export class FrameworkSelectionPage implements OnInit, OnDestroy { const dataSrc = ele.templateOptions.dataSrc; switch (dataSrc.marker) { case 'ACTIVE_CHANNEL.SUGGESTED_FRAMEWORK_LIST.MAPPED_TO_FRAMEWORKCATEGORIES': - ele.templateOptions.options = this.getClosure('board'); + ele.templateOptions.options = this.getClosure('framework'); break; case 'FRAMEWORK_CATEGORY_TERMS': ele.templateOptions.options = this.getClosure(dataSrc.params.categoryCode, !!(ele.children && ele.children.other)); @@ -124,16 +124,15 @@ export class FrameworkSelectionPage implements OnInit, OnDestroy { } getClosure(type: string, enableOtherOption?: boolean): FieldConfigOptionsBuilder { - switch (type) { - case 'board': - return this.frameworkCommonFormConfigBuilder.getBoardConfigOptionsBuilder(); - case 'medium': - return this.frameworkCommonFormConfigBuilder.getMediumConfigOptionsBuilder(); - case 'grade': - return this.frameworkCommonFormConfigBuilder.getGradeConfigOptionsBuilder(); - case 'subject': - return this.frameworkCommonFormConfigBuilder.getSubjectConfigOptionsBuilder(null, enableOtherOption); - } + if (enableOtherOption) { + return this.frameworkCommonFormConfigBuilder.getFrameworkConfigOptionsBuilder(null, null, enableOtherOption) + } else { + switch (type) { + case 'framework': + return this.frameworkCommonFormConfigBuilder.getBoardConfigOptionsBuilder(); + default: + return this.frameworkCommonFormConfigBuilder.getFrameworkConfigOptionsBuilder(type); + } + } } - } diff --git a/src/app/resources/resources.component.ts b/src/app/resources/resources.component.ts index 84b21e1941..40f264c3af 100644 --- a/src/app/resources/resources.component.ts +++ b/src/app/resources/resources.component.ts @@ -1174,7 +1174,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy, Fra PageId.LIBRARY, ); - const formConfig = await this.formAndFrameworkUtilService.getContentRequestFormConfig(); + const formConfig = await this.formAndFrameworkUtilService.getContentRequestFormConfig(this.profile.syllabus[0]); this.appGlobalService.formConfig = formConfig; this.frameworkSelectionDelegateService.delegate = this; await this.router.navigate([`/${RouterLinks.PROFILE}/${RouterLinks.FRAMEWORK_SELECTION}`], diff --git a/src/services/common-form-config-builders/framework-common-form-config-builder.ts b/src/services/common-form-config-builders/framework-common-form-config-builder.ts index 17abe141af..e57458bcbd 100644 --- a/src/services/common-form-config-builders/framework-common-form-config-builder.ts +++ b/src/services/common-form-config-builders/framework-common-form-config-builder.ts @@ -15,6 +15,7 @@ import { Profile } from '@project-sunbird/sunbird-sdk'; import {AliasBoardName} from '../../pipes/alias-board-name/alias-board-name'; +import { AppGlobalService } from '../app-global-service.service'; @Injectable({ providedIn: 'root' @@ -25,7 +26,8 @@ export class FrameworkCommonFormConfigBuilder { @Inject('FRAMEWORK_SERVICE') private frameworkService: FrameworkService, @Inject('FRAMEWORK_UTIL_SERVICE') private frameworkUtilService: FrameworkUtilService, private translate: TranslateService, - private alisaBoard: AliasBoardName + private alisaBoard: AliasBoardName, + private appGlobalService: AppGlobalService ) { } getBoardConfigOptionsBuilder(profile?: Profile): FieldConfigOptionsBuilder<{ name: string, code: string, deafult?: any }> { @@ -35,7 +37,7 @@ export class FrameworkCommonFormConfigBuilder { const getSuggestedFrameworksRequest: GetSuggestedFrameworksRequest = { from: CachedItemRequestSourceFrom.SERVER, language: this.translate.currentLang, - requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES + requiredCategories: this.appGlobalService.getRequiredCategories() || FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES }; const list = await this.frameworkUtilService.getActiveChannelSuggestedFrameworkList(getSuggestedFrameworksRequest).toPromise(); @@ -87,7 +89,7 @@ export class FrameworkCommonFormConfigBuilder { const framework = await this.frameworkService.getFrameworkDetails({ from: CachedItemRequestSourceFrom.SERVER, frameworkId: userInput.code, - requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES + requiredCategories: this.appGlobalService.getRequiredCategories() || FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES }).toPromise(); const boardCategoryTermsRequet: GetFrameworkCategoryTermsRequest = { @@ -272,4 +274,65 @@ export class FrameworkCommonFormConfigBuilder { return false; } + getFrameworkConfigOptionsBuilder(type?: any, profile?: Profile, enableOtherAsOption?: boolean): FieldConfigOptionsBuilder<{ name: string, code: string, frameworkCode: string }> { + return ((control: FormControl, context: FormControl, notifyLoading, notifyLoaded) => { + if (!context) { + return of([]); + } + return context.valueChanges.pipe( + distinctUntilChanged((v1, v2) => { + return this.valueComparator(v1 && v1.code, v2 && v2.code); + }), + tap(notifyLoading), + switchMap((value) => { + if (!value) { + return of([]); + } + const userInput: { name: string, code: string, frameworkCode: string } = value; + return defer(async () => { + const nextCategoryTermsRequet: GetFrameworkCategoryTermsRequest = { + frameworkId: userInput.frameworkCode ? userInput.frameworkCode : userInput.code, + requiredCategories: [type], + currentCategoryCode: type, + language: this.translate.currentLang, + selectedTermsCodes: [context.value.code] + }; + + const list = await this.frameworkUtilService.getFrameworkCategoryTerms(nextCategoryTermsRequet).toPromise(); + const options: FieldConfigOption<{ name: string, code: string, frameworkCode: string } | 'other'>[] = []; + list.forEach(element => { + const value: FieldConfigOption<{ name: string, code: string, frameworkCode: string }> = { + label: element.name, + value: { + name: element.name, + code: element.code, + frameworkCode: userInput.frameworkCode ? userInput.frameworkCode : userInput.code + } + }; + options.push(value); + + if (!context.dirty && profile && profile.medium && profile.medium.length + && profile.medium[0] === element.code) { + control.patchValue(value.value); + } + }); + if (enableOtherAsOption) { + options.push({ + label: 'Other', + value: 'other' + }); + } + return options; + }); + }), + tap(notifyLoaded), + catchError((e) => { + console.error(e); + notifyLoaded(); + return EMPTY; + }) + ); + }); + } + } diff --git a/src/services/formandframeworkutil.service.ts b/src/services/formandframeworkutil.service.ts index 7268b1e541..b602db3bff 100644 --- a/src/services/formandframeworkutil.service.ts +++ b/src/services/formandframeworkutil.service.ts @@ -634,8 +634,11 @@ export class FormAndFrameworkUtilService { return (await this.getFormFields(FormConstants.CONTACT_INFO).then() as any); } - async getContentRequestFormConfig() { - return (await this.getFormFields(FormConstants.DYNAMIC_CONTENT_REQUEST).then() as any); + async getContentRequestFormConfig(frameworkId, rootOrgId?) { + if (!rootOrgId) { + rootOrgId = await this.preferences.getString('defaultRootOrgId').toPromise(); + } + return this.getFrameworkCategoryList(frameworkId, {...FormConstants.DYNAMIC_CONTENT_REQUEST, framework: frameworkId, rootOrgId: (rootOrgId || '*')}) } async getConsentFormConfig() { @@ -755,7 +758,7 @@ export class FormAndFrameworkUtilService { if (!rootOrgId) { rootOrgId = await this.preferences.getString('defaultRootOrgId').toPromise(); } - return this.getFrameworkCategoryList(frameworkId, {...FormConstants.FRAMEWORK_CONFIG, framework: frameworkId, rootOrgId: (rootOrgId || '*')}, true) + return this.getFrameworkCategoryList(frameworkId, {...FormConstants.FRAMEWORK_CONFIG, framework: frameworkId, rootOrgId: (rootOrgId || '*')}, true); } async getFrameworkCategoryFilter (frameworkId: string, formRequest?: any,) {