src/app/modules/public/module/course/components/batch/public-batch-details/public-batch-details.component.ts
OnInit
OnDestroy
selector | app-public-batch-details |
styleUrls | ./public-batch-details.component.scss |
templateUrl | ./public-batch-details.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
constructor(browserCacheTtlService: BrowserCacheTtlService, cacheService: CacheService, resourceService: ResourceService, courseBatchService: CourseBatchService, toasterService: ToasterService, router: Router, userService: UserService, telemetryService: TelemetryService, activatedRoute: ActivatedRoute, courseConsumptionService: CourseConsumptionService, generaliseLabelService: GeneraliseLabelService, utilService: UtilService, config: ConfigService, electronService: ElectronService)
|
|||||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
courseHierarchy | |
Type : any
|
|
courseId | |
Type : string
|
|
allBatchDetails | |
Type : EventEmitter
|
|
closeLoginModal |
closeLoginModal()
|
Returns :
void
|
enrollBatch | ||||
enrollBatch(batchId)
|
||||
Parameters :
Returns :
void
|
getAllBatchDetails |
getAllBatchDetails()
|
Returns :
void
|
isEnrollmentAllowed | ||||
isEnrollmentAllowed(enrollmentEndDate)
|
||||
Parameters :
Returns :
any
|
isValidEnrollmentEndDate | ||||
isValidEnrollmentEndDate(enrollmentEndDate)
|
||||
Parameters :
Returns :
boolean
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
setTelemetryData |
setTelemetryData()
|
Returns :
void
|
setUrlToCourse |
setUrlToCourse()
|
Returns :
void
|
showBatchDetails |
showBatchDetails()
|
Returns :
void
|
ShowCertDetails |
ShowCertDetails()
|
Returns :
void
|
Public activatedRoute |
Type : ActivatedRoute
|
Public baseUrl |
Type : string
|
Default value : ''
|
batchDetails |
Type : any
|
batchList |
Type : []
|
Default value : []
|
batchStatus |
Type : Number
|
Public courseBatchService |
Type : CourseBatchService
|
Public courseConsumptionService |
Type : CourseConsumptionService
|
Public electronService |
Type : ElectronService
|
enrollBatchIntractEdata |
Type : IInteractEventEdata
|
enrollToBatch |
Type : any
|
Public generaliseLabelService |
Type : GeneraliseLabelService
|
meritCertPercent |
Type : number
|
Default value : 0
|
Public resourceService |
Type : ResourceService
|
Public router |
Type : Router
|
showBatchDetailsBeforeJoin |
Default value : false
|
showBatchList |
Default value : false
|
showCertificateDetails |
Default value : false
|
showCompletionCertificate |
Default value : false
|
showError |
Default value : false
|
Public showLoginModal |
Default value : false
|
showMeritCertificate |
Default value : false
|
signInInteractEdata |
Type : IInteractEventEdata
|
statusOptions |
Type : []
|
Default value : [
{ name: 'Ongoing', value: 1 },
{ name: 'Upcoming', value: 0 },
{ name: 'Expired', value: 2 }
]
|
telemetryInteractObject |
Type : IInteractEventObject
|
Public telemetryService |
Type : TelemetryService
|
Public toasterService |
Type : ToasterService
|
tocId |
Type : string
|
Default value : ''
|
todayDate |
Default value : dayjs(new Date()).format('YYYY-MM-DD')
|
Public unsubscribe |
Default value : new Subject<void>()
|
Public userService |
Type : UserService
|
Public utilService |
Type : UtilService
|
import { takeUntil } from 'rxjs/operators';
import { CourseBatchService, CourseConsumptionService } from '@sunbird/learn';
import { Router, ActivatedRoute } from '@angular/router';
import { Component, OnInit, Input, OnDestroy, Output, EventEmitter } from '@angular/core';
import { ResourceService, ServerResponse, ToasterService, BrowserCacheTtlService, UtilService, ConfigService } from '@sunbird/shared';
import * as _ from 'lodash-es';
import { Subject } from 'rxjs';
import dayjs from 'dayjs';
import { UserService, GeneraliseLabelService, ElectronService } from '@sunbird/core';
import { CacheService } from '../../../../../../shared/services/cache-service/cache.service';
import { IInteractEventObject, IInteractEventEdata, TelemetryService } from '@sunbird/telemetry';
@Component({
selector: 'app-public-batch-details',
templateUrl: './public-batch-details.component.html',
styleUrls: ['./public-batch-details.component.scss']
})
export class PublicBatchDetailsComponent implements OnInit, OnDestroy {
public unsubscribe = new Subject<void>();
batchStatus: Number;
@Input() courseId: string;
@Input() courseHierarchy: any;
@Output() allBatchDetails = new EventEmitter();
public baseUrl = '';
public showLoginModal = false;
batchList = [];
showError = false;
showBatchList = false;
statusOptions = [
{ name: 'Ongoing', value: 1 },
{ name: 'Upcoming', value: 0 },
{ name: 'Expired', value: 2 }
];
todayDate = dayjs(new Date()).format('YYYY-MM-DD');
signInInteractEdata: IInteractEventEdata;
enrollBatchIntractEdata: IInteractEventEdata;
telemetryInteractObject: IInteractEventObject;
enrollToBatch: any;
tocId = '';
showBatchDetailsBeforeJoin = false;
showCertificateDetails = false;
showCompletionCertificate = false;
showMeritCertificate = false;
meritCertPercent = 0;
batchDetails: any;
constructor(private browserCacheTtlService: BrowserCacheTtlService, private cacheService: CacheService,
public resourceService: ResourceService, public courseBatchService: CourseBatchService, public toasterService: ToasterService,
public router: Router, public userService: UserService, public telemetryService: TelemetryService,
public activatedRoute: ActivatedRoute, public courseConsumptionService: CourseConsumptionService,
public generaliseLabelService: GeneraliseLabelService, public utilService: UtilService, private config: ConfigService,
public electronService: ElectronService) {
this.batchStatus = this.statusOptions[0].value;
}
ngOnInit() {
this.tocId = _.get(this.activatedRoute, 'snapshot.queryParams.textbook');
this.courseConsumptionService.showJoinCourseModal
.pipe(takeUntil(this.unsubscribe))
.subscribe((data) => {
this.baseUrl = `/learn/course/${this.courseId}`;
this.showLoginModal = data;
});
this.getAllBatchDetails();
this.setTelemetryData();
}
getAllBatchDetails() {
this.showBatchList = false;
this.showError = false;
this.batchList = [];
const searchParams: any = {
filters: {
status: this.batchStatus.toString(),
courseId: this.courseId
},
offset: 0,
sort_by: { createdDate: 'desc' }
};
searchParams.filters.enrollmentType = 'open';
this.courseBatchService.getAllBatchDetails(searchParams).pipe(
takeUntil(this.unsubscribe))
.subscribe((data: ServerResponse) => {
this.allBatchDetails.emit(_.get(data, 'result.response'));
if (data.result.response.content && data.result.response.content.length > 0) {
this.batchList = data.result.response.content;
this.showBatchDetails();
this.ShowCertDetails();
}
this.showBatchList = true;
},
(err: ServerResponse) => {
this.showError = true;
this.toasterService.error(this.resourceService.messages?.fmsg?.m0004);
});
}
closeLoginModal() {
this.showLoginModal = false;
let telemetryCdata = [{ 'type': 'Course', 'id': this.courseId }];
if (this.enrollToBatch) {
telemetryCdata = [{ id: this.enrollToBatch, type: 'CourseBatch' }];
}
const interactData = {
context: {
env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env'),
cdata: telemetryCdata
},
edata: {
id: 'join-training-login-popup-close',
type: 'click',
pageid: 'course-details',
},
object: {
id: this.courseId,
type: 'Course',
ver: '1.0'
}
};
this.telemetryService.interact(interactData);
}
isValidEnrollmentEndDate(enrollmentEndDate) {
return !!enrollmentEndDate;
}
isEnrollmentAllowed(enrollmentEndDate) {
return dayjs(enrollmentEndDate).isBefore(this.todayDate);
}
enrollBatch(batchId) {
this.baseUrl = `/learn/course/${this.courseId}?batch=${batchId}&autoEnroll=true`;
if (!this.userService.loggedIn) {
this.showLoginModal = true;
this.enrollToBatch = batchId;
} else {
this.router.navigate([this.baseUrl], { queryParams: { textbook: this.tocId || undefined } });
}
}
setTelemetryData() {
this.signInInteractEdata = {
id: 'signin',
type: 'click',
pageid: 'explore-course',
};
this.enrollBatchIntractEdata = {
id: 'enroll-batch',
type: 'click',
pageid: 'explore-course'
};
this.telemetryInteractObject = {
id: this.courseId,
type: 'explore-course',
ver: '1.0'
};
}
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
setUrlToCourse() {
const queryParam = this.tocId ? `?textbook=${this.tocId}` : '';
if (this.utilService.isDesktopApp) {
this.electronService.get({ url: `${this.config.urlConFig.URLS.OFFLINE.LOGIN}?redirectTo=${this.baseUrl + queryParam}`}).subscribe();
} else {
window.location.href = this.baseUrl + queryParam;
}
}
showBatchDetails() {
this.showBatchDetailsBeforeJoin = this.batchList[0] ? true : false;
this.batchDetails = this.batchList[0];
}
ShowCertDetails() {
if (this.batchList && this.batchList[0]) {
const batchDetails = this.batchList[0];
this.showCertificateDetails = !(_.isEmpty(_.get(batchDetails, 'certTemplates'))) ? true : false;
const certDetails = _.get(batchDetails, 'certTemplates');
for (const key in certDetails) {
const certCriteria = certDetails[key]['criteria'];
this.showCompletionCertificate = _.get(certCriteria, 'enrollment.status') === 2 ? true : false;
this.showMeritCertificate = _.get(certCriteria, 'assessment.score') ? true : false;
this.meritCertPercent = _.get(certCriteria, 'assessment.score.>=');
}
}
}
}
<app-modal-wrapper *ngIf="showLoginModal" [config]="{disableClose: true, size: 'small', panelClass: 'material-modal'}" (dismiss)="closeLoginModal()"
#modal>
<ng-template sbModalContent>
<div class="sb-mat__modal sb-mat__modal--small">
<div mat-dialog-title class="mb-0 px-16">
<div class="title">{{generaliseLabelService?.frmelmnts?.lbl?.accessCourse}}</div>
<button aria-label="close dialog" mat-dialog-close class="close-btn"></button>
</div>
<div class="sb-mat__modal__content sb-join-modal-content">
<div class="fsmall px-0 py-8">
{{generaliseLabelService?.frmelmnts?.lbl?.accessToLogin}}
</div>
</div>
<div class="sb-mat__modal__actions">
<a appTelemetryInteract [telemetryInteractObject]="telemetryInteractObject"
[telemetryInteractEdata]="signInInteractEdata" tabindex="0"
(click)="setTelemetryData(); setUrlToCourse();" class="sb-btn sb-btn-normal sb-btn-primary">
{{resourceService.frmelmnts?.btn?.login}}
</a>
</div>
</div>
</ng-template>
</app-modal-wrapper>
<!-- batch details -->
<mat-accordion class="sb-mat-accordion mb-16">
<mat-expansion-panel [expanded]="true">
<mat-expansion-panel-header>
<mat-panel-title>
{{resourceService?.frmelmnts?.lbl?.batchdetails}}
</mat-panel-title>
</mat-expansion-panel-header>
<div class="sb-mat-accordion__content">
<div class="batch-details">
<div class="mb-16">
<div *ngIf="batchDetails?.startDate">
<div class="content-metadeta__title fsmall font-weight-bold mb-8 sb-color-gray-800">
{{resourceService?.frmelmnts?.lbl?.coursebatchstartdate}}</div>
<div class="content-metadeta__text fnormal sb-color-gray-400">{{batchDetails?.startDate | dateFormat}}
</div>
</div>
<hr class="section-hr" *ngIf="batchDetails?.endDate" />
<div *ngIf="batchDetails?.endDate">
<div class="content-metadeta__title fsmall font-weight-bold mb-8 sb-color-gray-800">
{{resourceService?.frmelmnts?.lbl?.coursebatchenddate}}</div>
<div class="content-metadeta__text fnormal sb-color-gray-400">{{batchDetails?.endDate | dateFormat}}</div>
</div>
<hr class="section-hr" *ngIf="isValidEnrollmentEndDate(batchDetails?.enrollmentEndDate)" />
<div *ngIf="isValidEnrollmentEndDate(batchDetails?.enrollmentEndDate)">
<div class="content-metadeta__title fsmall font-weight-bold mb-8 sb-color-gray-800">
{{resourceService?.frmelmnts?.lbl?.enrollmentenddate}}</div>
<div class="content-metadeta__text fnormal sb-color-gray-400"> {{batchDetails?.enrollmentEndDate |
dateFormat}}</div>
<div class="sb-label-status-error fsmall" *ngIf="isEnrollmentAllowed(batchDetails?.enrollmentEndDate)">
{{resourceService?.messages?.emsg?.m008 | interpolate:'{endDate}':batchDetails?.enrollmentEndDate}}</div>
</div>
</div>
</div>
</div>
</mat-expansion-panel>
</mat-accordion>
<mat-accordion *ngIf="showCertificateDetails" class="sb-mat-accordion mb-16">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title class="sb-mat-accordion__title d-flex flex-ai-center flex-jc-space-between">
{{resourceService?.frmelemnts?.scttl?.certques}}
</mat-panel-title>
</mat-expansion-panel-header>
<div class="sb-mat-accordion__content">
<div class="batch-details">
<div class="mb-16">
<ul>
<li *ngIf="showCompletionCertificate" class="fsmall mb-8 sb-color-gray-800">
{{resourceService?.frmelmnts?.bltpt?.earnyourcert}}</li>
<li *ngIf="showMeritCertificate" class="fsmall mb-8 sb-color-gray-800">
{{resourceService?.frmelemnts?.bltpt?.earnmcert |
interpolate:'{percent}': meritCertPercent}}</li>
</ul>
</div>
</div>
</div>
</mat-expansion-panel>
</mat-accordion>
./public-batch-details.component.scss
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
ul {
list-style-type: none;
padding:0px;margin:0px;
}
li {
display: grid;
grid-template-columns: calculateRem(20px) auto;
justify-content: start;
align-items: center;
margin-bottom:1rem
}
li::before {
content: ">";
font-size: calculateRem(12px);
color: var(--gray-200);
font-weight:bold;
}
::ng-deep {
.sb-modal .ui.modal .sb-join-modal-content.sb-modal-content {
min-height: auto;
}
}