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

Commit cbc5e66

Browse files
committed
Handle case where no available question
1 parent 7ba14f7 commit cbc5e66

3 files changed

Lines changed: 52 additions & 21 deletions

File tree

runestone/selectquestion/js/selectone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class SelectOne extends RunestoneBase {
8989
alert(
9090
`Error: Not able to find a question for ${selectorId} based on the criteria`
9191
);
92-
return response;
92+
throw new Error(`Unable to find a question for ${selectorId}`);
9393
}
9494
let res;
9595
if (opts.timed) {

runestone/timed/css/timed.css

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ ul#pageNums li {
55
padding: 10px 0;
66
}
77

8-
9-
.pagination>li>a:hover {
8+
.pagination > li > a:hover {
109
background-color: #eee !important;
1110
color: #000 !important;
1211
}
1312

14-
1513
/* The following override styles in Bootstrap distribution file (bootstrap.min.css) */
1614

17-
.pagination>.active>a,
18-
.pagination>.active>span {
15+
.pagination > .active > a,
16+
.pagination > .active > span {
1917
background-color: #428bca !important;
2018
color: #ffffff !important;
2119
}
@@ -27,37 +25,40 @@ ul#pageNums li {
2725

2826
/* end */
2927

30-
31-
32-
.pagination>.answered>a,
33-
.pagination>.answered>span {
28+
.pagination > .answered > a,
29+
.pagination > .answered > span {
3430
background-color: #eee;
3531
color: #000;
3632
}
3733

38-
.pagination>.correctCount>a,
39-
.pagination>.correctCount>span {
34+
.pagination > .broken > a,
35+
.pagination > .broken > span {
36+
background-color: #f99;
37+
color: #000;
38+
}
39+
40+
.pagination > .correctCount > a,
41+
.pagination > .correctCount > span {
4042
background-color: #dff0d8;
4143
color: #000000;
4244
border-color: #000000;
4345
}
4446

45-
.pagination>.skippedCount>a,
46-
.pagination>.skippedCount>span {
47+
.pagination > .skippedCount > a,
48+
.pagination > .skippedCount > span {
4749
background-color: #fcf8e3;
4850
color: #000000;
4951
border-color: #000000;
5052
}
5153

52-
.pagination>.incorrectCount>a,
53-
.pagination>.incorrectCount>span {
54+
.pagination > .incorrectCount > a,
55+
.pagination > .incorrectCount > span {
5456
background-color: #f2dede;
5557
color: #000000;
5658
border-color: #000000;
5759
}
5860

59-
6061
.switchcontainer {
6162
height: 600px;
6263
overflow: auto;
63-
}
64+
}

runestone/timed/js/timed.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ export default class Timed extends RunestoneBase {
302302
this.pagNavList.addEventListener(
303303
"click",
304304
function (event) {
305+
if (
306+
this.renderedQuestionArray[this.currentQuestionIndex]
307+
.state == "broken_exam"
308+
) {
309+
$(
310+
"ul#pageNums > ul > li:eq(" +
311+
this.currentQuestionIndex +
312+
")"
313+
).addClass("broken");
314+
}
305315
if (
306316
this.renderedQuestionArray[this.currentQuestionIndex]
307317
.question.isAnswered
@@ -358,6 +368,16 @@ export default class Timed extends RunestoneBase {
358368
this.qNumList.addEventListener(
359369
"click",
360370
function (event) {
371+
if (
372+
this.renderedQuestionArray[this.currentQuestionIndex]
373+
.state == "broken_exam"
374+
) {
375+
$(
376+
"ul#pageNums > ul > li:eq(" +
377+
this.currentQuestionIndex +
378+
")"
379+
).addClass("broken");
380+
}
361381
if (
362382
this.renderedQuestionArray[this.currentQuestionIndex]
363383
.question.isAnswered
@@ -538,13 +558,21 @@ export default class Timed extends RunestoneBase {
538558
this.renderedQuestionArray[this.currentQuestionIndex] = {
539559
question: newq,
540560
};
541-
await newq.initialize();
561+
try {
562+
await newq.initialize();
563+
} catch (e) {
564+
this.renderedQuestionArray[
565+
this.currentQuestionIndex
566+
].state = "broken_exam";
567+
}
542568
} else if ($(tmpChild).is("[data-component]")) {
543569
let componentKind = $(tmpChild).data("component");
544570
this.renderedQuestionArray[this.currentQuestionIndex] = {
545571
question: window.component_factory[componentKind](opts),
546572
};
547573
}
574+
} else if (opts.state === "broken_exam") {
575+
return;
548576
}
549577

550578
currentQuestion = this.renderedQuestionArray[this.currentQuestionIndex]
@@ -562,8 +590,10 @@ export default class Timed extends RunestoneBase {
562590
}
563591
}
564592

565-
$(this.switchDiv).replaceWith(currentQuestion.containerDiv);
566-
this.switchDiv = currentQuestion.containerDiv;
593+
if (currentQuestion.containerDiv) {
594+
$(this.switchDiv).replaceWith(currentQuestion.containerDiv);
595+
this.switchDiv = currentQuestion.containerDiv;
596+
}
567597

568598
// If the timed component has listeners, those might need to be reinitialized
569599
// This flag will only be set in the elements that need it--it will be undefined in the others and thus evaluate to false

0 commit comments

Comments
 (0)