Skip to content

Commit

Permalink
Merge pull request #81 from MatsMoll/develop
Browse files Browse the repository at this point in the history
New release LectureNote sessions
  • Loading branch information
MatsMoll authored Oct 7, 2020
2 parents 03497c8 + 1229f07 commit e71382d
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 40 deletions.
36 changes: 28 additions & 8 deletions Public/assets/js/flash-card/draft/create.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

function createDraft() {
try {
jsonData().then(function (jsonData){
fetch("/api/notes", {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: jsonData()
body: jsonData
})
.then(function (response) {
if (response.ok) {
Expand All @@ -21,12 +21,10 @@ function createDraft() {
.then(function (json) {
fetchNote(parseInt(json));
})
.catch(function (error) {
presentErrorMessage(error.message);
});
} catch(error) {
})
.catch(function (error) {
presentErrorMessage(error.message);
}
});
}

function fetchNote(id) {
Expand Down Expand Up @@ -80,7 +78,6 @@ function editJsonData() {
}

function resetCreateForm() {
$("#card-topic-id").val("");
$("#card-question").val("");
solution.value("");
}
Expand Down Expand Up @@ -130,4 +127,27 @@ function subjectID() {
path.indexOf(splitURI) + splitURI.length,
path.lastIndexOf("/tasks/")
));
}

function createSession() {
return fetch("/api/note-taking-sessions", {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
}
})
.then(function (response) {
if (response.ok) {
return response.json();
} else if (response.status == 400) {
throw new Error("Sjekk at all nødvendig info er fylt ut");
} else {
throw new Error(response.statusText);
}
})
.then(function (json) {
$("#note-session").val(json["id"]);
return json
})
}
47 changes: 31 additions & 16 deletions Public/assets/js/flash-card/draft/json-data.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
function jsonData() {
let noteSession = $("#note-session").val();
var subtopicId = parseInt($("#card-topic-id").val());
var question = $("#card-question").val();
var solutionValue = solution.value();

if (isNaN(subtopicId) || subtopicId < 1) {
throw Error("Velg et tema");
}
if (question.length < 1) {
throw Error("Du må skrive inn et spørsmål");
}
return new Promise(function (resolve, reject) {
let noteSession = $("#note-session").val();

return JSON.stringify({
"noteSession" : noteSession,
"subtopicID" : subtopicId,
"question" : question,
"solution" : solutionValue
});
var subtopicId = parseInt($("#card-topic-id").val());
var question = $("#card-question").val();
var solutionValue = solution.value();

if (isNaN(subtopicId) || subtopicId < 1) {
reject(Error("Velg et tema"));
}
if (question.length < 1) {
reject(Error("Du må skrive inn et spørsmål"));
}

if (noteSession == "" || noteSession == null) {
createSession().then(function (json) {
resolve(JSON.stringify({
"noteSession" : json["id"],
"subtopicID" : subtopicId,
"question" : question,
"solution" : solutionValue
}))
})
} else {
resolve(JSON.stringify({
"noteSession" : noteSession,
"subtopicID" : subtopicId,
"question" : question,
"solution" : solutionValue
}))
}
})
}
6 changes: 3 additions & 3 deletions Public/assets/js/flash-card/submit-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var now = new Date();

var isSubmitting = false;
var hasSubmittedSucessfully = false;
var knowledgeScore = 0;
var knowledgeScore = 2;
var didSubmitt = false;

var nextIndex=1;
Expand Down Expand Up @@ -163,7 +163,7 @@ function estimatedScore(shouldSetScore) {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: answerJsonData("1")
body: answerJsonData("3")
})
.then(function (response) {
if (response.ok) {
Expand All @@ -187,7 +187,7 @@ function estimatedScore(shouldSetScore) {
} else if (roundedScore >= 2) {
text += " kan noe 🙌"
} else {
text += " burde lese litt mer 🤔"
text += " kanskje burde lese litt mer 🤔"
}

$("#estimate-spinner").addClass("d-none");
Expand Down
34 changes: 34 additions & 0 deletions Public/assets/js/lecture-note-recap-session/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

function recapSessionJsonData() {
let sessionID = $("#note-session").val();
let numberOfNotes = Math.min($("#notes").children.length, 5);

return JSON.stringify({
"sessionID": sessionID,
"numberOfTasks": numberOfNotes
})
}

function startRecapSession() {
fetch("/api/lecture-note-recap", {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: recapSessionJsonData()
})
.then(function (response) {
if (response.ok) {
console.log(response);
return response.json();
} else if (response.status == 400) {
throw new Error("Sjekk at all nødvendig info er fylt ut");
} else {
throw new Error(response.statusText);
}
})
.then(function (sessionID) {
window.location = "/lecture-note-recap/" + sessionID + "/tasks/0";
})
}
183 changes: 183 additions & 0 deletions Public/assets/js/lecture-note-recap-session/submit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
var startDate = new Date();
var now = new Date();

var isSubmitting = false;
var hasSubmittedSucessfully = false;
var knowledgeScore = 2;
var didSubmitt = false;

function revealSolution() {
didSubmitt = $("#solution").hasClass("d-none");
presentControllsAndKnowledge();

if ($("#solution").hasClass("d-none")) {
now = new Date();
$("#nextButton").removeClass("d-none");
var goalValue = parseFloat($("#goal-value").text());
var porgressBarValue = parseFloat($("#goal-progress-bar").attr("aria-valuenow"))
var currentCompleted = porgressBarValue / 100 * goalValue;
var progress = parseInt(Math.ceil((currentCompleted + 1) * 100 / goalValue));

if (!isNaN(progress)) {
$("#goal-progress-label").text(progress + "% ");
$("#goal-progress-bar").attr("aria-valuenow", progress);
$("#goal-progress-bar").attr("style", "width: " + progress + "%;");
if (progress >= 100) {
$("#goal-progress-bar").addClass("bg-success");
}
}
submitPerformance(knowledgeScore)
}
}

function updateScoreButton() {
if (knowledgeScore < 2) {
$("#" + knowledgeScore).attr("class", "btn btn-danger");
} else if (knowledgeScore < 4) {
$("#" + knowledgeScore).attr("class", "btn btn-warning");
} else {
$("#" + knowledgeScore).attr("class", "btn btn-success");
}
}

function registerScore(score) {
$("#" + knowledgeScore).attr("class", "btn btn-light");
knowledgeScore = score;
updateScoreButton()
submitPerformance(knowledgeScore)
}

function submitAndEndSession() {
endSession()
}

function submitPerformance(score) {

if (isSubmitting) {
return
}
isSubmitting = true;

var url = "/api/lecture-note-recap/" + sessionID() + "/tasks/" + taskIndex() + "/submit";

fetch(url, {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: answerJsonData(score)
})
.then(function (response) {
isSubmitting = false;
if (response.ok) {
return
} else {
throw new Error(response.statusText);
}
})
.catch(function (error) {
isSubmitting = false;
$("#submitButton").attr("disabled", false);
$("#error-massage").text(error.message);
$("#error-div").fadeIn();
$("#error-div").removeClass("d-none");
});
}

function presentControlls() {
estimatedScore(didSubmitt);
$("#flash-card-answer").prop('readonly', true)
$("#submitButton").prop('disabled', true)
$("#nextButton").removeClass("d-none");
$(".reveal").each(function () {
$(this).fadeIn();
$(this).removeClass("d-none");
});
fetchSolutions();
$("#knowledge-card").removeClass("d-none");
updateScoreButton()
}

function presentControllsAndKnowledge() {
presentControlls()
hasSubmitted = false;
hasSubmittedSucessfully = false;
}


Number.prototype.toMinuteString = function() {
var minutes = Math.floor((this % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((this % (1000 * 60)) / 1000);
if (minutes < 10) { minutes = "0" + minutes; }
if (seconds < 10) { seconds = "0" + seconds; }
return minutes + ":" + seconds;
}

function endSession() {
$("#end-session-form").submit();
}

function answerJsonData(score) {
var timeUsed = (now.getTime() - startDate.getTime()) / 1000;
let knowledge = parseFloat(score);
let submitedAnswer = $("#flash-card-answer").val();

if (knowledge == null) {
return
}
return JSON.stringify({
"timeUsed" : timeUsed,
"knowledge": knowledge / 4,
"answer": submitedAnswer
});
}

function estimatedScore(shouldSetScore) {
let url = "/api/lecture-note-recap/" + sessionID() + "/tasks/" + taskIndex() + "/estimate";

$("#estimated-score-card").fadeIn();
$("#estimated-score-card").removeClass("d-none");
$("#estimate-spinner").html('<div class="d-flex justify-content-center"><div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div></div>')

fetch(url, {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: answerJsonData("2")
})
.then(function (response) {
if (response.ok) {
return response.json();
} else {
throw new Error(response.statusText);
}
})
.then(function (json) {
let score = json["score"];
let roundedScore = Math.round(score * 4);

var text = "Vi estimerer at du";
if (shouldSetScore == true) {
registerScore(roundedScore);
}
if (roundedScore >= 4) {
text += " kan denne oppgaven veldig godt 💯"
} else if (roundedScore >= 3) {
text += " kan denne oppgaven godt 🔥"
} else if (roundedScore >= 2) {
text += " kan noe 🙌"
} else {
text += " kanskje burde lese litt mer 🤔"
}

$("#estimate-spinner").addClass("d-none");
$("#answer-estimate").text(text);
$("#answer-estimate").removeClass("d-none");
})
.catch(function (error) {
console.log(error)
})
}
Loading

0 comments on commit e71382d

Please sign in to comment.