зеркало из https://github.com/mozilla/CSOL-site.git
This change allows the api paginate method to pass through empty
data, and introduces a no_data block into the templates to render a message when no data is found on the badges or programs pages, instead of erroring out.
This commit is contained in:
Родитель
212789efd4
Коммит
bce2de2dd8
4
api.js
4
api.js
|
@ -141,12 +141,12 @@ function paginate(key, dataFn) {
|
|||
if (err)
|
||||
return callback(err, data);
|
||||
|
||||
if (!data[key].length)
|
||||
if (typeof data[key].length !== 'number')
|
||||
return callback(new errors.BadGateway('Unpageable data returned from upstream'), data);
|
||||
|
||||
var pages = Math.ceil(data[key].length / pageSize);
|
||||
|
||||
if (page > pages)
|
||||
if (pages > 0 && page > pages)
|
||||
return callback(new errors.NotFound('Page not found'), {
|
||||
page: page,
|
||||
pages: pages
|
||||
|
|
|
@ -503,6 +503,19 @@ test('paginate', function(t) {
|
|||
t.end();
|
||||
});
|
||||
|
||||
t.test('don\'t error out on no data', function(t) {
|
||||
var method = sinon.stub().callsArgWith(1, null, { data: [] });;
|
||||
var api = new Api(ORIGIN, {
|
||||
method: { func: method, paginate: true }
|
||||
});
|
||||
var callback = sinon.stub();
|
||||
api.method(callback);
|
||||
var args = callback.getCall(0).args;
|
||||
t.notOk(args[0], 'no error');
|
||||
t.similar(args[1], { data: [], pages: 0 }, 'data');
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('calls paginated method with query and callback', function(t) {
|
||||
var method = sinon.stub();
|
||||
var api = new Api(ORIGIN, {
|
||||
|
|
|
@ -5,3 +5,7 @@
|
|||
{{ super() }}
|
||||
<a class="btn" href="{{ item.url }}/favorite"><i class="icon-heart"></i></a>
|
||||
{% endblock %}
|
||||
|
||||
{% block no_data %}
|
||||
No badges found.
|
||||
{% endblock %}
|
|
@ -38,6 +38,7 @@
|
|||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block list_wrapper %}
|
||||
{% if items.length %}
|
||||
<ul class="thumbnails">
|
||||
{% block list %}
|
||||
{% for item in items %}
|
||||
|
@ -65,6 +66,11 @@
|
|||
{% endfor %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% block no_data %}
|
||||
No data found.
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if pages > 1 %}
|
||||
|
|
|
@ -6,3 +6,7 @@
|
|||
{{ super() }}
|
||||
<a class="btn" href="{{ item.url }}/favorite"><i class="icon-heart"></i></a>
|
||||
{% endblock %}
|
||||
|
||||
{% block no_data %}
|
||||
No programs or activities found.
|
||||
{% endblock %}
|
Загрузка…
Ссылка в новой задаче