From 85f68a90b29e86d2af3b5f128c57277d91a58bb8 Mon Sep 17 00:00:00 2001 From: Carter Mayeux <159168644+cmayeux05@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:02:25 -0500 Subject: [PATCH] update api with arduino codes on session load --- client/src/Utils/requests.js | 11 ++ .../src/components/DayPanels/Utils/helpers.js | 10 ++ .../views/Researcher/DayLevelReportView.jsx | 14 ++- .../documentation/1.0.0/classroom.json | 3 + server/api/save/documentation/1.0.0/save.json | 3 + server/api/session/config/routes.json | 8 ++ server/api/session/controllers/session.js | 24 +++- .../session/documentation/1.0.0/session.json | 89 +++++++++++++++ .../api/session/models/session.settings.json | 3 + .../student/documentation/1.0.0/student.json | 3 + .../documentation/1.0.0/submission.json | 3 + .../1.0.0/full_documentation.json | 103 +++++++++++++++++- 12 files changed, 270 insertions(+), 4 deletions(-) diff --git a/client/src/Utils/requests.js b/client/src/Utils/requests.js index 427cb475..c58ee9c3 100644 --- a/client/src/Utils/requests.js +++ b/client/src/Utils/requests.js @@ -569,6 +569,17 @@ export const getSessions = async () => error: 'Sessions could not be retrieved.', }); +export const updateSessionArduino = async(id, arduino) => + makeRequest({ + method: PUT, + path: `${server}/sessions/arduino/${id}`, + data: { + arduino + }, + auth: true, + error: 'stuff did not work lol' + }) + export const getSessionsWithFilter = async (filterOptions) => makeRequest({ method: GET, diff --git a/client/src/components/DayPanels/Utils/helpers.js b/client/src/components/DayPanels/Utils/helpers.js index ca700ef0..936705e4 100644 --- a/client/src/components/DayPanels/Utils/helpers.js +++ b/client/src/components/DayPanels/Utils/helpers.js @@ -8,6 +8,7 @@ import { updateActivityTemplate, } from '../../../Utils/requests'; import { message } from 'antd'; +import { useRef } from 'react'; const AvrboyArduino = window.AvrgirlArduino; @@ -46,6 +47,14 @@ export const getArduino = (workspaceRef, shouldAlert = true) => { return code; }; +export const getArduinoXML = (xml_text, workspaceRef) => { + window.Blockly.Arduino.INFINITE_LOOP_TRAP = null; + let dom = window.Blockly.Xml.textToDom(xml_text); + let workspace = window.Blockly.Xml.domToWorkspace(dom, workspaceRef); + let code = window.Blockly.Arduino.workspaceToCode(workspace) + return code +}; + let intervalId; const compileFail = (setSelectedCompile, setCompileError, msg) => { setSelectedCompile(false); @@ -238,3 +247,4 @@ export const handleUpdateWorkspace = async (id, workspaceRef, blocksList) => { return await updateCCWorkspace(id, xml_text, blocksList); }; + diff --git a/client/src/views/Researcher/DayLevelReportView.jsx b/client/src/views/Researcher/DayLevelReportView.jsx index 9c127d90..942f9b7e 100644 --- a/client/src/views/Researcher/DayLevelReportView.jsx +++ b/client/src/views/Researcher/DayLevelReportView.jsx @@ -1,9 +1,10 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { Link, useParams, useNavigate } from 'react-router-dom'; import NavBar from '../../components/NavBar/NavBar'; -import { getSession } from '../../Utils/requests'; +import { getSession, updateSessionArduino } from '../../Utils/requests'; import './DayLevelReportView.less'; import { confirmRedirect } from '../../App'; +import { getArduinoXML } from '../../components/DayPanels/Utils/helpers'; const DayLevelReportView = () => { const { id } = useParams(); @@ -13,10 +14,17 @@ const DayLevelReportView = () => { const [className, setClassName] = useState([]); const [clicks, setClicks] = useState(0); const navigate = useNavigate(); + const workspaceRef = useRef(null); confirmRedirect(); useEffect(function () { const getData = async () => { const session = await getSession(id); + workspaceRef.current = window.Blockly.inject('root', { + toolbox: document.getElementById('toolbox'), + readOnly: true, + }); + //console.log(getArduinoXML(session.data.saves[session.data.saves.length - 1].workspace, workspaceRef.current)) + updateSessionArduino(session.data.id, getArduinoXML(session.data.saves[session.data.saves.length - 1].workspace, workspaceRef.current)) setSession(session.data); const fetchedStudents = session.data.students[0].name; @@ -35,6 +43,8 @@ const DayLevelReportView = () => { setClicks(fetchedClicks); }; getData(); + + }, []); const timeConverter = (timestamp) => { diff --git a/server/api/classroom/documentation/1.0.0/classroom.json b/server/api/classroom/documentation/1.0.0/classroom.json index cd5a63dc..be744f55 100644 --- a/server/api/classroom/documentation/1.0.0/classroom.json +++ b/server/api/classroom/documentation/1.0.0/classroom.json @@ -865,6 +865,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, diff --git a/server/api/save/documentation/1.0.0/save.json b/server/api/save/documentation/1.0.0/save.json index e9b731ae..b20765c6 100644 --- a/server/api/save/documentation/1.0.0/save.json +++ b/server/api/save/documentation/1.0.0/save.json @@ -727,6 +727,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, diff --git a/server/api/session/config/routes.json b/server/api/session/config/routes.json index b85beb2c..55d1e236 100644 --- a/server/api/session/config/routes.json +++ b/server/api/session/config/routes.json @@ -40,6 +40,14 @@ "policies": [] } }, + { + "method": "PUT", + "path": "/sessions/arduino/:id", + "handler": "session.arduinoUpdate", + "config": { + "policies": [] + } + }, { "method": "DELETE", "path": "/sessions/:id", diff --git a/server/api/session/controllers/session.js b/server/api/session/controllers/session.js index a589b84a..c2181a89 100644 --- a/server/api/session/controllers/session.js +++ b/server/api/session/controllers/session.js @@ -4,5 +4,27 @@ * Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) * to customize this controller */ +const { sanitizeEntity } = require('strapi-utils/lib'); -module.exports = {}; + +module.exports = { + async arduinoUpdate(ctx) { + const {id} = ctx.params; + const {arduino} = ctx.request.body; + const session = await strapi.services.session.findOne({ id }); + console.log(session) + console.log(arduino) + session.arduino = arduino; + const updatedSession = await strapi.services.session.update({id}, session); + return updatedSession + + }, + async findOne(ctx) { + // Extract the ID from the request parameters + const { id } = ctx.params; + // Implement custom logic to fetch a single record by ID + const session = await strapi.services.session.findOne({ id }); + // Customize the response as needed + ctx.send(session); + }, +}; diff --git a/server/api/session/documentation/1.0.0/session.json b/server/api/session/documentation/1.0.0/session.json index 0dae4081..0f724275 100644 --- a/server/api/session/documentation/1.0.0/session.json +++ b/server/api/session/documentation/1.0.0/session.json @@ -510,6 +510,89 @@ } ] } + }, + "/sessions/arduino/{id}": { + "put": { + "deprecated": false, + "description": "Update a record", + "responses": { + "200": { + "description": "response", + "content": { + "application/json": { + "schema": { + "properties": { + "foo": { + "type": "string" + } + } + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Session" + ], + "requestBody": { + "description": "", + "required": true, + "content": { + "application/json": { + "schema": { + "properties": { + "foo": { + "type": "string" + } + } + } + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "deprecated": false, + "required": true, + "schema": { + "type": "string" + } + } + ] + } } }, "components": { @@ -829,6 +912,9 @@ "type": "string" } } + }, + "arduino": { + "type": "string" } } }, @@ -864,6 +950,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, diff --git a/server/api/session/models/session.settings.json b/server/api/session/models/session.settings.json index fc413f39..d869af24 100644 --- a/server/api/session/models/session.settings.json +++ b/server/api/session/models/session.settings.json @@ -35,6 +35,9 @@ }, "learning_standard": { "model": "learning-standard" + }, + "arduino": { + "type": "text" } } } diff --git a/server/api/student/documentation/1.0.0/student.json b/server/api/student/documentation/1.0.0/student.json index 5918a021..4d99c2a7 100644 --- a/server/api/student/documentation/1.0.0/student.json +++ b/server/api/student/documentation/1.0.0/student.json @@ -768,6 +768,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, diff --git a/server/api/submission/documentation/1.0.0/submission.json b/server/api/submission/documentation/1.0.0/submission.json index ac92c18b..3ceca7a7 100644 --- a/server/api/submission/documentation/1.0.0/submission.json +++ b/server/api/submission/documentation/1.0.0/submission.json @@ -594,6 +594,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, diff --git a/server/extensions/documentation/documentation/1.0.0/full_documentation.json b/server/extensions/documentation/documentation/1.0.0/full_documentation.json index 52599929..c270522c 100755 --- a/server/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/server/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "03/06/2024 9:12:04 PM" + "x-generation-date": "04/25/2024 9:59:54 PM" }, "x-strapi-config": { "path": "/documentation", @@ -8220,6 +8220,89 @@ ] } }, + "/sessions/arduino/{id}": { + "put": { + "deprecated": false, + "description": "Update a record", + "responses": { + "200": { + "description": "response", + "content": { + "application/json": { + "schema": { + "properties": { + "foo": { + "type": "string" + } + } + } + } + } + }, + "403": { + "description": "Forbidden", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + }, + "summary": "", + "tags": [ + "Session" + ], + "requestBody": { + "description": "", + "required": true, + "content": { + "application/json": { + "schema": { + "properties": { + "foo": { + "type": "string" + } + } + } + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "description": "", + "deprecated": false, + "required": true, + "schema": { + "type": "string" + } + } + ] + } + }, "/admin/super-admin": { "get": { "deprecated": false, @@ -12133,6 +12216,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, @@ -13374,6 +13460,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, @@ -14015,6 +14104,9 @@ "type": "string" } } + }, + "arduino": { + "type": "string" } } }, @@ -14050,6 +14142,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, @@ -14172,6 +14267,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" }, @@ -14307,6 +14405,9 @@ "learning_standard": { "type": "string" }, + "arduino": { + "type": "string" + }, "created_by": { "type": "string" },