Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit edc3a5f

Browse files
committed
A functioning and properly rendered quizly component.
1 parent e2af37f commit edc3a5f

7 files changed

Lines changed: 1216 additions & 70 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "dist/runestone.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8+
"check-env": "node -e 'console.log(process.env)' | grep npm",
89
"build": "webpack --env.MODE=development",
910
"watch": "webpack --env.MODE=development --watch",
1011
"start": "webpack-dev-server --env.MODE=development --open",

runestone/quizly/README.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
README.txt
2+
3+
The quizly directive, in this first pass looks like this:
4+
-----------------------------------------------
5+
6+
.. quizly::
7+
:quizname: unique-quiz-name from quizzes.js
8+
9+
The quizly component uses and requires the following resources:
10+
----------------------------------------------
11+
12+
runestone/quizly/quizly.py -- creates QuizlyNode from directive
13+
runestone/quizly/__init__.py -- imports the quizly code
14+
runestone/quizly/toctree.rst
15+
16+
runestone/quizly/js -- javascript resources
17+
-- all_appinv.js -- compressed files
18+
-- all_blockly.js
19+
-- all_quizly.js
20+
-- blockly.html -- blockly iframe
21+
-- index.html -- quizly UI and iframe container
22+
-- main.css -- gcb style defs
23+
-- media -- image and icon files
24+
-- quizly.js -- renders quizly exercise and handles interface with runestone
25+
-- quizme-helper.js -- main quizly code
26+
-- quizzes.js -- quizly quiz collection in JSON format
27+
28+
runestone/quizly/test -- some test code
29+
-- _sources -- test files
30+
-- Quizly
31+
-- TestQuizly.rst -- contains 1 MC and 2 different quizly exercises
32+
-- toctree.rst
33+
-- conf.py -- sphinx config file for runestone
34+
-- pavement.py -- needed for runestone build
35+
36+
The files that need to be coded by the developer
37+
-----------------------------------------------
38+
39+
./runestone/quizly/quizly.py
40+
----------------------------
41+
Th script that runs during runestone build. Runestone build parses the
42+
source document and translates the directive and its options into a QuizlyNode.
43+
44+
- Copies resource files from quizly/js to the project/_static folder, from where
45+
they are copied to build/quizly/_static during build, where they are used by
46+
the _sources web pages.
47+
48+
- QuizlyNode -- defines the node. The only option needed for this is the quizname,
49+
which is parsed from the directive.
50+
51+
- visit_quizly_mode(self, node) -- appends the quizly template, instantiated, to the
52+
body of the html document that will represent the quizly exercise
53+
54+
- Quizly(RunestoneDirective) -- its run() method instantiates and returns QuizlyNode,
55+
probably called by runestone build.
56+
57+
./runestone/quizly/__init__.py -- called by runestone build, imports quizly.py
58+
------------------------------
59+
60+
./runestone/quizly/js/quizly.js
61+
-------------------------------
62+
63+
This script runs when the html page containing the quizly iframe is loaded. It contains
64+
methods to render the quizly component and to handle the interface with runestone.
65+
66+
This script will be invoked automatically when the page is loaded, provided a quizly entry
67+
is made in the module.exports list in webpack.config.js.
68+
69+
"./runestone/quizly/js/quizly.js",
70+
71+
quizly.js contains the following methods and functions:
72+
73+
-- class Quizly extends RunestoneBase -- constructs a Quizly object that holds the
74+
data from the exercise. Calls renderQuiz() method.
75+
76+
-- getIFrame() -- extracts the iframe from the fully instantiated html code produced
77+
by quizly.py and contained in QuizlyNode.
78+
79+
-- renderQuizly() -- renders the quizly iframe inside a container <div>.
80+
81+
-- submitQuizly() -- the method invoked from the callback function when the user
82+
clicks "Check Me" button in the quizly exercise.
83+
84+
$(document).bind( ,,, function() {}) -- function that sets up the callback function
85+
and binds it to the html document.
86+
87+
setupCallback(quizly) -- defines the callback function that is invoked when the "Check Me"
88+
button is clicked. It calls quizly.submitQuizly(result), where result is the
89+
quizly-graded response to the user's attempt.
90+

runestone/quizly/js/index.html

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<!-- NOTE: Don't change this Title -->
66
<title>Quizme App Inventor</title>
7-
<link type="text/css" rel="stylesheet" href="../../css/main.css">
7+
<link type="text/css" rel="stylesheet" href="../../_static/quizly/main.css">
88
<style>
99
body {
1010
background-color: white;
@@ -40,16 +40,6 @@
4040
</style>
4141

4242
<script>
43-
// Event listener and handler for quiz result
44-
window.addEventListener('message', handleMessage, false);
45-
46-
function handleMessage(event) {
47-
// if (event.origin != "http://localhost:85") { return; }
48-
console.log("handleMessage result: " + event.data)
49-
this.window.quizly_result = event.data;
50-
console.log("handleMessage window result: " + this.window.quizly_result);
51-
}
52-
5343
// Based on: https://www.developphp.com/video/JavaScript/Custom-Alert-Box-Programming-Tutorial
5444
// The variable doc is set based on where the dialogoverlay, which varies if index.html is embedded.
5545
function JavaScriptAlert(){
@@ -101,19 +91,15 @@
10191
*/
10292
function checkAnswer() {
10393
console.log("checkAnswer -- RAM");
94+
console.log("window.parent.component_factory = " + JSON.stringify(window.parent.component_factory));
95+
10496
document.getElementById('show_javascript').disabled = true;
10597
var result = Blockly.Quizme.evaluateUserAnswer();
10698
var quizName = Blockly.Quizme.quizName
107-
window.postMessage("Result=" + result, 'http://localhost:85');
108-
109-
// window.parent.quizlies['quizname']=quizName;
110-
// var thisQuiz = window.parent.quizlies[quizName];
111-
// thisQuiz.result = result[0];
112-
// thisQuiz.workspace = result[1];
113-
99+
var q_result = {"quizname": quizName, "result": result[0], "xml": result[1]};
114100

115-
// Comment this out if there is separate GCB button for submitting the result.
116-
// window.parent.checkAnswer(); // This parent script is in modules/quizly/quizly.py
101+
// Post the result to runestone
102+
window.parent.component_factory.quizly(q_result);
117103
}
118104

119105
function giveHint() {
@@ -160,7 +146,7 @@ <h1 hidden="true" id="heading">Quizly: Live Coding Exercises for App Inventor</h
160146
<button class="gcb-button gcb-button-primary" id="hint_button" onclick="giveHint()">Hint</button>
161147
</td>
162148
<td>
163-
<button class="gcb-button gcb-button-primary" id="gcb_check_answer" onclick="checkAnswer()">Check Answer</button>
149+
<button class="gcb-button gcb-button-primary" id="gcb_check_answer" onclick="checkAnswer()">Check Me</button>
164150
</td>
165151
<td>
166152
<button class="gcb-button gcb-button-primary" id="show_javascript" onclick="showJavascript()" style="visibility:hidden" disabled>Show Javascript</button>

0 commit comments

Comments
 (0)