Skip to content

Commit

Permalink
Merge pull request #59 from MatsMoll/develop
Browse files Browse the repository at this point in the history
Compendium ++
  • Loading branch information
MatsMoll authored Mar 25, 2020
2 parents e26ea71 + 782a7c8 commit 39e4327
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Public/assets/css/app.min.css

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Public/assets/js/flash-card/json-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ function jsonData() {
}
var question = $("#card-question").val();
var solutionValue = solution.value();
if (solutionValue.length == 0) {
solutionValue = null;
}

if (isNaN(subtopicId) || subtopicId < 1) {
throw Error("Velg et tema");
Expand Down
15 changes: 10 additions & 5 deletions Public/assets/js/flash-card/submit-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ var isSubmitting = false;
var hasSubmittedSucessfully = false;
var knowledgeScore = 0;

var nextIndex=1;
function navigateTo(index) {
submitPerformance(knowledgeScore, function() {
window.location.href = index;
if ($("#goal-progress-bar").attr("aria-valuenow") >= 100) {
nextIndex=index;
$("#goal-completed").modal("show");
} else {
location.href = index;
}
})
}

Expand All @@ -20,15 +26,14 @@ function revealSolution() {
var goalValue = parseFloat($("#goal-value").text());
var porgressBarValue = parseFloat($("#goal-progress-bar").attr("aria-valuenow"))
var currentCompleted = porgressBarValue / 100 * goalValue;
var progress = parseInt((currentCompleted + 1) * 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) {
if (progress >= 100) {
$("#goal-progress-bar").addClass("bg-success");
$("#achivement-success").modal();
}
}
submitPerformance(knowledgeScore, function (){})
Expand Down Expand Up @@ -115,7 +120,7 @@ function presentControlls() {
$(this).fadeIn();
$(this).removeClass("d-none");
});
fetchSolutions("practice");
fetchSolutions();
fetchDiscussions($("#task-id").val())
$("#knowledge-card").removeClass("d-none");
updateScoreButton()
Expand Down
13 changes: 9 additions & 4 deletions Public/assets/js/markdown-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ function renderKatex(plainText) {
}

function renderMarkdown(markdown) {
let stringMarkdown = String(markdown)
let stringMarkdown = String(markdown).replace(/&gt;+/g, '>')
let html = marked(renderKatex(stringMarkdown));
let parser = new DOMParser()
let document = parser.parseFromString(html, "text/html")
Array.from(document.getElementsByTagName("a")).map(x => x.setAttribute("target", "_blank"))
Array.from(document.getElementsByTagName("img")).map(x => x.setAttribute("style", "max-width:100%"))
Array.from(document.getElementsByTagName("blockquote")).map(x => x.setAttribute("class", "blockquote"))
return document.getElementsByTagName("body")[0].innerHTML
}

$(".render-markdown").each(function () {
this.innerHTML = renderMarkdown(this.innerHTML);
});
function renderMarkdownNodesIn(document) {
$(document).find(".render-markdown").each(function () {
this.innerHTML = renderMarkdown(this.innerHTML);
});
}

renderMarkdownNodesIn(document);
6 changes: 3 additions & 3 deletions Public/assets/js/multiple-choise/json-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ function jsonData() {
var isMultipleSelect = $("#create-multiple-select").prop("checked");
var isTestable = $("#create-multiple-testable").prop("checked");
var solutionValue = solution.value();
if (solutionValue.length < 1) {
solutionValue = null;
}

if (isNaN(subtopicId) || subtopicId < 1) {
throw Error("Velg et tema");
Expand All @@ -36,6 +33,9 @@ function jsonData() {
if (choises.length <= 1) {
throw Error("Lag to eller flere alternativer");
}
if (choises.filter(choise => choise.isCorrect).length < 1) {
throw Error("Minst et alternativ må være markert som riktig. Dette kan gjøres ved å trykke på det riktige alternativet")
}

return JSON.stringify({
"isTestable" : isTestable,
Expand Down
14 changes: 12 additions & 2 deletions Public/assets/js/multiple-choise/task-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ if (window.location.pathname.includes("session") == false) {
$("#nextButton").removeClass("d-none");
}

var nextIndex=1;
function navigateTo(index) {
location.href = index;
if ($("#goal-progress-bar").attr("aria-valuenow") >= 100) {
nextIndex=index;
$("#goal-completed").modal("show");
} else {
location.href = index;
}
}

function submitChoises() {
Expand Down Expand Up @@ -105,6 +111,10 @@ function handleSuccess(results) {
$("#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");
}
}
}

Expand All @@ -116,7 +126,7 @@ function presentControlls() {
$(this).fadeIn();
$(this).removeClass("d-none");
});
fetchSolutions("practice");
fetchSolutions();
fetchDiscussions($("#task-id").val())
}

Expand Down
34 changes: 33 additions & 1 deletion Public/assets/js/practice-session-create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function startPracticeSession(topicIds, subjectId) {
function startPracticeSessionWithTopicIDs(topicIds, subjectId) {

let taskGoal = 10;

Expand All @@ -9,6 +9,38 @@ function startPracticeSession(topicIds, subjectId) {

let url = "/api/subjects/" + subjectId + "/practice-sessions/start";

fetch(url, {
method: "POST",
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type" : "application/json"
},
body: data
})
.then(function (response) {
if (response.ok) {
return response.json();
} else {
throw new Error(response.statusText);
}
})
.then(function (json) {
let sessionID = json["id"];
window.location.href = "/practice-sessions/" + sessionID + "/tasks/1";
})
}

function startPracticeSessionWithSubtopicIDs(subtopicIDs, subjectId) {

let taskGoal = 10;

let data = JSON.stringify({
"subtopicsIDs" : subtopicIDs,
"numberOfTaskGoal" : taskGoal,
});

let url = "/api/subjects/" + subjectId + "/practice-sessions/start";

fetch(url, {
method: "POST",
headers: {
Expand Down
4 changes: 2 additions & 2 deletions Public/assets/js/task-discussion/create-response.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function taskDiscussionResponseData() {

let response = $("#create-discussion-response").val();
let response = creatediscussionresponse.value();
let discussionID = parseInt($("#disc-id").val());

if(response.length < 4) {
Expand Down Expand Up @@ -30,7 +30,7 @@ function createResponse() {
.then(function (response) {
if (response.ok) {
fetchDiscussionResponses(discussionID);
$("#create-discussion-response").val("");
creatediscussionresponse.value("")
} else {
throw new Error(response.statusText);
}
Expand Down
45 changes: 44 additions & 1 deletion Public/assets/js/task-discussion/fetch-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,54 @@ function fetchDiscussionResponses(discussionID) {
$("#disc-responses").html(html);
$("#disc-responses").fadeIn();
$("#disc-responses").removeClass("d-none");
renderMarkdownNodesIn($("#disc-responses"));
})
.catch(function (error) {
$("#submitButton").attr("disabled", false);
$("#error-massage").text(error.message);
$("#error-div").fadeIn();
$("#error-div").removeClass("d-none");
});
}
}

function fetchADiscussionResponse(button) {
let currentResponse = creatediscussionresponse.value()
let quote = $(button).siblings(".response").html();
var markdownQuote = ""

var leftovers = quote;
let quoteStart = "<blockquote class=\"blockquote\">\n"
var index = leftovers.indexOf(quoteStart);


while (index != -1) {
markdownQuote += leftovers.substring(0, index);
let endIndex = leftovers.indexOf("</blockquote>");
if (endIndex != -1) {
markdownQuote += "> " + leftovers.substring(index + quoteStart.length, endIndex)
leftovers = leftovers.substring(endIndex + "</blockquote>".length, leftovers.length);
}
index = leftovers.indexOf(quoteStart);
}

markdownQuote += leftovers;

markdownQuote = "> " + markdownQuote.replace(/<p>/gi, "").replace(/<\/p>/gi, "").replace(/\n/g, "\n> ")

if(currentResponse == "") {
creatediscussionresponse.value(markdownQuote + "\n\n");
} else {
creatediscussionresponse.value(currentResponse + "\n\n" + markdownQuote + "\n\n");
}
moveCursorToEnd()
}


function moveCursorToEnd() {

var cm = creatediscussionresponse.codemirror;
var textlenght = creatediscussionresponse.value().length;
cm.focus()
cm.setCursor({line:textlenght, ch: textlenght});

}
20 changes: 1 addition & 19 deletions Public/assets/js/task-solution/suggest-solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,4 @@ function jsonData() {
"taskID" : taskID,
"presentUser" : presentUser
})
}

// setTimeout(function () {
// suggestedsolution.codemirror.on("change", function(){
// let parser = new DOMParser(); let htmlDoc = parser.parseFromString(renderMarkdown(suggestedsolution.value()), 'text/html');
// let hrefs = new Set(Array.from(htmlDoc.getElementsByTagName("a")).map(x => x.getAttribute("href"))); let imgs = new Set(Array.from(htmlDoc.getElementsByTagName("img")).map(x => x.getAttribute("src"))); let lists = Array.from(htmlDoc.getElementsByTagName("li")); let text = htmlDoc.getElementsByTagName("body")[0].innerText.split(/\s+/)
// var totalPoints = 0; totalPoints += Math.min(hrefs.size * 3, 4); totalPoints += Math.min(imgs.size * 2, 3); totalPoints += Math.min(lists.length, 1); totalPoints += (text.length < 150 && text.length > 60) ? 3 : 0;
// // Lengde på text, punkt liste, bilde, kilder
// console.log(text.length);
// $("#solution-rating").text(totalPoints)
// if (totalPoints >= 6) {
// $("#solution-guide").addClass("text-success"); $("#solution-guide").removeClass("text-danger"); $("#solution-guide").removeClass("text-warning");
// } else if (totalPoints >= 3) {
// $("#solution-guide").addClass("text-warning"); $("#solution-guide").removeClass("text-danger"); $("#solution-guide").removeClass("text-success");
// } else {
// $("#solution-guide").addClass("text-danger"); $("#solution-guide").removeClass("text-warning"); $("#solution-guide").removeClass("text-success");
// }
// });
// }, 300)
}
17 changes: 17 additions & 0 deletions Public/manifest.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"short_name": "Kognita",
"name": "Kognita",
"description": "Lær mer effektivt",
"icons": [
{
"src": "assets/images/logo.png",
"type": "image/png",
"sizes": "400x238"
}
],
"start_url": "/login",
"background_color": "#3367D6",
"display": "standalone",
"scope": "/",
"theme_color": "#3367D6"
}
20 changes: 20 additions & 0 deletions Sources/App/Subject/SubjectWebController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class SubjectWebController: RouteCollection {
router.get("subjects", use: listAll)
router.get("subjects/create", use: createSubject)
router.get("subjects", Subject.parameter, use: details)
router.get("subjects", Subject.parameter, "compendium", use: compendium)
}


Expand Down Expand Up @@ -101,4 +102,23 @@ final class SubjectWebController: RouteCollection {
)
}
}

func compendium(on req: Request) throws -> EventLoopFuture<HTTPResponse> {

let user = try req.requireAuthenticated(User.self)

return try Subject.DefaultAPIController
.compendium(on: req)
.map { compendium in

try req.renderer()
.render(
Subject.Templates.Compendium.self,
with: .init(
user: user,
compendium: compendium
)
)
}
}
}

0 comments on commit 39e4327

Please sign in to comment.