From ad96f8685251f8266d60773e80697dbe38f78acb Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 11 Oct 2023 19:22:34 +0200 Subject: [PATCH] wip #6387 @0.75 --- js/quiz.attemptslog.js | 37 +++++++++++++++++++++++++++++++++++-- js/quiz.score.js | 4 +++- js/quiz.screen.outro.js | 1 + package.json | 7 +++++++ style/100-global.sass | 5 ++++- 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 package.json diff --git a/js/quiz.attemptslog.js b/js/quiz.attemptslog.js index 42dbb3d..5dbd1e4 100644 --- a/js/quiz.attemptslog.js +++ b/js/quiz.attemptslog.js @@ -1,8 +1,41 @@ +import axios from 'axios'; + function QuizAttemptsLog(quiz) { this.quiz = quiz; - } -QuizAttemptsLog.prototype = {} +QuizAttemptsLog.prototype = { + log: function () { + if (!this.quiz.data.logattempts) { + return; + } + + let score = this.quiz.score.getNormalizedScore(true); + if (isNaN(score)) { + score = 0; + } + let logdata = { + score: score, passed: this.quiz.score.isPassed(), questions: this.getQuestionsToLog(), + }; + + let dom = this.quiz.data.env === 'dev' ? 'dev.toolbox.fluidbook.com' : 'toolbox.fluidbook.com'; + + axios({ + url: 'https://' + dom + '/quiz/' + this.quiz.data.id + '/log', + method: 'post', + data: logdata, + withCredentials: false, + }).then(function (response) { + console.log(response); + }).catch(function (error) { + console.log(error); + }); + + }, + + getQuestionsToLog: function () { + return this.quiz.score.logQuestions; + }, +} export default QuizAttemptsLog; diff --git a/js/quiz.score.js b/js/quiz.score.js index 9c12405..3f82ec8 100644 --- a/js/quiz.score.js +++ b/js/quiz.score.js @@ -189,7 +189,9 @@ QuizScore.prototype = { return { q: this.lastAnsweredQuestion, a: this.answers }; - }, execAction: function (action) { + }, + + execAction: function (action) { if (action === undefined || action === null || action === '' || !action) { return; } diff --git a/js/quiz.screen.outro.js b/js/quiz.screen.outro.js index f1d7342..8462d7b 100644 --- a/js/quiz.screen.outro.js +++ b/js/quiz.screen.outro.js @@ -116,6 +116,7 @@ QuizScreenOutro.prototype = { $("[id^=maxScore-]").text(maxScore); this.quiz.score.runEndAction(); + this.quiz.attemptsLog.log(); this.animate(score, percent) this.displayReviewList() diff --git a/package.json b/package.json new file mode 100644 index 0000000..f639a63 --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "name": "fluidbook-toolbox-quiz", + "version": "1.0.0", + "dependencies": { + "axios": "^1.5.1" + } +} diff --git a/style/100-global.sass b/style/100-global.sass index dbe7506..31ca619 100644 --- a/style/100-global.sass +++ b/style/100-global.sass @@ -1,8 +1,11 @@ @use 'sass:color' @import 005-utilities +* + user-select: none + body - background-color: $neutral-color + background-color: $background-color font-family: $font color: $texts-color -- 2.39.5