Skip to content

Commit

Permalink
Add show more button and items per page options
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Nov 14, 2023
1 parent 2057611 commit 0f61901
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 47 additions & 1 deletion qgis-app/plugins/templates/plugins/plugin_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,54 @@ <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
{% endfor %}
</tbody>
</table>
<div class="pagination">
<div class="pagination" style="display:flex;justify-content: space-between;align-items: center;">
{% include 'sortable_listview/pagination.html' %}

<div style="margin-top:20px;">
{% if show_more_items_number <= page_obj.paginator.count %}
<button class="btn" onclick="set_per_page({{show_more_items_number}})">
{% trans "Show more" %}
</button>
{% else %}
<button class="btn" disabled>
{% trans "Show more" %}
</button>
{% endif %}
</div>
<div style="margin-top:20px;">
<span>
{% trans "Elements per page:" %}&nbsp;
</span>
<select class="form-select" id="items_per_page" style="margin:0;">
{% if paginator.per_page not in per_page_list%}
<option>{{paginator.per_page}}</option>
{% endif %}
{% for p in per_page_list %}
<option value="{{ p }}" {% if p == paginator.per_page%} selected {% endif %}>{{ p }}</option>
{% endfor %}
</select>

</div>
<script type="text/javascript">
function set_per_page(n){
if(window.location.href.search('per_page') >= 0){
new_page = window.location.href.replace(/per_page=\d+/, 'per_page=' + n);
} else {
new_page = -1 == window.location.href.search('\\?') ? window.location.href + '?' + 'per_page=' + n : window.location.href + '&' + 'per_page=' + n;
}
// Reset page
new_page = new_page.replace(/&page=\d+/, '&page=1');
new_page = new_page.replace(/\?page=\d+/, '?page=1');
window.location.href = new_page;
}

let itemsPerPageSelect = document.getElementById("items_per_page");
itemsPerPageSelect.addEventListener("change", function () {
if (itemsPerPageSelect.value) {
set_per_page(itemsPerPageSelect.value)
}
});
</script>
</div>
<div class="alert">
<button type="button" class="close" data-dismiss="alert">&times;</button>
Expand Down
2 changes: 2 additions & 0 deletions qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ def get_context_data(self, **kwargs):
context.update(self.additional_context)
context["current_sort_query"] = self.get_sortstring()
context["current_querystring"] = self.get_querystring()
context["per_page_list"] = [20, 50, 75, 100]
context["show_more_items_number"] = context["paginator"].per_page + 50
return context

def get_sortstring(self):
Expand Down

0 comments on commit 0f61901

Please sign in to comment.