| 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 | 2×
2×
2×
2×
2×
2×
2×
1×
1×
1×
1×
2×
1×
1×
1×
5×
3×
2×
1×
1×
5×
2×
2×
2×
2×
2×
2×
2×
2×
2×
10×
2×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
2×
2×
| var EXERCISE_TAGS, ExerciseConfig, TocStore, _, actions, flux, getImportantTags, getTagName, makeSimpleStore, ref, store;
flux = require('flux-react');
_ = require('underscore');
TocStore = require('./toc').TocStore;
makeSimpleStore = require('./helpers').makeSimpleStore;
EXERCISE_TAGS = {
TEKS: 'teks',
LO: ['lo', 'aplo'],
GENERIC: ['blooms', 'dok', 'length']
};
getTagName = function(tag) {
var name;
name = _.compact([tag.name, tag.description]).join(' ');
Iif (!name) {
name = tag.id;
}
return name;
};
getImportantTags = function(tags) {
var obj;
obj = {
lo: "",
section: "",
tagString: []
};
return _.reduce(_.sortBy(tags, 'name'), function(memo, tag) {
if (_.include(EXERCISE_TAGS.GENERIC, tag.type)) {
memo.tagString.push(tag.name);
} else if (_.include(EXERCISE_TAGS.LO, tag.type)) {
memo.lo = getTagName(tag);
memo.section = tag.chapter_section;
}
return memo;
}, obj);
};
ExerciseConfig = {
_exercises: [],
FAILED: function() {
return console.error('BUG: could not load exercises');
},
reset: function() {
this._exercises = [];
return this._exerciseCache = [];
},
load: function(courseId, pageIds) {},
loaded: function(obj, courseId, pageIds) {
var _exerciseCache, key;
key = pageIds.toString();
Iif (this._exercises[key] && this._HACK_DO_NOT_RELOAD) {
return;
}
this._exercises[key] = obj.items;
_exerciseCache = [];
_.each(obj.items, function(exercise) {
return _exerciseCache[exercise.id] = exercise;
});
this._exerciseCache = _exerciseCache;
return this.emitChange();
},
HACK_DO_NOT_RELOAD: function(bool) {
return this._HACK_DO_NOT_RELOAD = bool;
},
exports: {
isLoaded: function(pageIds) {
return !!this._exercises[pageIds.toString()];
},
get: function(pageIds) {
return this._exercises[pageIds.toString()] || (function() {
throw new Error('BUG: Invalid page ids');
})();
},
getGroupedExercises: function(pageIds) {
var byChapterSection, exercises;
byChapterSection = function(exercise) {
var tag;
tag = _.find(exercise.tags, function(t) {
return _.include(EXERCISE_TAGS.LO, t.type);
});
return tag != null ? tag.chapter_section : void 0;
};
exercises = _.sortBy(this._exercises[pageIds.toString()], byChapterSection);
return _.groupBy(exercises, byChapterSection);
},
getExerciseById: function(exercise_id) {
return this._exerciseCache[exercise_id];
},
getTeksString: function(exercise_id) {
var tags, teksTags;
tags = this._exerciseCache[exercise_id].tags;
teksTags = _.where(tags, {
type: EXERCISE_TAGS.TEKS
});
return _.map(teksTags, function(tag) {
var ref;
return (ref = tag.name) != null ? ref.replace(/[()]/g, '') : void 0;
}).join(" / ");
},
getContent: function(exercise_id) {
return this._exerciseCache[exercise_id].content.questions[0].stem_html;
},
getTagContent: function(tag) {
var content, isLO;
content = getTagName(tag) || tag.id;
isLO = _.include(EXERCISE_TAGS.LO, tag.type);
return {
content: content,
isLO: isLO
};
},
getTagStrings: function(exercise_id) {
var tags;
tags = this._exerciseCache[exercise_id].tags;
return getImportantTags(tags);
},
removeTopicExercises: function(exercise_ids, topic_id) {
var cache, topic_chapter_section;
cache = this._exerciseCache;
topic_chapter_section = TocStore.getChapterSection(topic_id);
return _.reject(exercise_ids, function(exercise_id) {
var exercise, section;
exercise = cache[exercise_id];
section = getImportantTags(exercise.tags).section;
return section.toString() === topic_chapter_section.toString();
});
},
hasQuestionWithFormat: function(format, arg) {
var content, exercise;
exercise = arg.exercise, content = arg.content;
if (content == null) {
content = exercise.content;
}
return !!_.detect(content.questions, function(q) {
return _.include(q.formats, format);
});
},
getPagePoolTypes: function(pageId) {
var types;
types = _.unique(_.flatten(_.pluck(this._exercises[pageId], 'pool_types')));
return _.without(types, 'all_exercises').sort();
},
poolTypes: function(exercise) {
return _.without(exercise.pool_types, 'all_exercises');
},
allForPage: function(pageId) {
return this._exercises[pageId] || [];
}
}
};
ref = makeSimpleStore(ExerciseConfig), actions = ref.actions, store = ref.store;
module.exports = {
ExerciseActions: actions,
ExerciseStore: store
};
|