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

Commit cb879da

Browse files
committed
2 parents 2379a17 + 8be18a9 commit cb879da

File tree

4 files changed

+85
-17
lines changed

4 files changed

+85
-17
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"handsontable": "7.2.2",
3737
"jexcel": "^3.9.1",
3838
"jquery-ui": "1.10.4",
39-
"micro-parsons": "https://github.com/amy21206/micro-parsons-element/releases/download/v0.1.3/micro-parsons-0.1.3.tgz",
39+
"micro-parsons": "https://github.com/amy21206/micro-parsons-element/releases/download/v0.1.4/micro-parsons-0.1.4.tgz",
4040
"select2": "^4.1.0-rc.0",
4141
"sql.js": "1.5.0",
4242
"vega-embed": "3.14.0",

runestone/hparsons/js/SQLFeedback.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,10 @@ export default class SQLFeedback extends HParsonsFeedback {
261261
// adapted from activecode
262262
async buildProg() {
263263
// assemble code from prefix, suffix, and editor for running.
264-
// TODO: fix or remove text entry
264+
// TODO: automatically joins the text array with space.
265+
// Should be joining without space when implementing regex.
265266
var prog;
266-
if (this.hparsons.textentry) {
267-
prog = this.hparsons.hparsonsInput.getCurrentInput();
268-
} else {
269-
prog = this.hparsons.hparsonsInput.getParsonsTextArray().join(' ') + "\n";
270-
}
267+
prog = this.hparsons.hparsonsInput.getParsonsTextArray().join(' ') + "\n";
271268
return Promise.resolve(prog);
272269
}
273270

runestone/hparsons/js/hparsons.js

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export default class HParsons extends RunestoneBase {
2828
this.divid = opts.orig.id;
2929
this.containerDiv = opts.orig;
3030
this.useRunestoneServices = opts.useRunestoneServices;
31+
32+
// Set the storageId (key for storing data)
33+
var storageId = super.localStorageKey();
34+
this.storageId = storageId;
35+
3136
this.origElem = orig;
3237
this.origText = this.origElem.textContent;
3338
this.code = $(orig).text() || "\n\n\n\n\n";
@@ -71,6 +76,7 @@ export default class HParsons extends RunestoneBase {
7176

7277
// initializing functionalities for different feedback
7378
this.feedbackController.init();
79+
this.checkServer('hparsons', true);
7480
}
7581

7682
// copied from activecode, already modified to add parsons
@@ -110,7 +116,6 @@ export default class HParsons extends RunestoneBase {
110116
this.feedbackController.createOutput();
111117
}
112118

113-
// copied from activecode
114119
createControls() {
115120
var ctrlDiv = document.createElement("div");
116121
$(ctrlDiv).addClass("hp_actions");
@@ -122,8 +127,10 @@ export default class HParsons extends RunestoneBase {
122127
ctrlDiv.appendChild(this.runButton);
123128
$(this.runButton).attr("type", "button");
124129
$(this.runButton).text("Run");
130+
var that = this;
125131
this.runButton.onclick = () => {
126-
this.feedbackController.runButtonHandler();
132+
that.feedbackController.runButtonHandler();
133+
that.setLocalStorage();
127134
};
128135

129136
// Reset button
@@ -134,15 +141,79 @@ export default class HParsons extends RunestoneBase {
134141
ctrlDiv.appendChild(resetBtn);
135142
this.resetButton = resetBtn;
136143
this.resetButton.onclick = () => {
137-
this.hparsonsInput.resetInput();
138-
this.feedbackController.reset();
144+
that.hparsonsInput.resetInput();
145+
that.setLocalStorage();
146+
that.feedbackController.reset();
139147
};
140148
$(resetBtn).attr("type", "button");
141149

142150
$(this.outerDiv).prepend(ctrlDiv);
143151
this.controlDiv = ctrlDiv;
144152
}
145153

154+
// Return previous answers in local storage
155+
//
156+
localData() {
157+
var data = localStorage.getItem(this.storageId);
158+
if (data !== null) {
159+
if (data.charAt(0) == "{") {
160+
data = JSON.parse(data);
161+
} else {
162+
data = {};
163+
}
164+
} else {
165+
data = {};
166+
}
167+
return data;
168+
}
169+
// RunestoneBase: Sent when the server has data
170+
restoreAnswers(serverData) {
171+
// TODO: not tested with server data yet.
172+
// Server side data should be:
173+
/*
174+
{
175+
answer: Array<string>, // list of answer block content
176+
count: ?number // number of previous attempts if block-based feedback
177+
}
178+
*/
179+
if (serverData.answer){
180+
this.hparsonsInput.restoreAnswer(serverData.answer);
181+
}
182+
if (serverData.count) {
183+
this.feedbackController.checkCount = serverData.count;
184+
}
185+
}
186+
// RunestoneBase: Load what is in local storage
187+
checkLocalStorage() {
188+
if (this.graderactive) {
189+
// Zihan: I think this means the component is still loading?
190+
return;
191+
}
192+
let localData = this.localData();
193+
if (localData.answer) {
194+
this.hparsonsInput.restoreAnswer(localData.answer);
195+
}
196+
if (localData.count) {
197+
this.feedbackController.checkCount = localData.count;
198+
}
199+
}
200+
// RunestoneBase: Set the state of the problem in local storage
201+
setLocalStorage(data) {
202+
let currentState = {};
203+
if (data == undefined) {
204+
currentState = {
205+
answer: this.hparsonsInput.getParsonsTextArray()
206+
}
207+
if (this.isBlockGrading) {
208+
// if this is block grading, add number of previous attempts too
209+
currentState.count = this.feedbackController.checkCount;
210+
}
211+
} else {
212+
currentState = data;
213+
}
214+
localStorage.setItem(this.storageId, JSON.stringify(currentState));
215+
}
216+
146217
logHorizontalParsonsEvent(hparsonsEvent) {
147218
let ev = {
148219
event: "hparsons",

0 commit comments

Comments
 (0)