Skip to content

Commit

Permalink
Clean and DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
runestonetest committed Nov 9, 2020
1 parent bc58be3 commit c3dda23
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 97 deletions.
8 changes: 1 addition & 7 deletions runestone/activecode/js/timed_activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ var TimedActiveCodeMixin = {
$(this.output).css("visibility", "hidden");
},

processTimedSubmission: function (logFlag) {
this.runProg(true, logFlag); // true means no GUI
$(`#${this.divid}_unit_results`).show();
this.disableInteraction();
},

reinitializeListeners: function (taken) {
// re-attach the run button listener
$(this.runButton).click(this.runProg.bind(this));
Expand Down Expand Up @@ -115,7 +109,7 @@ export class TimedActiveCode extends ActiveCode {

// for timed exams we need to call runProg and tell it that there is
// no GUI for sliders or other things. We also do not want it to log
// the answers. See also processTimedSubmission which gets called at the end.
// the answers.
checkCurrentAnswer() {
this.run_promise = this.runProg(true, false);
}
Expand Down
10 changes: 0 additions & 10 deletions runestone/clickableArea/js/timedclickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ export default class TimedClickableArea extends ClickableArea {
hideFeedback() {
$(this.feedBackDiv).hide();
}

processTimedSubmission(logFlag) {
// Disable input, then evaluate component
this.disableInteraction();
this.checkCurrentAnswer();
this.renderFeedback();
if (logFlag) {
this.logCurrentAnswer();
}
}
}

if (typeof window.component_factory === "undefined") {
Expand Down
9 changes: 0 additions & 9 deletions runestone/dragndrop/js/timeddnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ export default class TimedDragNDrop extends DragNDrop {
hideFeedback() {
$(this.feedBackDiv).hide();
}
processTimedSubmission(logFlag) {
// Disable input & evaluate component
this.checkCurrentAnswer();
if (logFlag) {
this.logCurrentAnswer();
}
this.renderFeedback();
this.disableInteraction();
}
}

if (typeof window.component_factory === "undefined") {
Expand Down
5 changes: 0 additions & 5 deletions runestone/fitb/js/timedfitb.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export default class TimedFITB extends FITB {
}
this.feedBackDiv.style.display = "none";
}
processTimedSubmission(logFlag) {
// Disable input, then evaluate component
this.disableInteraction();
this.startEvaluation(logFlag);
}

reinitializeListeners() {
for (let blank of this.blankArray) {
Expand Down
55 changes: 8 additions & 47 deletions runestone/mchoice/js/timedmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default class TimedMC extends MultipleChoice {
$(this.submitButton).hide();
$(this.compareButton).hide();
}

// These methods override the methods in the base class. Called from renderFeedback()
//
renderMCMAFeedBack() {
this.feedbackTimedMC();
}
Expand All @@ -39,7 +42,9 @@ export default class TimedMC extends MultipleChoice {
feedbackTimedMC() {
for (var i = 0; i < this.indexArray.length; i++) {
var tmpindex = this.indexArray[i];
$(this.feedBackEachArray[i]).text(this.feedbackList[i]);
$(this.feedBackEachArray[i]).text(
String.fromCharCode(65 + i) + ". " + this.feedbackList[i]
);
var tmpid = this.answerList[tmpindex].id;
if (this.correctList.indexOf(tmpid) >= 0) {
this.feedBackEachArray[i].classList.add(
Expand All @@ -55,47 +60,10 @@ export default class TimedMC extends MultipleChoice {
}
}
renderMCFormOpts() {
this.optionArray = []; // array with an object for each option containing the input and label for that option
super.renderMCFormOpts();
this.feedBackEachArray = [];
var input_type = "radio";
if (this.multipleanswers) {
input_type = "checkbox";
}
// this.indexArray is used to index through the answers
// it is just 0-n normally, but the order is shuffled if the random option is present
this.indexArray = [];
for (var i = 0; i < this.answerList.length; i++) {
this.indexArray.push(i);
}
if (this.random) {
this.randomizeAnswers();
}
for (var j = 0; j < this.answerList.length; j++) {
var k = this.indexArray[j];
var optid = this.divid + "_opt_" + k;
// Create the input
var input = document.createElement("input");
input.type = input_type;
input.name = "group1";
input.value = String(k);
input.id = optid;
// Create the label for the input
var label = document.createElement("label");
var labelspan = document.createElement("span");
label.appendChild(input);
label.appendChild(labelspan);
$(labelspan).html(
String.fromCharCode(65 + j) + ". " + this.answerList[k].content
);
// create the object to store in optionArray
var optObj = {
input: input,
label: label,
};
this.optionArray.push(optObj);
// add the option to the form
this.optsForm.appendChild(label);
this.optsForm.appendChild(document.createElement("br"));
var feedBackEach = document.createElement("div");
feedBackEach.id = this.divid + "_eachFeedback_" + k;
feedBackEach.classList.add("eachFeedback");
Expand Down Expand Up @@ -147,14 +115,7 @@ export default class TimedMC extends MultipleChoice {
$(this.feedBackEachArray[i]).hide();
}
}
processTimedSubmission(logFlag) {
this.disableInteraction();
if (this.multipleanswers) {
this.processMCMASubmission(logFlag);
} else {
this.processMCMFSubmission(logFlag);
}
}

reinitializeListeners() {
let self = this;
let answerFunc = function () {
Expand Down
12 changes: 0 additions & 12 deletions runestone/parsons/js/timedparsons.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ export default class TimedParsons extends Parsons {
hideFeedback() {
$(this.messageDiv).hide();
}
processTimedSubmission(logFlag) {
if (logFlag) {
this.setLocalStorage();
}
this.checkCurrentAnswer();
if (logFlag) {
this.logCurrentAnswer();
}
this.renderFeedback();
this.correct = this.grade;
this.disableInteraction();
}
}

if (typeof window.component_factory === "undefined") {
Expand Down
4 changes: 0 additions & 4 deletions runestone/shortanswer/js/timed_shortanswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export default class TimedShortAnswer extends ShortAnswer {
hideFeedback() {
$(this.feedbackDiv).hide();
}
processTimedSubmission() {
// Disable input & evaluate component
this.submitJournal();
}
}

if (typeof window.component_factory === "undefined") {
Expand Down
7 changes: 4 additions & 3 deletions runestone/timed/js/timed.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ export default class Timed extends RunestoneBase {
this.running = 0;
this.done = 1;
this.taken = 1;
this.submitTimedProblems(true); // log results
this.finalizeProblems(true); // log results
this.checkScore();
this.displayScore();
this.storeScore();
Expand Down Expand Up @@ -804,8 +804,8 @@ export default class Timed extends RunestoneBase {
}, 2000);
}

submitTimedProblems(logFlag) {
//Because we have submitted each question as we navigate we only need to
finalizeProblems(logFlag) {
// Because we have submitted each question as we navigate we only need to
// send the final version of the question the student is on when they press the
// finish exam button.

Expand All @@ -818,6 +818,7 @@ export default class Timed extends RunestoneBase {

for (var i = 0; i < this.renderedQuestionArray.length; i++) {
var currentQuestion = this.renderedQuestionArray[i];
// set the state to forreview so we know that feedback may be appropriate
currentQuestion.state = "forreview";
}

Expand Down

0 comments on commit c3dda23

Please sign in to comment.