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
2 changes: 1 addition & 1 deletion src/app/home/user-home/user-home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`],
Expand Down
23 changes: 11 additions & 12 deletions src/app/profile/framework-selection/framework-selection.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -124,16 +124,15 @@ export class FrameworkSelectionPage implements OnInit, OnDestroy {
}

getClosure(type: string, enableOtherOption?: boolean): FieldConfigOptionsBuilder<any> {
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);
}
}
}

}
2 changes: 1 addition & 1 deletion src/app/resources/resources.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }> {
Expand All @@ -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();
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
})
);
});
}

}
9 changes: 6 additions & 3 deletions src/services/formandframeworkutil.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,) {
Expand Down