| 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168 | 2×
2×
2×
2×
2×
| var TaskTeacherReviewStore, _, camelCase;
_ = require('underscore');
camelCase = require('camelcase');
TaskTeacherReviewStore = require('../../flux/task-teacher-review').TaskTeacherReviewStore;
module.exports = {
_pages: ['current_pages', 'spaced_pages'],
_setChapterSectionOnQuestions: function(page) {
var chapter_section, title;
chapter_section = page.chapter_section;
title = page.title;
return _.each(page.exercises, function(exercise) {
exercise.chapter_section = chapter_section;
exercise.title = title;
return _.each(exercise.content.questions, function(question) {
return question.chapter_section = chapter_section;
});
});
},
_getStatsForPeriod: function(review, period) {
if ((period != null ? period.id : void 0) == null) {
return _.first(review.stats);
}
return _.findWhere(review.stats, {
period_id: period.id
});
},
_getExercisesFromStats: function(stats) {
var pagedExercises;
pagedExercises = _.map(this._pages, (function(_this) {
return function(page) {
var exercises;
exercises = _.chain(stats[page]).clone().each(_this._setChapterSectionOnQuestions).pluck('exercises').flatten(true).compact().value();
exercises["for"] = page;
return exercises;
};
})(this));
return _.flatten(pagedExercises, true);
},
_makeCrumb: function(data) {
var crumb;
crumb = {
data: data,
type: 'step',
listeners: this._getStepListeners('exercise')
};
if (data.length) {
crumb.sectionLabel = this._buildSectionLabel(data[0].chapter_section);
_.each(crumb.data, function(data) {
return data.sectionLabel = crumb.sectionLabel;
});
} else {
crumb.sectionLabel = this._buildSectionLabel(data.chapter_section);
crumb.data.sectionLabel = crumb.sectionLabel;
}
return crumb;
},
_indexCrumb: function(crumb, index) {
crumb.key = index;
crumb.crumb = this._shouldStepCrumb(index);
if (crumb.data.length) {
return _.each(crumb.data, function(data) {
return data.key = crumb.key;
});
} else {
return crumb.data.key = crumb.key;
}
},
_getCrumbsForHomework: function(stats) {
var crumbs, exercises;
exercises = this._getExercisesFromStats(stats);
return crumbs = _.chain(exercises).map(this._makeCrumb).each(this._indexCrumb).value();
},
_getCrumbsForReading: function(stats) {
var crumbs, exercises;
exercises = this._getExercisesFromStats(stats);
crumbs = _.chain(exercises).groupBy('chapter_section').map(this._makeCrumb).each(this._indexCrumb).value();
return crumbs;
},
_getCrumbsForExternal: function() {
return [];
},
_getContentsForHomework: function(crumbs) {
var contents;
return contents = _.pluck(crumbs, 'data');
},
_getContentsForReading: function(crumbs) {
return _.chain(crumbs).pluck('data').map(function(data) {
var content, key, ref, sectionLabel, title;
content = _.clone(data);
ref = data[0], title = ref.title, key = ref.key, sectionLabel = ref.sectionLabel;
content.unshift({
sectionLabel: sectionLabel,
title: title,
key: key
});
return content;
}).flatten(true).value();
},
_getContentsForExternal: function() {
return [];
},
_shouldStepCrumb: function() {
return true;
},
_getStepListeners: function(stepType) {
var listeners;
listeners = {
placeholder: 3
};
return listeners[stepType] || 1;
},
_buildSectionLabel: function(chapter_section) {
var sectionLabel;
if (chapter_section != null) {
return sectionLabel = typeof this.sectionFormat === "function" ? this.sectionFormat(chapter_section, this.props.sectionSeparator) : void 0;
}
},
_generateCrumbsFromStats: function(stats, type) {
var crumbs, getCrumbs;
getCrumbs = camelCase("get-crumbs-for-" + type);
return crumbs = this["_" + getCrumbs](stats);
},
_generateCrumbs: function(id, period) {
var crumbs, review, stats;
review = TaskTeacherReviewStore.get(id);
stats = this._getStatsForPeriod(review, period);
return crumbs = this._generateCrumbsFromStats(stats, review.type);
},
generateCrumbs: function() {
var id, period, periodCrumbs, ref;
ref = this.props, id = ref.id, period = ref.period;
periodCrumbs = this._generateCrumbs(id, period);
return _.sortBy(periodCrumbs, function(crumb) {
return crumb.data.average_step_number;
});
},
getContents: function() {
var allCrumbs, contents, getContents, id, period, ref, review;
ref = this.props, id = ref.id, period = ref.period;
review = TaskTeacherReviewStore.get(id);
allCrumbs = this.generateCrumbs();
getContents = camelCase("get-contents-for-" + review.type);
return contents = this["_" + getContents](allCrumbs);
},
getCrumableCrumbs: function() {
var allCrumbs, crumbableCrumbs;
allCrumbs = this.generateCrumbs();
return crumbableCrumbs = _.where(allCrumbs, {
crumb: true
});
},
getMaxListeners: function() {
var crumbs, listeners;
crumbs = this.generateCrumbs();
return listeners = _.reduce(crumbs, function(memo, crumb) {
return memo + crumb.listeners;
}, 0);
},
getDefaultCurrentStep: function() {
return 0;
}
};
|