This repository was archived by the owner on Jun 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtimed_activecode.js
More file actions
141 lines (126 loc) · 4.35 KB
/
timed_activecode.js
File metadata and controls
141 lines (126 loc) · 4.35 KB
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
/*
The TimedActivecode classes are a great example of where multiple inheritance would be useful
But since Javascript does not support multiple inheritance we use the mixin pattern.
*/
import LiveCode from "./livecode";
import { ActiveCode } from "./activecode";
import JSActiveCode from "./activecode_js";
import HTMLActiveCode from "./activecode_html";
import SQLActiveCode from "./activecode_sql";
var TimedActiveCodeMixin = {
timedInit: async function (opts) {
this.isTimed = true;
this.renderTimedIcon(this.containerDiv);
this.hideButtons();
await this.addHistoryScrubber(true); // position last
this.needsReinitialization = true; // the run button click listener needs to be reinitialized
this.containerDiv.classList.add("timedComponent", "alert", "alert-warning");
window.edList[this.divid] = this;
return true;
},
hideButtons: function () {
var buttonList = [
this.saveButton,
this.loadButton,
this.gradeButton,
this.showHideButt,
this.coachButton,
this.atButton,
];
for (var i = 0; i < buttonList.length; i++) {
if (buttonList[i] !== undefined && buttonList[i] !== null)
$(buttonList[i]).hide();
}
},
renderTimedIcon: function (component) {
// renders the clock icon on timed components. The component parameter
// is the element that the icon should be appended to.
var timeIconDiv = document.createElement("div");
timeIconDiv.className = "timeTip";
timeIconDiv.title = "";
$(component).prepend(timeIconDiv);
},
checkCorrectTimed: function () {
// pct_correct is set by the unittest/gui.py module in skulpt.
// it relies on finding this object in the edList
if (this.isAnswered) {
if (this.pct_correct >= 100.0) {
return "T";
} else {
return "F";
}
} else {
return "I"; // we ignore this in the grading if no unittests
}
},
hideFeedback: function () {
$(this.output).css("visibility", "hidden");
},
reinitializeListeners: function (taken) {
if (!this.runButton.onclick) {
console.log("reattaching runbuttonhandler");
this.runButton.onclick = this.runButtonHander.bind(this);
}
$(this.codeDiv).show();
this.runButton.disabled = false;
$(this.codeDiv).removeClass("ac-disabled");
this.editor.refresh();
$(this.histButton).click(this.addHistoryScrubber.bind(this));
if (this.historyScrubber !== null) {
$(this.historyScrubber).slider({
max: this.history.length - 1,
value: this.history.length - 1,
slide: this.slideit.bind(this),
change: this.slideit.bind(this),
});
}
if (taken) {
$(`#${this.divid}_unit_results`).show();
}
},
};
export class TimedLiveCode extends LiveCode {
constructor(opts) {
super(opts);
this.timedInit(opts);
}
}
Object.assign(TimedLiveCode.prototype, TimedActiveCodeMixin);
export class TimedActiveCode extends ActiveCode {
constructor(opts) {
super(opts);
this.timedInitComplete = this.timedInit(opts);
}
// for timed exams we need to call runProg and tell it that there is
// no GUI for sliders or other things.
// the answers.
async checkCurrentAnswer() {
let noUI = true;
const result = await this.timedInitComplete;
if (this.isAnswered) {
await this.runProg(noUI, false);
}
}
}
Object.assign(TimedActiveCode.prototype, TimedActiveCodeMixin);
export class TimedJSActiveCode extends JSActiveCode {
constructor(opts) {
super(opts);
this.timedInit(opts);
}
}
Object.assign(TimedJSActiveCode.prototype, TimedActiveCodeMixin);
export class TimedHTMLActiveCode extends HTMLActiveCode {
constructor(opts) {
super(opts);
this.timedInit(opts);
}
}
Object.assign(TimedHTMLActiveCode.prototype, TimedActiveCodeMixin);
export class TimedSQLActiveCode extends SQLActiveCode {
constructor(opts) {
super(opts);
this.timedInit(opts);
}
}
Object.assign(TimedSQLActiveCode.prototype, TimedActiveCodeMixin);