diff --git a/next.config.mjs b/next.config.mjs index bf8aac38..cc6326c7 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -92,6 +92,10 @@ const nextConfig = { source: routes.API.GENERAL.CONTENT_PLUGINS, destination: `${PORTAL_BASE_URL}${routes.API.GENERAL.CONTENT_PLUGINS}`, // Proxy to portal }, + { + source: '/sunbird-plugins/renderer/:path*', + destination: `${process.env.WORKSPACE_BASE_URL}/sunbird-plugins/renderer/:path*`, + }, ]; }, webpack: (config, { isServer }) => { diff --git a/src/components/ContentCard.tsx b/src/components/ContentCard.tsx index 64b93b9d..f2417e17 100644 --- a/src/components/ContentCard.tsx +++ b/src/components/ContentCard.tsx @@ -82,10 +82,19 @@ const ContentCard: React.FC = ({ let status = ''; response.data?.some((item: any) => item.contents?.some((content: any) => { - if (content.contentId === identifier) { - status = content.status || ''; - // status = parseInt(content.percentage, 10); - return true; + if ( + content.contentId === identifier && + (content.contentMime === ContentType.HTML || + content.contentMime === ContentType.H5P) && + content.status === contentStatus.IN_PROGRESS + ) { + status = contentStatus.COMPLETED; + } else { + if (content.contentId === identifier) { + status = content.status || ''; + // status = parseInt(content.percentage, 10); + return true; + } } }) ); @@ -102,6 +111,10 @@ const ContentCard: React.FC = ({ setProgress(0); setStatusMsg(t('CENTER_SESSION.NOTSTARTED')); break; + case '': + setProgress(0); + setStatusMsg(t('CENTER_SESSION.NOTSTARTED')); + break; default: setProgress(0); setStatusMsg(''); @@ -129,7 +142,79 @@ const ContentCard: React.FC = ({ relevantKeys.forEach((key) => { const telemetryEvent = localStorage.getItem(key); if (telemetryEvent) { - detailsObject.push(JSON.parse(telemetryEvent)); + const parsedTelemetryEvent = JSON.parse(telemetryEvent); + let progressFromSummary = null; + let progressFromExtra = null; + const mimeType = parsedTelemetryEvent?.mimeType; + + // Check `summary` for progress + if (parsedTelemetryEvent?.edata?.summary?.length > 0) { + progressFromSummary = + parsedTelemetryEvent.edata.summary[0]?.progress; + } + + // Check `extra` for progress + if (parsedTelemetryEvent?.edata?.extra?.length > 0) { + const progressEntry = parsedTelemetryEvent.edata.extra.find( + (entry: any) => entry.id === 'progress' + ); + if (progressEntry) { + progressFromExtra = parseInt(progressEntry.value, 10); + } + } + + // Skip event if `eid === 'END'` and progress is not 100 in either `summary` or `extra` + if ( + parsedTelemetryEvent?.eid === 'END' && + ((progressFromSummary !== 100 && progressFromSummary !== null) || + (progressFromExtra !== 100 && progressFromExtra !== null)) + ) { + return; + } + + // Push parsed telemetry event + detailsObject.push(parsedTelemetryEvent); + } + }); + + // After processing all keys, check if an END event exists in detailsObject for html or h5p + const requiredMimeTypes = [ContentType.H5P, ContentType.HTML]; + requiredMimeTypes.forEach((type) => { + const hasEndEvent = detailsObject.some( + (event) => event?.eid === 'END' && mimeType === type + ); + + if (!hasEndEvent) { + // Push the default END event for missing types + detailsObject.push({ + eid: 'END', + edata: { + duration: 0, + mode: 'play', + pageid: 'sunbird-player-Endpage', + summary: [ + { + progress: 100, + }, + { + totallength: '', + }, + { + visitedlength: '', + }, + { + visitedcontentend: '', + }, + { + totalseekedlength: '', + }, + { + endpageseen: false, + }, + ], + type: 'content', + }, + }); } }); } @@ -142,7 +227,6 @@ const ContentCard: React.FC = ({ const ContentTypeReverseMap = Object.fromEntries( Object.entries(ContentType).map(([key, value]) => [value, key]) ); - console.log(ContentTypeReverseMap); const reqBody: ContentCreate = { userId: userId, @@ -154,6 +238,7 @@ const ContentCard: React.FC = ({ lastAccessOn: lastAccessOn, detailsObject: detailsObject, }; + console.log('reqBody', reqBody); if (detailsObject.length > 0) { const response = await createContentTracking(reqBody); if (response) { diff --git a/src/pages/course-planner/center/[cohortId].tsx b/src/pages/course-planner/center/[cohortId].tsx index 0f4f92b8..353652c8 100644 --- a/src/pages/course-planner/center/[cohortId].tsx +++ b/src/pages/course-planner/center/[cohortId].tsx @@ -209,7 +209,11 @@ const CoursePlannerDetail = () => { }, [fetchCourseDetails]); const handleBackEvent = () => { - window.history.back(); + if (typeof window !== 'undefined' && window.localStorage) { + const classId = localStorage.getItem('classId'); + router.push(`/course-planner?center=${classId}`); + } + // window.history.back(); logEvent({ action: 'back-button-clicked-attendance-overview', category: 'Attendance Overview Page', diff --git a/src/pages/topic-detail-view.tsx b/src/pages/topic-detail-view.tsx index df000b53..1b7d8e26 100644 --- a/src/pages/topic-detail-view.tsx +++ b/src/pages/topic-detail-view.tsx @@ -43,7 +43,11 @@ const TopicDetailView = () => { const handleBackEvent = () => { // window.history.back(); - router.back(); + if (typeof window !== 'undefined' && window.localStorage) { + const classId = localStorage.getItem('classId'); + router.push(`course-planner/center/${classId}`); + } + // router.back(); logEvent({ action: 'back-button-clicked-attendance-overview', category: 'Attendance Overview Page',