Skip to content

Commit

Permalink
add user setting for pagination (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Feb 13, 2025
1 parent a32f538 commit 2b15603
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 16 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Added
- ``UserRetrieveAPIView`` REST API view (#1555)
- ``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)
- ``project_list_highlight`` and ``project_list_pagination`` app settings (#1005)

Changed
-------
Expand Down
4 changes: 0 additions & 4 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,6 @@ 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: 0 additions & 1 deletion config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
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
13 changes: 13 additions & 0 deletions projectroles/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
APP_SETTING_SCOPE_PROJECT_USER: {'project': True, 'user': True},
APP_SETTING_SCOPE_SITE: {'project': False, 'user': False},
}
# TODO: Add label for -1 once validation is fixed (see #1564, #1565)
PROJECT_LIST_PAGE_OPTIONS = [10, 25, 50, 100, -1]
DELETE_SCOPE_ERR_MSG = 'Argument "{arg}" must be set for {scope} scope setting'
GLOBAL_PROJECT_ERR_MSG = (
'Overriding global settings for remote projects not allowed'
Expand Down Expand Up @@ -154,6 +156,17 @@
user_modifiable=True,
global_edit=True,
),
PluginAppSettingDef(
name='project_list_pagination',
scope=APP_SETTING_SCOPE_USER,
type=APP_SETTING_TYPE_INTEGER,
default=10,
label='Project list page size',
description='Amount of projects per page in the project list.',
options=PROJECT_LIST_PAGE_OPTIONS,
user_modifiable=True,
global_edit=True,
),
]


Expand Down
13 changes: 12 additions & 1 deletion projectroles/static/projectroles/js/project_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,18 @@ $(document).ready(function () {
'#sodar-pr-project-list').find('table').DataTable();
var value = parseInt($(this).val());
dt.page.len(value).draw();
// TODO: Update user setting here
// Update user setting
$.ajax({
url: 'project/api/settings/set/user',
method: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
'plugin_name': 'projectroles',
'setting_name': 'project_list_pagination',
'value': value
})
})
});

if (projectUuids.length > 0) {
Expand Down
4 changes: 1 addition & 3 deletions projectroles/templates/projectroles/_project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ <h4>
</button>
</div>
{% endif %}
{# TODO: Get user setting instead #}
{% get_django_setting 'PROJECTROLES_PROJECT_LIST_PAGINATION' 10 as list_pagination %}
<select class="form-control sodar-pr-project-list-page-length">
<option selected value="{{ list_pagination }}">Page</option>
<option selected value="{{ page_options_default }}">Page</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
Expand Down
2 changes: 1 addition & 1 deletion projectroles/templates/projectroles/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 class="sodar-pr-content-title pt-2">Home</h2>
{{ block.super }}
<!-- Variables -->
<script type="text/javascript">
window.projectListPagination = {% get_django_setting 'PROJECTROLES_PROJECT_LIST_PAGINATION' 10 %};
window.projectListPagination = {{ page_options_default }};
</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>
Expand Down
2 changes: 1 addition & 1 deletion projectroles/templates/projectroles/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h4>
{{ block.super }}
<!-- Variables -->
<script type="text/javascript">
window.projectListPagination = {% get_django_setting 'PROJECTROLES_PROJECT_LIST_PAGINATION' 10 %};
window.projectListPagination = {{ page_options_default }};
window.remoteLinkUrl = "{% url 'projectroles:ajax_remote_access' project=object.sodar_uuid %}";
</script>
{% if object.type == 'CATEGORY' %}
Expand Down
16 changes: 13 additions & 3 deletions projectroles/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
REMOTE_LEVEL_REVOKED = SODAR_CONSTANTS['REMOTE_LEVEL_REVOKED']

# Local constants
APP_NAME = 'projectroles'
PROJECT_LINK_IDS = [
'sodar-pr-link-project-roles',
'sodar-pr-link-project-update',
Expand Down Expand Up @@ -873,16 +874,25 @@ def test_project_list_paginate_disabled(self):
elem = self.selenium.find_element(By.CLASS_NAME, 'dataTables_paginate')
self.assertEqual(elem.is_displayed(), False)

@override_settings(PROJECTROLES_PROJECT_LIST_PAGINATION=1)
def test_project_list_paginate_enabled(self):
"""Test project list pagination with pagination enabled"""
# Create additional categories to fill first page
for i in range(1, 10):
c = self.make_project(
f'Additional Category {i}', PROJECT_TYPE_CATEGORY, None
)
self.make_assignment(c, self.user_owner, self.role_owner)
self.login_and_redirect(self.user_owner, self.url, **self.wait_kwargs)
elem = self.selenium.find_element(By.CLASS_NAME, 'dataTables_paginate')
self.assertEqual(elem.is_displayed(), True)

@override_settings(PROJECTROLES_PROJECT_LIST_PAGINATION=1)
def test_project_list_paginate_update(self):
"""Test project list pagination updating on second page"""
for i in range(1, 10):
c = self.make_project(
f'Additional Category {i}', PROJECT_TYPE_CATEGORY, None
)
self.make_assignment(c, self.user_owner, self.role_owner)
self.login_and_redirect(self.user_owner, self.url, **self.wait_kwargs)
self._wait_for_async_requests()
# Only category should be visible
Expand Down Expand Up @@ -914,7 +924,7 @@ def test_project_list_paginate_update(self):
)
self.assertEqual(col.get_attribute('innerHTML'), 'Owner')

# TODO: Test pagination controls and settings once implemented
# TODO: Test pagination controls and settings

def test_link_create_toplevel(self):
"""Test project creation link visibility"""
Expand Down
8 changes: 8 additions & 0 deletions projectroles/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@
user_modifiable=True,
global_edit=False,
),
PluginAppSettingDef(
name='project_list_pagination',
scope=APP_SETTING_SCOPE_USER,
type=APP_SETTING_TYPE_INTEGER,
default=10,
user_modifiable=True,
global_edit=True,
),
]

EX_PROJECT_UI_SETTINGS = [
Expand Down
3 changes: 3 additions & 0 deletions projectroles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ def get_context_data(self, *args, **kwargs):
context['project_col_count'] = base_col_count + len(
context['project_custom_cols']
)
context['page_options_default'] = app_settings.get(
APP_NAME, 'project_list_pagination', user=self.request.user
)
return context


Expand Down

0 comments on commit 2b15603

Please sign in to comment.