File

src/app/plugins/profile/components/profile-page/profile-page.component.ts

Metadata

styleUrls profile-page.component.scss
templateUrl profile-page.component.html

Constructor

constructor(cacheService: CacheService, resourceService: any, coursesService: any, toasterService: any, profileService: ProfileService, userService: any, configService: any, router: Router, utilService: any, searchService: any, playerService: any, activatedRoute: ActivatedRoute, orgDetailsService: any, navigationhelperService: any)

Methods

getOrgDetails
getOrgDetails()
Returns: void
convertToString
convertToString(value: any)
Returns: void
getLocationDetails
getLocationDetails(locations: any, type: any)
Returns: void
getContribution
getContribution()
Returns: void
getTrainingAttended
getTrainingAttended()
Returns: void
downloadCert
downloadCert(certificates: any)
Returns: void
toggle
toggle(showMore: any)
Returns: void
toggleCourse
toggleCourse(showMoreCourse: any)
Returns: void
updateProfile
updateProfile(data: any)
Returns: void
openContent
openContent(content: any)
Returns: void
Public prepareVisits
prepareVisits(event: any)
Returns: void
Private getCustodianOrgUser
getCustodianOrgUser()
Returns: void
setInteractEventData
setInteractEventData()
Returns: void

Properties

addRecoveryIdInteractEdata
addRecoveryIdInteractEdata: any
attendedTraining
attendedTraining: object[]
configService
configService: any
contributions
contributions: any[]
courseLimit
courseLimit: any
coursesService
coursesService: any
district
district: string
downloadCertificateEData
downloadCertificateEData: any
editEmailInteractEdata
editEmailInteractEdata: any
editMobileInteractEdata
editMobileInteractEdata: any
editProfileInteractEdata
editProfileInteractEdata: any
editRecoveryIdInteractEdata
editRecoveryIdInteractEdata: any
isCustodianOrgUser
isCustodianOrgUser: boolean
Default value: false
myFrameworkEditEdata
myFrameworkEditEdata: any
navigationhelperService
navigationhelperService: any
orgDetails
orgDetails: any[]
orgDetailsService
orgDetailsService: any
profileModal
profileModal: any
profileService
profileService: ProfileService
resourceService
resourceService: any
roles
roles: string[]
router
router: Router
searchService
searchService: any
showContactPopup
showContactPopup: boolean
Default value: false
showEdit
showEdit: boolean
Default value: false
showEditUserDetailsPopup
showEditUserDetailsPopup: boolean
Default value: false
showMoreRoles
showMoreRoles: boolean
Default value: true
showMoreRolesLimit
showMoreRolesLimit: any
showMoreTrainings
showMoreTrainings: boolean
Default value: true
showRecoveryId
showRecoveryId: boolean
Default value: false
slickModal
slickModal: any
state
state: string
telemetryImpression
telemetryImpression: any
telemetryInteractObject
telemetryInteractObject: any
toasterService
toasterService: any
userFrameWork
userFrameWork: any
userProfile
userProfile: any
userService
userService: any
userSubscription
userSubscription: Subscription
utilService
utilService: any
import { ProfileService } from '../../services';
import { Component, OnInit, ViewChild, OnDestroy, AfterViewInit } from '@angular/core';
import { UserService, SearchService, PlayerService, CoursesService, OrgDetailsService } from '@sunbird/core';
import {
  ResourceService, ConfigService, ServerResponse, IUserProfile, IUserData, ToasterService, UtilService,
  NavigationHelperService
} from '@sunbird/shared';
import { first } from 'rxjs/operators';
import * as _ from 'lodash-es';
import { Subscription } from 'rxjs';
import { IImpressionEventInput, IInteractEventEdata, IInteractEventObject } from '@sunbird/telemetry';
import { ActivatedRoute, Router } from '@angular/router';
import { CacheService } from '../../../../modules/shared/services/cache-service/cache.service';
@Component({
  templateUrl: './profile-page.component.html',
  styleUrls: ['./profile-page.component.scss']
})
export class ProfilePageComponent implements OnInit, OnDestroy, AfterViewInit {

  @ViewChild('profileModal') profileModal;
  @ViewChild('slickModal') slickModal;
  userProfile: any;
  contributions = [];
  attendedTraining: Array<object>;
  roles: Array<string>;
  showMoreRoles = true;
  showMoreTrainings = true;
  isCustodianOrgUser = false;
  showMoreRolesLimit = this.configService.appConfig.PROFILE.defaultShowMoreLimit;
  courseLimit = this.configService.appConfig.PROFILE.defaultViewMoreLimit;
  showEdit = false;
  userSubscription: Subscription;
  orgDetails = [];
  showContactPopup = false;
  showEditUserDetailsPopup = false;
  state: string;
  district: string;
  userFrameWork: any;
  telemetryImpression: IImpressionEventInput;
  myFrameworkEditEdata: IInteractEventEdata;
  editProfileInteractEdata: IInteractEventEdata;
  editMobileInteractEdata: IInteractEventEdata;
  editEmailInteractEdata: IInteractEventEdata;
  downloadCertificateEData: IInteractEventEdata;
  editRecoveryIdInteractEdata: IInteractEventEdata;
  addRecoveryIdInteractEdata: IInteractEventEdata;
  telemetryInteractObject: IInteractEventObject;
  showRecoveryId = false;
  constructor(private cacheService: CacheService, public resourceService: ResourceService, public coursesService: CoursesService,
    public toasterService: ToasterService, public profileService: ProfileService, public userService: UserService,
    public configService: ConfigService, public router: Router, public utilService: UtilService, public searchService: SearchService,
    private playerService: PlayerService, private activatedRoute: ActivatedRoute, public orgDetailsService: OrgDetailsService,
    public navigationhelperService: NavigationHelperService) {
  }

  ngOnInit() {
    this.getCustodianOrgUser();
    this.userSubscription = this.userService.userData$.subscribe((user: IUserData) => {
      if (user.userProfile) {
        this.userProfile = user.userProfile;
        this.state = _.get(_.find(this.userProfile.userLocations, { type: 'state' }), 'name');
        this.district = _.get(_.find(this.userProfile.userLocations, { type: 'district' }), 'name');
        this.userFrameWork = this.userProfile.framework ? _.cloneDeep(this.userProfile.framework) : {};
        this.getOrgDetails();
      }
    });
    this.getContribution();
    this.getTrainingAttended();
    this.setInteractEventData();
  }

  getOrgDetails() {
    let orgList = [];
    this.roles = [];
    _.forEach(this.userProfile.organisations, (org, index) => {
      if (this.userProfile.rootOrgId !== org.organisationId) {
        if (org.locations && org.locations.length === 0) {
          if (this.userProfile.organisations[0].locationIds && this.userProfile.organisations[0].locations) {
            org.locationIds = this.userProfile.organisations[0].locationIds;
            org.locations = this.userProfile.organisations[0].locations;
          }
        }
        orgList.push(org);
      }
      _.forEach(org.roles, (value, key) => {
        if (value !== 'PUBLIC') {
          const roleName = _.find(this.userProfile.roleList, { id: value });
          if (roleName) {
            this.roles.push(roleName['name']);
          }
        }
      });
    });
    this.roles = _.uniq(this.roles);
    orgList = _.sortBy(orgList, ['orgjoindate']);
    this.orgDetails = orgList[0];
  }

  convertToString(value) {
    return _.isArray(value) ? _.join(value, ', ') : undefined;
  }

  getLocationDetails(locations, type) {
    const location: any = _.find(locations, { type: type });
    return location ? location.name : false;
  }

  getContribution(): void {
    const response = this.searchService.searchedContentList;
    const { constantData, metaData, dynamicFields } = this.configService.appConfig.Course.otherCourse;
    if (response) {
      this.contributions = this.utilService.getDataForCard(response.content, constantData, dynamicFields, metaData);
    } else {
      const searchParams = {
        status: ['Live'],
        contentType: this.configService.appConfig.WORKSPACE.contentType,
        params: { lastUpdatedOn: 'desc' }
      };
      const inputParams = { params: this.configService.appConfig.PROFILE.contentApiQueryParams };
      this.searchService.searchContentByUserId(searchParams, inputParams).subscribe((data: ServerResponse) => {
        this.contributions = this.utilService.getDataForCard(data.result.content, constantData, dynamicFields, metaData);
      });
    }
  }

  getTrainingAttended() {
    this.coursesService.enrolledCourseData$.pipe(first()).subscribe(data => {
      this.attendedTraining = _.reverse(_.sortBy(_.filter(data.enrolledCourses, { status: 2 }), val => {
        return _.isNumber(_.get(val, 'completedOn')) ? _.get(val, 'completedOn') : Date.parse(val.completedOn);
      })) || [];
    });
  }

  downloadCert(certificates) {
    _.forEach(certificates, (value, key) => {
      if (key === 0) {
        const request = {
          request: {
            pdfUrl: _.get(value, 'url')
          }
        };
        this.profileService.downloadCertificates(request).subscribe((apiResponse) => {
          const signedPdfUrl = _.get(apiResponse, 'result.signedUrl');
          if (signedPdfUrl) {
            window.open(signedPdfUrl, '_blank');
          } else {
            this.toasterService.error(this.resourceService.messages.emsg.m0076);
          }
        }, (err) => {
          this.toasterService.error(this.resourceService.messages.emsg.m0076);
        });
      }
    });
  }

  toggle(showMore) {
    if (showMore === true) {
      this.showMoreRolesLimit = this.roles.length;
      this.showMoreRoles = false;
    } else {
      this.showMoreRoles = true;
      this.showMoreRolesLimit = this.configService.appConfig.PROFILE.defaultShowMoreLimit;
    }
  }

  toggleCourse(showMoreCourse) {
    if (showMoreCourse === true) {
      this.courseLimit = this.attendedTraining.length;
      this.showMoreTrainings = false;
    } else {
      this.showMoreTrainings = true;
      this.courseLimit = 3;
    }
  }

  updateProfile(data) {
    this.profileService.updateProfile({ framework: data }).subscribe(res => {
      this.userProfile.framework = data;
      this.toasterService.success(this.resourceService.messages.smsg.m0046);
      this.profileModal.modal.deny();
      this.showEdit = false;
    }, err => {
      this.showEdit = false;
      this.toasterService.warning(this.resourceService.messages.emsg.m0012);
      this.profileModal.modal.deny();
      this.cacheService.set('showFrameWorkPopUp', 'installApp');
    });
  }

  openContent(content) {
    this.playerService.playContent(content.data.metaData);
  }

  public prepareVisits(event) {
    const inViewLogs = _.map(event, (content, index) => ({
      objid: content.metaData.courseId ? content.metaData.courseId : content.metaData.identifier,
      objtype: 'course', index: index,
      section: content.section,
    }));
    if (this.telemetryImpression) {
      this.telemetryImpression.edata.visits = inViewLogs;
      this.telemetryImpression.edata.subtype = 'pageexit';
      this.telemetryImpression = Object.assign({}, this.telemetryImpression);
    }
  }
  private getCustodianOrgUser() {
    this.orgDetailsService.getCustodianOrg().subscribe(custodianOrg => {
      if (_.get(this.userService, 'userProfile.rootOrg.rootOrgId') === _.get(custodianOrg, 'result.response.value')) {
        this.isCustodianOrgUser = true;
      }
    });
  }

  setInteractEventData() {
    this.myFrameworkEditEdata = {
      id: 'profile-edit-framework',
      type: 'click',
      pageid: 'profile-read'
    };
    this.editProfileInteractEdata = {
      id: 'profile-edit-address',
      type: 'click',
      pageid: 'profile-read'
    };
    this.editMobileInteractEdata = {
      id: 'profile-edit-mobile',
      type: 'click',
      pageid: 'profile-read'
    };
    this.editEmailInteractEdata = {
      id: 'profile-edit-emailId',
      type: 'click',
      pageid: 'profile-read'
    };
    this.telemetryInteractObject = {
      id: this.userService.userid,
      type: 'User',
      ver: '1.0'
    };
    this.downloadCertificateEData = {
      id: 'profile-download-certificate',
      type: 'click',
      pageid: 'profile-read'
    };
    this.editRecoveryIdInteractEdata = {
      id: 'profile-edit-recoveryId',
      type: 'click',
      pageid: 'profile-read'
    };
    this.addRecoveryIdInteractEdata = {
      id: 'profile-add-recoveryId',
      type: 'click',
      pageid: 'profile-read'
    };
  }

  ngAfterViewInit() {
    setTimeout(() => {
      this.telemetryImpression = {
        context: {
          env: this.activatedRoute.snapshot.data.telemetry.env
        },
        object: {
          id: this.userService.userid,
          type: 'User',
          ver: '1.0'
        },
        edata: {
          type: this.activatedRoute.snapshot.data.telemetry.type,
          pageid: 'profile-read',
          subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
          uri: this.router.url,
          duration: this.navigationhelperService.getPageLoadTime()
        }
      };
    });
  }

  ngOnDestroy() {
    if (this.userSubscription) {
      this.userSubscription.unsubscribe();
    }
  }
}

results matching ""

    No results matching ""