forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteacher.js
More file actions
121 lines (106 loc) · 3.23 KB
/
teacher.js
File metadata and controls
121 lines (106 loc) · 3.23 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
import $ from 'jquery';
import debounce from 'lodash/debounce';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { getStore } from './redux';
import clientState from './clientState';
import ScriptTeacherPanel from './components/progress/ScriptTeacherPanel';
import { setSections, fullyLockedStageMapping } from './stageLockRedux';
import commonMsg from '@cdo/locale';
function resizeScrollable() {
var newHeight = $('.teacher-panel').innerHeight() -
$('.teacher-panel h3').outerHeight() -
15 - // magic..
$('.non-scrollable-wrapper').outerHeight();
$('.scrollable-wrapper').css('max-height', newHeight);
}
export function onReady() {
$(window).resize(debounce(resizeScrollable, 250));
resizeScrollable();
var submittedTimestamp = $('#submitted .timestamp');
submittedTimestamp.text((new Date(submittedTimestamp.text())).toLocaleString());
$('select#sections').change(function (ev) {
window.location.href = ev.target.value;
});
$('#unsubmit').click(function (ev) {
$.ajax({
url: $(ev.target).attr('data-user-level-url'),
method: 'PUT',
user_level: {
best_result: 1,
submitted: false
}
}).done(data => {
// Let's just refresh so that the dots are correct, etc.
location.reload();
}).fail(err => console.error(err));
});
$("#clear-response").click(ev => {
$.ajax({
url: $(ev.target).attr('data-user-level-url'),
method: 'DELETE'
}).done(data => {
// Refresh, so that we no longer have the students response loaded
location.reload();
}).fail(err => console.error(err));
});
setStageLockedText();
}
/**
* Query the server for lock status of this teacher's students
* @returns {Promise} when finished
*/
function queryLockStatus(store, scriptId) {
return new Promise((resolve, reject) => {
$.ajax(
'/api/lock_status',
{
data: {
user_id: clientState.queryParams('user_id'),
script_id: scriptId
}
}
).done(data => {
store.dispatch(setSections(data));
resolve();
});
});
}
/**
* Render our teacher panel that shows up on our course overview page.
*/
export function renderTeacherPanel(store, scriptId) {
const div = document.createElement('div');
div.setAttribute('id', 'teacher-panel-container');
queryLockStatus(store, scriptId);
ReactDOM.render(
<Provider store={store}>
<ScriptTeacherPanel/>
</Provider>,
div
);
document.body.appendChild(div);
}
/**
* On puzzle page, update text in teacher panel (which is not a React component)
* stating whether this stage is locked for all students or not.
*/
function setStageLockedText() {
const element = $('#stage-locked-text');
if (element.length === 0) {
return;
}
const store = getStore();
const scriptId = store.getState().progress.stages[0].script_id;
queryLockStatus(store, scriptId).then(() => {
const state = store.getState();
const { currentStageId } = state.progress;
const fullyLocked = fullyLockedStageMapping(state.stageLock);
if (fullyLocked[currentStageId]) {
element.text(commonMsg.stageLocked());
} else {
element.text(commonMsg.stageNotFullyLocked());
}
});
}