Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C4GT] - Support for Optional Material #8911

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ export class AssessmentPlayerComponent implements OnInit, OnDestroy, ComponentCa

/* istanbul ignore else */
if (_.get(unit, 'children.length')) {
flattenDeepContents = this.courseConsumptionService.flattenDeep(unit.children).filter(item => item.mimeType !== 'application/vnd.ekstep.content-collection');
// exclude optional material in content list of course module
Saurabhbalke marked this conversation as resolved.
Show resolved Hide resolved
flattenDeepContents = this.courseConsumptionService.flattenDeep(unit.children).filter(item => item.mimeType !== 'application/vnd.ekstep.content-collection' && !(item?.relationalMetadata?.optional));
/* istanbul ignore else */
if (this.contentStatus && this.contentStatus.length) {
consumedContents = flattenDeepContents.filter(o => {
Expand All @@ -533,6 +534,8 @@ export class AssessmentPlayerComponent implements OnInit, OnDestroy, ComponentCa
unit.progress = 0;
unit.isUnitConsumptionStart = false;
}
this.consumedContents = this.consumedContents + unit.consumedContent;
this.totalContents = this.totalContents + unit.contentCount;

} else {
const consumedContent = this.contentStatus.filter(({ contentId, status }) => unit.identifier === contentId && status === 2);
Expand All @@ -541,10 +544,13 @@ export class AssessmentPlayerComponent implements OnInit, OnDestroy, ComponentCa
unit.isUnitConsumed = consumedContent.length === 1;
unit.progress = consumedContent.length ? 100 : 0;
unit.isUnitConsumptionStart = Boolean(consumedContent.length);
}

this.consumedContents = this.consumedContents + unit.consumedContent;
this.totalContents = this.totalContents + unit.contentCount;
// exclude optional material in both consumed content and total content in order to calculate course progress
if(!unit?.relationalMetadata?.optional) {
this.consumedContents = this.consumedContents + unit.consumedContent;
this.totalContents = this.totalContents + unit.contentCount;
}
}
this.courseHierarchy.progress = 0;
/* istanbul ignore else */
if (this.consumedContents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {
isConnected = false;
dropdownContent = true;
showForceSync = true;
totalModule=0;
consumedModule =0;
constructor(
public activatedRoute: ActivatedRoute,
private configService: ConfigService,
Expand Down Expand Up @@ -340,10 +342,11 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.unsubscribe))
.subscribe((res) => {
const _parsedResponse = this.courseProgressService.getContentProgressState(req, res);
this.progressToDisplay = Math.floor((_parsedResponse.completedCount / this.courseHierarchy.leafNodesCount) * 100);
this.contentStatus = _parsedResponse.content || [];
this._routerStateContentStatus = _parsedResponse;
this.calculateProgress();
// calculate progress with mandatory course only instead of all content
this.progressToDisplay = Math.floor((this.consumedModule / this.totalModule) * 100);
}, error => {
console.log('Content state read CSL API failed ', error);
});
Expand Down Expand Up @@ -558,6 +561,8 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {

calculateProgress() {
/* istanbul ignore else */
this.totalModule =0;
this.consumedModule =0;
if (_.get(this.courseHierarchy, 'children')) {
this.courseHierarchy.children.forEach(unit => {
if (unit.mimeType === 'application/vnd.ekstep.content-collection') {
Expand All @@ -566,7 +571,7 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {

/* istanbul ignore else */
if (_.get(unit, 'children.length')) {
flattenDeepContents = this.courseConsumptionService.flattenDeep(unit.children).filter(item => item.mimeType !== 'application/vnd.ekstep.content-collection' && item.mimeType !== 'application/vnd.sunbird.question');
flattenDeepContents = this.courseConsumptionService.flattenDeep(unit.children).filter(item => item.mimeType !== 'application/vnd.ekstep.content-collection' && item.mimeType !== 'application/vnd.sunbird.question' && !(item?.relationalMetadata?.optional));
/* istanbul ignore else */
if (this.contentStatus.length) {
consumedContents = flattenDeepContents.filter(o => {
Expand All @@ -576,6 +581,9 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {
}

unit.consumedContent = consumedContents.length;
// count mandatory content in module
this.totalModule = this.totalModule + flattenDeepContents.length;
this.consumedModule = this.consumedModule + consumedContents.length;
unit.contentCount = flattenDeepContents.length;
unit.isUnitConsumed = consumedContents.length === flattenDeepContents.length;
unit.isUnitConsumptionStart = false;
Expand All @@ -595,6 +603,10 @@ export class CoursePlayerComponent implements OnInit, OnDestroy {
unit.isUnitConsumed = consumedContent.length === 1;
unit.progress = consumedContent.length ? 100 : 0;
unit.isUnitConsumptionStart = Boolean(consumedContent.length);
if(!unit?.relationalMetadata?.optional) {
this.totalModule = this.totalModule + unit.consumedContent;
this.consumedModule = this.consumedModule + unit.contentCount;
}
}
});
}
Expand Down