зеркало из https://github.com/mozilla/CSOL-site.git
Merge pull request #519 from mozilla/505-fix-explore-filters
Implement filtering.
This commit is contained in:
Коммит
e849180bd6
2
api.js
2
api.js
|
@ -273,5 +273,3 @@ module.exports = function Api(origin, globalFilters, config) {
|
|||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ module.exports = function (app) {
|
|||
|
||||
app.get('/explore', badger.middleware('getPrograms'), function (req, res, next) {
|
||||
var data = req.remote;
|
||||
|
||||
res.render('programs/list.html', {
|
||||
filters: getFilters(req.query, ['categories', 'orgs', 'ageRanges', 'activityTypes']),
|
||||
items: data.programs,
|
||||
|
|
|
@ -169,23 +169,6 @@ function filterBadges (data, query) {
|
|||
return data;
|
||||
}
|
||||
|
||||
function filterPrograms (data, query) {
|
||||
var category = confirmFilterValue(query.category, categories),
|
||||
org = confirmFilterValue(query.org, orgs),
|
||||
ageGroup = confirmFilterValue(query.age, ageRanges),
|
||||
activityType = confirmFilterValue(query.activity, activityTypes);
|
||||
|
||||
if (!category && !org && !ageGroup && !activityType)
|
||||
return data;
|
||||
|
||||
return applyFilter(data, {
|
||||
'categories': category,
|
||||
'issuer.shortname': org,
|
||||
'ageRange': ageGroup,
|
||||
'activityType': activityType
|
||||
});
|
||||
}
|
||||
|
||||
function getJWTToken(email) {
|
||||
var claims = {
|
||||
prn: email,
|
||||
|
@ -234,7 +217,13 @@ var openbadger = new Api(ENDPOINT, {
|
|||
|
||||
getPrograms: {
|
||||
func: function getPrograms (query, callback) {
|
||||
this.get('/programs', function(err, data) {
|
||||
var qs = {
|
||||
category: query.category,
|
||||
org: query.org,
|
||||
age: query.age,
|
||||
activity: query.activity,
|
||||
};
|
||||
this.get('/programs', {qs: qs}, function(err, data) {
|
||||
if (err)
|
||||
return callback(err, data);
|
||||
|
||||
|
@ -243,7 +232,6 @@ var openbadger = new Api(ENDPOINT, {
|
|||
});
|
||||
});
|
||||
},
|
||||
filters: filterPrograms,
|
||||
paginate: true,
|
||||
key: 'programs'
|
||||
},
|
||||
|
|
|
@ -211,10 +211,11 @@ test('getProgram', function(t) {
|
|||
});
|
||||
|
||||
test('getPrograms', function(t) {
|
||||
const CALLBACK_INDEX = 2;
|
||||
|
||||
t.test('on error', function(t) {
|
||||
var getStub = mock.expects('get');
|
||||
getStub.callsArgWith(1, 500, 'error of some sort');
|
||||
getStub.callsArgWith(CALLBACK_INDEX, 500, 'error of some sort');
|
||||
openbadger.getPrograms(DEFAULT_QUERY, function(err, data) {
|
||||
t.same(err, 500, 'error');
|
||||
t.similar(data, 'error of some sort', 'data');
|
||||
|
@ -224,7 +225,7 @@ test('getPrograms', function(t) {
|
|||
|
||||
t.test('with data', function(t) {
|
||||
var getStub = mock.expects('get');
|
||||
getStub.callsArgWith(1, null, DATA['programs']);
|
||||
getStub.callsArgWith(CALLBACK_INDEX, null, DATA['programs']);
|
||||
openbadger.getPrograms(DEFAULT_QUERY, function(err, data) {
|
||||
t.notOk(err, 'no error');
|
||||
t.same(data.programs.length, 3, 'data length');
|
||||
|
@ -237,7 +238,7 @@ test('getPrograms', function(t) {
|
|||
|
||||
t.test('paginates', function(t) {
|
||||
var getStub = mock.expects('get');
|
||||
getStub.callsArgWith(1, null, DATA['programs']);
|
||||
getStub.callsArgWith(CALLBACK_INDEX, null, DATA['programs']);
|
||||
openbadger.getPrograms({ pageSize: 2, page: 1 }, function(err, data) {
|
||||
t.notOk(err, 'no error');
|
||||
t.same(data.programs.length, 2, 'paginated');
|
||||
|
|
Загрузка…
Ссылка в новой задаче