From d33a79a0b041f1d6955df0480da463d929164542 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Tue, 29 Oct 2024 13:06:32 +0530 Subject: [PATCH 1/2] Issue #PS-2348 feat:Integration of QuML Player in course Planner in admin --- src/pages/players.tsx | 26 ++++++++++++++++++++------ src/services/PlayerService.tsx | 25 +++++++++++++++++++++++++ src/utils/url.config.ts | 3 +++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/pages/players.tsx b/src/pages/players.tsx index cd922b7f..763bd6fe 100644 --- a/src/pages/players.tsx +++ b/src/pages/players.tsx @@ -2,7 +2,11 @@ import React, { useEffect, useState } from "react"; import dynamic from "next/dynamic"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { useRouter } from "next/router"; -import { fetchContent } from "@/services/PlayerService"; +import { + fetchContent, + getHierarchy, + getQumlData, +} from "@/services/PlayerService"; import { PlayerConfig } from "@/utils/Interfaces"; // @ts-ignore @@ -71,7 +75,7 @@ interface SunbirdPlayerProps { const players: React.FC = () => { const router = useRouter(); const { identifier } = router.query; - const [metadata, setMetadata] = useState(); + const [loading, setLoading] = useState(true); // playerConfig.metadata = pdfMetadata; useEffect(() => { @@ -80,19 +84,29 @@ const players: React.FC = () => { if (identifier) { console.log("identifier on players page:", identifier); const data = await fetchContent(identifier); - setMetadata(data); console.log("data", data); - playerConfig.metadata = data; - // You can pass identifier to SunbirdPlayers if needed + if (data.mimeType === "application/vnd.sunbird.questionset") { + const Q1 = await getHierarchy(identifier); + console.log("Q1", Q1?.questionset); + const Q2 = await getQumlData(identifier); + console.log("Q2", Q2?.questionset); + const metadata = { ...Q1?.questionset, ...Q2?.questionset }; + playerConfig.metadata = metadata; + console.log("playerConfig", playerConfig); + } else { + playerConfig.metadata = data; + } + setLoading(false); } } catch (error) { console.log(error); + setLoading(false); } }; loadContent(); }, [identifier]); - return metadata ? : null; + return !loading ? : null; }; export async function getStaticProps({ locale }: any) { diff --git a/src/services/PlayerService.tsx b/src/services/PlayerService.tsx index 9c41a05e..26066812 100644 --- a/src/services/PlayerService.tsx +++ b/src/services/PlayerService.tsx @@ -17,3 +17,28 @@ export const fetchContent = async (identifier: any) => { throw error; } }; + +export const getHierarchy = async (identifier: any) => { + try { + const API_URL = `${process.env.NEXT_PUBLIC_WORKSPACE_BASE_URL}${URL_CONFIG.API.HIERARCHY_API}${identifier}`; + const response = await axios.get(API_URL); + console.log("response =====>", response); + return response.data.result; + } catch (error) { + console.error("Error fetching content:", error); + throw error; + } +}; + +export const getQumlData = async (identifier: any) => { + try { + const API_URL = `${process.env.NEXT_PUBLIC_WORKSPACE_BASE_URL}${URL_CONFIG.API.QUESTIONSET_READ}${identifier}`; + const FIELDS = URL_CONFIG.PARAMS.HIERARCHY_FEILDS; + const response = await axios.get(`${API_URL}?fields=${FIELDS}`); + console.log("response =====>", response); + return response.data.result; + } catch (error) { + console.error("Error fetching content:", error); + throw error; + } +}; diff --git a/src/utils/url.config.ts b/src/utils/url.config.ts index 5550edd6..844d8f9b 100644 --- a/src/utils/url.config.ts +++ b/src/utils/url.config.ts @@ -3,8 +3,11 @@ export const URL_CONFIG = { CONTENT_GET: "transcripts,ageGroup,appIcon,artifactUrl,attributions,attributions,audience,author,badgeAssertions,body,channel,code,concepts,contentCredits,contentType,contributors,copyright,copyrightYear,createdBy,createdOn,creator,creators,description,displayScore,domain,editorState,flagReasons,flaggedBy,flags,framework,identifier,itemSetPreviewUrl,keywords,language,languageCode,lastUpdatedOn,license,mediaType,mimeType,name,originData,osId,owner,pkgVersion,publisher,questions,resourceType,scoreDisplayConfig,status,streamingUrl,template,templateId,totalQuestions,totalScore,versionKey,visibility,year,primaryCategory,additionalCategories,interceptionPoints,interceptionType", LICENSE_DETAILS: "name,description,url", + HIERARCHY_FEILDS: "instructions,outcomeDeclaration", }, API: { CONTENT_READ: "/api/content/v1/read/", + HIERARCHY_API: "/action/questionset/v2/hierarchy/", + QUESTIONSET_READ: "/action/questionset/v2/read/", }, }; From e267ff387c76d8e30f3c17d7f65dda2f1bf29f06 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Tue, 29 Oct 2024 18:02:12 +0530 Subject: [PATCH 2/2] Issue #PS-2348 chore : build issue fixed --- src/types/global.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 9c760655..1d634f24 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1,7 +1,9 @@ import { PlayerConfig } from "@/utils/Interfaces"; -interface Window { - GA_INITIALIZED: boolean; +declare global { + interface Window { + GA_INITIALIZED: boolean; + } } declare namespace JSX {