Skip to content

Commit

Permalink
all the stuff for updating day template codes with api
Browse files Browse the repository at this point in the history
  • Loading branch information
cmayeux05 committed Jul 16, 2024
1 parent ca599d3 commit 43af739
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getConfirmed } from './Utils/AuthRequests';
import MentorRegister from './views/Mentor/Dashboard/MentorRegister';
import AddMentor from './views/Mentor/Dashboard/AddMentor';
import CodeViz from './views/Researcher/viz';
import CodeDayz from './views/Researcher/dayz';

export function confirmRedirect () {
const navigate = useNavigate();
Expand Down Expand Up @@ -60,6 +61,8 @@ const App = () => {
<AddMentor /></PrivateRoute>} />
<Route path='/viz' element={<PrivateRoute>
<CodeViz /></PrivateRoute>} />
<Route path='/dayz' element={<PrivateRoute>
<CodeDayz /></PrivateRoute>} />
<Route
path='/report'
element={
Expand Down
13 changes: 12 additions & 1 deletion client/src/Utils/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,18 @@ export const updateSessionArduino = async(id, arduino) =>
},
auth: true,
error: 'stuff did not work lol'
})
});

export const updateDayArduino = async(id, arduino) =>
makeRequest({
method: PUT,
path: `${server}/days/arduino/${id}`,
data: {
arduino
},
auth: true,
error: 'stuff did not work lol'
});

export const getSessionsWithFilter = async (filterOptions) =>
makeRequest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
handleCreatorSaveActivity,
handleCreatorSaveDay,
handleUpdateWorkspace,
getArduino,
} from '../../Utils/helpers';
import { message, Spin, Row, Col, Alert, Dropdown, Menu } from 'antd';
import CodeModal from '../modals/CodeModal';
Expand Down Expand Up @@ -124,6 +125,7 @@ export default function ContentCreatorCanvas({
// once the day state is set, set the workspace and save
const setUp = async () => {
dayRef.current = day;

if (!workspaceRef.current && day && Object.keys(day).length !== 0) {
setWorkspace();

Expand All @@ -133,10 +135,15 @@ export default function ContentCreatorCanvas({
window.Blockly.Xml.domToWorkspace(xml, workspaceRef.current);
workspaceRef.current.clearUndo();
}
const my_arduino = getArduino(workspaceRef.current, false);
console.log(my_arduino);
};
setUp();


}, [day, isSandbox]);


const handleCreatorSave = async () => {
// Save day template
if (!isSandbox && !isMentorActivity) {
Expand Down
102 changes: 102 additions & 0 deletions client/src/views/Researcher/dayz.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { message } from 'antd';
import React, { useState, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import NavBar from '../../components/NavBar/NavBar';
import { getArduinoXML } from '../../components/DayPanels/Utils/helpers';
import { getSession, getDay, updateDayArduino } from '../../Utils/requests';
import './dayz.less';
//import { findSuperAdmins } from '../../../../server/extensions/users-permissions/controllers/Auth';


const useFormInput = (initialValue) => {
const [value, setValue] = useState(initialValue);

const handleChange = (e) => {
setValue(e.target.value);
};
return {
value,
onChange: handleChange,
};
};

export default function CodeDayz() {
const rID = useFormInput('');
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const workspaceRef = useRef(null);

const handleLogin = () => {
setLoading(true);
//console.log(rID)
getDay(parseInt(rID.value))
.then((response) => {
//console.log(response)
if (workspaceRef.current) {
workspaceRef.current.dispose()
}
workspaceRef.current = window.Blockly.inject('blockly-box', {
toolbox: document.getElementById('toolbox'),
readOnly: true,
});



if (response.data === '') {
workspaceRef.current.dispose();
message.error('No workspace associated with ID');
setLoading(false);
}
else {
setLoading(false);
//console.log(response.data.template);
workspaceRef.current.dispose();
//console.log(getArduinoXML(response.data.template, workspaceRef.current));
updateDayArduino(parseInt(rID.value), getArduinoXML(response.data.template, workspaceRef.current))
.catch(error => {
console.log(error)
});
}


})
.catch((error) => {
message.error('Please enter a valid workspace ID');
setLoading(false);
workspaceRef.current.dispose();

});
};

return (
<div className='container nav-padding'>
<NavBar />
<div id='content-wrapper'>
<form
id='box'
onKeyPress={(e) => {
if (e.key === 'Enter') handleLogin();
}}
>
<div id='box-title'>Update Day Record</div>
<input
type='email'
{...rID}
placeholder='Day ID'
autoComplete='username'
/>
<input
type='button'
value={loading ? 'Loading...' : 'Update Day'}
onClick={handleLogin}
disabled={loading}
/>



</form>
</div>
<div id='blockly-box'></div>
</div>
);
}
109 changes: 109 additions & 0 deletions client/src/views/Researcher/dayz.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
@import '../../assets/style.less';

.container {
background-color: #colors[primary];
height: 100%;
min-height: 100vh;
width: 100%;
min-width: 100vw;
text-align: center;
}

#content-wrapper {
margin: 12vh auto 8vh auto;
display: inline-block;
}

#box {
width: 300px;
padding: 40px 20px;
background-color: #colors[tertiary];
text-align: center;
border-radius: 15px;
border: 4px solid;
border-color: #colors[secondary];
}

#box-title {
background-color: #colors[secondary];
border-radius: 80px;
width: 80%;
min-height: 8%;
color: #colors[text-secondary];
font-size: 1.5em;
font-weight: bold;
position: relative;
top: -60px;
left: -40px;
line-height: 50px;
text-align: center;
}

#box input[type='text'],
#box input[type='email'],
#box input[type='password'] {
display: block;
background: none;
margin: 20px auto 0px;
border: 2px solid;
border-color: #colors[secondary];
padding: 14px 10px;
width: 200px;
outline: none;
color: #colors[text-primary];
border-radius: 8px;
transition: 0.25s;
}

#box input[type='text']:focus,
#box input[type='email']:focus,
#box input[type='password']:focus {
width: 220px;
}

#box input[type='button'] {
background: darken(#colors[tertiary], 30%);
width: 80%;
display: block;
margin: 0 auto;
border: 2px solid;
border-color: #colors[secondary];
padding: 14px 40px;
outline: none;
color: #colors[text-primary];
background-color: #colors[quaternary];
font-size: 1.2em;
font-weight: 500;
border-radius: 30px;
cursor: pointer;
transition: 0.25s;
position: relative;
bottom: -65px;

&:hover {
background-color: #colors[quinary];
color: #colors[text-primary];
}
}

#box #forgot-password {
margin-top: 10px;
margin-bottom: 0px;
float: none;


&:hover {
cursor: pointer;
}
}
#box #create-account {
margin-top: 15px;
margin-bottom: 0px;
float: none;


&:hover {
cursor: pointer;
}
}

8 changes: 8 additions & 0 deletions server/api/day/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
"policies": []
}
},
{
"method": "PUT",
"path": "/days/arduino/:id",
"handler": "day.arduinoUpdate",
"config": {
"policies": []
}
},
{
"method": "POST",
"path": "/days",
Expand Down
12 changes: 12 additions & 0 deletions server/api/day/controllers/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ module.exports = {
return sanitizeEntity(updatedDay, { model: strapi.models.day });
},

async arduinoUpdate(ctx) {
const {id} = ctx.params;
const {arduino} = ctx.request.body;
const day = await strapi.services.day.findOne({ id });
//console.log(session)
//console.log(arduino)
day.template_code = arduino;
const updatedDay = await strapi.services.day.update({id}, day);
return updatedDay

},

// Update day template and block list
async templateUpdate(ctx) {
// find the day
Expand Down
Loading

0 comments on commit 43af739

Please sign in to comment.