File

src/app/modules/learn/components/batch/unenroll-batch/unenroll-batch.component.ts

Implements

OnInit OnDestroy AfterViewInit

Metadata

Index

Properties
Methods

Constructor

constructor(router: Router, activatedRoute: ActivatedRoute, courseBatchService: CourseBatchService, resourceService: ResourceService, toasterService: ToasterService, userService: UserService, configService: ConfigService, coursesService: CoursesService, telemetryService: TelemetryService, navigationhelperService: NavigationHelperService, generaliseLabelService: GeneraliseLabelService)
Parameters :
Name Type Optional
router Router No
activatedRoute ActivatedRoute No
courseBatchService CourseBatchService No
resourceService ResourceService No
toasterService ToasterService No
userService UserService No
configService ConfigService No
coursesService CoursesService No
telemetryService TelemetryService No
navigationhelperService NavigationHelperService No
generaliseLabelService GeneraliseLabelService No

Methods

fetchParticipantsDetails
fetchParticipantsDetails()
Returns : void
goBackToCoursePage
goBackToCoursePage()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
redirect
redirect()
Returns : void
setTelemetryData
setTelemetryData()
Returns : void
unenrollFromCourse
unenrollFromCourse()
Returns : void

Properties

Public activatedRoute
Type : ActivatedRoute
batchDetails
Type : any
batchId
Type : string
Public configService
Type : ConfigService
Public courseBatchService
Type : CourseBatchService
Public coursesService
Type : CoursesService
disableSubmitBtn
Default value : false
Public generaliseLabelService
Type : GeneraliseLabelService
Public navigationhelperService
Type : NavigationHelperService
readMore
Default value : false
Public resourceService
Type : ResourceService
Public router
Type : Router
showEnrollDetails
Default value : false
submitInteractEdata
Type : IInteractEventEdata
telemetryCdata
Type : Array<literal type>
telemetryImpression
Type : IImpressionEventInput

telemetryImpression object for update batch page

telemetryInteractObject
Type : IInteractEventObject
Public toasterService
Type : ToasterService
Public unsubscribe
Default value : new Subject<void>()
Public userService
Type : UserService
import { takeUntil } from 'rxjs/operators';
import { UserService, CoursesService, GeneraliseLabelService } from '@sunbird/core';
import { ResourceService, ToasterService, ConfigService, NavigationHelperService } from '@sunbird/shared';
import { CourseBatchService } from '../../../services';
import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { IImpressionEventInput } from '@sunbird/telemetry';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import { TelemetryService, IInteractEventObject, IInteractEventEdata } from '@sunbird/telemetry';
@Component({
  selector: 'app-unenroll-batch',
  templateUrl: './unenroll-batch.component.html'
})
export class UnEnrollBatchComponent implements OnInit, OnDestroy, AfterViewInit {
  batchId: string;
  batchDetails: any;
  showEnrollDetails = false;
  readMore = false;
  disableSubmitBtn = false;
  public unsubscribe = new Subject<void>();
  telemetryCdata: Array<{}>;
  submitInteractEdata: IInteractEventEdata;
  telemetryInteractObject: IInteractEventObject;
  /**
	 * telemetryImpression object for update batch page
	*/
  telemetryImpression: IImpressionEventInput;
  constructor(public router: Router, public activatedRoute: ActivatedRoute, public courseBatchService: CourseBatchService,
    public resourceService: ResourceService, public toasterService: ToasterService, public userService: UserService,
    public configService: ConfigService, public coursesService: CoursesService,
    private telemetryService: TelemetryService,
    public navigationhelperService: NavigationHelperService, public generaliseLabelService: GeneraliseLabelService) { }

  ngOnInit() {
    this.activatedRoute.params.subscribe((params) => {
      this.batchId = params.batchId;
      const primaryCategory = _.get(this.activatedRoute, 'snapshot.queryParams.primaryCategory');
      this.telemetryInteractObject = { id: this.batchId, type: primaryCategory || 'Course', ver: '1.0' };
      this.courseBatchService.getEnrollToBatchDetails(this.batchId).pipe(
        takeUntil(this.unsubscribe))
        .subscribe((data) => {
          this.batchDetails = data;
          this.telemetryInteractObject = { id: this.batchId, type: primaryCategory || 'Course', ver: '1.0', rollup: {l1: _.get(data, 'courseId'),
          l2: this.batchId}};
          if (this.batchDetails.enrollmentType !== 'open') {
            this.toasterService.error(this.generaliseLabelService.messages.fmsg.m0082);
            this.redirect();
          }
          this.fetchParticipantsDetails();
          this.setTelemetryData();
        }, (err) => {
          this.toasterService.error(this.resourceService.messages.fmsg.m0054);
          this.redirect();
        });
    });
  }
  ngOnDestroy() {
    this.unsubscribe.next();
    this.unsubscribe.complete();
  }
  redirect() {
    this.router.navigate(['./'], { relativeTo: this.activatedRoute.parent });
  }
  fetchParticipantsDetails() {
    if (!_.isUndefined(this.batchDetails.participants)) {
      const request = {
        filters: {
          identifier: this.batchDetails.participants
        }
      };
      this.courseBatchService.getUserList(request).pipe(
        takeUntil(this.unsubscribe))
        .subscribe((res) => {
          this.batchDetails.participantDetails = res.result.response.content;
          this.showEnrollDetails = true;
        }, (err) => {
          this.toasterService.error(this.resourceService.messages.fmsg.m0056);
          this.redirect();
        });
    } else {
      this.showEnrollDetails = true;
    }
  }
  unenrollFromCourse() {
    this.setTelemetryData();
    const request = {
      request: {
        courseId: this.batchDetails.courseId,
        userId: this.userService.userid,
        batchId: this.batchDetails.identifier
      }
    };
    this.disableSubmitBtn = true;
    this.courseBatchService.unenrollFromCourse(request).pipe(
      takeUntil(this.unsubscribe))
      .subscribe((data) => {
        this.coursesService.revokeConsent.emit();
        this.disableSubmitBtn = true;
        this.toasterService.success(this.resourceService.messages.smsg.m0045);
        this.goBackToCoursePage();
      }, (err) => {
        this.disableSubmitBtn = false;
        this.toasterService.error(this.resourceService.messages.emsg.m0009);
      });
  }
  goBackToCoursePage() {
    const textbook = _.get(this.activatedRoute, 'snapshot.queryParams.textbook');
    const queryParams = textbook ? { textbook } : {};
    this.router.navigate(['/learn/course', this.batchDetails.courseId], { queryParams }).then(() => {
      this.telemetryService.syncEvents(false);
      window.location.reload();
    });
  }
  ngAfterViewInit () {
    setTimeout(() => {
      this.telemetryImpression = {
        context: {
          env: this.activatedRoute.snapshot.data.telemetry.env
        },
        edata: {
          type: this.activatedRoute.snapshot.data.telemetry.type,
          pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
          uri: '/unenroll/batch/' + this.activatedRoute.snapshot.params.batchId,
          duration: this.navigationhelperService.getPageLoadTime()
        },
        object: {
          id: this.activatedRoute.snapshot.params.batchId,
          type: this.activatedRoute.snapshot.data.telemetry.object.type,
          ver: this.activatedRoute.snapshot.data.telemetry.object.ver
        }
      };
    });
  }
  setTelemetryData() {
    this.telemetryCdata = [{ 'type': 'batch', 'id': this.batchDetails.identifier}];
    this.submitInteractEdata = {
      id: 'unenrollBatch',
      type: 'click',
      pageid: 'Unenroll-Batch'
    };
  }
}
<app-modal-wrapper [config]="{disableClose: true, size: 'small'}" (dismiss)="redirect()">
    <ng-template sbModalContent>
        <div class="sb-modal sb-error">
            <div class="transition ui dimmer page modals active visible">
                <div class="ui modal transition active visible small">
                    <button aria-label="close dialog" mat-dialog-close class="mat-close-btn">
                        <span>&times;</span>
                    </button>
                    <!--Header-->
                    <div class="sb-modal-header">
                        {{resourceService.frmelmnts.lbl.unenrollTitle}}
                    </div>
                    <!--/Header-->
                    <!--Content-->
                    <div class="sb-modal-content">
                        {{resourceService.frmelmnts.lbl.unenrollMsg}}
                    </div>
                    <!--/Content-->
                    <!--Actions-->
                    <div class="sb-modal-actions">
                        <button appTelemetryInteract [telemetryInteractObject]="telemetryInteractObject"
                            [telemetryInteractEdata]="submitInteractEdata" [telemetryInteractCdata]="telemetryCdata"
                            class="sb-btn sb-btn-normal sb-btn-error" [disabled]="disableSubmitBtn"
                            id="unenrollFromCourse" tabindex="0" (click)="unenrollFromCourse()">
                            {{generaliseLabelService?.frmelmnts?.btn?.unenroll}}
                        </button>
                        <button class="sb-btn sb-btn-normal sb-btn-outline-error" tabindex="0" mat-dialog-close>
                            {{resourceService?.frmelmnts?.btn?.cancel}}
                        </button>
                    </div>
                    <!--/Actions-->
                </div>
            </div>
        </div>
    </ng-template>
</app-modal-wrapper>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""