File

src/app/profile/categories-edit/categories-edit.page.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Accessors

Constructor

constructor(profileService: ProfileService, frameworkService: FrameworkService, frameworkUtilService: FrameworkUtilService, preferences: SharedPreferences, commonUtilService: CommonUtilService, fb: FormBuilder, translate: TranslateService, appGlobalService: AppGlobalService, headerService: AppHeaderService, router: Router, location: Location, platform: Platform, activePageService: ActivePageService, sbProgressLoader: SbProgressLoader, profileHandler: ProfileHandler, segmentationTagService: SegmentationTagService, categoriesEditService: CategoriesEditService, telemetryGeneratorService: TelemetryGeneratorService, formAndFrameworkUtilService: FormAndFrameworkUtilService)
Parameters :
Name Type Optional
profileService ProfileService No
frameworkService FrameworkService No
frameworkUtilService FrameworkUtilService No
preferences SharedPreferences No
commonUtilService CommonUtilService No
fb FormBuilder No
translate TranslateService No
appGlobalService AppGlobalService No
headerService AppHeaderService No
router Router No
location Location No
platform Platform No
activePageService ActivePageService No
sbProgressLoader SbProgressLoader No
profileHandler ProfileHandler No
segmentationTagService SegmentationTagService No
categoriesEditService CategoriesEditService No
telemetryGeneratorService TelemetryGeneratorService No
formAndFrameworkUtilService FormAndFrameworkUtilService No

Methods

Private addAttributeSubscription
addAttributeSubscription()
Returns : void
enableSubmitButton
enableSubmitButton()

It changes the color of the submit button on change of class.

Returns : void
Private getCategoriesAndUpdateAttributes
getCategoriesAndUpdateAttributes(userType)
Parameters :
Name Optional
userType No
Returns : void
Private Async getFrameworkData
getFrameworkData(frameworkId)
Parameters :
Name Optional
frameworkId No
Returns : any
Async getLoggedInFrameworkCategory
getLoggedInFrameworkCategory()
Returns : any
Async getSyllabusDetails
getSyllabusDetails()
Returns : any
goBack
goBack()
Returns : void
initializeForm
initializeForm()

Initializes form with default values or empty values

Returns : void
Async initializeLoader
initializeLoader()
Returns : any
ionViewDidEnter
ionViewDidEnter()
Returns : void
ionViewWillEnter
ionViewWillEnter()

Ionic life cycle event - Fires every time page visits

Returns : void
ionViewWillLeave
ionViewWillLeave()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
Async ngOnInit
ngOnInit()
Returns : any
Private onGradeChange
onGradeChange()
Returns : Observable<string[]>
Private onMediumChange
onMediumChange()
Returns : Observable<string[]>
onSubmit
onSubmit()

It will validate the forms and internally call submit method

Returns : void
Private onSyllabusChange
onSyllabusChange()
Returns : Observable<string[]>
refreshSegmentTags
refreshSegmentTags()
Returns : void
Async setDefaultBMG
setDefaultBMG()
Returns : any
showErrorToastMessage
showErrorToastMessage(fieldName: string)

Shows Toast Message with red color

Parameters :
Name Type Optional Description
fieldName string No

Name of the field in the form

Returns : void
Async submitForm
submitForm(formVal)

It makes an update API call.

Parameters :
Name Optional Description
formVal No

Object of Form values

Returns : any
Private updateAttributeStreamsnSetValidators
updateAttributeStreamsnSetValidators(attributes: literal type)
Parameters :
Name Type Optional
attributes literal type No
Returns : Array<any>

Properties

backButtonFunc
Type : Subscription
Public boardList
Type : literal type[]
Default value : []
boardOptions
Type : object
Default value : { title: this.commonUtilService.translateMessage('BOARD').toLocaleUpperCase(), cssClass: 'select-box' }
boardSelect
Type : IonSelect
Decorators :
@ViewChild('boardSelect', {static: false})
btnColor
Type : string
Default value : '#8FC4FF'
categories
Type : []
Default value : []
classOptions
Type : object
Default value : { title: this.commonUtilService.translateMessage('CLASS').toLocaleUpperCase(), cssClass: 'select-box' }
disableSubmitButton
Default value : false
editData
Default value : true
Private formControlSubscriptions
Type : Subscription
Private framework
Type : Framework
frameworkData
Type : []
Default value : []
frameworkId
Type : string
Public gradeList
Type : literal type[]
Default value : []
gradeSelect
Type : IonSelect
Decorators :
@ViewChild('gradeSelect', {static: false})
guestUserProfile
Type : any
hasFilledLocation
Default value : false
headerConfig
Type : object
Default value : { showHeader: false, showBurgerMenu: false, actionButtons: [] }
isBoardAvailable
Default value : true
isRootPage
Default value : false
loader
Type : any
Public mediumList
Type : literal type[]
Default value : []
mediumOptions
Type : object
Default value : { title: this.commonUtilService.translateMessage('MEDIUM').toLocaleUpperCase(), cssClass: 'select-box' }
mediumSelect
Type : IonSelect
Decorators :
@ViewChild('mediumSelect', {static: false})
noOfStepsToCourseToc
Type : number
Default value : 0
profile
Type : Profile
profileEditForm
Type : FormGroup
shouldUpdatePreference
Type : boolean
showOnlyMandatoryFields
Default value : true
Public subjectList
Type : literal type[]
Default value : []
subjectOptions
Type : object
Default value : { title: this.commonUtilService.translateMessage('SUBJECTS').toLocaleUpperCase(), cssClass: 'select-box' }
Public supportedProfileAttributes
Type : literal type
Default value : {}
Public syllabusList
Type : literal type[]
Default value : []
userType
Type : string

Accessors

syllabusControl
getsyllabusControl()
boardControl
getboardControl()
mediumControl
getmediumControl()
gradeControl
getgradeControl()
subjectControl
getsubjectControl()
import { tap } from 'rxjs/operators';
import { Subscription, combineLatest, Observable } from 'rxjs';
import { Component, Inject, ViewChild, OnInit, OnDestroy } from '@angular/core';
import { IonSelect, Platform } from '@ionic/angular';
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import {
  FrameworkService,
  FrameworkUtilService,
  GetSuggestedFrameworksRequest,
  GetFrameworkCategoryTermsRequest,
  Framework,
  FrameworkCategoryCodesGroup,
  Profile,
  ProfileService,
  UpdateServerProfileInfoRequest,
  ServerProfileDetailsRequest,
  CachedItemRequestSourceFrom,
  Channel,
  FrameworkCategoryCode,
  SharedPreferences,
  InteractType
} from 'sunbird-sdk';
import { CommonUtilService } from '@app/services/common-util.service';
import { AppGlobalService } from '@app/services/app-global-service.service';
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, 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';
import { CategoriesEditService } from './categories-edit.service';


@Component({
  selector: 'app-categories-edit',
  templateUrl: './categories-edit.page.html',
  styleUrls: ['./categories-edit.page.scss'],
})
export class CategoriesEditPage implements OnInit, OnDestroy {

  @ViewChild('boardSelect', { static: false }) boardSelect: IonSelect;
  @ViewChild('mediumSelect', { static: false }) mediumSelect: IonSelect;
  @ViewChild('gradeSelect', { static: false }) gradeSelect: IonSelect;

  private framework: Framework;
  private formControlSubscriptions: Subscription;

  public syllabusList: { name: string, code: string }[] = [];
  public mediumList: { name: string, code: string }[] = [];
  public gradeList: { name: string, code: string }[] = [];
  public subjectList: { name: string, code: string }[] = [];
  public boardList: { name: string, code: string }[] = [];

  disableSubmitButton = false;

  profile: Profile;
  profileEditForm: FormGroup;
  frameworkId: string;
  categories = [];
  btnColor = '#8FC4FF';
  showOnlyMandatoryFields = true;
  editData = true;
  loader: any;
  headerConfig = {
    showHeader: false,
    showBurgerMenu: false,
    actionButtons: []
  };

  backButtonFunc: Subscription;
  isRootPage = false;
  hasFilledLocation = false;
  public supportedProfileAttributes: { [key: string]: string } = {};
  userType: string;
  shouldUpdatePreference: boolean;
  noOfStepsToCourseToc = 0;
  guestUserProfile: any;
  frameworkData = [];

  /* Custom styles for the select box popup */
  boardOptions = {
    title: this.commonUtilService.translateMessage('BOARD').toLocaleUpperCase(),
    cssClass: 'select-box'
  };
  mediumOptions = {
    title: this.commonUtilService.translateMessage('MEDIUM').toLocaleUpperCase(),
    cssClass: 'select-box'
  };
  classOptions = {
    title: this.commonUtilService.translateMessage('CLASS').toLocaleUpperCase(),
    cssClass: 'select-box'
  };
  subjectOptions = {
    title: this.commonUtilService.translateMessage('SUBJECTS').toLocaleUpperCase(),
    cssClass: 'select-box'
  };

  isBoardAvailable = true;

  get syllabusControl(): FormControl {
    return this.profileEditForm.get('syllabus') as FormControl;
  }

  get boardControl(): FormControl {
    return this.profileEditForm.get('boards') as FormControl;
  }

  get mediumControl(): FormControl {
    return this.profileEditForm.get('medium') as FormControl;
  }

  get gradeControl(): FormControl {
    return this.profileEditForm.get('grades') as FormControl;
  }

  get subjectControl(): FormControl {
    return this.profileEditForm.get('subjects') as FormControl;
  }

  constructor(
    @Inject('PROFILE_SERVICE') private profileService: ProfileService,
    @Inject('FRAMEWORK_SERVICE') private frameworkService: FrameworkService,
    @Inject('FRAMEWORK_UTIL_SERVICE') private frameworkUtilService: FrameworkUtilService,
    @Inject('SHARED_PREFERENCES') private preferences: SharedPreferences,
    private commonUtilService: CommonUtilService,
    private fb: FormBuilder,
    private translate: TranslateService,
    private appGlobalService: AppGlobalService,
    private headerService: AppHeaderService,
    private router: Router,
    private location: Location,
    private platform: Platform,
    private activePageService: ActivePageService,
    private sbProgressLoader: SbProgressLoader,
    private profileHandler: ProfileHandler,
    private segmentationTagService: SegmentationTagService,
    private categoriesEditService: CategoriesEditService,
    private telemetryGeneratorService: TelemetryGeneratorService,
    private formAndFrameworkUtilService: FormAndFrameworkUtilService

  ) {
    this.appGlobalService.closeSigninOnboardingLoader();
    this.profile = this.appGlobalService.getCurrentUser();
    const extrasState = this.router.getCurrentNavigation().extras.state;
    if (extrasState && extrasState.showOnlyMandatoryFields) {
      this.hasFilledLocation = extrasState.hasFilledLocation;
      this.showOnlyMandatoryFields = extrasState.showOnlyMandatoryFields;
      this.isRootPage = Boolean(extrasState.isRootPage);
      this.noOfStepsToCourseToc = extrasState.noOfStepsToCourseToc;
      if (extrasState.profile) {
        this.profile = extrasState.profile;
      }
    } else {
      this.showOnlyMandatoryFields = false;
    }
    this.shouldUpdatePreference = extrasState && extrasState.shouldUpdatePreference ? extrasState.shouldUpdatePreference : false;
    this.initializeForm();
  }

  async ngOnInit() {
    this.userType = await this.preferences.getString(PreferenceKey.SELECTED_USER_TYPE).toPromise();
    this.getCategoriesAndUpdateAttributes((this.profile.serverProfile.profileUserTypes.length > 1 ?
      this.profile.serverProfile.profileUserTypes[0].type : this.profile.profileType) || undefined);
  }

  ngOnDestroy() {
    this.formControlSubscriptions.unsubscribe();
  }
  /**
   * Ionic life cycle event - Fires every time page visits
   */
  ionViewWillEnter() {
    this.setDefaultBMG();
    this.initializeLoader();
    if (this.appGlobalService.isUserLoggedIn()) {
      this.getLoggedInFrameworkCategory();
    } else {
      this.getSyllabusDetails();
    }
    this.disableSubmitButton = false;
    this.headerConfig = this.headerService.getDefaultPageConfig();
    this.headerConfig.actionButtons = [];
    this.headerConfig.showHeader = false;
    this.headerConfig.showBurgerMenu = false;
    this.headerService.updatePageConfig(this.headerConfig);

    if (this.isRootPage) {
      this.backButtonFunc = this.platform.backButton.subscribeWithPriority(0, () => {
        if (this.platform.is('ios')) {
          this.headerService.showHeaderWithHomeButton();
        } else {
          this.commonUtilService.showExitPopUp(this.activePageService.computePageId(this.router.url), Environment.HOME, false);
        }
      });
    }
  }

  ionViewDidEnter() {
    this.sbProgressLoader.hide({ id: 'login' });
  }

  /**
   * Initializes form with default values or empty values
   */

  initializeForm() {
    if (this.profile.board && this.profile.board.length > 1) {
      this.profile.board.splice(1, this.profile.board.length);
    }
    this.profileEditForm = this.fb.group({
      syllabus: [],
      boards: [],
      medium: [],
      grades: [],
      subjects: []
    });
  }

  async initializeLoader() {
    this.loader = await this.commonUtilService.getLoader();
  }

  async getSyllabusDetails() {
    this.loader = await this.commonUtilService.getLoader();
    await this.loader.present();

    const getSuggestedFrameworksRequest: GetSuggestedFrameworksRequest = {
      from: CachedItemRequestSourceFrom.SERVER,
      language: this.translate.currentLang,
      requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES
    };

    this.frameworkUtilService.getActiveChannelSuggestedFrameworkList(getSuggestedFrameworksRequest).toPromise()
      .then(async (frameworks: Framework[]) => {
        if (!frameworks || !frameworks.length) {
          await this.loader.dismiss();
          this.commonUtilService.showToast('NO_DATA_FOUND');
          return;
        }
        this.syllabusList = frameworks.map(r => ({ name: r.name, code: r.identifier }));
        const syllabus = (this.profile.syllabus && this.profile.syllabus[0]) ||
          (this.guestUserProfile.syllabus && this.guestUserProfile.syllabus[0]);
        this.syllabusControl.patchValue([syllabus] || []);
        await this.loader.dismiss();
      });
  }

  private onSyllabusChange(): Observable<string[]> {
    return this.syllabusControl.valueChanges.pipe(
      tap(async (value) => {
        if (!Array.isArray(value)) {
          this.syllabusControl.patchValue([value]);
          return;
        }

        if (!value.length) {
          return;
        }

        await this.commonUtilService.getLoader().then((loader) => {
          this.loader = loader;
          this.loader.present();
        });

        try {
          await this.getFrameworkData(value[0]);

          const boardCategoryTermsRequet: GetFrameworkCategoryTermsRequest = {
            frameworkId: this.framework.identifier,
            requiredCategories: [FrameworkCategoryCode.BOARD],
            currentCategoryCode: FrameworkCategoryCode.BOARD,
            language: this.translate.currentLang
          };

          const boards = await this.frameworkUtilService.getFrameworkCategoryTerms(boardCategoryTermsRequet).toPromise();
          this.boardList = boards.map(t => ({ name: t.name, code: t.code }));

          const boardTerm = boards.find(b => b.name === (this.syllabusList.find((s) => s.code === value[0]).name));

          this.boardControl.patchValue([boardTerm.code]);

          const nextCategoryTermsRequet: GetFrameworkCategoryTermsRequest = {
            frameworkId: this.framework.identifier,
            requiredCategories: [FrameworkCategoryCode.MEDIUM],
            prevCategoryCode: FrameworkCategoryCode.BOARD,
            currentCategoryCode: FrameworkCategoryCode.MEDIUM,
            language: this.translate.currentLang,
            selectedTermsCodes: this.boardControl.value
          };
          if(Object.keys(this.supportedProfileAttributes).length == 1  && this.supportedProfileAttributes['board']) {
            this.disableSubmitButton = false;
          }
          this.mediumList = (await this.frameworkUtilService.getFrameworkCategoryTerms(nextCategoryTermsRequet).toPromise())
            .map(t => ({ name: t.name, code: t.code }));
          if (!this.mediumControl.value) {
            this.mediumControl.patchValue((this.profile.medium.length ?  this.profile.medium : this.guestUserProfile.medium) || []);
          } else {
            this.mediumControl.patchValue([]);
          }
        } catch (e) {
          console.error(e);
        } finally {
          this.loader.dismiss();
        }
      })
    );
  }

  private onMediumChange(): Observable<string[]> {
    return this.mediumControl.valueChanges.pipe(
      tap(async () => {
        this.telemetryGeneratorService.generateInteractTelemetry(InteractType.TOUCH, InteractSubtype.SUBMIT_CLICKED,
          Environment.USER, PageId.PROFILE);
        await this.commonUtilService.getLoader().then((loader) => {
          this.loader = loader;
          this.loader.present();
        });

        try {
          const nextCategoryTermsRequet: GetFrameworkCategoryTermsRequest = {
            frameworkId: this.framework.identifier,
            requiredCategories: [FrameworkCategoryCode.GRADE_LEVEL],
            prevCategoryCode: FrameworkCategoryCode.MEDIUM,
            currentCategoryCode: FrameworkCategoryCode.GRADE_LEVEL,
            language: this.translate.currentLang,
            selectedTermsCodes: this.mediumControl.value
          };
          if(Object.keys(this.supportedProfileAttributes).length == 2 && this.supportedProfileAttributes['medium']) {
            this.disableSubmitButton = false;
          }
          this.gradeList = (await this.frameworkUtilService.getFrameworkCategoryTerms(nextCategoryTermsRequet).toPromise())
            .map(t => ({ name: t.name, code: t.code }));
          if (!this.gradeControl.value) {
            this.gradeControl.patchValue((this.profile.grade.length ?  this.profile.grade : this.guestUserProfile.grade) || []);
          } else {
            this.gradeControl.patchValue([]);
          }
        } catch (e) {
          console.error(e);
        } finally {
          this.loader.dismiss();
        }
      })
    );
  }

  private onGradeChange(): Observable<string[]> {
    return this.gradeControl.valueChanges.pipe(
      tap(async () => {
        this.telemetryGeneratorService.generateInteractTelemetry(InteractType.TOUCH, InteractSubtype.SUBMIT_CLICKED,
          Environment.USER, PageId.PROFILE);
        try {
          const nextCategoryTermsRequet: GetFrameworkCategoryTermsRequest = {
            frameworkId: this.framework.identifier,
            requiredCategories: [FrameworkCategoryCode.SUBJECT],
            prevCategoryCode: FrameworkCategoryCode.GRADE_LEVEL,
            currentCategoryCode: FrameworkCategoryCode.SUBJECT,
            language: this.translate.currentLang,
            selectedTermsCodes: this.gradeControl.value
          };

          this.subjectList = (await this.frameworkUtilService.getFrameworkCategoryTerms(nextCategoryTermsRequet).toPromise())
            .map(t => ({ name: t.name, code: t.code }));
          if (!this.subjectControl.value) {
            this.subjectControl.patchValue((this.profile.subject.length ?  this.profile.subject : this.guestUserProfile.subject)  || []);
          } else {
            this.subjectControl.patchValue([]);
          }
        } catch (e) {
          console.error(e);
        } finally {
          this.loader.dismiss();
        }
      })
    );
  }

  /**
   * It will validate the forms and internally call submit method
   */
  onSubmit() {
    const formVal = this.profileEditForm.value;
    if (formVal.boards && !formVal.boards.length && this.syllabusList.length && this.isBoardAvailable) {
      if (this.showOnlyMandatoryFields) {
        this.boardSelect.open();
      } else {
        this.showErrorToastMessage('BOARD');
      }
    } else if (formVal.medium && !formVal.medium.length && this.supportedProfileAttributes['medium']) {
      if (this.showOnlyMandatoryFields) {
        this.mediumSelect.open();
      } else {
        this.showErrorToastMessage('MEDIUM');
      }
    } else if (formVal.grades && !formVal.grades.length && this.supportedProfileAttributes['gradeLevel']) {
      if (this.showOnlyMandatoryFields) {
        this.gradeSelect.open();
      } else {
        this.showErrorToastMessage('CLASS');
      }
    } else {
      this.submitForm(formVal);
    }
  }

  /**
   * Shows Toast Message with `red` color
   * @param fieldName Name of the field in the form
   */
  showErrorToastMessage(fieldName: string) {
    this.btnColor = '#8FC4FF';
    this.commonUtilService.showToast(this.commonUtilService.translateMessage('PLEASE_SELECT', this.commonUtilService
      .translateMessage(fieldName)), false, 'redErrorToast');
  }

  /**
   * It changes the color of the submit button on change of class.
   */
  enableSubmitButton() {
    if (this.profileEditForm.value.grades.length) {
      this.disableSubmitButton = false;
      this.btnColor = '#006DE5';
    } else {
      this.btnColor = '#8FC4FF';
    }
  }

  /**
   * It makes an update API call.
   * @param formVal Object of Form values
   */

  async submitForm(formVal) {
    await this.loader.present();
    const req: UpdateServerProfileInfoRequest = {
      userId: this.profile.uid,
      framework: {}
    };
    if (!this.isBoardAvailable) {
      req.framework['id'] = [this.frameworkId];
    } else if (formVal.syllabus && formVal.syllabus.length) {
      req.framework['id'] = [...formVal.syllabus];
    }
    if (formVal.boards && formVal.boards.length) {
      const code = typeof (formVal.boards) === 'string' ? formVal.boards : formVal.boards[0];
      req.framework['board'] = [this.boardList.find(board => code === board.code).name];
    }
    if (formVal.medium && formVal.medium.length) {
      const Names = [];
      formVal.medium.forEach(element => {
        Names.push(this.mediumList.find(medium => element === medium.code).name);
      });
      req.framework['medium'] = Names;
    }
    if (formVal.grades && formVal.grades.length) {
      const Names = [];
      formVal.grades.forEach(element => {
        Names.push(this.gradeList.find(grade => element === grade.code).name);
      });
      req.framework['gradeLevel'] = Names;
    }
    if (formVal.subjects && formVal.subjects.length) {
      const Names = [];
      formVal.subjects.forEach(element => {
        Names.push(this.subjectList.find(subject => element === subject.code).name);
      });
      req.framework['subject'] = Names;
    }
    this.profileService.updateServerProfile(req).toPromise()
      .then(async () => {
        await this.loader.dismiss();
        this.disableSubmitButton = true;
        await this.categoriesEditService.updateServerProfile(req, this.profile, this.showOnlyMandatoryFields,
          this.shouldUpdatePreference, this.hasFilledLocation, this.noOfStepsToCourseToc);
      }).catch(async (error) => {
        await this.loader.dismiss();
        this.commonUtilService.showToast(this.commonUtilService.translateMessage('PROFILE_UPDATE_FAILED'));
        console.error('Unable to submit:', error);
      });
  }

  refreshSegmentTags() {
    const reqObj: ServerProfileDetailsRequest = {
      userId: this.profile.uid,
      requiredFields: ProfileConstants.REQUIRED_FIELDS,
      from: CachedItemRequestSourceFrom.SERVER
    };
    this.profileService.getServerProfilesDetails(reqObj).toPromise()
      .then(updatedProfile => {
         // ******* Segmentation
        let segmentDetails = JSON.parse(JSON.stringify(updatedProfile.framework));
        Object.keys(segmentDetails).forEach((key) => {
          if (key !== 'id' && Array.isArray(segmentDetails[key])) {
            segmentDetails[key] = segmentDetails[key].map(x => x.replace(/\s/g, '').toLowerCase());
          }
        });
        window['segmentation'].SBTagService.pushTag(segmentDetails, TagPrefixConstants.USER_ATRIBUTE, true);
        let userLocation = [];
        (updatedProfile['userLocations'] || []).forEach(element => {
          userLocation.push({ name: element.name, code: element.code });
        });
        window['segmentation'].SBTagService.pushTag({ location: userLocation }, TagPrefixConstants.USER_LOCATION, true);
        window['segmentation'].SBTagService.pushTag(updatedProfile.profileUserType.type, TagPrefixConstants.USER_LOCATION, true);
        this.segmentationTagService.evalCriteria();
      });
  }

  ionViewWillLeave() {
    if (this.backButtonFunc) {
      this.backButtonFunc.unsubscribe();
    }
  }

  async getLoggedInFrameworkCategory() {
    try {
      const activeChannelDetails: Channel = await this.frameworkService.getChannelDetails(
        { channelId: this.frameworkService.activeChannelId }).toPromise();
      const defaultFrameworkDetails: Framework = await this.frameworkService.getFrameworkDetails({
        frameworkId: activeChannelDetails.defaultFramework, requiredCategories: []
      }).toPromise();
      const activeChannelSuggestedFrameworkList: Framework[] = await this.frameworkUtilService.getActiveChannelSuggestedFrameworkList({
        language: '',
        requiredCategories: []
      }).toPromise();
      this.frameworkId = activeChannelDetails.defaultFramework;
      this.categories = defaultFrameworkDetails.categories;
      const boardCategory = defaultFrameworkDetails.categories.find((c) => c.code === 'board');
      const mediumCategory = defaultFrameworkDetails.categories.find((c) => c.code === 'medium');

      if (boardCategory) {
        this.syllabusList = activeChannelSuggestedFrameworkList.map(f => ({ name: f.name, code: f.identifier }));
        this.isBoardAvailable = true;
        const syllabus = (this.profile.syllabus && this.profile.syllabus[0]) ||
         (this.guestUserProfile.syllabus && this.guestUserProfile.syllabus[0]);
        this.syllabusControl.patchValue([syllabus] || []);
      } else {
        await this.getFrameworkData(this.frameworkId);
        this.categories.unshift([]);
        this.isBoardAvailable = false;
        this.mediumList = mediumCategory.terms;
        this.mediumControl.patchValue((this.profile.medium.length ?  this.profile.medium : this.guestUserProfile.medium) || []);
      }
    } catch (err) {
      if (!this.commonUtilService.networkInfo.isNetworkAvailable) {
        this.commonUtilService.showToast(this.commonUtilService.translateMessage('NEED_INTERNET_TO_CHANGE'));
      }
      console.error('getFrameWorkCategoryOrder', err);
    }
  }

  private async getFrameworkData(frameworkId) {
    this.framework = await this.frameworkService.getFrameworkDetails({
      from: CachedItemRequestSourceFrom.SERVER,
      frameworkId,
      requiredCategories: FrameworkCategoryCodesGroup.DEFAULT_FRAMEWORK_CATEGORIES
    }).toPromise();
  }

  private updateAttributeStreamsnSetValidators(attributes: { [key: string]: string }): Array<any> {
    const subscriptionArray = [];
    Object.keys(attributes).forEach((attribute) => {
      switch (attribute) {
        case 'board':
          subscriptionArray.push(this.onSyllabusChange());
          break;
        case 'medium':
          subscriptionArray.push(this.onMediumChange());
          break;
        case 'gradeLevel':
          subscriptionArray.push(this.onGradeChange());
          break;
      }
    });
    return subscriptionArray;
  }

  goBack() {
    this.location.back();
  }

  async setDefaultBMG() {
    await this.commonUtilService.getGuestUserConfig().then((profile) => {
      this.guestUserProfile = profile;
    });
  }

  private addAttributeSubscription() {
    const subscriptionArray: Array<any> = this.updateAttributeStreamsnSetValidators(this.supportedProfileAttributes);
    this.formControlSubscriptions = combineLatest(subscriptionArray).subscribe();
    if (Object.keys(this.supportedProfileAttributes).length > 0) {
      console.log('disable button ', this.disableSubmitButton);
      this.disableSubmitButton = true;
    }
  }

  private getCategoriesAndUpdateAttributes(userType) {
    this.formAndFrameworkUtilService.getFrameworkCategoryList(userType).then((categories) => {
      if (categories && categories.supportedFrameworkConfig && categories.supportedAttributes) {
        this.frameworkData = categories.supportedFrameworkConfig;
        this.supportedProfileAttributes = categories.supportedAttributes;
        this.addAttributeSubscription();
      }
    });
  }
}
<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start" *ngIf="!isRootPage">
      <ion-button icon-only (click)="goBack()">
        <ion-icon class="arrow-icon back-arrow" role="button" aria-label="back" name="arrow-back"></ion-icon>
      </ion-button>
    </ion-buttons>
    <ion-title role="heading" aria-level="1">{{'EDIT_PROFILE' | translate}}</ion-title>
  </ion-toolbar>
</ion-header>

<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">{{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 ? (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}}">
          {{eachSyllabus?.name | aliased}}
          &lrm;</ion-select-option>
      </ion-select>
    </ion-item>
    <ion-item *ngIf="!!supportedProfileAttributes['medium']">
      <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 ? (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">{{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 ? (frameworkData[2].placeHolder | translateJson):'NO_DATA_FOUND') | translate }}"
        okText="{{'BTN_SUBMIT' | translate}}" cancelText="{{'CANCEL' | translate}}"
        [attr.disabled]="(!gradeList.length || !(profileEditForm.value.medium != ''))"
        (ionChange)="enableSubmitButton();">
        <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="(!showOnlyMandatoryFields || !!supportedProfileAttributes['subject']) && userType!='administrator' && frameworkData.length>3">
      <ion-label position="stacked" class="label-font">{{frameworkData[3].label | translateJson}}</ion-label>
      <ion-select formControlName="subjects" multiple="true" [interfaceOptions]="subjectOptions"
        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}}">
        <ion-select-option *ngFor="let subject of subjectList" value="{{subject?.code}}">{{subject?.name}}
        </ion-select-option>
      </ion-select>
    </ion-item>
  </form>
</ion-content>

<ion-footer>
  <ion-row class="padding-12">
    <ion-col size-md="10" offset-md="1">
      <ion-button expand="block" [ngStyle]="{'background-color': btnColor}"
        [attr.disabled]="profileEditForm.invalid || disableSubmitButton" (click)="onSubmit()">{{'SAVE' | translate}}
      </ion-button>
    </ion-col>
  </ion-row>
</ion-footer>

./categories-edit.page.scss

@import "src/assets/styles/_variables.scss";
:host {
  .label-font {
    font-weight: 600 !important;
    color: map-get($colors, dark_gray) !important;
    font-size: 1.4rem !important;
  }
  .select-text {
    //font-size: 1.2rem !important;
  }
  .select-text:first-letter {
    text-transform: capitalize;
  }

  .custom-footer-background .toolbar-background-ios,
  .custom-footer-background .toolbar-background-md {
    background: unset !important;
  }
  .padding-12 {
    padding: 12px !important;
  }
  .item-select-disabled {
    .label-md {
      color: map-get($colors, medium_gray);
      opacity: 1;
    }
  }
}

.back-arrow{
  font-size: 1.75rem;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""