Skip to content

Commit

Permalink
add pagination django setting and pagination hiding (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Feb 11, 2025
1 parent d38d1af commit 5994c5a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Added
- ``active`` arg in ``ProjectInviteMixin.make_invite()`` (#1403)
- Ability for users to leave project (#918)
- ``project_list_highlight`` app setting (#1005)
- ``PROJECTROLES_PROJECT_LIST_PAGINATION`` Django setting (#1005)

Changed
-------
Expand Down
4 changes: 4 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ def set_logging(level=None):
# PROJECTROLES_BREADCRUMB_STICKY = True
# Custom message to be displayed if site read-only mode is enabled
PROJECTROLES_READ_ONLY_MSG = env.str('PROJECTROLES_READ_ONLY_MSG', None)
# Default project list pagination page size
PROJECTROLES_PROJECT_LIST_PAGINATION = env.int(
'PROJECTROLES_PROJECT_LIST_PAGINATION', 10
)

# Hide project apps from the UI (sidebar, dropdown menus and project details)
PROJECTROLES_HIDE_PROJECT_APPS = env.list(
Expand Down
1 change: 1 addition & 0 deletions config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
PROJECTROLES_CUSTOM_JS_INCLUDES = []
PROJECTROLES_CUSTOM_CSS_INCLUDES = []
PROJECTROLES_SIDEBAR_ICON_SIZE = 36
PROJECTROLES_PROJECT_LIST_PAGINATION = 10

# Bgjobs app settings
BGJOBS_PAGINATION = 15
Expand Down
11 changes: 9 additions & 2 deletions projectroles/static/projectroles/js/project_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ $(document).ready(function () {
$.fn.dataTable.ext.classes.sPageButton =
'btn sodar-list-btn ml-1 sodar-paginate-button btn-outline-light ' +
'text-primary';
$('#sodar-pr-project-list-table').DataTable({
var dt = $('#sodar-pr-project-list-table').DataTable({
ordering: false,
scrollX: false,
paging: true,
pageLength: 10,
pageLength: window.projectListPagination,
lengthChange: true,
scrollCollapse: true,
info: false,
Expand All @@ -328,6 +328,12 @@ $(document).ready(function () {
},
dom: 'tp'
});
// Hide pagination if only one page
if (dt.page.info().pages === 1) {
// TODO: Disable pagination control once implemented
$('.dataTables_paginate').hide();
}
// Add star filter
$.fn.dataTable.ext.search.push(
function(settings, data, dataIndex, rowObj, counter) {
var api = new $.fn.dataTable.Api('#sodar-pr-project-list-table');
Expand All @@ -337,6 +343,7 @@ $(document).ready(function () {
return $(api.row(dataIndex).node()).data('starred');
} else return true;
});

if (projectUuids.length > 0) {
// Update custom columns
updateCustomColumns(projectUuids);
Expand Down
4 changes: 4 additions & 0 deletions projectroles/templates/projectroles/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ <h2 class="sodar-pr-content-title pt-2">Home</h2>

{% block javascript %}
{{ block.super }}
<!-- Variables -->
<script type="text/javascript">
window.projectListPagination = {% get_django_setting 'PROJECTROLES_PROJECT_LIST_PAGINATION' 10 %};
</script>
<!-- DataTables -->
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.11.3/b-2.0.1/datatables.min.js"></script>
<!-- Project list -->
Expand Down
2 changes: 2 additions & 0 deletions projectroles/templates/projectroles/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ <h4>

{% block javascript %}
{{ block.super }}
<!-- Variables -->
<script type="text/javascript">
window.projectListPagination = {% get_django_setting 'PROJECTROLES_PROJECT_LIST_PAGINATION' 10 %};
window.remoteLinkUrl = "{% url 'projectroles:ajax_remote_access' project=object.sodar_uuid %}";
</script>
{% if object.type == 'CATEGORY' %}
Expand Down
1 change: 1 addition & 0 deletions projectroles/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ def test_project_list_role_col_category_inherit(self):
self.assertEqual(col.get_attribute('innerHTML'), 'N/A')

# TODO: Test paginated list
# TODO: Test lack of pagination with less projects than setting
# TODO: Test custom columns retrieval on paginated list
# TODO: Test role column retrieval on paginated list
# TODO: Test pagination controls and settings once implemented
Expand Down

0 comments on commit 5994c5a

Please sign in to comment.