| 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 | 2×
2×
2×
2×
2×
2×
2×
2×
2×
50×
50×
50×
50×
2×
50×
50×
50×
2×
2×
2×
2×
2×
2×
1×
1×
1×
2×
1×
1×
1×
1×
50×
50×
1×
1×
1×
1×
1×
1×
2×
2×
2×
| var CrudConfig, LOADING, QUERY_START_STRING, ReferenceBookExerciseConfig, _, actions, combineQueries, extendConfig, getMultipleUrl, makeSimpleStore, ref, ref1, store;
ref = require('./helpers'), CrudConfig = ref.CrudConfig, makeSimpleStore = ref.makeSimpleStore, extendConfig = ref.extendConfig;
_ = require('underscore');
LOADING = 'loading';
QUERY_START_STRING = '?q=';
combineQueries = function(multipleUrls) {
var params, queryString, queryStrings, tags, urlsAndTags;
params = {};
tags = _.map(multipleUrls, function(url) {
var param, queryString, ref1, value;
queryString = decodeURIComponent(url.split(QUERY_START_STRING)[1]);
ref1 = queryString.split(':'), param = ref1[0], value = ref1[1];
if (params[param] == null) {
params[param] = [];
}
params[param].push(value);
Eif (param === 'tag') {
return value;
}
});
urlsAndTags = _.object(multipleUrls, tags);
queryStrings = _.map(params, function(values, paramKey) {
return paramKey + ":" + (values.join(','));
});
queryString = queryStrings.join(' ');
return {
queryString: queryString,
urlsAndTags: urlsAndTags
};
};
getMultipleUrl = function(multipleUrls, baseUrl) {
var queryString;
queryString = combineQueries(multipleUrls).queryString;
return baseUrl + "?q=" + queryString;
};
ReferenceBookExerciseConfig = {
_toSeparate: {},
loadMultiple: function(multipleUrls, baseUrl) {
var queryString, ref1, url, urlsAndTags;
ref1 = combineQueries(multipleUrls, baseUrl), queryString = ref1.queryString, urlsAndTags = ref1.urlsAndTags;
url = baseUrl + "?q=" + queryString;
return this._toSeparate[url] = urlsAndTags;
},
_loaded: function(obj, id) {
if (this._toSeparate[id] != null) {
_.each(this._toSeparate[id], (function(_this) {
return function(tag, url) {
var exercise, exerciseObj;
exercise = _.find(obj.items, function(item) {
return item.tags.indexOf(tag) > -1;
});
exerciseObj = {
items: [exercise]
};
return _this.loaded(exerciseObj, url);
};
})(this));
delete this._toSeparate[id];
this.emit('loaded.multiple');
} else {
this.emit("loaded." + id);
}
return obj;
},
exports: {
isQueued: function(id) {
return _.chain(this._toSeparate).find(function(urlsAndTags) {
return urlsAndTags[id] != null;
}).isObject().value();
},
getMultipleUrl: function(multipleUrls) {
var baseUrl, url;
baseUrl = _.first(multipleUrls).split(QUERY_START_STRING)[0];
url = getMultipleUrl(multipleUrls, baseUrl);
Eif (this._toSeparate[url] == null) {
this.loadMultiple(multipleUrls, baseUrl);
}
return url;
}
}
};
extendConfig(ReferenceBookExerciseConfig, new CrudConfig());
ref1 = makeSimpleStore(ReferenceBookExerciseConfig), actions = ref1.actions, store = ref1.store;
module.exports = {
ReferenceBookExerciseActions: actions,
ReferenceBookExerciseStore: store
};
|