-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
328 lines (297 loc) · 11.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Blocks for Open edX --by elite</title>
<script src="./blockly_compressed.js"></script>
<script src="./blocks_compressed.js"></script>
<script src="./python_compressed.js"></script>
<script src="./storage.js"></script>
<script src="./en.js"></script>
<script src="./blocks.js" type="text/javascript"></script>
<script src="./demo_xml.js" type="text/javascript"></script>
<script
src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js"
type="text/javascript"
></script>
<script
src="https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js"
type="text/javascript"
></script>
<style>
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
</style>
</head>
<body>
<!--
js运行Python skulpt 校验
python2.7
https://blockly-demo.appspot.com/static/demos/code/index.html 完整的,自定意义的包装。
分组
数字
运算
逻辑
比较
检验工具组
答案 可以是一个函数
Python评估(随机出题)
https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html#write-your-own-grader-problem
案例: https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html#example-with-the-script-tag
不同输入的反馈
https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html#example-of-the-check-function-returning-a-dictionary
动态恢复类型 customresponse
随机 https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html#create-a-randomized-custom-python-evaluated-input-problem
使用
选择 高级 Select Custom Python-Evaluated Input
Select Custom Python-Evaluated Input
作为chrome 插件,替换当前页面的Python标签,注入进入
todo
需要在图形中明确题目类型
题型积木组
https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html#create-a-randomized-custom-python-evaluated-input-problem
主体是Python(文本),将xml是为模版(文本), js是处理这些的工具
全球化
https://github.com/google/blockly/blob/master/demos/code/index.html
https://blockly-demo.appspot.com/static/demos/code/index.html code编辑器
持久化
导出和导入 xml
https://developers.google.com/blockly/guides/get-started/web
从本地加载,或者线上例子 localstorage online leancloud
todo
下拉菜单选择 题型
导入导出
-->
<h1>Blocks for Open edX --by elite <a href="https://github.com/e-ducation/blocks4edx/blob/master/readme.md" target="_blank">Help</a></h1>
<p>
<span>choose:</span>
<select id="mySel">
<option value="null">null</option>
<option value="multiplechoiceresponse">multiple choice response</option>
<option value="numericalresponse">numerical response</option>
</select>
<button id="clipboard_btn" class="btn" data-clipboard-text="hello">
copy to edx
</button>
<button onclick="download_xml()">export</button> <span>import</span>
<input type="file" id="files" name="files[]" />
</p>
<div id="blocklyDiv" style="height: 600px; width: 1200px;"></div>
<xml id="toolbox" style="display: none">
<category name="Problem" colour="#3333ff">
<block type="problem"></block> <block type="numericalresponse"></block>
<block type="multiplechoiceresponse"></block>
<block type="choice"></block>
</category>
<category name="Text" colour="#3333ff">
<block type="html_p"></block>
<block type="html_p_input"></block>
<block type="text_join_elite"></block>
<block type="text"></block>
<block type="output_variable"></block>
</category>
<category name="Format" colour="#3333ff">
<block type="thousands_separator"></block>
<block type="percent_sign"></block>
<block type="fraction"></block>
<block type="decimal"></block>
</category>
<category name="Tools" colour="#3333ff">
<block type="image"></block>
<block type="table"></block>
</category>
<category name="Logic" colour="%{BKY_LOGIC_HUE}">
<block type="controls_if"></block> <block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block> <block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
<category name="Math" colour="%{BKY_MATH_HUE}">
<block type="math_number"> <field name="NUM">123</field> </block>
<block type="math_arithmetic">
<value name="A">
<shadow type="math_number"> <field name="NUM">1</field> </shadow>
</value>
<value name="B">
<shadow type="math_number"> <field name="NUM">1</field> </shadow>
</value>
</block>
<block type="math_single">
<value name="NUM">
<shadow type="math_number"> <field name="NUM">9</field> </shadow>
</value>
</block>
<block type="math_trig">
<value name="NUM">
<shadow type="math_number"> <field name="NUM">45</field> </shadow>
</value>
</block>
<block type="math_constant"></block>
<block type="math_number_property">
<value name="NUMBER_TO_CHECK">
<shadow type="math_number"> <field name="NUM">0</field> </shadow>
</value>
</block>
<block type="math_round">
<value name="NUM">
<shadow type="math_number"> <field name="NUM">3.1</field> </shadow>
</value>
</block>
<block type="math_on_list"></block>
<block type="math_modulo">
<value name="DIVIDEND">
<shadow type="math_number"> <field name="NUM">64</field> </shadow>
</value>
<value name="DIVISOR">
<shadow type="math_number"> <field name="NUM">10</field> </shadow>
</value>
</block>
<block type="math_constrain">
<value name="VALUE">
<shadow type="math_number"> <field name="NUM">50</field> </shadow>
</value>
<value name="LOW">
<shadow type="math_number"> <field name="NUM">1</field> </shadow>
</value>
<value name="HIGH">
<shadow type="math_number"> <field name="NUM">100</field> </shadow>
</value>
</block>
<block type="math_random_int">
<value name="FROM">
<shadow type="math_number"> <field name="NUM">1</field> </shadow>
</value>
<value name="TO">
<shadow type="math_number"> <field name="NUM">100</field> </shadow>
</value>
</block>
<!--<block type="math_random_float"></block>-->
<block type="elite_random_float">
<value name="from">
<shadow type="math_number"> <field name="NUM">1</field> </shadow>
</value>
<value name="to">
<shadow type="math_number"> <field name="NUM">100</field> </shadow>
</value>
</block>
</category>
<category name="Controls" colour="%{BKY_LOOPS_HUE}">
<block type="controls_repeat_ext">
<value name="TIMES">
<shadow type="math_number">
<field name="NUM">10</field>
</shadow>
</value>
</block>
<block type="controls_whileUntil"></block>
<block type="controls_for">
<value name="FROM">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
<value name="TO">
<shadow type="math_number">
<field name="NUM">10</field>
</shadow>
</value>
<value name="BY">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
</block>
<block type="controls_forEach"></block>
<block type="controls_flow_statements"></block>
</category>
<category
name="Variable"
colour="%{BKY_VARIABLES_HUE}"
custom="VARIABLE"
></category>
<category
name="Function"
colour="%{BKY_PROCEDURES_HUE}"
custom="PROCEDURE"
></category>
</xml>
<script>
function change_handle() {
var code = showCode();
document
.getElementById("clipboard_btn")
.setAttribute("data-clipboard-text", code);
}
function init_workspace() {
var demoWorkspace = Blockly.inject("blocklyDiv", {
media: "./media/",
toolbox: document.getElementById("toolbox"),
// https://github.com/google/blockly/blob/master/demos/code/code.js#L414
zoom: { controls: true, wheel: true }
});
window.setTimeout(BlocklyStorage.restoreBlocks, 0); //定时存储,也可模仿它来上传状态 storage.js->Blockly.getMainWorkspace(),可以加上workspace参数
BlocklyStorage.backupOnUnload(); // listener on the page's unload event //拉取状态同步到本地
window.demoWorkspace = demoWorkspace;
demoWorkspace.addChangeListener(change_handle);
new ClipboardJS(".btn"); // 初始化剪切板工具
}
window.onload = init_workspace;
window.Blockly = Blockly;
function showCode() {
// Generate JavaScript code and display it.
// Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
var origin_code = Blockly.Python.workspaceToCode(demoWorkspace);
var code = `<problem>\n<script type="loncapa/python">\n${origin_code}`;
console.log(code);
return code;
// alert(code)
}
function copeCode() {
console.log("copeCode");
}
// https://developers.google.com/blockly/guides/get-started/web#importing_and_exporting_blocks
function import_xml(xml_text) {
demoWorkspace.clear();
var xml = Blockly.Xml.textToDom(xml_text);
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
}
function handleFileSelect(evt) {
window.files = evt.target.files; // FileList object
var reader = new FileReader();
reader.readAsText(files[0], "UTF-8");
reader.onload = function(e) {
var filedata = this.result;
import_xml(filedata);
};
}
document
.getElementById("files")
.addEventListener("change", handleFileSelect, false);
// export xml
function download_xml() {
var xml = Blockly.Xml.workspaceToDom(demoWorkspace);
var xml_text = Blockly.Xml.domToText(xml);
var blob = new Blob([xml_text], { type: "text/plain;charset=utf-8" });
saveAs(blob, "edx_problem_blocks.xml");
}
// select change
var sel = document.getElementById("mySel");
sel.onchange = function() {
var selectedvalue = this.options[this.selectedIndex].value;
if (selectedvalue == "multiplechoiceresponse") {
import_xml(xml_multiplechoiceresponse_demo);
}
if (selectedvalue == "numericalresponse") {
import_xml(xml_numericalresponse_demo);
}
};
</script>
</body>
</html>