Skip to content

Commit

Permalink
Merge pull request #53 from polyglot-edu/20-new-execution-api-concept
Browse files Browse the repository at this point in the history
20 new execution api concept
  • Loading branch information
tmaog authored Sep 2, 2024
2 parents f67834d + 9b9566b commit 3785874
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 70 deletions.
16 changes: 8 additions & 8 deletions src/controllers/course.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export async function createCourse(req: Request, res: Response) {
return res.status(400).send("userId is required");
}

if(!title) res.status(400).send("title is required");
if (!title) res.status(400).send("title is required");


if(!description) res.status(400).send("description is required");
if (!description) res.status(400).send("description is required");

const user = await User.findById(userId);
if (!user) {
Expand Down Expand Up @@ -47,13 +46,14 @@ export async function createCourse(req: Request, res: Response) {
author: userId,
});

if (flowsId) for (const flow of flowsId) if (flow!=null) course.flows.push(flow);
if (flowsId)
for (const flow of flowsId) if (flow != null) course.flows.push(flow);

console.log(course);
await course.save();
const courseRes = await Course.find({title: course.title})
.populate("author")
.populate("flows");
const courseRes = await Course.find({ title: course.title })
.populate("author")
.populate("flows");

return res.status(201).json(courseRes);
} catch (err) {
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function getCourses(req: Request, res: Response) {
const q = req.query?.q?.toString();
const me = req.query?.me?.toString();
const query: any = q ? { title: { $regex: q, $options: "i" } } : {};

if (me) {
query.author = req.user?._id;
}
Expand Down
58 changes: 28 additions & 30 deletions src/controllers/execution.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ export async function getFlowCtxs(
if (flow.author != userId && userId != "admin")
res.status(400).send("You need to be the author to see the progress");



// Utilizza Object.entries per ottenere un array di coppie [chiave, valore]
const matchingEntries = Object.entries(ctxs).filter(
([key, ctx]) => ctx ? ctx.flowId === flowId : false,
const matchingEntries = Object.entries(ctxs).filter(([key, ctx]) =>
ctx ? ctx.flowId === flowId : false,
);

const matchingCtxs = matchingEntries.map(([key, ctx]) => ({ ctx, key }));
Expand All @@ -172,33 +170,33 @@ export async function getFlowCtxs(
export async function resetExecution(
req: Request<{}, any, ProgressBody>,
res: Response,
next: NextFunction,) {
const { ctxId, authorId } = req.body;

try {
const ctx = ctxs[ctxId];

if (!ctx) {
return res.status(400).json({ error: "Ctx not found!" });
}

const flow = await PolyglotFlowModel.findById(ctx.flowId).populate([
"nodes",
"edges",
]);

if (!flow) return res.status(404).send();

if (flow.author != authorId && authorId != "admin")
res.status(400).send("You need to be the author to reset the progress");

ctxs[ctxId] = undefined;

return res.status(200).json('The user context had been canceled');
} catch (err) {
next(err);
next: NextFunction,
) {
const { ctxId, authorId } = req.body;

try {
const ctx = ctxs[ctxId];

if (!ctx) {
return res.status(400).json({ error: "Ctx not found!" });
}


const flow = await PolyglotFlowModel.findById(ctx.flowId).populate([
"nodes",
"edges",
]);

if (!flow) return res.status(404).send();

if (flow.author != authorId && authorId != "admin")
res.status(400).send("You need to be the author to reset the progress");

ctxs[ctxId] = undefined;

return res.status(200).json("The user context had been canceled");
} catch (err) {
next(err);
}
}

export async function progressExecution(
Expand Down
2 changes: 1 addition & 1 deletion src/execution/plugins/pluginMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { vsCodeExecution, webAppExecution } from "./index";

export function nodeTypeExecution(node: PolyglotNode | null, ctx: string) {
if (node?.platform == "VSCode") return vsCodeExecution(node);
if (node?.platform == "WebApp" || node?.platform == "Eraser" || node?.platform == 'PapyrusWeb')
if (node?.platform == "WebApp" || node?.platform == "Eraser" || node?.platform == "PapyrusWeb")
return webAppExecution(node, ctx);
console.log("not execution run");
return node;
Expand Down
44 changes: 15 additions & 29 deletions src/execution/plugins/webAppExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

type webAppSpecifics = {
webAppSetup: WebAppSetup[];
webAppContent: WebAppContent[];
webAppContent: WebAppContent;
};

//LessonTextNodeData Execution block
Expand All @@ -24,9 +24,7 @@ function lessonTextNodeExecution(node: PolyglotNode) {
const data = node.data as LessonTextNodeData;
const webAppSetup: WebAppSetup[] = [];

const webAppContent: WebAppContent[] = [
{ content: data, type: "LessonText" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -41,9 +39,7 @@ function readMaterialNodeExecution(node: PolyglotNode) {

const webAppSetup: WebAppSetup[] = [];

const webAppContent: WebAppContent[] = [
{ content: data, type: "ReadMaterial" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -57,9 +53,7 @@ function closeEndedQuestionNodeExecution(node: PolyglotNode) {

const webAppSetup: WebAppSetup[] = [];

const webAppContent: WebAppContent[] = [
{ content: data, type: "CloseEndedQuestion" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -73,9 +67,7 @@ function openQuestionNodeExecution(node: PolyglotNode) {

const webAppSetup: WebAppSetup[] = [];

const webAppContent: WebAppContent[] = [
{ content: data, type: "OpenQuestion" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -87,9 +79,7 @@ function openQuestionNodeExecution(node: PolyglotNode) {
function multipleChoiceQuestionNodeExecution(node: PolyglotNode) {
const data = node.data as MultipleChoiceQuestionNodeData;
const webAppSetup: WebAppSetup[] = [];
const webAppContent: WebAppContent[] = [
{ content: data, type: "MultChoiceQuestion" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -101,7 +91,7 @@ function multipleChoiceQuestionNodeExecution(node: PolyglotNode) {
function trueFalseNodeExecution(node: PolyglotNode) {
const data = node.data as TrueFalseNodeData;
const webAppSetup: WebAppSetup[] = [];
const webAppContent: WebAppContent[] = [{ content: data, type: "TrueFalse" }];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -113,9 +103,7 @@ function trueFalseNodeExecution(node: PolyglotNode) {
function watchVideoNodeExecution(node: PolyglotNode) {
const data = node.data as TextLinkNodeData;
const webAppSetup: WebAppSetup[] = [];
const webAppContent: WebAppContent[] = [
{ content: data, type: "WatchVideo" },
];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -126,7 +114,7 @@ function watchVideoNodeExecution(node: PolyglotNode) {
function summaryNodeExecution(node: PolyglotNode) {
const data = node.data as TextLinkNodeData;
const webAppSetup: WebAppSetup[] = [];
const webAppContent: WebAppContent[] = [{ content: data, type: "Summary" }];
const webAppContent: WebAppContent = { content: data };

return {
webAppSetup,
Expand All @@ -136,14 +124,12 @@ function summaryNodeExecution(node: PolyglotNode) {

function notImplementedNodeExecution(node: PolyglotNode) {
const webAppSetup: WebAppSetup[] = [];
const webAppContent: WebAppContent[] = [
{
const webAppContent: WebAppContent = {
content:
"This node type is not implemented for WebApp execution, go to: " +
node.platform,
type: node.type,
},
];
};

return {
webAppSetup,
Expand All @@ -152,19 +138,19 @@ function notImplementedNodeExecution(node: PolyglotNode) {
}

export function webAppExecution(node: PolyglotNode, ctx: string) {
if (node.platform == "Eraser") {
if (node.platform == "Eraser" || node.platform == "PapyrusWeb") {
const challengeSetup: ChallengeSetup[] = [];

const challengeContent: ChallengeContent[] = [
{
type: "markdown",
content:
"You can do this activity in Eraser, please go in our workadventure world to complete it.",
"You can do this activity in WorkAdventure, please go in our world to complete it.",
},
];
const webAppSpecifics: webAppSpecifics = {
webAppSetup: [],
webAppContent: [{ content: node.data, type: "Collaborative" }],
webAppContent: { content: node.data, type: "Collaborative" },
};
return {
...node,
Expand All @@ -189,7 +175,7 @@ export function webAppExecution(node: PolyglotNode, ctx: string) {
" !",
},
];
let webAppSpecifics: webAppSpecifics = { webAppSetup: [], webAppContent: [] };
let webAppSpecifics: webAppSpecifics = { webAppSetup: [], webAppContent: {content: ''} };
if (node?.type == "multipleChoiceQuestionNode")
webAppSpecifics = multipleChoiceQuestionNodeExecution(node);
if (node?.type == "lessonTextNode")
Expand Down
15 changes: 13 additions & 2 deletions src/models/node.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,22 @@ export const CollaborativeModelingNodeSchema = new mongoose.Schema(

export const UMLModelingNodeSchema = new mongoose.Schema(
{
data:{
data: {
assignment: { type: String },
title: { type: String },
idUML: { type: String },
projectUML: { type: String },
typeExercise: { type: String },
mode: { type: String },
tags: [
{
type: {
name: { type: String },
color: { type: String },
_id: { type: String },
},
default: [],
},
],
},
},
options,
Expand Down

0 comments on commit 3785874

Please sign in to comment.