Skip to content
Snippets Groups Projects
Commit 74583c36 authored by Tor Martin Frøberg Wang's avatar Tor Martin Frøberg Wang
Browse files

Made fixes in frontend and backend; leaderboards are now working

parent 0c0ae8a9
No related branches found
No related tags found
3 merge requests!5Ad ci/cs setup,!4Dev,!1Leaderboards
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/tdt4242-base.iml" filepath="$PROJECT_DIR$/.idea/tdt4242-base.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -140,8 +140,9 @@ REST_FRAMEWORK = {
# "rest_framework_simplejwt.authentication.JWTAuthentication",
#),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
),
'rest_framework.authentication.SessionAuthentication',
"rest_framework_simplejwt.authentication.JWTAuthentication"
),
}
AUTH_USER_MODEL = "users.User"
......
......@@ -47,11 +47,11 @@
</form>
<div class="row">
<div class="col-lg">
<h3 class="mt-3">Leaderboards</h3>
<h3 class="mt-3">Leaderboard</h3>
</div>
</div>
<table id="leaderboardstable" class="table table-striped">
<tr><th>#<th>Name<th>Value
<tr><th>Rank<th>Username<th>Score
</table>
</div>
<script src="scripts/defaults.js"></script>
......
......@@ -125,49 +125,41 @@ async function updateExercise(id) {
}
}
async function fetchLeaderBoards() {
async function fetchLeaderBoards(id) {
// Fetches leaderboard data
let response = await sendRequest("GET", `${HOST}/api/leaderboards/${id}/`);
console.log(response.ok);
//Placeholder response and status:
let response = [
{ name: "Mark", value: 301, rank: 1 },
{ name: "Anton", value: 245, rank: 2 },
{ name: "John", value: 112, rank: 3 },
{ name: "Joe", value: 84, rank: 4 },
{ name: "Larry", value: 80, rank: 5 },
{ name: "Glaum", value: 1, rank: 85 },
];
response.ok = true;
let data = await response.json();
if (response.ok) {
let table = document.getElementById("leaderboardstable");
let row, cell;
//The users own score will always be placed last in the JSON response
let userIndex = response.length - 1;
//The user's own score will always be placed last in the JSON response
let userIndex = data.length - 1;
for (let i = 0; i < response.length - 1; i++) {
for (let i = 0; i < data.length - 1; i++) {
row = table.insertRow();
cell = row.insertCell();
cell.textContent = response[i].rank;
cell.textContent = data[i].rank;
cell = row.insertCell();
cell.textContent = response[i].name;
cell.textContent = data[i].name;
cell = row.insertCell();
cell.textContent = response[i].value;
cell.textContent = data[i].value;
}
//If the user is not in top 5, the users score will also be rendered
if (response[userIndex].rank > 5) {
if (data[userIndex].rank > 5) {
row = table.insertRow();
cell = row.insertCell();
cell.textContent = response[userIndex].rank;
cell.textContent = data[userIndex].rank;
cell = row.insertCell();
cell.textContent = response[userIndex].name;
cell.textContent = data[userIndex].name;
cell = row.insertCell();
cell.textContent = response[userIndex].value;
cell.textContent = data[userIndex].value;
}
}
return response;
return data;
}
window.addEventListener("DOMContentLoaded", async () => {
......@@ -183,6 +175,7 @@ window.addEventListener("DOMContentLoaded", async () => {
if (urlParams.has("id")) {
const exerciseId = urlParams.get("id");
await retrieveExercise(exerciseId);
await fetchLeaderBoards(exerciseId);
editButton.addEventListener("click", handleEditExerciseButtonClick);
deleteButton.addEventListener(
......@@ -206,5 +199,5 @@ window.addEventListener("DOMContentLoaded", async () => {
cancelButton.addEventListener("click", handleCancelButtonDuringCreate);
}
await fetchLeaderBoards();
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment