зеркало из 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, {
|
||||
|
|
|
@ -4,4 +4,8 @@
|
|||
{% block item_actions %}
|
||||
{{ super() }}
|
||||
<a class="btn" href="{{ item.url }}/favorite"><i class="icon-heart"></i></a>
|
||||
{% endblock %}
|
||||
|
||||
{% block no_data %}
|
||||
No badges found.
|
||||
{% endblock %}
|
|
@ -38,33 +38,39 @@
|
|||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block list_wrapper %}
|
||||
<ul class="thumbnails">
|
||||
{% block list %}
|
||||
{% for item in items %}
|
||||
{% block item %}
|
||||
<li class="span3">
|
||||
{% if item.template %}
|
||||
{% include item.template %}
|
||||
{% else %}
|
||||
<figure class="thumbnail">
|
||||
<a href="{{ item.url }}"><img src="{{ item.image }}"></a>
|
||||
<figcaption class="caption">
|
||||
<p>{{ item.name }}</p>
|
||||
{% block item_actions_wrapper %}
|
||||
<p class="text-right">
|
||||
{% block item_actions %}
|
||||
<a href="{{ item.url }}" class="btn">Details</a>
|
||||
{% endblock %}
|
||||
</p>
|
||||
{% endblock %}
|
||||
</figcaption>
|
||||
</figure>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
{% if items.length %}
|
||||
<ul class="thumbnails">
|
||||
{% block list %}
|
||||
{% for item in items %}
|
||||
{% block item %}
|
||||
<li class="span3">
|
||||
{% if item.template %}
|
||||
{% include item.template %}
|
||||
{% else %}
|
||||
<figure class="thumbnail">
|
||||
<a href="{{ item.url }}"><img src="{{ item.image }}"></a>
|
||||
<figcaption class="caption">
|
||||
<p>{{ item.name }}</p>
|
||||
{% block item_actions_wrapper %}
|
||||
<p class="text-right">
|
||||
{% block item_actions %}
|
||||
<a href="{{ item.url }}" class="btn">Details</a>
|
||||
{% endblock %}
|
||||
</p>
|
||||
{% endblock %}
|
||||
</figcaption>
|
||||
</figure>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% block no_data %}
|
||||
No data found.
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block pagination %}
|
||||
{% if pages > 1 %}
|
||||
|
|
|
@ -5,4 +5,8 @@
|
|||
{% block item_actions %}
|
||||
{{ super() }}
|
||||
<a class="btn" href="{{ item.url }}/favorite"><i class="icon-heart"></i></a>
|
||||
{% endblock %}
|
||||
|
||||
{% block no_data %}
|
||||
No programs or activities found.
|
||||
{% endblock %}
|
Загрузка…
Ссылка в новой задаче