src/app/modules/learn/components/batch/enroll-batch/enroll-batch.component.ts
OnInit
OnDestroy
AfterViewInit
selector | app-enroll-batch |
templateUrl | ./enroll-batch.component.html |
Properties |
|
Methods |
constructor(router: Router, activatedRoute: ActivatedRoute, courseBatchService: CourseBatchService, resourceService: ResourceService, toasterService: ToasterService, userService: UserService, configService: ConfigService, coursesService: CoursesService, telemetryService: TelemetryService, navigationhelperService: NavigationHelperService, generaliseLabelService: GeneraliseLabelService)
|
||||||||||||||||||||||||||||||||||||
Parameters :
|
enrollToCourse | ||||||
enrollToCourse(batchId?: any)
|
||||||
Parameters :
Returns :
void
|
fetchEnrolledCourseData |
fetchEnrolledCourseData()
|
Returns :
void
|
logAuditEvent |
logAuditEvent()
|
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
redirect |
redirect()
|
Returns :
void
|
setTelemetryData |
setTelemetryData()
|
Returns :
void
|
telemetryLogEvents | ||||||
telemetryLogEvents(status: boolean)
|
||||||
Parameters :
Returns :
void
|
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
|
enrollBatch |
Decorators :
@ViewChild('enrollBatch')
|
Public generaliseLabelService |
Type : GeneraliseLabelService
|
Public modalVisibility |
Default value : true
|
Public navigationhelperService |
Type : NavigationHelperService
|
readMore |
Default value : false
|
Public resourceService |
Type : ResourceService
|
Public router |
Type : Router
|
showEnrollDetails |
Default value : false
|
showLoader |
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
|
tocId |
Type : string
|
Default value : ''
|
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, ViewChild, OnDestroy, AfterViewInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { TelemetryService, IImpressionEventInput, IInteractEventObject, IInteractEventEdata, IAuditEventInput } from '@sunbird/telemetry';
import { Subject } from 'rxjs';
@Component({
selector: 'app-enroll-batch',
templateUrl: './enroll-batch.component.html'
})
export class EnrollBatchComponent implements OnInit, OnDestroy, AfterViewInit {
@ViewChild('enrollBatch') enrollBatch;
batchId: string;
batchDetails: any;
showEnrollDetails = false;
readMore = false;
showLoader = false;
disableSubmitBtn = false;
public unsubscribe = new Subject<void>();
telemetryCdata: Array<{}>;
submitInteractEdata: IInteractEventEdata;
telemetryInteractObject: IInteractEventObject;
/**
* telemetryImpression object for update batch page
*/
telemetryImpression: IImpressionEventInput;
public modalVisibility = true;
tocId = '';
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;
this.courseBatchService.getEnrollToBatchDetails(this.batchId).pipe(
takeUntil(this.unsubscribe))
.subscribe((data) => {
this.batchDetails = data;
this.setTelemetryData();
if (this.batchDetails.enrollmentType !== 'open') {
this.toasterService.error(this.generaliseLabelService.messages.fmsg.m0082);
this.redirect();
}
if (this.activatedRoute.queryParams) {
this.activatedRoute.queryParams.subscribe((queryParams) => {
this.tocId = queryParams && queryParams.textbook;
if (queryParams.autoEnroll) {
this.modalVisibility = false;
this.enrollToCourse(this.batchId);
}
});
}
}, (err) => {
this.toasterService.error(this.resourceService.messages.fmsg.m0054);
this.redirect();
});
});
}
ngOnDestroy() {
if (this.enrollBatch && this.enrollBatch.deny) {
this.enrollBatch.deny();
}
this.unsubscribe.next();
this.unsubscribe.complete();
}
redirect() {
const queryParams = this.tocId ? { textbook: this.tocId } : {};
this.router.navigate(['./'], { relativeTo: this.activatedRoute.parent, queryParams });
}
telemetryLogEvents(status: boolean) {
let level = 'ERROR';
let msg = 'Enrollment to the batch failed';
if (status) {
level = 'SUCCESS';
msg = 'Enrollment to the batch was success';
}
const event = {
context: {
env: 'portal'
},
edata: {
type: 'enroll-batch',
level: level,
message: msg,
pageid: this.router.url.split('?')[0]
}
};
this.telemetryService.log(event);
}
enrollToCourse(batchId?: any) {
this.setTelemetryData();
this.logAuditEvent();
const request = {
request: {
courseId: this.batchDetails.courseId,
userId: this.userService.userid,
batchId: this.batchDetails.identifier
}
};
this.disableSubmitBtn = true;
this.courseBatchService.enrollToCourse(request).pipe(
takeUntil(this.unsubscribe))
.subscribe((data) => {
this.disableSubmitBtn = true;
this.toasterService.success(this.resourceService.messages.smsg.m0036);
this.fetchEnrolledCourseData();
this.telemetryLogEvents(true);
}, (err) => {
this.modalVisibility = true;
this.disableSubmitBtn = false;
this.toasterService.error(this.resourceService.messages.emsg.m0001);
this.telemetryLogEvents(false);
});
}
fetchEnrolledCourseData() {
this.showLoader = true;
setTimeout(() => {
this.coursesService.getEnrolledCourses().pipe(
takeUntil(this.unsubscribe))
.subscribe(() => {
this.disableSubmitBtn = false;
this.showLoader = false;
this.router.navigate(['/learn/course', this.batchDetails.courseId, 'batch', this.batchDetails.identifier],
{ queryParams: { consent: true , textbook: this.tocId || undefined} }).then(() => {
this.telemetryService.syncEvents(false);
window.location.reload();
});
}, (err) => {
this.disableSubmitBtn = false;
this.router.navigate(['/learn']);
});
}, 2000);
}
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: '/enroll/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.submitInteractEdata = {
id: 'enroll-batch-popup',
type: 'click',
pageid: 'course-consumption'
};
this.telemetryCdata = [{ 'type': 'batch', 'id': this.batchDetails.identifier }];
}
logAuditEvent() {
const auditEventInput: IAuditEventInput = {
'context': {
'env': this.activatedRoute.snapshot.data.telemetry.env,
'cdata': [
{ id: this.batchDetails.courseId, type: 'CourseId' },
{ id: this.userService.userid, type: 'UserId' },
{ id: this.batchDetails.identifier, type: 'BatchId' },
]
},
'object': {
'id': this.batchDetails.identifier,
'type': this.activatedRoute.snapshot.data.telemetry.object.type,
'ver': this.activatedRoute.snapshot.data.telemetry.object.ver
},
'edata': {
props: ['courseId', 'userId', 'batchId'],
state: '',
prevstate: ''
}
};
this.telemetryService.audit(auditEventInput);
}
}
<app-modal-wrapper *ngIf="modalVisibility" [config]="{disableClose: true, size: 'normal', panelClass: 'material-modal'}" (dismiss)="redirect()"
#enrollBatch>
<ng-template sbModalContent>
<div class="sb-mat__modal">
<!--Header-->
<div mat-dialog-title class="mb-0 px-16">
<div class="title">{{batchDetails.name}}</div>
<button aria-label="close dialog" mat-dialog-close class="close-btn"></button>
</div>
<!--/Header-->
<!--Content-->
<div class="sb-mat__modal__content">
<div class="ui grid">
<div class="twelve wide column">
<div class="content">
<div class="ui grid">
<div class="ten wide column pl-25">
<div class="ui grid">
<div class="twelve wide column batch-des pb-0"
*ngIf="batchDetails.description">
<label>{{resourceService.frmelmnts.lbl.batchdescription}}</label>
<div *ngIf="batchDetails.description" class="des-content">
<p *ngIf="!readMore"> {{ batchDetails.description |
slice:0:120}}
<span class="ui cardsKnowMore mouse-pointer"
*ngIf="batchDetails.description && batchDetails.description.length > 120 && readMore === false"
tabindex="0"
(click)="readMore = !readMore;">{{resourceService.frmelmnts.lbl.readmore}}</span>
</p>
<p *ngIf="readMore" class="courseStructureDesc"> {{
batchDetails.description}}
<span class="ui cardsKnowMore mouse-pointer" tabindex="0"
(click)="readMore = false;">{{resourceService.frmelmnts.lbl.readless}}</span>
</p>
</div>
</div>
</div>
<div class="ui grid batch-date">
<div class="twelve wide column start-date pb-0">
<label>{{resourceService.frmelmnts.lbl.startdate}}</label>
<span class="pl-10">{{batchDetails.startDate | dateFormat}}</span>
</div>
<div class="twelve wide column end-date" *ngIf="batchDetails.endDate">
<label>{{resourceService.frmelmnts.lbl.enddate}}</label>
<span *ngIf="batchDetails.endDate"
class="pl-10">{{batchDetails.endDate | dateFormat}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--/Content-->
<!--Actions-->
<div class="sb-mat__modal__actions">
<button appTelemetryInteract
[telemetryInteractObject]="{id:batchId , ver : '1.0' , type:'CourseBatch' , rollup:{l1: batchDetails.courseId,l2: batchDetails.identifier}}"
[telemetryInteractEdata]="submitInteractEdata" [telemetryInteractCdata]="telemetryCdata"
[disabled]="disableSubmitBtn" class="sb-btn sb-btn-normal sb-btn-primary"
id="enrollToCourse" tabindex="0" (click)="enrollToCourse()">
{{generaliseLabelService?.frmelmnts?.btn?.enroll}}
</button>
</div>
<!--Actions-->
</div>
</ng-template>
</app-modal-wrapper>
<app-modal-wrapper *ngIf="showLoader" [config]="{disableClose: false, size: 'normal'}">
<ng-template sbModalContent>
<div class="sb-modal">
<div class="transition ui dimmer page modals active visible">
<div class="ui modal transition active visible normal">
<div class="twelve wide column my-20">
<app-loader></app-loader>
</div>
</div>
</div>
</div>
</ng-template>
</app-modal-wrapper>