src/app/modules/dashboard/components/course-dashboard/course-dashboard.component.ts
OnInit
OnDestroy
selector | app-course-dashboard |
styleUrls | ./course-dashboard.component.scss |
templateUrl | ./course-dashboard.component.html |
Properties |
|
Methods |
constructor(courseProgressService: CourseProgressService, activatedRoute: ActivatedRoute, userService: UserService, router: Router, navigationhelperService: NavigationHelperService, resourceService: ResourceService, toasterService: ToasterService)
|
||||||||||||||||||||||||
Parameters :
|
getBatchList |
getBatchList()
|
Returns :
void
|
getDashboardData | ||||
getDashboardData(batchList)
|
||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
setImpressionEvent |
setImpressionEvent()
|
Returns :
void
|
updateDashBoardItems |
updateDashBoardItems(title: string, count: number, type: string)
|
Returns :
void
|
courseId |
Type : string
|
Public dashBoardItems |
Type : Array<IDashboardItems>
|
Default value : []
|
Public resourceService |
Type : ResourceService
|
telemetryImpression |
Type : IImpressionEventInput
|
Public unsubscribe$ |
Default value : new Subject<void>()
|
import { NavigationHelperService, ResourceService, ToasterService } from '@sunbird/shared';
import { IImpressionEventInput } from '@sunbird/telemetry';
import { UserService } from '@sunbird/core';
import { Subject } from 'rxjs';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { IDashboardItems } from '../../interfaces';
import * as _ from 'lodash-es';
import { CourseProgressService } from '../../services';
import { ActivatedRoute, Router } from '@angular/router';
import { } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'app-course-dashboard',
templateUrl: './course-dashboard.component.html',
styleUrls: ['./course-dashboard.component.scss']
})
export class CourseDashboardComponent implements OnInit, OnDestroy {
public dashBoardItems: Array<IDashboardItems> = [];
courseId: string;
telemetryImpression: IImpressionEventInput;
public unsubscribe$ = new Subject<void>();
constructor(
private courseProgressService: CourseProgressService,
private activatedRoute: ActivatedRoute,
private userService: UserService,
private router: Router,
private navigationhelperService: NavigationHelperService,
public resourceService: ResourceService,
private toasterService: ToasterService,
) { }
ngOnInit() {
this.activatedRoute.parent.params.pipe(takeUntil(this.unsubscribe$)).subscribe(params => {
this.courseId = _.get(params, 'courseId');
this.getBatchList();
this.setImpressionEvent();
});
}
// To set telemetry impression
setImpressionEvent() {
this.telemetryImpression = {
context: {
env: _.get(this.activatedRoute.snapshot, 'data.telemetry.env')
},
edata: {
type: _.get(this.activatedRoute.snapshot, 'data.telemetry.type'),
pageid: _.get(this.activatedRoute.snapshot, 'data.telemetry.pageid'),
uri: this.router.url,
duration: this.navigationhelperService.getPageLoadTime()
},
object: {
id: this.courseId,
type: _.get(this.activatedRoute.snapshot, 'data.telemetry.object.type'),
ver: _.get(this.activatedRoute.snapshot, 'data.telemetry.object.ver'),
}
};
}
// To get the loggedIn user created batch list for the course
getBatchList() {
const searchParams = {
courseId: this.courseId,
status: ['0', '1', '2'],
createdBy: this.userService.userid
};
this.courseProgressService.getBatches(searchParams).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
this.getDashboardData(_.get(data, 'result.response'));
}, err => {
this.toasterService.error(this.resourceService.messages.emsg.m0005);
});
}
// To get the user enrolled/completed count for the Course
getDashboardData(batchList) {
const batches = _.get(batchList, 'content');
if (batches) {
this.dashBoardItems.push({
title: _.get(this.resourceService, 'frmelmnts.lbl.totalBatches'),
count: _.get(batchList, 'count'),
type: 'small',
});
_.forEach(batches, batch => {
this.updateDashBoardItems(_.get(this.resourceService, 'frmelmnts.lbl.totalCompletions'), _.get(batch, 'completedCount'), 'large');
this.updateDashBoardItems(_.get(this.resourceService, 'frmelmnts.lbl.totalEnrollments'), _.get(batch, 'participantCount'), 'small');
});
}
}
// To update the dashboardItems count
updateDashBoardItems(title: string, count: number, type: string) {
const enrollmentCount = _.find(this.dashBoardItems, { title: title });
if (enrollmentCount) {
enrollmentCount.count += count;
} else {
this.dashBoardItems.push({
title: title,
count: count,
type: type,
});
}
}
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}
<div class="content" [appTelemetryImpression]="telemetryImpression">
<div class="batch-content-area">
<div class="batch-sbcard" *ngFor="let item of dashBoardItems">
<div class="d-flex flex-ai-center flex-jc-center flex-dc p-16 batch-sbcard-content" >
<div class="batch-card-title">{{item?.title}}</div>
<div class="batch-card-number">{{item?.count || 0}}</div>
</div>
</div>
</div>
</div>
./course-dashboard.component.scss
@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
div.content {
height: 100%;
position: relative;
z-index: 1;
margin-top: calculateRem(36px);
@include respond-below(sm) {
margin-left: 0px;
margin-top: 0px;
}
.batch-details {
.img-text {
color: var(--gray-200);
}
}
//cards css
.batch-content-area {
display: grid;
grid-template-areas:
"smallcard largecard"
"smallcard2 largecard";
grid-gap: calculateRem(16px);
grid-template-columns: calculateRem(392px) 1fr;
@include respond-below(sm) {
grid-template-columns: 1fr 2fr;
}
.batch-sbcard {
width: 100%;
border-radius: calculateRem(2px);
background-color: var(--white);
box-shadow: none;
cursor: pointer;
border: calculateRem(2px) solid var(--white);
box-shadow: 0 0.125rem 0.4375rem 0 rgba(var(--rc-rgba-black), .16);
&:nth-child(1) {
grid-area: smallcard;
}
&:nth-child(2) {
grid-area: largecard;
}
&:nth-child(3) {
grid-area: smallcard2;
}
.batch-sbcard-content {
height: 100%;
.batch-card-title {
font-size: calculateRem(14px);
color: var(--gray-100);
}
.batch-card-number {
font-size: calculateRem(36px);
font-weight: bold;
}
.batch-card-total-number {
font-size: calculateRem(72px);
font-weight: bold;
}
}
}
}
}
::ng-deep {
.course-dashboard-select {
width: calculateRem(300px);
}
.ui.selection.dropdown {
line-height: 1em;
}
.ui.search.dropdown.course-dashboard-select>.text {
margin: calculateRem(6px) calculateRem(16px) calculateRem(6px) calculateRem(6px);
}
}