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

Commit 9f8fa10

Browse files
authored
Merge pull request #1181 from bjones1/more-tests
Fix: Rewrite fitb to use new framework.
2 parents d1fdf14 + 6e96333 commit 9f8fa10

1 file changed

Lines changed: 24 additions & 40 deletions

File tree

runestone/fitb/js/fitb.js

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export default class FITB extends RunestoneBase {
9595
this.submitButton.addEventListener(
9696
"click",
9797
function () {
98-
this.startEvaluation(true);
98+
this.checkCurrentAnswer();
99+
this.logCurrentAnswer();
99100
}.bind(this),
100101
false
101102
);
@@ -162,7 +163,7 @@ export default class FITB extends RunestoneBase {
162163
this.renderFeedback();
163164
}
164165
} else {
165-
this.startEvaluation(false);
166+
this.checkCurrentAnswer();
166167
}
167168
}
168169
checkLocalStorage() {
@@ -194,15 +195,21 @@ export default class FITB extends RunestoneBase {
194195
}
195196

196197
checkCurrentAnswer() {
197-
// Start of the evaulation chain
198+
// Start of the evaluation chain
198199
this.isCorrectArray = [];
199200
this.displayFeed = [];
200201
this.given_arr = [];
201202
for (var i = 0; i < this.blankArray.length; i++)
202203
this.given_arr.push(this.blankArray[i].value);
204+
if (this.useRunestoneServices) {
205+
if (eBookConfig.enableCompareMe) {
206+
this.enableCompareButton();
207+
}
208+
}
203209
// Grade locally if we can't ask the server to grade.
204210
if (this.feedbackArray) {
205211
this.evaluateAnswers();
212+
this.renderFeedback();
206213
}
207214
}
208215

@@ -213,54 +220,31 @@ export default class FITB extends RunestoneBase {
213220
answer: answer,
214221
timestamp: new Date(),
215222
});
216-
var ret = this.logBookEvent({
223+
let data = await this.logBookEvent({
217224
event: "fillb",
218225
act: answer,
219226
answer: answer,
220227
correct: this.correct ? "T" : "F",
221228
div_id: this.divid,
222229
});
223-
return ret;
224-
}
230+
if (!this.feedbackArray) {
231+
// On success, update the feedback from the server's grade.
232+
this.setLocalStorage({
233+
answer: answer,
234+
timestamp: data.timestamp,
235+
});
236+
this.correct = data.correct;
237+
this.displayFeed = data.displayFeed;
238+
this.isCorrectArray = data.isCorrectArray;
239+
this.renderFeedback();
240+
}
241+
return data;
242+
}
225243

226244
/*==============================
227245
=== Evaluation of answer and ===
228246
=== display feedback ===
229247
==============================*/
230-
/*
231-
* keeping this function for backward compatiblitiy
232-
* going forward we should be using
233-
* checkCurrentAnswer()
234-
* logCurrentAnswer()
235-
* renderFeedback()
236-
* independently.
237-
*/
238-
async startEvaluation(logFlag) {
239-
this.checkCurrentAnswer();
240-
if (this.feedbackArray) {
241-
this.renderFeedback();
242-
}
243-
if (logFlag) {
244-
// Sometimes we don't want to log the answer--for example, when timed exam questions are re-loaded
245-
let data = await this.logCurrentAnswer();
246-
if (!this.feedbackArray) {
247-
// On success, update the feedback from the server's grade.
248-
this.setLocalStorage({
249-
answer: JSON.stringify(this.given_arr),
250-
timestamp: data.timestamp,
251-
});
252-
this.correct = data.correct;
253-
this.displayFeed = data.displayFeed;
254-
this.isCorrectArray = data.isCorrectArray;
255-
this.renderFeedback();
256-
}
257-
}
258-
if (this.useRunestoneServices) {
259-
if (eBookConfig.enableCompareMe) {
260-
this.enableCompareButton();
261-
}
262-
}
263-
}
264248
// Inputs:
265249
//
266250
// - Strings entered by the student in ``this.blankArray[i].value``.

0 commit comments

Comments
 (0)