Skip to content

Commit

Permalink
Merge pull request #285 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-2348 feat:Integration of QuML Player in course Planner in admin
  • Loading branch information
itsvick authored Oct 30, 2024
2 parents a75422b + e267ff3 commit 8a49d2e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/pages/players.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +75,7 @@ interface SunbirdPlayerProps {
const players: React.FC<SunbirdPlayerProps> = () => {
const router = useRouter();
const { identifier } = router.query;
const [metadata, setMetadata] = useState<any>();
const [loading, setLoading] = useState(true);
// playerConfig.metadata = pdfMetadata;

useEffect(() => {
Expand All @@ -80,19 +84,29 @@ const players: React.FC<SunbirdPlayerProps> = () => {
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 ? <SunbirdPlayers player-config={playerConfig} /> : null;
return !loading ? <SunbirdPlayers player-config={playerConfig} /> : null;
};

export async function getStaticProps({ locale }: any) {
Expand Down
25 changes: 25 additions & 0 deletions src/services/PlayerService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
3 changes: 3 additions & 0 deletions src/utils/url.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
},
};

0 comments on commit 8a49d2e

Please sign in to comment.