File

src/app/modules/notification/services/group-notification-wrapper/group-notification-wrapper.service.ts

Index

Properties
Methods

Constructor

constructor(configService: ConfigService, router: Router, navigationHelperService: NavigationHelperService)
Parameters :
Name Type Optional
configService ConfigService No
router Router No
navigationHelperService NavigationHelperService No

Methods

handleNavigation
handleNavigation(content, isTrackable, queryParams?)
Parameters :
Name Optional Description
content No
isTrackable No
queryParams Yes

?

Returns : void
navigateNotification
navigateNotification(data, additionalInfo)
Parameters :
Name Optional
data No
additionalInfo No
Returns : { path: string; } | { path?: undefined; }
navigateToActivityToc
navigateToActivityToc(activity, groupId, isAdmin, includeMembers?, includeActivities?, groupActivities?)
Parameters :
Name Optional
activity No
groupId No
isAdmin No
includeMembers Yes
includeActivities Yes
groupActivities Yes
Returns : void
playContent
playContent(content, queryParams?)
Parameters :
Name Optional Description
content No
queryParams Yes

?

Returns : void

Properties

groupCservice
Type : any
Public navigationHelperService
Type : NavigationHelperService
Public router
Type : Router
import { Injectable } from '@angular/core';
import { ConfigService, NavigationHelperService } from '@sunbird/shared';
import { CsModule } from '@project-sunbird/client-services';
import * as _ from 'lodash-es';
import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class GroupNotificationWrapperService {
  groupCservice: any;

  constructor(
    private configService: ConfigService,
    public router: Router,
    public navigationHelperService: NavigationHelperService
  ) {
    this.groupCservice = CsModule.instance.groupService;
  }

  /**
   * @description - decide wheather the notification will redirect to group-detial or activity-toc-page
   * @param  {} data
   * @param  {} additionalInfo
   */
  navigateNotification(data, additionalInfo) {
    const type = _.get(data, 'data.action.type');
    if (type === 'member-added' || type === 'member-exit' || type === 'group-activity-removed') {
      return ({ path: `my-groups/group-details/` + _.get(additionalInfo, 'group.id') });
    }
    if (type === 'group-activity-added') {
      const isAdmin = _.get(additionalInfo, 'groupRole') === 'admin' ? true : false;
      this.navigateToActivityToc(additionalInfo.activity, _.get(additionalInfo, 'group.id'), isAdmin, true, true, true);
    }
    return {};
  }

  /**
   * @description - will redirect to activity toc page based on the activity type
   * @param  {} activity
   * @param  {} groupId
   * @param  {} isAdmin
   */
  navigateToActivityToc(activity, groupId, isAdmin, includeMembers?, includeActivities?, groupActivities?) {
    this.groupCservice.getById(groupId, { includeMembers, includeActivities, groupActivities }).subscribe((groupData) => {
      const Selectedactivity = this.groupCservice.getActivityDataById(groupData, activity);
      if (Selectedactivity) {
        this.playContent(Selectedactivity, { groupId: groupId, isAdmin: isAdmin });
      }
    });
  }

  /**
   * @description - will do the redirection for activity toc based on activity type
   * @param  {} content
   * @param  {} queryParams?
   */
  playContent(content, queryParams?) {
    this.navigationHelperService.storeResourceCloseUrl();
    setTimeout(() => { // setTimeOut is used to trigger telemetry interact event as changeDetectorRef.detectChanges() not working.
      if (content.mimeType === this.configService.appConfig.PLAYER_CONFIG.MIME_TYPE.collection ||
        _.get(content, 'metaData.mimeType') === this.configService.appConfig.PLAYER_CONFIG.MIME_TYPE.collection) {
        if (!content.trackable && content.primaryCategory !== 'Course') {
          this.handleNavigation(content, false, queryParams);
        } else {
          const isTrackable = content.trackable && content.trackable.enabled === 'No' ? false : true;
          this.handleNavigation(content, isTrackable, queryParams);
        }
      } else if (content.mimeType === this.configService.appConfig.PLAYER_CONFIG.MIME_TYPE.ecmlContent) {
        this.router.navigate(['/resources/play/content', content.identifier]);
      } else if (content.mimeType === this.configService.appConfig.PLAYER_CONFIG.MIME_TYPE.questionset) {
        this.router.navigate(['/resources/play/questionset', content.identifier]);
      } else {
        this.router.navigate(['/resources/play/content', content.identifier]);
      }
    }, 0);
  }

  /**
   * @param  {} content
   * @param  {} isTrackable
   * @param  {} queryParams?
   */
  handleNavigation(content, isTrackable, queryParams?) {
    if (!isTrackable) {
      this.router.navigate(['/resources/play/collection', content.courseId || content.identifier],
        { queryParams: { contentType: content.contentType } });
    } else if (content.batchId) {
      this.router.navigate(['/learn/course', content.courseId || content.identifier, 'batch', content.batchId],
        { queryParams });
    } else {
      this.router.navigate(['/learn/course', content.identifier], { queryParams });
    }
  }
}

results matching ""

    No results matching ""