File

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

Metadata

Index

Properties
Methods

Constructor

constructor(profileService: ProfileService, sharedPreferences: SharedPreferences, formService: FormService, commonUtilService: CommonUtilService, appGlobalService: AppGlobalService, headerService: AppHeaderService, location: Location, platform: Platform, telemetryGeneratorService: TelemetryGeneratorService, locationHandler: LocationHandler, formAndFrameworkUtilService: FormAndFrameworkUtilService)
Parameters :
Name Type Optional
profileService ProfileService No
sharedPreferences SharedPreferences No
formService FormService No
commonUtilService CommonUtilService No
appGlobalService AppGlobalService No
headerService AppHeaderService No
location Location No
platform Platform No
telemetryGeneratorService TelemetryGeneratorService No
locationHandler LocationHandler No
formAndFrameworkUtilService FormAndFrameworkUtilService No

Methods

formStatusChanges
formStatusChanges(event)
Parameters :
Name Optional
event No
Returns : void
formValueChanges
formValueChanges(event)
Parameters :
Name Optional
event No
Returns : void
generateTelemetryInteract
generateTelemetryInteract(type, id?)
Parameters :
Name Optional
type No
id Yes
Returns : void
getCreateManagedUserFormApi
getCreateManagedUserFormApi()
Returns : void
handleBackButtonEvents
handleBackButtonEvents()
Returns : void
handleHeaderEvents
handleHeaderEvents($event)
Parameters :
Name Optional
$event No
Returns : void
initializeFormData
initializeFormData()
Returns : void
ionViewDidEnter
ionViewDidEnter()
Returns : void
ionViewWillEnter
ionViewWillEnter()
Returns : void
ionViewWillLeave
ionViewWillLeave()
Returns : void
onCancel
onCancel()
Returns : void
showTncDetails
showTncDetails()
Returns : void
Async submitForm
submitForm()
Returns : any

Properties

Private appName
Type : string
Default value : ''
Private backButtonFunc
Type : Subscription
commonForms
Type : CommonFormsComponent
Decorators :
@ViewChild('commonForms', {static: false})
formInitilized
Default value : false
Private formValue
Type : any
Private headerObservable
Type : any
Public isFormValid
Default value : false
managedUserFormList
Type : any
Default value : []
Private profile
Type : Profile
import { Subscription } from 'rxjs';
import { Component, Inject, ViewChild } from '@angular/core';
import { Platform } from '@ionic/angular';
import {
  Profile,
  ProfileService,
  SharedPreferences,
  CorrelationData,
  FormService,
  CachedItemRequestSourceFrom,
} 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 { Location } from '@angular/common';
import { AddManagedProfileRequest } from '@project-sunbird/sunbird-sdk/profile/def/add-managed-profile-request';
import { CommonFormsComponent } from '@app/app/components/common-forms/common-forms.component';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { Environment, InteractType, ID, PageId, CorReleationDataType, ImpressionType } from '@app/services/telemetry-constants';
import { ProfileConstants } from '@app/app/app.constant';
import {LocationHandler} from '@app/services/location-handler';
import { FormAndFrameworkUtilService } from '@app/services';
import { FormConstants } from '@app/app/form.constants';

@Component({
  selector: 'app-sub-profile-edit',
  templateUrl: './sub-profile-edit.page.html',
  styleUrls: ['./sub-profile-edit.page.scss'],
  providers: [LocationHandler]
})
export class SubProfileEditPage {

  private profile: Profile;
  private appName = '';
  private formValue: any;
  private backButtonFunc: Subscription;
  private headerObservable: any;

  public isFormValid = false;

  formInitilized = false;

  @ViewChild('commonForms', { static: false }) commonForms: CommonFormsComponent;

  managedUserFormList: any = [];

  constructor(
    @Inject('PROFILE_SERVICE') private profileService: ProfileService,
    @Inject('SHARED_PREFERENCES') private sharedPreferences: SharedPreferences,
    @Inject('FORM_SERVICE') private formService: FormService,
    private commonUtilService: CommonUtilService,
    private appGlobalService: AppGlobalService,
    private headerService: AppHeaderService,
    private location: Location,
    private platform: Platform,
    private telemetryGeneratorService: TelemetryGeneratorService,
    private locationHandler: LocationHandler,
    private formAndFrameworkUtilService: FormAndFrameworkUtilService
  ) {
    this.profile = this.appGlobalService.getCurrentUser();

    this.sharedPreferences.getString('app_name').toPromise().then(value => {
      this.appName = value;
    });
  }

  ionViewWillEnter() {
    this.headerService.showHeaderWithBackButton();
    this.handleBackButtonEvents();
    this.headerObservable = this.headerService.headerEventEmitted$.subscribe(eventName => {
      this.handleHeaderEvents(eventName);
    });
    this.telemetryGeneratorService.generateImpressionTelemetry(
      ImpressionType.VIEW,
      '',
      PageId.CREATE_MANAGED_USER,
      Environment.USER,
    );
  }

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

  ionViewDidEnter() {
    this.getCreateManagedUserFormApi();
  }

  getCreateManagedUserFormApi() {
    this.formAndFrameworkUtilService.getFormFields(FormConstants.MANAGED_USER).then((data) => {
      if (data.length) {
        this.managedUserFormList = data;
        this.initializeFormData();
        console.log('this.managedUserFormList', this.managedUserFormList);
      }
    }).catch((error) => {
      console.log(error);
    });
  }

  initializeFormData() {
    for (let index = 0; index < this.managedUserFormList.length; index++) {
      const formDetails: any = this.managedUserFormList[index];
      if (formDetails.code === 'tnc' && formDetails.templateOptions && formDetails.templateOptions.labelHtml &&
        formDetails.templateOptions.labelHtml.contents) {
          formDetails.templateOptions.labelHtml.values['$url'] = this.profile.serverProfile.tncLatestVersionUrl;
          formDetails.templateOptions.labelHtml.values['$appName'] = this.appName + ' ';
      }
    }
    this.formInitilized = true;
  }

  handleBackButtonEvents() {
    this.backButtonFunc = this.platform.backButton.subscribeWithPriority(0, async () => {
      this.telemetryGeneratorService.generateBackClickedTelemetry(
        PageId.CREATE_MANAGED_USER,
        Environment.USER,
        false
      );
      this.location.back();
    });
  }

  async submitForm() {

    if (!this.profile || !this.profile.serverProfile || !this.formValue || !this.formValue.name ) {
      return;
    }

    const cData: Array<CorrelationData> = [
      { id: this.formValue.name, type: CorReleationDataType.NAME },
      { id: this.profile.serverProfile.tncLatestVersion || '', type: CorReleationDataType.TNC_VERSION },
      { id: this.profile.serverProfile['managedBy'] || this.profile.uid || '', type: CorReleationDataType.LIUA }
    ];
    this.generateTelemetryInteract(InteractType.SELECT_ADD, ID.BTN_ADD);

    const loader = await this.commonUtilService.getLoader();
    try {
      await loader.present();
      let parentProfile;
      if (this.profile.serverProfile.managedBy) {
        parentProfile = await this.profileService.getServerProfilesDetails({
          from: CachedItemRequestSourceFrom.CACHE,
          userId: this.profile.serverProfile.managedBy,
          requiredFields: ProfileConstants.REQUIRED_FIELDS
        }).toPromise();
      } else {
        parentProfile = this.profile.serverProfile;
      }
      const userDetails: AddManagedProfileRequest = {
        firstName: this.formValue.name,
        managedBy: parentProfile.userId,
        framework: parentProfile['framework'] || undefined
      };
      const profileLocation = (await this.locationHandler.getAvailableLocation(parentProfile));
      if (userDetails && userDetails.framework && userDetails.framework.subject) {
        userDetails.framework.subject = [];
      }
      if (profileLocation && profileLocation.length) {
        userDetails.profileLocation =  profileLocation;
      }
      const response = await this.profileService.managedProfileManager.addManagedProfile(userDetails).toPromise();
      if (response) {
        this.commonUtilService.showToast('SUCCESSFULLY_ADDED_USER', null, null, null, null, this.formValue.name);
        this.location.back();
      }
      this.generateTelemetryInteract(InteractType.CREATE_SUCCESS, ID.MUA_USER_CREATION);

    } catch (err) {
      this.generateTelemetryInteract(InteractType.CREATE_FAILURE, ID.MUA_USER_CREATION);
      if (err.response.body && err.response.body.params && err.response.body.params.err === 'UOS_USRCRT0066') {
        this.commonUtilService.showToast('FRMELEMNTS_MSG_USER_CREATION_LIMIT_EXCEEDED');
      } else {
        this.commonUtilService.showToast('ERROR_WHILE_ADDING_USER');
      }
    } finally {
      await loader.dismiss();
    }
  }

  onCancel() {
    this.location.back();
    this.generateTelemetryInteract(InteractType.SELECT_CANCEL, ID.BTN_CANCEL);
  }

  showTncDetails() {
    this.commonUtilService.openLink(this.profile.serverProfile.tncLatestVersionUrl);
  }

  handleHeaderEvents($event) {
    if($event.name === 'back')
    {
      this.telemetryGeneratorService.generateBackClickedTelemetry(
        PageId.CREATE_MANAGED_USER,
        Environment.USER,
        true
        );
    }
  }

  generateTelemetryInteract(type, id?) {
    this.telemetryGeneratorService.generateInteractTelemetry(
      type,
      '',
      Environment.USER,
      PageId.CREATE_MANAGED_USER,
      undefined,
      undefined,
      undefined,
      undefined,
      id
    );
  }

  formValueChanges(event) {
    this.formValue = event;
  }

  formStatusChanges(event) {
    this.isFormValid = event.isValid;
  }

}
<ion-content>

  <div>
    <h4 class="sp-title">{{'ADD_USER' | translate}}</h4>
    <div class="text-center MT16">
      <img src="assets/imgs/round_blue_profile.svg" class="sub-profile-img" alt="managed-user-profile" aria-hidden="true">
    </div>
  </div>

  <app-common-forms *ngIf="formInitilized" 
    [config]="managedUserFormList" 
    (valueChanges)="formValueChanges($event)"
    (statusChanges)="formStatusChanges($event)">
  </app-common-forms>
</ion-content>

<ion-footer>
  <ion-row class="padding-12">

    <ion-col>
      <ion-button class="ion-text-capitalize mb-16" expand="block" (click)="onCancel()">
        {{'CANCEL' | translate}}
      </ion-button>
    </ion-col>

    <ion-col>
      <ion-button class="ion-text-capitalize mb-16" expand="block" [disabled]="!isFormValid"
        (click)="submitForm()">{{'ADD_USER' | translate}}
      </ion-button>
    </ion-col>

  </ion-row>
</ion-footer>

./sub-profile-edit.page.scss

@import "src/assets/styles/_variables.scss";
:host {
  .label-font {
    color: map-get($colors, primary_black) !important;
    font-family: "Noto Sans", sans-serif !important;
    font-size: 1.375rem !important;
    font-weight: normal;
  }

  .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;
    }
    ion-select {
      border-color: map-get($colors, primary_black);
    }
  }

  .item-label-stacked ion-select {
    border: 1px solid map-get($colors, thick_blue);
    border-radius: 5px;
    margin-top: 16px;
    padding-left: 8px;
    padding-right: 16px !important;
    font-size: $font-size-base;
    font-family: "Noto Sans Bold", sans-serif;
    .select-icon {
      .select-icon-inner {
        border: solid blue;
        border-width: 0 2px 2px 0;
        display: inline-block;
        padding: 4px;
        transform: rotate(45deg);
        animation: upDownAnimate 5s linear infinite;
        animation-duration: 0.9s;
      }
    }
  }

  .item-label-stacked.item-select-disabled {
    ion-label {
      color: map-get($colors, primary_black);
    }
    ion-select {
      border-color: map-get($colors, primary_black);
      .select-icon {
        .select-icon-inner {
          border-color: map-get($colors, primary_black);
          animation: none;
        }
      }
      .select-placeholder {
        color: map-get($colors, primary_black);
      }
    }
  }

  ion-item {
    --border-color: var(--ion-color-danger, #f1453d);
  }

  ion-button{
    --background: #{$blue} !important;
  }

  .item-label-stacked ion-input {
    border-radius: 5px;
    margin-top: 16px;
    padding-left: 16px !important;
    padding-right: 16px !important;
    font-size: $font-size-base;
  }

  .sp-input-primary ion-input{
    font-weight: bold;
    border: 1px solid map-get($colors, primary);
    --placeholder-opacity: 0.3 !important;
  }

  .sp-input-error ion-input{
    border: 1px solid red;
  }

  ion-item.item-label-stacked {
    --border-width: 0;
    --highlight-background: transparent;
  }
  .item-select ion-label {
    color: map-get($colors, primary);
  }

  ion-label {
    color: map-get($colors, primary_black);
    font-family: "Noto Sans", sans-serif;
    font-size: $font-size-base;
    letter-spacing: 0;
    line-height: 1.188rem;
  }

}

.sp-title{
  font-size: 1rem;
  font-weight: bold;
  color: $blue;
  margin: 16px 16px 0;
}

.sp-input-title{
  color: map-get($colors, primary_black);
  font-family: "Noto Sans", sans-serif;
  font-size: $font-size-base;
  letter-spacing: 0;
  line-height: 1.188rem;
  margin: 16px 0 8px;
}

.sp-input-box{
  border: 0.5px solid map-get($colors, primary_black);
  border-radius: 2px;
  ion-input{
    margin: 0 8px;
  }
}

.sp-error{
  margin-top: 8px;
  display: block;
  font-size: 0.75rem;
  color: red;
  line-height: 0.625rem;
}

.input-item{
  padding-top: 8px;
}

.sp-tnc-text{
  padding: 0 8px;
}

ion-footer{
  ion-button{
    --background: #{$blue} !important;
    height: 2.5rem !important;
    font-family: "Noto Sans", sans-serif;
    font-size: 1rem;
  }
}

.blur-btn {
  opacity: 0.5;
}

.tnc-link {
  color: $blue;
  text-decoration: underline;
}

.sub-profile-img {
  width: 4.875rem;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""