Skip to content

Commit

Permalink
update api with arduino codes on session load
Browse files Browse the repository at this point in the history
  • Loading branch information
cmayeux05 committed Apr 25, 2024
1 parent bf0b4c1 commit 85f68a9
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 4 deletions.
11 changes: 11 additions & 0 deletions client/src/Utils/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions client/src/components/DayPanels/Utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
updateActivityTemplate,
} from '../../../Utils/requests';
import { message } from 'antd';
import { useRef } from 'react';

const AvrboyArduino = window.AvrgirlArduino;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -238,3 +247,4 @@ export const handleUpdateWorkspace = async (id, workspaceRef, blocksList) => {

return await updateCCWorkspace(id, xml_text, blocksList);
};

14 changes: 12 additions & 2 deletions client/src/views/Researcher/DayLevelReportView.jsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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;
Expand All @@ -35,6 +43,8 @@ const DayLevelReportView = () => {
setClicks(fetchedClicks);
};
getData();


}, []);

const timeConverter = (timestamp) => {
Expand Down
3 changes: 3 additions & 0 deletions server/api/classroom/documentation/1.0.0/classroom.json
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@
"learning_standard": {
"type": "string"
},
"arduino": {
"type": "string"
},
"created_by": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions server/api/save/documentation/1.0.0/save.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@
"learning_standard": {
"type": "string"
},
"arduino": {
"type": "string"
},
"created_by": {
"type": "string"
},
Expand Down
8 changes: 8 additions & 0 deletions server/api/session/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
"policies": []
}
},
{
"method": "PUT",
"path": "/sessions/arduino/:id",
"handler": "session.arduinoUpdate",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/sessions/:id",
Expand Down
24 changes: 23 additions & 1 deletion server/api/session/controllers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
89 changes: 89 additions & 0 deletions server/api/session/documentation/1.0.0/session.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -829,6 +912,9 @@
"type": "string"
}
}
},
"arduino": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -864,6 +950,9 @@
"learning_standard": {
"type": "string"
},
"arduino": {
"type": "string"
},
"created_by": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions server/api/session/models/session.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
},
"learning_standard": {
"model": "learning-standard"
},
"arduino": {
"type": "text"
}
}
}
3 changes: 3 additions & 0 deletions server/api/student/documentation/1.0.0/student.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@
"learning_standard": {
"type": "string"
},
"arduino": {
"type": "string"
},
"created_by": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions server/api/submission/documentation/1.0.0/submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@
"learning_standard": {
"type": "string"
},
"arduino": {
"type": "string"
},
"created_by": {
"type": "string"
},
Expand Down
Loading

0 comments on commit 85f68a9

Please sign in to comment.