Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #SB-0000 feat: Integrated BMG formconfig #3244

Merged
merged 2 commits into from
Nov 16, 2022
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
7 changes: 7 additions & 0 deletions src/app/form.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,11 @@ export class FormConstants {
action: 'get',
component: 'app',
};

public static FRAMEWORK_CONFIG: FormRequest = {
type: 'config',
subType: 'frameworkCategory',
action: 'get',
component: 'app',
};
}
84 changes: 43 additions & 41 deletions src/app/profile-settings/profile-settings.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,66 +30,68 @@
<div class="fill-in-content" tabindex="0" >{{'PROVIDE_BELOW_INFO' | translate}}</div>
</div>

<div class="board-select-dummy" (click)="boardClicked($event)">
<div class="board-select-dummy" (click)="boardClicked($event)" *ngIf="categories && categories.length>0">
<ion-item appCustomIonSelect>
<ion-label position="stacked" class="label-font text-uppercase align-text">
{{'' | category: 'category1'}}</ion-label>
{{categories[0].label | translateJson}}</ion-label>
<ion-select multiple="false" class="ion-text-capitalize" formControlName="syllabus"
[interfaceOptions]="boardOptions" (ionCancel)="cancelEvent()"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
placeholder="{{'FRMELEMENTS_LBL_SELECT_CATEGORY1' | category: 'category1'}}">
placeholder="{{categories[0].placeHolder | translateJson}}">
<ion-select-option *ngFor="let eachSyllabus of syllabusList" value="{{eachSyllabus.code}}">
{{eachSyllabus.name}}&lrm;</ion-select-option>
</ion-select>
</ion-item>
<div class="ps-board">
<div class="ps-board-label">{{'' | category: 'category1'}}</div>
<div class="ps-board-label">{{categories[0].label | translateJson}}</div>
<button class="sb-btn-secondary sb-btn-md PR35 W100 ellipsis btn-block">
{{'FRMELEMENTS_LBL_SELECT_CATEGORY1' | category: 'category1'}}
{{categories[0].placeHolder | translateJson}}
<img class="arrow-icon" src="assets/imgs/ic_back_black.svg" alt="">
</button>
</div>
</div>
</div>
</div>
<div novalidate class="form-position" *ngIf="!showQRScanner">
<ion-item *ngIf="!!supportedProfileAttributes['board']" appCustomIonSelect (click)="onCategoryCliked('board')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{'' | category: 'category1'}}
</ion-label>
<ion-select multiple="false" #boardSelect class="ion-text-capitalize" formControlName="syllabus"
[disabled]="!syllabusList.length" [interfaceOptions]="boardOptions" (ionCancel)="cancelEvent('board')"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
placeholder="{{'FRMELEMENTS_LBL_SELECT_CATEGORY1' | category: 'category1'}}">
<ion-select-option *ngFor="let eachSyllabus of syllabusList" value="{{eachSyllabus.code}}">
{{eachSyllabus.name | aliased}}&lrm;</ion-select-option>
</ion-select>
</ion-item>
<div *ngFor="let category of categories">
<ion-item *ngIf="!!supportedProfileAttributes['board'] && category.code=== 'category1'" appCustomIonSelect (click)="onCategoryCliked('board')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{category.label | translateJson}}
</ion-label>
<ion-select multiple="false" #boardSelect class="ion-text-capitalize" formControlName="syllabus"
[disabled]="!syllabusList.length" [interfaceOptions]="boardOptions" (ionCancel)="cancelEvent('board')"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
placeholder="{{category.placeHolder | translateJson}}">
<ion-select-option *ngFor="let eachSyllabus of syllabusList" value="{{eachSyllabus.code}}">
{{eachSyllabus.name | aliased}}&lrm;</ion-select-option>
</ion-select>
</ion-item>

<ion-item *ngIf="!!supportedProfileAttributes['medium']" appCustomIonSelect (click)="onCategoryCliked('medium')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{'' | category: 'category2'}}
</ion-label>
<ion-select formControlName="medium" #mediumSelect multiple="true" class="ion-text-capitalize"
[interfaceOptions]="mediumOptions" (ionCancel)="cancelEvent('medium')" okText="{{'BTN_SUBMIT' | translate}}"
cancelText="{{'CANCEL' | translate}}" [disabled]="!mediumList.length || !boardControl.value.length"
placeholder="{{'FRMELEMENTS_LBL_SELECT_CATEGORY1' | category: 'category2'}}">
<ion-select-option *ngFor="let medium of mediumList" class="ion-text-capitalize"
value="{{medium.code}}">
{{medium.name}}</ion-select-option>
</ion-select>
</ion-item>

<ion-item *ngIf="!!supportedProfileAttributes['gradeLevel']" appCustomIonSelect (click)="onCategoryCliked('grade')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{'' | category: 'category3'}}
</ion-label>
<ion-select multiple="true" #gradeSelect class="ion-text-capitalize" formControlName="grade"
[interfaceOptions]="classOptions" okText="{{'BTN_SUBMIT' | translate}}"
cancelText="{{'CANCEL' | translate}}" [disabled]="!gradeList.length || !mediumControl.value.length"
(ionCancel)="cancelEvent('grade')" placeholder="{{'FRMELEMENTS_LBL_SELECT_CATEGORY1' | category: 'category3'}}">
<ion-select-option *ngFor="let grade of gradeList" class="ion-text-capitalize"
value="{{grade.code}}">
{{grade.name}}</ion-select-option>
</ion-select>
</ion-item>
<ion-item *ngIf="!!supportedProfileAttributes['medium'] && category.code=== 'category2'" appCustomIonSelect (click)="onCategoryCliked('medium')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{category.label | translateJson}}
</ion-label>
<ion-select formControlName="medium" #mediumSelect multiple="true" class="ion-text-capitalize"
[interfaceOptions]="mediumOptions" (ionCancel)="cancelEvent('medium')" okText="{{'BTN_SUBMIT' | translate}}"
cancelText="{{'CANCEL' | translate}}" [disabled]="!mediumList.length || !boardControl.value.length"
placeholder="{{category.placeHolder | translateJson}}">
<ion-select-option *ngFor="let medium of mediumList" class="ion-text-capitalize"
value="{{medium.code}}">
{{medium.name}}</ion-select-option>
</ion-select>
</ion-item>

<ion-item *ngIf="!!supportedProfileAttributes['gradeLevel'] && category.code=== 'category3'" appCustomIonSelect (click)="onCategoryCliked('grade')">
<ion-label position="stacked" class="label-font text-uppercase align-text">{{category.label | translateJson}}
</ion-label>
<ion-select multiple="true" #gradeSelect class="ion-text-capitalize" formControlName="grade"
[interfaceOptions]="classOptions" okText="{{'BTN_SUBMIT' | translate}}"
cancelText="{{'CANCEL' | translate}}" [disabled]="!gradeList.length || !mediumControl.value.length"
(ionCancel)="cancelEvent('grade')" placeholder="{{category.placeHolder | translateJson}}">
<ion-select-option *ngFor="let grade of gradeList" class="ion-text-capitalize"
value="{{grade.code}}">
{{grade.name}}</ion-select-option>
</ion-select>
</ion-item>
</div>

</div>
</form>
Expand Down
1 change: 1 addition & 0 deletions src/app/profile-settings/profile-settings.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ describe('ProfileSettingsPage', () => {

it('should fetch active profile by invoked ngOnInit()', (done) => {
// arrange
mockFormAndFrameworkUtilService.getFrameworkCategories = jest.fn(() => Promise.resolve());
mockOnboardingConfigurationService.getOnboardingConfig = jest.fn(() => mockOnboardingConfigData.onboarding[0] as any)
mockTelemetryGeneratorService.generateImpressionTelemetry = jest.fn();
jest.spyOn(profileSettingsPage, 'handleActiveScanner').mockImplementation(() => {
Expand Down
9 changes: 8 additions & 1 deletion src/app/profile-settings/profile-settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ProfileSettingsPage implements OnInit, OnDestroy, AfterViewInit {
btnColor = '#8FC4FF';
appName: string;
showQRScanner = true;
categories = [];

public profileSettingsForm: FormGroup;
public hideBackButton = true;
Expand Down Expand Up @@ -143,8 +144,8 @@ export class ProfileSettingsPage implements OnInit, OnDestroy, AfterViewInit {
}

async ngOnInit() {
this.fetchCategories();
this.handleActiveScanner();

this.appVersion.getAppName().then((appName) => {
this.appName = (appName).toUpperCase();
});
Expand Down Expand Up @@ -827,4 +828,10 @@ export class ProfileSettingsPage implements OnInit, OnDestroy, AfterViewInit {
});
}

private fetchCategories() {
this.formAndFrameworkUtilService.getFrameworkCategories().then((categories) => {
this.categories = categories;
});
}

}
18 changes: 9 additions & 9 deletions src/app/profile/categories-edit/categories-edit.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
</ion-toolbar>
</ion-header>

<ion-content class="ion-padding-vertical">
<ion-content class="ion-padding-vertical" *ngIf="frameworkData.length>0">
<form [formGroup]="profileEditForm">
<ion-item *ngIf="isBoardAvailable || !!supportedProfileAttributes['board']">
<ion-label position="stacked" class="label-font">{{'BOARD' | translate}} &lrm;<ion-text>
<ion-label position="stacked" class="label-font">{{frameworkData[0].label | translateJson}} &lrm;<ion-text>
<span style="color: red;">&nbsp;*</span>
</ion-text>
</ion-label>
<ion-select formControlName="syllabus" #boardSelect multiple="false" [interfaceOptions]="boardOptions"
placeholder="{{ (syllabusList.length ? 'BOARD_OPTION_TEXT':'NO_DATA_FOUND') | translate }}"
placeholder="{{ (syllabusList.length ? (frameworkData[0].placeHolder | translateJson):'NO_DATA_FOUND') | translate }}"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
[attr.disabled]="!syllabusList.length">
<ion-select-option *ngFor="let eachSyllabus of syllabusList" value="{{eachSyllabus?.code}}">
Expand All @@ -26,25 +26,25 @@
</ion-select>
</ion-item>
<ion-item *ngIf="!!supportedProfileAttributes['medium']">
<ion-label position="stacked" class="label-font">{{'MEDIUM' | translate}}<ion-text>
<ion-label position="stacked" class="label-font">{{frameworkData[1].label | translateJson}}<ion-text>
<span style="color: red;">&nbsp;*</span>
</ion-text>
</ion-label>
<ion-select formControlName="medium" #mediumSelect multiple="true" [interfaceOptions]="mediumOptions"
placeholder="{{ (mediumList.length ? 'MEDIUM_OPTION_TEXT':'NO_DATA_FOUND') | translate }}"
placeholder="{{ (mediumList.length ? (frameworkData[1].placeHolder | translateJson) :'NO_DATA_FOUND') | translate }}"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
[attr.disabled]="(!mediumList.length || (profileEditForm.value.boards === '' && isBoardAvailable))">
<ion-select-option *ngFor="let medium of mediumList" value="{{medium?.code}}">{{medium?.name}}
</ion-select-option>
</ion-select>
</ion-item>
<ion-item *ngIf="!!supportedProfileAttributes['gradeLevel']">
<ion-label position="stacked" class="label-font">{{'CLASS' | translate}}<ion-text>
<ion-label position="stacked" class="label-font">{{frameworkData[2].label | translateJson}}<ion-text>
<span style="color: red;">&nbsp;*</span>
</ion-text>
</ion-label>
<ion-select formControlName="grades" #gradeSelect multiple="true" [interfaceOptions]="classOptions"
placeholder="{{ (gradeList.length ? 'GRADE_OPTION_TEXT':'NO_DATA_FOUND') | translate }}"
placeholder="{{ (gradeList.length ? (frameworkData[2].placeHolder | translateJson):'NO_DATA_FOUND') | translate }}"
okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
[attr.disabled]="(!gradeList.length || !(profileEditForm.value.medium != ''))"
(ionChange)="enableSubmitButton();">
Expand All @@ -54,9 +54,9 @@
</ion-select>
</ion-item>
<ion-item *ngIf="(!showOnlyMandatoryFields || !!supportedProfileAttributes['subject']) && userType!='administrator'">
<ion-label position="stacked" class="label-font">{{'SUBJECTS' | translate}}</ion-label>
<ion-label position="stacked" class="label-font">{{frameworkData[3].label | translateJson}}</ion-label>
<ion-select formControlName="subjects" multiple="true" [interfaceOptions]="subjectOptions"
placeholder="{{ (subjectList.length ? 'SUBJECT_OPTION_TEXT':'NO_DATA_FOUND') | translate }}"
placeholder="{{ (subjectList.length ? (frameworkData[3].placeHolder | translateJson):'NO_DATA_FOUND') | translate }}"
okText="{{'BTN_SUBMIT' | translate}}"
[attr.disabled]="(!subjectList.length || !(profileEditForm.value.grades != ''))"
cancelText="{{'CANCEL' | translate}}">
Expand Down
10 changes: 8 additions & 2 deletions src/app/profile/categories-edit/categories-edit.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
ContainerService,
AppHeaderService,
ActivePageService,
FormAndFrameworkUtilService
FormAndFrameworkUtilService,
TelemetryGeneratorService
} from '../../../services';
import { Location } from '@angular/common';
import { FormBuilder } from '@angular/forms';
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('CategoryEditPage', () => {
}
};
const mockCategoriesEditService: Partial<CategoriesEditService> = {};
const mockTelemetryGeneratorService: Partial<TelemetryGeneratorService> = {};


beforeAll(() => {
Expand All @@ -129,7 +131,9 @@ describe('CategoryEditPage', () => {
mockProgressLoader as SbProgressLoader,
mockProfileHandler as ProfileHandler,
mockSegmentationTagService as SegmentationTagService,
mockCategoriesEditService as CategoriesEditService
mockCategoriesEditService as CategoriesEditService,
mockTelemetryGeneratorService as TelemetryGeneratorService,
mockFormAndFrameworkUtilService as FormAndFrameworkUtilService
);
});

Expand Down Expand Up @@ -291,9 +295,11 @@ describe('CategoryEditPage', () => {
},
} as any));
mockSharedPreferences.getString = jest.fn(() => of('userType'));
mockFormAndFrameworkUtilService.getFrameworkCategories = jest.fn(() => Promise.resolve());
// act
categoryEditPage.ngOnInit().then(() => {
// assert
expect(mockFormAndFrameworkUtilService.getFrameworkCategories).toHaveBeenCalled();
expect(mockSharedPreferences.getString).toHaveBeenCalledWith(PreferenceKey.SELECTED_USER_TYPE);
expect(categoryEditPage.supportedProfileAttributes).toEqual({
board: 'board',
Expand Down
14 changes: 12 additions & 2 deletions src/app/profile/categories-edit/categories-edit.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { AppHeaderService } from '@app/services/app-header.service';
import { PreferenceKey, ProfileConstants } from '@app/app/app.constant';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { Environment, ActivePageService, InteractSubtype, PageId, TelemetryGeneratorService } from '@app/services';
import { Environment, ActivePageService, TelemetryGeneratorService,
FormAndFrameworkUtilService, InteractSubtype, PageId, } from '@app/services';
import { SbProgressLoader } from '@app/services/sb-progress-loader.service';
import { ProfileHandler } from '@app/services/profile-handler';
import { SegmentationTagService, TagPrefixConstants } from '@app/services/segmentation-tag/segmentation-tag.service';
Expand Down Expand Up @@ -78,6 +79,7 @@ export class CategoriesEditPage implements OnInit, OnDestroy {
shouldUpdatePreference: boolean;
noOfStepsToCourseToc = 0;
guestUserProfile: any;
frameworkData = [];

/* Custom styles for the select box popup */
boardOptions = {
Expand Down Expand Up @@ -137,7 +139,8 @@ export class CategoriesEditPage implements OnInit, OnDestroy {
private profileHandler: ProfileHandler,
private segmentationTagService: SegmentationTagService,
private categoriesEditService: CategoriesEditService,
private telemetryGeneratorService: TelemetryGeneratorService
private telemetryGeneratorService: TelemetryGeneratorService,
private formAndFrameworkUtilService: FormAndFrameworkUtilService

) {
this.appGlobalService.closeSigninOnboardingLoader();
Expand All @@ -159,6 +162,7 @@ export class CategoriesEditPage implements OnInit, OnDestroy {
}

async ngOnInit() {
this.getCategories();
this.supportedProfileAttributes = await this.profileHandler.getSupportedProfileAttributes(false);
const subscriptionArray: Array<any> = this.updateAttributeStreamsnSetValidators(this.supportedProfileAttributes);
this.formControlSubscriptions = combineLatest(subscriptionArray).subscribe();
Expand Down Expand Up @@ -580,4 +584,10 @@ export class CategoriesEditPage implements OnInit, OnDestroy {
this.guestUserProfile = profile;
});
}

private getCategories() {
this.formAndFrameworkUtilService.getFrameworkCategories().then((categories) => {
this.frameworkData = categories;
});
}
}
Loading