-
Notifications
You must be signed in to change notification settings - Fork 481
/
show.js
117 lines (109 loc) · 3.71 KB
/
show.js
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
import $ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router, Route} from 'react-router-dom';
import {Provider} from 'react-redux';
import {getStore, registerReducers} from '@cdo/apps/redux';
import manageStudents, {
setLoginType,
setStudents,
convertStudentServerData,
setShowSharingColumn
} from '@cdo/apps/templates/manageStudents/manageStudentsRedux';
import teacherSections, {
setSections,
selectSection,
setRosterProvider
} from '@cdo/apps/templates/teacherDashboard/teacherSectionsRedux';
import sectionData, {setSection} from '@cdo/apps/redux/sectionDataRedux';
import stats, {
asyncSetCompletedLevelCount
} from '@cdo/apps/templates/teacherDashboard/statsRedux';
import textResponses, {
asyncLoadTextResponses
} from '@cdo/apps/templates/textResponses/textResponsesRedux';
import sectionAssessments, {
asyncLoadAssessments
} from '@cdo/apps/templates/sectionAssessments/sectionAssessmentsRedux';
import sectionProgress from '@cdo/apps/templates/sectionProgress/sectionProgressRedux';
import scriptSelection, {
loadValidScripts
} from '@cdo/apps/redux/scriptSelectionRedux';
import TeacherDashboard from '@cdo/apps/templates/teacherDashboard/TeacherDashboard';
const script = document.querySelector('script[data-dashboard]');
const scriptData = JSON.parse(script.dataset.dashboard);
const section = scriptData.section;
const allSections = scriptData.allSections;
const baseUrl = `/teacher_dashboard/sections/${section.id}`;
$(document).ready(function() {
registerReducers({
teacherSections,
sectionData,
manageStudents,
sectionProgress,
scriptSelection,
stats,
textResponses,
sectionAssessments
});
const store = getStore();
// TODO: (madelynkasula) remove duplication in sectionData.setSection and teacherSections.setSections
store.dispatch(setSection(section));
store.dispatch(setSections(allSections));
store.dispatch(selectSection(section.id));
store.dispatch(setRosterProvider(section.login_type));
store.dispatch(setLoginType(section.login_type));
store.dispatch(asyncSetCompletedLevelCount(section.id));
// Show share column by default for CSD and CSP courses,
// or any script in either course.
const courseFamiliesToShowShareColumn = ['csd', 'csp'];
if (
courseFamiliesToShowShareColumn.includes(section.script.course_family_name)
) {
store.dispatch(setShowSharingColumn(true));
}
$.ajax({
method: 'GET',
url: `/dashboardapi/sections/${section.id}/students`,
dataType: 'json'
}).done(studentData => {
const convertedStudentData = convertStudentServerData(
studentData,
section.login_type,
section.id
);
store.dispatch(setStudents(convertedStudentData));
});
$.ajax({
method: 'GET',
url: '/dashboardapi/sections/valid_scripts',
dataType: 'json'
}).done(validScripts => {
store.dispatch(loadValidScripts(section, validScripts)).then(() => {
const scriptId = store.getState().scriptSelection.scriptId;
store.dispatch(asyncLoadTextResponses(section.id, scriptId));
store.dispatch(asyncLoadAssessments(section.id, scriptId));
renderTeacherDashboard();
});
});
const renderTeacherDashboard = () => {
ReactDOM.render(
<Provider store={store}>
<Router basename={baseUrl}>
<Route
path="/"
component={props => (
<TeacherDashboard
{...props}
studioUrlPrefix={scriptData.studioUrlPrefix}
pegasusUrlPrefix={scriptData.pegasusUrlPrefix}
sectionName={section.name}
/>
)}
/>
</Router>
</Provider>,
document.getElementById('teacher-dashboard')
);
};
});